Python scripts for exporting Qwen3 models to the Q8_0 quantized binary format used by q3inf.
- Python 3.11+
- uv package manager (recommended)
cd scripts
uv syncExport Qwen3-0.6B with optimized 32K English vocabulary:
uv run export_q8.py ../model_q8.bin Qwen/Qwen3-0.6B --vocab-size 32000This generates:
model_q8.bin(604MB) - Quantized INT8 model weightsmodel_q8.bin.tokenizer(403KB) - BPE tokenizer vocabulary
export_q8.py <output_path> <hf_model_path> [options]
Arguments:
output_path Output binary file path
hf_model_path HuggingFace model path (e.g., Qwen/Qwen3-0.6B)
Options:
--vocab-size N Target vocabulary size for pruning (default: full vocab)
--group-size N Quantization group size (default: 64)
# Export with pruned vocabulary (recommended for q3inf)
uv run export_q8.py ../model_q8.bin Qwen/Qwen3-0.6B --vocab-size 32000
# Export with full vocabulary (larger file, ~151K tokens)
uv run export_q8.py ../model_q8_full.bin Qwen/Qwen3-0.6B
# Export with different group size
uv run export_q8.py ../model_q8_g128.bin Qwen/Qwen3-0.6B --vocab-size 32000 --group-size 128| File | Description |
|---|---|
export_q8.py |
Main export script with Q8_0 quantization and vocabulary pruning |
model.py |
Qwen3 model architecture definition |
pyproject.toml |
Python dependencies |
The --vocab-size option enables intelligent vocabulary pruning that:
- Preserves all special tokens (BOS, EOS, etc.)
- Prioritizes English function words and common patterns
- Keeps essential punctuation and formatting tokens
- Maintains number tokens for arithmetic
This reduces the model size while preserving English language capability.