Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while loading fine-tuned simpletransformer model in Docker Container

I am saving and loading a model using torch.save() and torch.load() commands.

While loading a fine-tuned simple transformer model in Docker Container, I am facing this error which I am not able to resolve:

 Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 594, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 853, in _load
    result = unpickler.load()
  File "/usr/local/lib/python3.7/dist-packages/transformers/models/xlm_roberta/tokenization_xlm_roberta.py", line 161, in __setstate__
    self.sp_model.Load(self.vocab_file)
  File "/usr/local/lib/python3.7/dist-packages/sentencepiece.py", line 367, in Load
    return self.LoadFromFile(model_file)
  File "/usr/local/lib/python3.7/dist-packages/sentencepiece.py", line 177, in LoadFromFile
    return _sentencepiece.SentencePieceProcessor_LoadFromFile(self, arg)
OSError: Not found: "/home/jupyter/.cache/huggingface/transformers/9df9ae4442348b73950203b63d1b8ed2d18eba68921872aee0c3a9d05b9673c6.00628a9eeb8baf4080d44a0abe9fe8057893de20c7cb6e6423cddbf452f7d4d8": No such file or directory Error #2

If anyone has any idea about it, please let me know.

I am using:

  • torch ==1.7.1+cu101
  • sentence-transformers 0.3.9
  • simpletransformers 0.51.15
  • transformers 4.4.2
  • tensorflow 2.2.0
like image 423
SK Singh Avatar asked Apr 02 '21 12:04

SK Singh


1 Answers

I suggest using state_dict objects - the Python dictionaries as they can be easily saved, updated and restored giving you a flexibility for restoring the model later. Here are the recommended Save/Load methods for saving models with state_dict:

Save

torch.save(model.state_dict(), PATH)

Load

model = TheModelClass(*args, **kwargs)
model.load_state_dict(torch.load(PATH))
model.eval()
like image 74
Kate Orlova Avatar answered Oct 19 '22 18:10

Kate Orlova