question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

please add option to load fine-tuned file to CPU if trained on GPU

See original GitHub issue

I fine-tuned the pytorch_model.bin on a GPU machine (google cloud) but need to use it on my home computer (no GPU). When I tried to open it using model = BertForMaskedLM.from_pretrained(bert_version) I got the following error:

 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='cpu'
 to map your storages to the CPU.

Perhaps you can add an option into from_pretrained() such as cpu=True which will then call

torch.load(weights_path, map_location=lambda storage, location: 'cpu')

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
CBvanYperencommented, Aug 5, 2020

Would love some explanation on how to do this as well!

0reactions
iliaNecrovcommented, May 13, 2022

same

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fine-tune a pretrained model - Hugging Face
This is known as fine-tuning, an incredibly powerful training technique. In this tutorial, you will fine-tune a pretrained model with a deep learning...
Read more >
Saving and loading models across devices in PyTorch
When loading a model on a CPU that was trained with a GPU, pass torch.device('cpu') to the map_location argument in the torch.load() function....
Read more >
Inference and train with existing models and standard datasets
It is usually used for finetuning. Training on CPU. The process of training on the CPU is consistent with single GPU training. We...
Read more >
Fine-Tune a Pretrained Deep Learning Model - Esri
If you are unfamiliar with the process of setting up a deep learning ... You can also create training data to fine-tune the...
Read more >
NeMo ASR Configuration Files - NVIDIA Documentation Center
Any initialization parameter that is accepted for the Dataset class used in the experiment can be set in the config file. Refer to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found