I have a very simple scenario. I have 1 custom class (not a NN model) I am pickling with torch.save
. When I try to load it it fails with error:
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
exec(exp, global_vars, local_vars)
File "<input>", line 1, in <module>
File "/Users/brando/anaconda3/envs/metalearning/lib/python3.8/site-packages/torch/serialization.py", line 594, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "/Users/brando/anaconda3/envs/metalearning/lib/python3.8/site-packages/torch/serialization.py", line 853, in _load
result = unpickler.load()
AttributeError: Can't get attribute 'DagDataPreparation' on <module '__main__' from '/Users/brando/ML4Coq/ml4coq-proj/data_lib/dag/dag_dataloader.py'>
but the class is basically empty (though it's in a different file DagDataPreparation
:
class DagDataPreparation:
def __init__(self, root):
print('1')
def create_everything(self):
return 1
if I use dill
as an argument for torch.load and torch.save it works. It also works if I simply import the class at the top of the file
from data_lib.dag.dataset_preparation import DagDataPreparation
I understand why the error might be happening, it can't find the definition of the class...but this is really weird because I am 200% I've done this type of thing (saving/loading arbitrary classes with torch) and I've never had this issue before.
What might be the issue? Does everyone else do experience the same bug in my scenario if you have two files one that loads the pickle file and it throws that error at you?