Attribute Error when loading my model on huggingface/gradio

Hi all,

I am trying to recreate the first part of lesson 10 in fast books by creating a Language Model, but I am using the yelp reviews dataset.

It seems to be working when I tests it out on kaggle however when I save the ‘finetuned.pth’ model and upload it to huggingface I get an error saying:

Traceback (most recent call last):
  File "/home/user/app/app.py", line 3, in <module>
    learn = load_learner('finetuned.pth')
  File "/usr/local/lib/python3.10/site-packages/fastai/learner.py", line 451, in load_learner
    res.dls.cpu()
AttributeError: 'collections.OrderedDict' object has no attribute 'dls'
Traceback (most recent call last):
  File "/home/user/app/app.py", line 3, in <module>
    learn = load_learner('finetuned.pth')
  File "/usr/local/lib/python3.10/site-packages/fastai/learner.py", line 451, in load_learner
    res.dls.cpu()
AttributeError: 'collections.OrderedDict' object has no attribute 'dls'

Have I loaded the model incorrectly?

Thanks in advance

I seem to have solved but dont understand why! Had some modules that werent needed in the requirements file. deleted them and app started to work. :grin:

Hey I am wondering if load_learner is compatible with huggingface spaces. I am receiving the error: UserWarning: load_learner uses Python’s insecure pickle module, which can execute malicious arbitrary code when loading. Only load files you trust.
If you only need to load model weights and optimizer state, use the safe Learner.load instead.
warn("load_learner uses Python's insecure pickle module, which can execute malicious arbitrary code when loading.

Are we not able to use load_learner when deploying to huggingface spaces now?