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

When convert a ml using backend of pytorch, how can I save the converted model into pytorch format? #641

Open
GoHard2023 opened this issue Oct 18, 2022 · 6 comments

Comments

@GoHard2023
Copy link

As titled. Is there a way I can save a converted model as pytorch format?

@interesaaat
Copy link
Collaborator

You can find the tests here showing how to do it with the different backends

@GoHard2023
Copy link
Author

You can find the tests here showing how to do it with the different backends

Thank you for replying! I walked over the test cases. I did not find the test code to save converted model as pytorch format. Maybe I was not clear enough. I want to the saved model can be loaded by some pytorch code.

Thanks.

@interesaaat
Copy link
Collaborator

When you save a model we create a zip file containing a bunch of metadata and the model in the pytorch format (if you chose that as backend).

If you want just to save and load the pytorch model you can just do hb_model.model.save(path) and torch.load(path). (the model attribute is a pytorch model). Doing this way however you will lose the Hummingbird metadata so you will have to convert the input data yourself, for example.

@GoHard2023
Copy link
Author

GoHard2023 commented Oct 18, 2022

When you save a model we create a zip file containing a bunch of metadata and the model in the pytorch format (if you chose that as backend).

If you want just to save and load the pytorch model you can just do hb_model.model.save(path) and torch.load(path). (the model attribute is a pytorch model). Doing this way however you will lose the Hummingbird metadata so you will have to convert the input data yourself, for example.

Thanks for the tip! hb_model.model.save(path) does not work out for me. I used torch.save(hb_model.model.state_dict()) to save the model as pytorch match I guess,

@GoHard2023
Copy link
Author

By the way, is there a way that I can select only probability when converting random forest to pytorch in hummingbird?

@interesaaat
Copy link
Collaborator

interesaaat commented Oct 19, 2022 via email

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

2 participants