Skip to main content
The ONNX Runtime GenAI Model Builder allows you to quickly create optimized and quantized ONNX models that run with ONNX Runtime GenAI.

Supported Model Architectures

The model builder currently supports the following architectures:
  • AMD OLMo
  • ChatGLM
  • DeepSeek
  • ERNIE 4.5
  • Gemma
  • gpt-oss
  • Granite
  • InternLM2
  • Llama
  • Mistral
  • Nemotron
  • Phi
  • Qwen
  • SmolLM3

Installation

The model builder is included in the ONNX Runtime GenAI Python package:

Basic Usage

View all available options:

Converting Models

PyTorch Model from Hugging Face

Convert a model directly from Hugging Face:
Parameters:
  • -m: Model name from Hugging Face
  • -o: Output directory for the ONNX model
  • -p: Precision (fp16, fp32, int4, etc.)
  • -e: Execution provider (cpu, cuda, dml, etc.)
  • -c: Cache directory for Hugging Face files

PyTorch Model from Disk

Convert a locally downloaded PyTorch model:

Customized or Finetuned Model

Convert your custom or finetuned PyTorch model:

GGUF Model

Convert a GGUF model to ONNX format:

Quantization Options

INT4 Quantization

Convert a pre-quantized INT4 model (AutoGPTQ or AutoAWQ):

Shared Embeddings

Enable weight sharing between embedding layer and language modeling head to reduce model size:
Shared embeddings are automatically enabled if tie_word_embeddings=true in the model’s config.json. Cannot be used with exclude_embeds=true or exclude_lm_head=true.

QDQ Pattern Quantization

Use the QDQ (Quantize-Dequantize) pattern for 4-bit quantization:

Advanced Options

Config Only Mode

Generate only the configuration files for an existing ONNX model:
After running this, modify the genai_config.json file in the output folder as needed.

Exclude Components

Exclude specific model components:

Include Hidden States

Include last hidden states as model output:
The last hidden states are also known as embeddings.

CUDA Graph Support

Enable CUDA graph optimization:

Disable QKV Fusion

Keep Q/K/V projections separate instead of fusing them:

LoRA Adapter Support

Convert models with LoRA adapters using PEFT:
  • Base weights should be in path_to_local_folder_on_disk
  • Adapter weights should be in path_to_adapter_files
See the Multi-LoRA guide for runtime usage.

Testing Models

Create a model with reduced layers for testing:

Option 1: Direct Builder Command

Option 2: Edit config.json

1

Locate the Model Files

Navigate to where the PyTorch model is saved on disk.
2

Edit config.json

Modify num_hidden_layers in config.json to your desired value (e.g., 4 layers).
3

Run the Builder

Hugging Face Configuration

Custom Authentication

Disable or use a different Hugging Face token:

Remote Code Trust

Disable trusting remote code from Hugging Face:

Next Steps

Download Models

Learn about other ways to obtain models

Runtime Options

Configure your model at runtime

Multi-LoRA

Use multiple LoRA adapters dynamically

Quickstart

Run your first inference