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

if i have saved a pytorch_based model, i want to run inference on cpu, how to change the codes? #739

Closed
Bobby-youngking opened this issue Oct 31, 2023 · 5 comments

Comments

@Bobby-youngking
Copy link

from sklearn import datasets
from sklearn.ensemble import RandomForestClassifier
from hummingbird.ml import convert, load
iris = datasets.load_iris()
X, y = iris.data, iris.target
rfmodel = load('hb_model')
rfmodel.to('cpu')
print(rfmodel.predict(X))

i tried this way, but the result showed that i was running on gpu

@interesaaat
Copy link
Collaborator

Hi! Just change rfmodel.to('cpu') to rfmodel = rfmodel.to('cpu'). This should work.

@mshr-h
Copy link
Collaborator

mshr-h commented Nov 1, 2023

I think we have to update the readme.

https://github.com/microsoft/hummingbird#examples

# Use Hummingbird to convert the model to PyTorch
model = convert(skl_model, 'pytorch')

# Run predictions on CPU
model.predict(X)

# Run predictions on GPU
model.to('cuda')
model.predict(X)

@ksaur
Copy link
Collaborator

ksaur commented Nov 1, 2023

Was this an API change in a newer version of torch? Because the README example definitely works, or used to!

@ksaur
Copy link
Collaborator

ksaur commented Nov 1, 2023

I was not able to reproduce this issue with the latest (torch==2.1.0), and the example in the documentation still worked as written for me.

@Bobby-youngking can you please post which versions you are using and a bit more info? you shouldn't have to reassign the model

@ksaur
Copy link
Collaborator

ksaur commented Nov 6, 2023

Closing due to inactivity and we cannot repro, please reopen if you still have problems with this.

@ksaur ksaur closed this as completed Nov 6, 2023
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

4 participants