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

TabularModel.load_model issue: Trained GPU model and loading CPU-only machine #531

Open
arcturus9725 opened this issue Jan 7, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@arcturus9725
Copy link

Hello,
I am trying to load model and predict in CPU only machine,
which is trained with GPU machine.

I tried following code:
tabular_model = TabularModel.load_model("md_tmp2", map_location=torch.device('cpu'))

But error comes out:
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Please let me know how to deal with this.

Desktop:

  • OS: Windows
  • Version
  • pytorch_tabular 1.1.1
  • torch 2.5.1+cu124(GPU Machine), torch 2.5.1(CPU Only machine)
Copy link

dosubot bot commented Jan 7, 2025

Hey @arcturus9725! 👋 I'm here to help you with your code issues and questions. Let's squash those bugs together!

To resolve the issue of loading a model trained on a GPU machine and predicting on a CPU-only machine, you should ensure that the map_location argument is correctly set to 'cpu' when using TabularModel.load_model. Here's how you can do it:

from pytorch_tabular import TabularModel

# Load the model with map_location set to 'cpu'
tabular_model = TabularModel.load_model("md_tmp2", map_location='cpu')

By setting map_location='cpu', the model will be loaded onto the CPU, which should prevent the error you're encountering [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@dosubot dosubot bot added the bug Something isn't working label Jan 7, 2025
@arcturus9725
Copy link
Author

arcturus9725 commented Jan 7, 2025

Hello, I tried your code but same error came out.

from pytorch_tabular import TabularModel

tabular_model = TabularModel.load_model("md_tmp2", map_location='cpu')

RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=torch.device('cpu') to map your storages to the CPU.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant