Attribute Error reported when loading training_args.bin

I got attribute error when loading the trianing_args.bin using:

training_args = torch.load("model_path/training_args.bin")

Error report:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 607, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 882, in _load
    result = unpickler.load()
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 875, in find_class
    return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'OurTrainingArguments' on <module '__main__' (built-in)>
>>> training_args = torch.load("result/my-sup-simcse-roberta-base/training_args.bin")Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 607, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 882, in _load
    result = unpickler.load()
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 875, in find_class
    return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'OurTrainingArguments' on <module '__main__' (built-in)>
>>> torch.load("result/my-sup-simcse-roberta-base")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 594, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 230, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 211, in __init__
    super(_open_file, self).__init__(open(name, mode))
IsADirectoryError: [Errno 21] Is a directory: 'result/my-sup-simcse-roberta-base'
>>> training_args = torch.load("result/my-sup-simcse-roberta-base/training_args.bin")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 607, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 882, in _load
    result = unpickler.load()
  File "/home/cxsun/anaconda3/envs/SimCSE/lib/python3.8/site-packages/torch/serialization.py", line 875, in find_class
    return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'OurTrainingArguments' on <module '__main__' (built-in)>

Anyone can help?

It looks like you are using a subclass of TrainingArguments, and that this subclass is not defined in the script you’re trying to run.