How to saved trained model in cloud notebook and load it in windows?

Hello. I’m looking at the server setup at:

I’m trying to train a language model on one of the possible servers, save it, download it to my PC, and make inference on my PC.

It doesn’t work well. I’ve tried kaggle, azure, gradient, colab, and I have problems at all of them.

I’ve also looked at this forum post:

But the answer there just says that bugs where fixed and I can’t solve this in the proposed method.

This is my tries:

learn = language_model_learner(wiki_data, AWD_LSTM, drop_mult=0.3)
learn.fit_one_cycle(1, 1e-1, moms=(0.8,0.7))

Saving the data‘data_lm’)

Now the tries for saving & loading after reading the docs:
and this tutorial:


Then on my PC:

data_lm_loaded = load_data(path, ‘data_lm.pkl’)
learn_try_1 = load_learner(path, ‘lm.pkl’)
learn_try_2 = language_model_learner(data_lm_loaded, AWD_LSTM, drop_mult=0.3)

I’ve also tried save_encoder & load_encoder.

For the first try:

learn_try_1 = load_learner(path, ‘lm.pkl’)

when I do


I get the following error:

Exception: This is an empty Learner and Learner.summary requires some data to pass through the model.

For the second try:

learn_try_2 = language_model_learner(data_lm_loaded, AWD_LSTM, drop_mult=0.3)

I receive the following error on my PC while trying to load the model (Loading in the Gradient server works fine):

NotImplementedError: cannot instantiate ‘PosixPath’ on your system

This error occured on Colab as well.

In the kaggle I had problems with bad fastai version.

I’m trying to solve it for long time now.
What am I missing?

I’m willing to take any solution as well as other paid services, but till now I’ve tried 4 servers and couldn’t figure it out so I think that i’m doing something with the code.

Hey, using export worked for me at the time (after bug fixes in v1.0.46):

## on server (after training)

## on local PC (for inference)
lm = load_learner(path, 'lm.pkl')
learner.predict("Some string to predict the next word ")

Can you try this and tell us what you’re getting?

The error you got when using save might be related to you trying to use a Posix path on a windows machine.

1 Like

Hey, yes, in the same Linux machine it works, but when I try to transfer to windows it doesn’t because of the Posix path.

So my question is, assuming I have Windows PC with no gpu, how can I train a model on machine with GPU and use it on my Windows PC.

In Keras for example, it’s possible to save in linux and load in windows.

Is there any such solution with fastai ?

Thanks :slight_smile:

Updating the packages:
!curl -s | bash

Has solved this problem, and it now works with export & load_learner.
I still didn’t solve it from Posix -> Windows, so I’ll work with Posix -> Posix for the predictions part.



for the poxis path error

when you train your model on colab / gradient and download it
then do inference on windows

Just redirect PosixPath to WindowsPath.

import pathlib
temp = pathlib.PosixPath
pathlib.PosixPath = pathlib.WindowsPath

Thx @D_SM.
your solution is working !

Colab for training and export model.
on Windows10 (VS Code) with Streamlit inference