ONNX Model Zoo

maxious/embeddinggemma-300m-onnx

By maxious · ↓ 0 · ♥ 1 · Updated 2025-09-06

What's in this repo

This page lists the files in maxious/embeddinggemma-300m-onnx, including model.onnx, dense1.onnx, dense2.onnx and more.

  • 5 ONNX models (.onnx files)
  • 31 files, including 12 .json, 8 .py, 5 .onnx, 2 .md, 1 .model
  • Last updated 2025-09-06

ONNX files

File Size Download
embeddinggemma-300m/model.onnx — Download
embeddinggemma-300m/onnx/dense1.onnx — Download
embeddinggemma-300m/onnx/dense2.onnx — Download
embeddinggemma-300m/onnx/model_int4.onnx — Download
embeddinggemma-300m/onnx/model_int8.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

Gemma3 Embedding Model: ONNX Conversion Demonstration

This repository demonstrates the conversion and comparison of the Gemma3 embedding model from Hugging Face to ONNX format using optimum-onnx. It includes scripts for both ONNX and PyTorch inference pipelines, as well as a comparison of their outputs.

Files

  • onnx_gemma3_pipeline.py: Runs the Gemma3 embedding model using ONNXRuntime, including post-processing steps (Pooling, Dense, Normalize) with ONNX exported layers.
  • pytorch_gemma3_pipeline.py: Runs the original Gemma3 embedding model using PyTorch and SentenceTransformer for reference.
  • compare_gemma3_onnx_vs_pytorch.py: Compares the output embeddings and cosine similarities between the ONNX and PyTorch pipelines.
  • download_missing_hf_files.py: Downloads required files from Hugging Face and exports Dense layers to ONNX.
  • gemma3_mean_pooling_basic.py: The most basic implementation, running Gemma3 ONNX inference with only mean pooling (no Dense or Normalize stages).

Pipeline Differences

Both pipelines use ONNXRuntime for transformer inference via ORTModelForFeatureExtraction. The key difference is in post-processing:

  • ONNX pipeline (onnx_gemma3_pipeline.py): Uses ONNXRuntime for both the transformer and Dense layers (exported to ONNX), making most of the pipeline ONNX-based except for normalization.
  • PyTorch pipeline (pytorch_gemma3_pipeline.py): Uses ONNXRuntime for the transformer, but all post-processing (Pooling, Dense, Normalize) is performed with PyTorch modules from SentenceTransformer.

This demonstrates how ONNX conversion can offload more computation for faster, hardware-agnostic inference, while the PyTorch pipeline serves as the reference implementation.

Setup

  1. Install dependencies:
    pip install git+https://github.com/simondanielsson/optimum-onnx.git@feature/add-gemma3-export
    pip install git+https://github.com/huggingface/transformers@v4.56.0-Embedding-Gemma-preview
    pip install sentence-transformers onnxruntime safetensors huggingface_hub
    
  2. Export the ONNX model:
    optimum-cli export onnx --model google/embeddinggemma-300m-qat-q4_0-unquantized --optimize O3 --slim embeddinggemma-300m-onnx
    python download_missing_hf_files.py
    

Usage

  • Run the ONNX pipeline:
    python onnx_gemma3_pipeline.py
    
  • Run the PyTorch pipeline:
    python pytorch_gemma3_pipeline.py
    
  • Compare outputs:
    python compare_gemma3_onnx_vs_pytorch.py
    

Results

The comparison script prints cosine similarities between sample word embeddings (e.g., "apple", "banana", "car") for both ONNX and PyTorch pipelines, demonstrating the fidelity of the ONNX conversion.

References

Model info

onnx base_model:google/embeddinggemma-300m-qat-q4_0-unquantized base_model:quantized:google/embeddinggemma-300m-qat-q4_0-unquantized region:us
↓ 0 ♥ 1

Created: 2025-09-06

Updated: 2025-09-06

View on Hugging Face

Files (31)

.gitattributes
.gitignore
README.md
compare_gemma3_onnx_vs_pytorch.py
download_missing_hf_files.py
embeddinggemma-300m/.gitattributes
embeddinggemma-300m/1_Pooling/config.json
embeddinggemma-300m/2_Dense/config.json
embeddinggemma-300m/3_Dense/config.json
embeddinggemma-300m/README.md
embeddinggemma-300m/added_tokens.json
embeddinggemma-300m/config.json
embeddinggemma-300m/config_sentence_transformers.json
embeddinggemma-300m/generation_config.json
embeddinggemma-300m/model.onnx ONNX
embeddinggemma-300m/modules.json
embeddinggemma-300m/onnx/dense1.onnx ONNX
embeddinggemma-300m/onnx/dense2.onnx ONNX
embeddinggemma-300m/onnx/model_int4.onnx ONNX
embeddinggemma-300m/onnx/model_int8.onnx ONNX
embeddinggemma-300m/sentence_bert_config.json
embeddinggemma-300m/special_tokens_map.json
embeddinggemma-300m/tokenizer.json
embeddinggemma-300m/tokenizer.model
embeddinggemma-300m/tokenizer_config.json
float16.py
gemma3_mean_pooling_basic.py
onnx_gemma3_pipeline.py
pytorch_gemma3_pipeline.py
quantize_extended.py
utils.py

Related models