Question
I have trained a model and save it to folder my_model and downloaded the folder . I went to the next tutorial and uploaded my_model folder and load it again with FAMReader , and i can't load it . It said "AttributeError: 'PosixPath' object has no attribute 'tell' "
Hey @doanthienthuan ,
Thanks for reporting. We will have a look at this. Can you please share the exact code you used for loading plus the full error message?
@tholor
11/15/2020 23:47:01 - INFO - farm.utils - device: cuda n_gpu: 1, distributed training: False, automatic mixed precision training: None
11/15/2020 23:47:02 - WARNING - farm.modeling.prediction_head - Some unused parameters are passed to the QuestionAnsweringHead. Might not be a problem. Params: {"training": true, "num_labels": 2, "ph_output_type": "per_token_squad", "model_type": "span_classification", "label_tensor_name": "question_answering_label_ids", "label_list": ["start_token", "end_token"], "metric": "squad", "name": "QuestionAnsweringHead"}
Traceback (most recent call last):
File "server.py", line 32, in
reader = FARMReader(model_name_or_path="model", use_gpu=True)
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/site-packages/haystack/reader/farm.py", line 94, in __init__
self.inferencer = QAInferencer.load(model_name_or_path, batch_size=batch_size, gpu=use_gpu,
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/site-packages/farm/infer.py", line 243, in load
model = BaseAdaptiveModel.load(load_dir=model_name_or_path, device=device, strict=strict)
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/site-packages/farm/modeling/adaptive_model.py", line 53, in load
model = cls.subclasses["AdaptiveModel"].load(**kwargs)
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/site-packages/farm/modeling/adaptive_model.py", line 340, in load
head = PredictionHead.load(config_file, strict=strict)
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/site-packages/farm/modeling/prediction_head.py", line 126, in load
prediction_head.load_state_dict(torch.load(model_file, map_location=torch.device("cpu")), strict=strict)
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/site-packages/torch/serialization.py", line 586, in load
with _open_zipfile_reader(f) as opened_zipfile:
File "/home/doanthienthuan/.virtualenvs/plaidml/lib/python3.8/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'
Code :

And my model folder:

It could be due to mismatched python or python modules versions on system where you trained model and system where you are loading module.
Refer this https://forums.fast.ai/t/a2-voila-posixpath-attribute-tell-error/76358/2 as error seems related.
https://discuss.pytorch.org/t/error-when-loading-model-trained-with-python3-7-pytorch-0-4-1-using-python2-7-pytorch-0-4-1/30931/9
I鈥檝e managed to fix the issue. The issue was cause by incorrect versions of different modules.
If you are running your web app on Google Colab and then testing it locally with Voila and get errors,
you need to check that the versions of the modules/Python match locally and in Google Colab.
At the time I鈥檓 running this, Google Colab is using Python version 3.6.9, Pytorch version 1.6.0, and Torchvision 0.7.0.
Did this solve your issue @doanthienthuan ?
it's will work with python 3.6.9 , torch =1.16 and torchvision =0.8.1 . Thanks