Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load GPU trained model on CPU #13

Open
nihit97natu opened this issue Sep 22, 2020 · 2 comments
Open

Unable to load GPU trained model on CPU #13

nihit97natu opened this issue Sep 22, 2020 · 2 comments

Comments

@nihit97natu
Copy link

I trained this model on google colab on a GPU. I am trying to load the model on my local machine(CPU) using load_model() but unable to load it. I am unable to to use pytorch.save() function too to save the model. It gives some error unable to pickle threads.
How can I solve this?

@nihit97natu nihit97natu changed the title Unable to load GPU trained model to CPU Unable to load GPU trained model on CPU Sep 22, 2020
@metalrt
Copy link

metalrt commented Jan 26, 2021

Hi @nihit97natu,

I have the same problem. Can you find any solution for this? Thanks

@LiudmylaN
Copy link

LiudmylaN commented May 30, 2022

class CPU_Unpickler(pickle.Unpickler):
    def find_class(self, module, name):
        if module == 'torch.storage' and name == '_load_from_bytes':
            return lambda b: torch.load(io.BytesIO(b), map_location='cpu')
        else:
            return super().find_class(module, name)

with open(pathname + '/model.pkl', 'rb') as fp:
        model = CPU_Unpickler(fp).load()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants