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

Saving Transformers model as binary instead of safetensors format? #28863

Closed
StatsGary opened this issue Feb 5, 2024 · 2 comments
Closed

Saving Transformers model as binary instead of safetensors format? #28863

StatsGary opened this issue Feb 5, 2024 · 2 comments

Comments

@StatsGary
Copy link

I am trying to Torchserve (https://pytorch.org/serve/) a Transformers model to be deployed as a prediction API on GCP as a custom prediction service.

However, torchserve requires that the model be in either .bin format or .pt format. Is there a way to deactivate safetensors and return the .bin PyTorch file?

I have tried to use torch.save(model.state_dict(), PATH) but have been unsuccessful thus far? Anyone encountered similar issues?

@StatsGary
Copy link
Author

➡️💡 SOLUTION ➡️💡

I dig some digging of the parameters of the save_pretrained and trainer methods and you can actually 🔧 turn off the storing of the safetensors format models, by using the following example:

model.save_pretrained(<PATH_TO_SAVE_MODEL>, safe_serialization=False) #Replace path

@Narsil
Copy link
Contributor

Narsil commented Feb 6, 2024

Could luck trying to secure your servers from malicious actors ! :)

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