Learn.save() location of models

Should learn.save() be saving the models in the default fastai config folder for models?

'model_path': '~/.fastai/models'

Datasets are being downloaded as expected to the ~/.fastai/data folder, but the models don’t appear to be doing so when I do learn.save(). I looked through the library code for Learner, and I couldn’t find where this read from the Config class (but I might be missing something). Just wanted to see if that was the expectation when doing learn.save() and learn.load().

They get stored within your {path}/models folder with extension ‘.pth’. These are kind of hidden.
ls *.pth
inside your local dir.
Models are saved using Pytorch’s default serialization method.

1 Like

Actually, (at least in 1.0.15.dev0) learn.save by default saves in a local “models” directory…
Which is better than a global directory, as very soon we can’t keep up as to what saved model belongs to what notebook…

Ya. That’s correct. Local directory only.

If still unsure, use this find . -type f -name '*.pth

1 Like

Do check this topic to see how to modify it.

just answered this in a different thread in more detail:

1 Like

Same here:

1 Like

What’s the rationale for fastai library putting the models folder within the datasets?

I’m re-running my week one notebook and my preprocessing for the input data (which is a bunch of pictures within labeled folders) is now also hilariously running through the models folder, and changing their names to models_01.png (which is what my little preprocessing cell was doing).

It feels like we will always have to be careful to blacklist the models folder within our datasets. Am I thinking about this incorrectly?

You can use an absolute pathlib.Path object to put them wherever you like :slight_smile:


can you elaborate it