Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from torch.testing._internal.common_utils import TestCase, IS_WINDOWS, \
TEST_DILL, run_tests, download_file, BytesIOContext
from torch.testing._internal.common_device_type import instantiate_device_type_tests

# These tests were all copied from `test/test_torch.py` at some point, so see
# the actual blame, see this revision
Expand Down Expand Up @@ -583,10 +584,10 @@ def wrapper(*args, **kwargs):
def __exit__(self, *args, **kwargs):
torch.save = self.torch_save

class TestBothSerialization(TestCase, SerializationMixin):
class TestBothSerialization(TestCase):
@unittest.skipIf(IS_WINDOWS, "NamedTemporaryFile on windows")
def test_serialization_new_format_old_format_compat(self):
x = [torch.ones(200, 200) for i in range(30)]
def test_serialization_new_format_old_format_compat(self, device):
x = [torch.ones(200, 200, device=device) for i in range(30)]

def test(filename):
torch.save(x, filename, _use_new_zipfile_serialization=True)
Expand Down Expand Up @@ -747,6 +748,7 @@ def run(self, *args, **kwargs):
with serialization_method(use_zip=True):
return super(TestSerialization, self).run(*args, **kwargs)

instantiate_device_type_tests(TestBothSerialization, globals())

if __name__ == '__main__':
run_tests()
6 changes: 3 additions & 3 deletions torch/csrc/generic/StorageMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ static PyObject * THPStorage_(fromFile)(PyObject *_unused, PyObject *args, PyObj
PyObject * THPStorage_(writeFile)(THPStorage *self, PyObject *args)
{
HANDLE_TH_ERRORS
PyObject *file = PyTuple_GET_ITEM(args, 0);
bool is_real_file = PyTuple_GET_ITEM(args, 1) == Py_True;
bool save_size = PyTuple_GET_ITEM(args, 2) == Py_True;
PyObject *file = PyTuple_GetItem(args, 0);
bool is_real_file = PyTuple_GetItem(args, 1) == Py_True;
bool save_size = PyTuple_GetItem(args, 2) == Py_True;

if (!is_real_file) {
THPStorage_(writeFileRaw<PyObject*>)(self->cdata, file, save_size);
Expand Down
2 changes: 1 addition & 1 deletion torch/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def persistent_id(obj):
else:
# Copy to a buffer, then serialize that
buf = io.BytesIO()
storage._write_file(buf, _should_read_directly(buf))
storage._write_file(buf, _should_read_directly(buf), False)
buf_value = buf.getvalue()
zip_file.write_record(name, buf_value, len(buf_value))

Expand Down