Repository: pytorch
Issue: `torch.load()` cannot load data saved at non-zero position in a file (`failed finding central directory`)
Labels: module: serialization,triaged

### 🐛 Describe the bug

The data saved by `torch.save()` at position in a file other than the beginning cannot be loaded by `torch.load()`.

```
Python 3.10.7 (main, Oct 11 2022, 21:51:23) [Clang 14.0.0 (clang-1400.0.29.102)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import io, torch
>>> torch.__version__
'1.13.0'
>>> with open('test.bin', 'wb') as out:
...     out.write(b'header')
...     pos = out.tell()
...     torch.save(b'data', out)
...
6
>>> with open('test.bin', 'rb') as inp:
...     inp.seek(pos)
...     data = torch.load(inp)
...
6
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/Users/azawlocki/.pyenv/versions/torch-13/lib/python3.10/site-packages/torch/serialization.py", line 777, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/Users/azawlocki/.pyenv/versions/torch-13/lib/python3.10/site-packages/torch/serialization.py", line 282, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory
```
The same happens when using a `BytesIO` buffer instead of a file:
``` # ... continuing
>>> bio = io.BytesIO()
>>> bio.write(b'header')
6
>>> pos = bio.tell()
>>> torch.save(b'data', bio)
>>>
>>> bio.seek(pos)
6
>>> torch.load(bio)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/azawlocki/.pyenv/versions/torch-13/lib/python3.10/site-packages/torch/serialization.py", line 777, in load
    with _open_zipfile_reader(opened_file) as opened_zipfile:
  File "/Users/azawlocki/.pyenv/versions/torch-13/lib/python3.10/site-packages/torch/serialization.py", line 282, in __init__
    super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
RuntimeError: PytorchStreamReader failed reading zip archive: failed finding central directory
```
But:
```
>>> torch.load(io.BytesIO(bio.getvalue()[pos:]))
b'data' 
```

I think the errors are due to a bug in this code:

https://github.com/pytorch/pytorch/blob/7c98e70d44abc7a1aead68b6ea6c8adc8c554db5/torch/csrc/jit/python/init.cpp#L1709-L1714

Line 1712 should be
```
buffer.attr("seek")(0, py::module::import("os").attr("SEEK_END"));
```
the current code sets file position not at the end of file but `current` bytes before.


### Versions

```
Collecting environment information...
PyTorch version: 1.13.0
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 12.6 (arm64)
GCC version: Could not collect
Clang version: 14.0.0 (clang-1400.0.29.102)
CMake version: Could not collect
Libc version: N/A

Python version: 3.10.7 (main, Oct 11 2022, 21:51:23) [Clang 14.0.0 (clang-1400.0.29.102)] (64-bit runtime)
Python platform: macOS-12.6-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] torch==1.13.0
[conda] Could not collect
```

cc @mruberry