TextLearner learn.save() saving learner as a zip file instead of Torchscript Archive

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

~/.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))

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?

The library does not save it as torchscript (it never did? It’s always the raw weights). It’s whatever torch’s torch.save functionality is. The newest version uses zips instead of pickle.



In that case what does the error I put in my post actually refer to then? My .pth files on disk are now zip, whereas before they were octet-stream. Perhaps this is a red-herring, but should the new zip format prevent me from loading a saved Textlearner on a different machine? Based on the error log I pasted why would the library be displaying: AttributeError: 'PosixPath' object has no attribute 'tell'.