self.assertFalse(m2.p0.is_cuda)
self.assertFalse(m2.b0.is_cuda)
- def test_model_save_error(self):
- with TemporaryFileName() as fname:
- with self.assertRaisesRegex(pickle.PickleError, "not supported"):
- torch.save(FooToPickle(), fname)
-
@unittest.skipIf(not RUN_CUDA, "restore device requires CUDA")
def test_restore_device_cuda(self):
class MyModule(torch.jit.ScriptModule):
"""
return self.module_rref
+ @torch.jit.export
def __getstate__(self):
raise RuntimeError(
"Cannot pickle RemoteModule in python pickler. RemoteModule can only be pickled when using RPC"
)
+ @torch.jit.export
def __setstate__(self, state):
raise RuntimeError(
"Cannot unpickle RemoteModule in python pickler. RemoteModule can only be unpickled when using RPC"
# It's fairly trivial to save enough info to warn in this case.
return super(RecursiveScriptModule, self).__setattr__(attr, value)
- def __getstate__(self):
- raise pickle.PickleError(
- "ScriptModules cannot be deepcopied using copy.deepcopy or saved using torch.save. "
- + "Mixed serialization of script and non-script modules is not supported. "
- + "For purely script modules use my_script_module.save(<filename>) instead."
- )
-
def __copy__(self):
return torch.jit._recursive.wrap_cpp_module(copy.copy(self._c))
#!/usr/bin/python3
import enum
-import pickle
from typing import Tuple
import torch
dst_worker_name, modes=[ModuleCreationMode.MODULE_CTOR_WITH_INTERFACE]
):
with TemporaryFileName() as fname:
- with self.assertRaises(pickle.PickleError):
+ with self.assertRaisesRegex(torch.jit.Error, "can only be pickled when using RPC"):
torch.save(remote_module, fname)