This repository hosts the optimized versions of the Phi-4 reasoning models to accelerate inference with ONNX Runtime.
Optimized models are published here in ONNX format to run with ONNX Runtime on CPU and GPU across devices, including server platforms, Windows, Linux and Mac desktops, and mobile CPUs, with the precision best suited to each of these targets.
You can see how to run examples with ORT GenAI
here
1# Download the model directly using the Hugging Face CLI
2huggingface-cli download microsoft/Phi-4-reasoning-onnx --include cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/* --local-dir .
3
4# Install the CPU package of ONNX Runtime GenAI
5pip install --pre onnxruntime-genai
6
7# Please adjust the model directory (-m) accordingly
8curl https://raw.githubusercontent.com/microsoft/onnxruntime-genai/main/examples/python/common.py -o common.py
9curl https://raw.githubusercontent.com/microsoft/onnxruntime-genai/main/examples/python/model-qa.py -o model-qa.py
10python model-qa.py -m cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4 -e cpu
1# Download the model directly using the Hugging Face CLI
2huggingface-cli download microsoft/Phi-4-reasoning-onnx --include gpu/* --local-dir .
3
4# Install the CUDA package of ONNX Runtime GenAI
5pip install --pre onnxruntime-genai-cuda
6
7# Please adjust the model directory (-m) accordingly
8curl https://raw.githubusercontent.com/microsoft/onnxruntime-genai/main/examples/python/common.py -o common.py
9curl https://raw.githubusercontent.com/microsoft/onnxruntime-genai/main/examples/python/model-qa.py -o model-qa.py
10python model-qa.py -m gpu/gpu-int4-rtn-block-32 -e cuda
1# Download the model directly using the Hugging Face CLI
2huggingface-cli download microsoft/Phi-4-reasoning-onnx --include gpu/* --local-dir .
3
4# Install the DML package of ONNX Runtime GenAI
5onnxruntime-genai-directml
6
7# Please adjust the model directory (-m) accordingly
8curl https://raw.githubusercontent.com/microsoft/onnxruntime-genai/main/examples/python/common.py -o common.py
9curl https://raw.githubusercontent.com/microsoft/onnxruntime-genai/main/examples/python/model-qa.py -o model-qa.py
10python model-qa.py -m gpu/gpu-int4-rtn-block-32 -e dml
Phi-4 reasoning is a state-of-the-art open model built upon a blend of synthetic datasets, data from filtered public domain websites, and acquired academic books and Q&A datasets. The goal of this approach was to ensure that small capable models were trained with data focused on high quality and advanced reasoning.
See details at
https://huggingface.co/microsoft/Phi-4-reasoning/blob/main/README.md.