share code convert model

#1
by williamljx - opened

Hi, could you share code for converting the Medgemma-4b-pt model (.safetensors) to ONNX?

I convert the models to onnx using onnxruntime-genai

pip install onnxruntime-genai --pre
pip install onnx onnx-ir safetensors torch transformers gguf

then run the following command


from onnxruntime_genai.models.builder import create _model

create_model("hf id name"
,"None /model dir/gguf)
,"output dir ",
," precision int4 f16 "
," cpu /cuda/webgpu",
,"cache_dir",
**extra)

I convert the models to onnx using onnxruntime-genai

pip install onnxruntime-genai --pre
pip install onnx onnx-ir safetensors torch transformers gguf

then run the following command


from onnxruntime_genai.models.builder import create _model

create_model("hf id name"
,"None /model dir/gguf)
,"output dir ",
," precision int4 f16 "
," cpu /cuda/webgpu",
,"cache_dir",
**extra)

Just change the inputs

Not all model types are supported

image.png
onnxruntime_genai\models\builder.py

Thanks for your reply! Since both MedGemma-4b-pt and MedGemma-4b-it use the Gemma3ForConditionalGeneration architecture, the builder will generate only the text component of the model.

Vision onnx model is still in development

Sign up or log in to comment