When saving a TextLearner after training, as in Notebook 10 on a different corpus, it seems the library should save a Torchscript Archive. I’m noticing a weird error where the archive is saves as a zip
file instead.
Notice Line 588 in the following error log:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-57b9612d5d30> in <module>
----> 1 learn.load('dls_cls')
~/.local/lib/python3.6/site-packages/fastai2/learner.py in load(self, file, with_opt, device, **kwargs)
271 if self.opt is None: self.create_opt()
272 file = join_path_file(file, self.path/self.model_dir, ext='.pth')
--> 273 load_model(file, self.model, self.opt, device=device, **kwargs)
274 return self
275
~/.local/lib/python3.6/site-packages/fastai2/learner.py in load_model(file, model, opt, with_opt, device, strict)
49 if isinstance(device, int): device = torch.device('cuda', device)
50 elif device is None: device = 'cpu'
---> 51 state = torch.load(file, map_location=device)
52 hasopt = set(state)=={'model', 'opt'}
53 model_state = state['model'] if hasopt else state
~/.local/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
584 with _open_file_like(f, 'rb') as opened_file:
585 if _is_zipfile(opened_file):
--> 586 with _open_zipfile_reader(f) as opened_zipfile:
587 if _is_torchscript_zip(opened_zipfile):
588 warnings.warn("'torch.load' received a zip file that looks like a TorchScript archive"
~/.local/lib/python3.6/site-packages/torch/serialization.py in __init__(self, name_or_buffer)
244 class _open_zipfile_reader(_opener):
245 def __init__(self, name_or_buffer):
--> 246 super(_open_zipfile_reader, self).__init__(torch._C.PyTorchFileReader(name_or_buffer))
247
248
AttributeError: 'PosixPath' object has no attribute 'tell'
When I actually view the file type of saved learner using file -i dls_cls
it treats the learner as a Zip file:
application/zip; charset=binary
instead of the expected:
application/octet-stream; charset=binary
.
I say “expected” because all other learners I have saved with “learn.save()” use application/octet-stream; charset=binary
but for no apparent reason, some learners are saved as zip files.
I’m training on an AWS GPU server, and despite the “zip” application type the learner loads the saved TextLearner. However on other machines, or servers it gives the above error.
Any ideas on how this can be fixed?