Skip to content
Closed
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
6 changes: 4 additions & 2 deletions batchflow/models/torch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,8 +1747,10 @@ def save(self, path, use_onnx=False, path_onnx=None, use_openvino=False, path_op
path, pickle_module=pickle_module, **kwargs)

else:
torch.save({item: getattr(self, item) for item in self.PRESERVE},
path, pickle_module=pickle_module, **kwargs)
attributes = {item: getattr(self, item) for item in self.PRESERVE if item != "optimizer"}
optimizer = getattr(self, "optimizer")
attributes["optimizer"] = optimizer.state_dict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But how do we load the optimizer from that state if we need to? In the current implementation we dump Optimizer instance and can deserialize it to use.

torch.save(attributes, path, pickle_module=pickle_module, **kwargs)

def load(self, file, make_infrastructure=False, mode='eval', pickle_module=dill, **kwargs):
""" Load a torch model from a file.
Expand Down
Loading