Skip to content

Conversation

@hedgeho
Copy link
Contributor

@hedgeho hedgeho commented Mar 14, 2025

What does this PR do?

This PR removes unnecessary imports of torch from model load/save code to enable lightweight installation (without torch) as described here in docs.

It achieves this mainly by replacing calls to safetensors.torch.[save|load]_file() with safetensors.numpy.[save|load]_file(), and removing other calls to torch methods.

Fixes #2304

Before submitting

  • This PR fixes a typo or improves the docs (if yes, ignore all other checks!).
  • Did you read the contributor guideline?
  • Was this discussed/approved via a Github issue? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes (if applicable)?
  • Did you write any new necessary tests?

@hedgeho
Copy link
Contributor Author

hedgeho commented Mar 14, 2025

Should work now. Tested saving&loading locally with environment without torch.

Tested also loading of a model that was saved with stable version, the model behaved exactly the same.

@MaartenGr
Copy link
Owner

Thanks for the PR, it is greatly appreciated. Just did some tests and it is working nicely for me. The code is looking great, so no comments there.

@MaartenGr MaartenGr merged commit 8976e64 into MaartenGr:master Mar 17, 2025
6 checks passed
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

Successfully merging this pull request may close these issues.

Lightweight installation: use safetensors without torch

2 participants