-
Notifications
You must be signed in to change notification settings - Fork 432
Model Exporting (.pt2) #2732
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
Comments
I really like this in general. I am marginally concerned about this though: ![]() If this is something Wherobots needs, I'm inclined to move forward with it. However, if the main motivation is to get around security issues with pickling, note that torch.hub.load_state_dict_from_url has the following option which gets around some (but not all) security issues:
|
This is mainly needed for our production environments. Note that I can simply create a script that loops through all torchgeo pretrained models and exports them to .pt2 format. We don't need to replace the .pt files in HuggingFace only support an additional option -- I can take on this work of managing them in HuggingFace. |
Ditto what Isaac said! Some additional reasons .pt2 is really helpful for us and others cataloguing models and using them for inference:
On the breaking changes callout, I expect the spec and APIs for torch.export to evolve, partly with feedback from users like us and TorchGeo. But I think we could adapt our internal use and implementation of torch.export without user facing changes in TorchGeo. |
Alright, I would say let's move forward with it. We can still rehost all weights on TorchGeo's HF. Note that we've been trying to follow the following naming convention and I would like to keep this:
|
I spoke with Angela Yi from the Pytorch team in the Pytorch slack about improving support for storing nn.Module transforms from kornia in the same .pt2 archive as the model. This would allow for loading models and inference-only transforms (or any kind of transforms) together as a single callable. Would make it easier to immediately use the model without figuring out how to run the correct transforms. She said she'll look into this and that it seems like a generally useful feature for Pytorch. cc @isaaccorley For now I talked with Isaac who is working on making the .pt2 archives and we can skip storing transforms in .pt2, then add them back when/if that feature becomes available upstream. |
Summary
It's common in production environments to export a torch model to a file which can be loaded without the need for the model code (only need the checkpoint). We should consider storing our weights in HuggingFace with additional versions which are exported to .pt2 archive format. If I understand correctly, this gets around the security issue with pickling, and is also capable of storing metadata like transforms and other hyperparameters within the .pt2 archive.
A common example of this is:
Then the model can be loaded with only torch as a dependency (no model code or dependencies needed!) like so:
CC @rbavery @ljstrnadiii @jiayuasu @calebrob6 @adamjstewart
The text was updated successfully, but these errors were encountered: