How to convert safetensors model to onnx model?

1.1k Views Asked by At

I want to convert a model.safetensors to ONNX, unfortunately I haven't found enough information about the procedure. The documentation of safetensors package isn't enough and actually is not clear even how to get the original (pytorch in my case) model, since when I try something as

with st.safe_open(modelsafetensors, framework="pt") as mystf:
   ...

the mystf object has get_tensor('sometensorname') but it seems hasn't any get_model() method or something similar.

1

There are 1 best solutions below

0
On

I had the same problem and this is what I found for the conversion of model:

Convertor

Download from repo convert.py and requirements.txt from scripts, put it to some folder.

  1. Create a virtual environment by running python -m venv .venv
  2. Activate it by running source .venv/bin/activate
  3. Install requirements by pip install -r requirements.txt
  4. Run a script for converting a model, in my case it was: python convert.py --quantize --model_id BAAI/bge-small-en-v1.5