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.

Moving trained model between devices

See original GitHub issue

Hello! Is there a way to move the trained SetFit model to another device? E.g. I train a model on a GPU, and after initializing the model on a CPU-only machine I get 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.

I have managed to fix the error by running:

model.model_body = model.model_body.to("cpu")
model.model_head = model.model_head.to("cpu")

However, I guess it depends on the type of the head (in case of the Logistic regression head there is no need to move it).

If there is no single method to move a model between devices, shall I open a PR?

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
JackMurphy97commented, Dec 11, 2022

I have also come across this exact issue - it would be awesome to have some .to(device) functionality for the SetFitModel class!

1reaction
blakechicommented, Dec 2, 2022

Thank you for your detailed explanation! I guess the error raised because of the initialization method of SetFitHead. Will validate my guess shortly.

Thanks again for raising this up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Does it Take to Train Deep Learning Models On-Device?
The key thing to realize is that there are two different stages to training a model. The first is building the back-propagation machinery...
Read more >
On-Device Training with TensorFlow Lite
Setup · Classify images of clothing · Build a model for on-device training · Prepare the data · Train the model · Convert...
Read more >
Training on the device - Machine, Think!
To be fair, you often don't need to train a model from scratch. Most people take a pre-trained model and then use transfer...
Read more >
How to Distribute Deep Learning Model Training?
This post details why you need to distribute the model training, different distribution strategies, and how they work. Finally, how to apply ...
Read more >
Training and deploying ML models on edge devices (TF Fall ...
Learn how to train and deploy an ML model on an Android app in just a few lines of code with TensorFlow Lite...
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