-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't save a model with torch.save
if model has a torch.Device
attr
#7545
Comments
Let's say your model is The recommended way to save a model is |
torch.save
if model has a torch.Device
as parameter
torch.save
if model has a torch.Device
as parametertorch.save
if model has a torch.Device
attr
Here is a minimal example demonstrating the problem.
|
The real problem is that how to make |
We can add getstate and setstate attributes |
thanks you, solve this problem @zou3519 |
Fixed in #7713 |
I still encounter similar problems. How do you solve them |
If you have a question or would like help and support, please ask at our
forums.
If you are submitting a feature request, please preface the title with [feature request].
If you are submitting a bug report, please fill in the following details.
Issue description
File "/home/wangqianlong/MODELS/sentence_express_model/src/sst_main.py", line 393, in main train(train_data_set, test_data_set, parameters) File "/home/wangqianlong/MODELS/sentence_express_model/src/sst_main.py", line 283, in train save_model(model, epoch, loss, e_acc, parameters.model_dir) File "/home/wangqianlong/MODELS/sentence_express_model/src/utils.py", line 109, in save_model torch.save(model, fp) File "/home/wangqianlong/.local/lib/python3.6/site-packages/torch/serialization.py", line 161, in save return _with_file_like(f, "wb", lambda f: _save(obj, f, pickle_module, pickle_protocol)) File "/home/wangqianlong/.local/lib/python3.6/site-packages/torch/serialization.py", line 118, in _with_file_like return body(f) File "/home/wangqianlong/.local/lib/python3.6/site-packages/torch/serialization.py", line 161, in <lambda> return _with_file_like(f, "wb", lambda f: _save(obj, f, pickle_module, pickle_protocol)) File "/home/wangqianlong/.local/lib/python3.6/site-packages/torch/serialization.py", line 232, in _save pickler.dump(obj) TypeError: can't pickle torch.Device objects class RaceModel(nn.Module): def __init__(self, parameter): super(RaceModel, self).__init__() self.cuda_device = parameter.device self.A = Model(parameter) self.B = Model(parameter)
model = RaceModel(parameters).to(parameters.device)
Provide a short description.
Code example
Please try to provide a minimal example to repro the bug.
Error messages and stack traces are also helpful.
System Info
Please copy and paste the output from our
environment collection script
(or fill out the checklist below manually).
You can get the script and run it with:
The text was updated successfully, but these errors were encountered: