I have been training and exporting several versions of a model on colab. My export code has always been this:
model.export('model.pkl')
I have been able to reload the model and make predictions to confirm everything works, like this:
x = load_learner('', 'model.pkl')
x.predict()
All of a sudden, the export code is behaving differently. I am still able to export and load_learner with not problem on colab, but when I download the model file from colab to my local machine and try to run locally, I get this error:
Traceback (most recent call last):
File "process.py", line 127, in <module>
predict_utterances_in_transcript(i, path_to_processed_and_predicted_transcript_dir, audio_id)
File "process.py", line 94, in predict_utterances_in_transcript
predict()
File "/Users/src/predict.py", line 9, in predict_utterances
model = load_learner('', 'models/model.pkl')
File "/Users//anaconda3/envs/nlp/lib/python3.6/site-packages/fastai/basic_train.py", line 621, in load_learner
state = torch.load(source, map_location='cpu') if defaults.device == torch.device('cpu') else torch.load(source)
File "/Users//anaconda3/envs/nlp/lib/python3.6/site-packages/torch/serialization.py", line 586, in load
with _open_zipfile_reader(f) as opened_zipfile:
File "/Users//anaconda3/envs/nlp/lib/python3.6/site-packages/torch/serialization.py", line 246, in __init__
super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
AttributeError: 'PosixPath' object has no attribute 'tell'
Also, I have been able to open and read model pickle files in a text editor just fine until now. The broken model files cannot be read because an error says they are corrupted.
Nothing has changed in my code or my environment. Any ideas?
I had the exact same problem. Moving from torch 1.5 to torch 1.6 solved it for me. After that, the downloaded pkl file worked like a charm. After installation, in a python console, import torch and check the torch version. It should return: '1.6.0'
Best regards, Stéph