ONNX Model Zoo

lokinfey/Qwen3-1.7B-ONNX-INT4-CPU

By lokinfey · ↓ 4 · ♥ 1 · Updated 2025-06-29

What's in this repo

This page lists the files in lokinfey/Qwen3-1.7B-ONNX-INT4-CPU, including model.onnx.

  • 1 ONNX models (.onnx files)
  • 14 files, including 8 .json, 1 .md, 1 .jinja, 1 .txt, 1 .onnx, 1 .data
  • Last updated 2025-06-29

ONNX files

File Size Download
model.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

Qwen3-1.7B-ONNX-INT4-CPU

Note: This is an unofficial version, intended for testing and development purposes only.

Model Conversion

This guide demonstrates how to convert the Qwen3-1.7B model to ONNX format using Microsoft Olive and Microsoft ONNXRuntime GenAI.

Prerequisites

Ensure you have the following tools installed:

  1. CMake 3.31+
  2. Transformers 4.51+
  3. Microsoft Olive (development version)
  4. Microsoft ONNXRuntime GenAI (development version)
Installation Steps
# Update your transformers library
pip install transformers -U

# Install Microsoft Olive
pip install git+https://github.com/microsoft/Olive.git

# Install Microsoft ONNXRuntime GenAI
git clone https://github.com/microsoft/onnxruntime-genai
cd onnxruntime-genai && python build.py --config Release

Note: If you don't have CMake installed, please install it first before proceeding.

Conversion Command
# Convert the model using Microsoft Olive
olive auto-opt \
    --model_name_or_path {Qwen3-1.7B_PATH} \
    --device cpu \
    --provider CPUExecutionProvider \
    --use_model_builder \
    --precision int4 \
    --output_path {Your_Qwen3-1.7B_ONNX_Output_Path} \
    --log_level 1

Inference

Qwen3 supports two inference modes with different parameter configurations:

Thinking Mode

When you want the model to show its reasoning process:

  • Parameters: Temperature=0.6, TopP=0.95, TopK=20, MinP=0.0
  • Chat Template: <|im_start|>user\n/think {input}<|im_end|><|im_start|>assistant\n
Non-Thinking Mode

For direct responses without showing reasoning:

  • Parameters: Temperature=0.7, TopP=0.8, TopK=20, MinP=0.0
  • Chat Template: <|im_start|>user\n/no_think {input}<|im_end|><|im_start|>assistant\n
Python Example
import onnxruntime_genai as og
import json

# Set your model path
model_folder = "Your_Qwen3-1.7B_ONNX_Path"

# Initialize model and tokenizer
model = og.Model(model_folder)
tokenizer = og.Tokenizer(model)
tokenizer_stream = tokenizer.create_stream()

# Configuration for thinking mode
search_options = {
    'temperature': 0.6,
    'top_p': 0.95,
    'top_k': 20,
    'max_length': 32768,
    'repetition_penalty': 1
}
chat_template = "<|im_start|>user\n/think {input}<|im_end|><|im_start|>assistant\n"
text = 'What is the derivative of x^2?'

# Alternative configuration for non-thinking mode
# search_options = {
#     'temperature': 0.7,
#     'top_p': 0.8,
#     'top_k': 20,
#     'max_length': 4096,
#     'repetition_penalty': 1
# }
# chat_template = "<|im_start|>user\n/no_think {input}<|im_end|><|im_start|>assistant\n"
# text = 'Can you introduce yourself?'

# Prepare the prompt and generate response
prompt = chat_template.format(input=text)
input_tokens = tokenizer.encode(prompt)

params = og.GeneratorParams(model)
params.set_search_options(**search_options)
generator = og.Generator(model, params)

generator.append_tokens(input_tokens)

# Generate and stream the response
while not generator.is_done():
    generator.generate_next_token()
    new_token = generator.get_next_tokens()[0]
    print(tokenizer_stream.decode(new_token), end='', flush=True)

Model info

onnx qwen3 license:mit region:us
↓ 4 ♥ 1

Created: 2025-06-29

Updated: 2025-06-29

View on Hugging Face

Files (14)

.gitattributes
README.md
added_tokens.json
chat_template.jinja
config.json
genai_config.json
generation_config.json
merges.txt
model.onnx ONNX
model.onnx.data
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.json

Related models