Skip to content

Commit

Permalink
convert space option only
Browse files Browse the repository at this point in the history
  • Loading branch information
stevhliu authored Sep 5, 2023
1 parent d7fc304 commit 9f15cfb
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions docs/source/convert-weights.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,12 @@

PyTorch model weights are commonly saved and stored as `.bin` files with Python's [`pickle`](https://docs.python.org/3/library/pickle.html) utility. To save and store your model weights in the more secure `safetensor` format, we recommend converting your weights to `.safetensors`.

The easiest way to convert your model weights is to use the [Convert Space](https://huggingface.co/spaces/diffusers/convert), given your model weights are already stored on the Hub. The Convert Space downloads the pickled weights, converts them, and opens a Pull Request to upload the newly converted `.safetensors` file to your repository. Merge the Pull Request to upload the weights, but if you can't wait to try it out, you can also use the `.safetensors` immediately by specifying the reference to the Pull Request in the revision parameter:
The easiest way to convert your model weights is to use the [Convert Space](https://huggingface.co/spaces/diffusers/convert), given your model weights are already stored on the Hub. The Convert Space downloads the pickled weights, converts them, and opens a Pull Request to upload the newly converted `.safetensors` file to your repository.

```py
from transformers import AutoModel
<Tip warning={true}>

model = AutoModel.from_pretrained(
"my-safe-model", revision="refs/pr/1", use_safetensors=True
)
```
For larger models, the Space may be a bit slower because its resources are tied up in converting other models. You can also try running the [convert.py](https://github.com/huggingface/safetensors/blob/main/bindings/python/convert.py) script (this is what the Space is running) locally to convert your weights.

Another way to convert your `.bin` files is to use the [`~safetensors.torch.save_model`] function:
Feel free to ping [@Narsil](https://huggingface.co/Narsil) for any issues with the Space.

```py
from transformers import AutoModel
from safetensors.torch import save_model

unsafe_model = AutoModel.from_pretrained("my-unsafe-model")
save_model(unsafe_model, "model.safetensors")
```
</Tip>

0 comments on commit 9f15cfb

Please sign in to comment.