ModuleNotFoundError: No module named 'fastai.utils'

I am running a Jupyter notebook on Paperspace Gradient.
I’ve run many of the notebooks from the Practical Deep Learning for coders and all seems fine there. I guess the fastai library is already loaded in the environment that I chose with Gradient.
I just pulled the notebooks from the NLP course that Rachael taught and tried to run one of those but got an error early on. the line that generated the error is an import of utils.mem

from fastai.utils.mem import GPUMemTrace #call with mtrace
I suspect this has to do with the version of the fastai library.
version 2 is on the machine I am using and maybe the course used version 1.
Any suggestions on what I can do here?

Hey @jhmuller have you checked out this? Major new changes and features. They talk about what you can do to fix the problem there. In case you are having issues with the new fastbook as well, please use git pull to update your notebooks.

I hope that helps.

What helped me was changing ‘pip install fastai’ (not fastai2!) to ‘pip install fastai --upgrade’, restarting the runtime and running everything again

1 Like

So how does one go about fixing this? I’m receiving the same error, I can of course run utils from torch but it would be useful to know how utils should now be imported for the new fastai2 library.

The linked Major new changes and features, doesn’t clearly say how to go about fixing this @radikubwa unless there was an edit that is no longer there. So how would one go about fixing this now?

This thread is the top post on google for anyone trying to resolve this issue. I’m using 2.1.7 installed using conda.

Hey @than3
I think this was related to installing fastai. I thought that some problems would be solved by looking at the link above. However, the docs are great resource to refer to if you are having trouble. See here. Also, exporting your conda environment removing could help me or someone else in the forum to help you further. How to export environment

Thanks @radikubwa, I’ve reviewed the docs and links and unfortunately I still have the same issue when I rebuild my docker image. There doesn’t appear to be anything standing out other than the fact that module appears to be missing.

Doing a search of the github it appears utils.py is missing from fastai, it may have been split into a separate project with fastai2 but there’s no documentation about where it may have been moved to (at least from what I’ve seen). I didn’t see an equivalent module (1:1 move) so I’ve opened an issue on the github for clarification.

I had posted in another thread seeking help for getting a local and repeatable container up and running so I could follow along with the course (fastbook) without many issues that have plagued me with the online services. That post is here if your interested.

The conda env export is here.
My most recent dockerfile is here.
The scripts copied as part of the build are from the github from the article mentioned in the other thread (the medium post about repeatable environments).

So you’re trying to find utils? That’s a part of the fastbook package, not fastai I believe if we’re talking about the same one

Otherwise if this is the utils from fastai version 1.x, that’s not a part of it anymore to my knowledge, I’d have to go digging to see where that is in v2 (if it is)

@muellerzr Yes, I’ve been trying to find the utils package originally from fastai version 1.x.

There is still documentation in a number of places including the troubleshooting section which only references fastai 1.x imports without a corresponding fastai 2.x alternative. A few functions like the previously mentioned utils.mem.gpumemtrace, collect_env, and I’m sure there are others I’ve only worked with the library briefly so not too sure how much the other functions were used.

In that case, that only lives in fastai up to v 1.0.61. fastai currently doesn’t have utility functions like that to my knowledge

1 Like

do you have an update for fastai.utils.mem, I am moving a project from 1.0.54 to 2.0.0 for later move to 2.4