mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-11 22:34:53 +08:00
Fix misuse of offset param in seek (#140633)
Fixes #115630. The size of BufferAdapter has been calculated wrongly due to misuse of python method seek. Causes miniz reader initialized with wrong size. Pull Request resolved: https://github.com/pytorch/pytorch/pull/140633 Approved by: https://github.com/ezyang Co-authored-by: Edward Z. Yang <ezyang@fb.com>
This commit is contained in:
@ -4394,6 +4394,15 @@ class TestSerialization(TestCase, SerializationMixin):
|
||||
with zipfile.ZipFile(f) as zip_file:
|
||||
zip_file.extractall(path=temp_dir)
|
||||
|
||||
def test_serialization_with_header(self):
|
||||
orig = torch.randn(3, 3)
|
||||
with BytesIOContext() as f:
|
||||
f.write(b'header')
|
||||
torch.save(orig, f)
|
||||
f.seek(6)
|
||||
loaded = torch.load(f)
|
||||
self.assertEqual(orig, loaded)
|
||||
|
||||
def test_get_unsafe_globals_in_checkpoint(self):
|
||||
t = torch.randn(2, 3)
|
||||
tt = TwoTensor(t, t)
|
||||
|
||||
@ -1514,7 +1514,7 @@ void initJITBindings(PyObject* module) {
|
||||
// Jump to the end of the buffer to get its size
|
||||
auto current = buffer.attr("tell")();
|
||||
start_offset_ = py::cast<size_t>(current);
|
||||
buffer.attr("seek")(current, py::module::import("os").attr("SEEK_END"));
|
||||
buffer.attr("seek")(0, py::module::import("os").attr("SEEK_END"));
|
||||
size_ = py::cast<size_t>(buffer.attr("tell")()) - start_offset_;
|
||||
buffer.attr("seek")(current);
|
||||
// If we can read directly into a buffer, do that instead of an extra copy
|
||||
|
||||
Reference in New Issue
Block a user