Use the CGC backend with Windows ML CLI¶
[!IMPORTANT] The CGC backend is experimental, not supported for use in production environments, and new in Windows ML 2.9 experimental.
CGC is the Windows-native backend that compiles a model into programs for a Direct3D 12 device and runs them on the GPU target your app picked. It runs on the GPU only, with no CPU fallback. Finding a GPU doesn't establish that CGC supports its driver or a given model: a model that CGC can't run fails to load with an error.
This article explains how to convert a model to a format supported by CGC and run it using the Windows ML CLI.
Environment setup¶
First, follow the guidance in The CGC backend in Windows ML to choose recommended hardware and prepare your environment. Then, follow the instructions below to set up a Python environment for winml-cli.
Create a virtual environment and install WinML CLI version 0.5.0 or above:
Activate the virtual environment:
Build the model¶
The .mlir format is the model intermediate representation (IR) that can be executed by the CGC backend. For recommended models, see The CGC backend in Windows ML.
Export PyTorch model to MLIR¶
Export a Hugging Face PyTorch model to MLIR:
Export ONNX model to MLIR¶
Export an existing ONNX model to MLIR:
You can also use winml build to build the model with additional configuration options. For details, see the winml build command reference.
Benchmark the model¶
Use winml perf to explore model compatibility and performance before changing your application. It exercises the same paths available to the application and lets you compare them without first writing integration code. Use winml eval similarly to evaluate accuracy.
The winml perf and winml eval commands support models in .onnx, .mlir, .gguf, and .safetensors formats. For recommended models, see The CGC backend in Windows ML.
Benchmark .mlir model¶
Use this path when you already have an offline-converted .mlir model:
A .mlir model can only run on the CGC backend through the Windows ML Runtime API, selected using the --runtime winml-runtime CLI option. It cannot be loaded by ONNX Runtime.
Benchmark .onnx model¶
The winml perf command supports running ONNX models through either the Windows ML Runtime API or ONNX Runtime.
Via ONNX Runtime with WinMLCG EP¶
The WinMLCG Execution Provider (EP) makes CGC functionality available through ONNX Runtime.
Use this path when the application uses ONNX Runtime and should keep ONNX as its model contract:
The WinMLCG Execution Provider converts the model for CGC when the ONNX Runtime session is created. No reusable CGIR artifact is produced. After this test succeeds, keep the ONNX model and configure the WinMLCG EP in the application.
Via Windows ML Runtime API¶
Use this path when the application uses the Windows ML Runtime API but should keep ONNX as its model contract:
The CLI calls the Runtime compiler API to compile ONNX to temporary, device-targeted CGC output IR, then loads that artifact and runs it through CGC. No EP is selected and no reusable CGIR artifact is retained. Applications using this path must likewise invoke the compiler API before pipeline execution.
Benchmark LLM model (gguf and safetensor)¶
The Windows ML Task API handles prompt tokenization and text generation, streaming generated tokens back to the application. Use this path to benchmark LLM generation on the GPU with CGC. No ONNX or MLIR export is required.
Safetensors checkpoint: Download Qwen3-0.6B into .\Qwen3-0.6B, keeping the weights, configuration, and tokenizer files together. Pass the folder, not an individual .safetensors file:
GGUF: Download Qwen3-0.6B-Q4_0.gguf into the current directory, then pass the file:
Both commands select the CGC backend, report time to first token and generation throughput, and save the results as JSON.
Illustrative JSON excerpt (values vary by model and device):
{
"benchmark_info": {
"runtime": "winml-runtime",
"backend": "cgc",
"model_format": "gguf"
},
"aggregate": {
"warmup_excluded": true,
"task_ttft_duration_ms": {
"mean": 20
},
"steady_state_decode_tokens_per_second": {
"mean": 500
},
"request_duration_ms": {
"mean": 300
}
}
}
These fields show the average Task time to first token, subsequent generation speed, and total request time, excluding warmup requests.
Tutorials and samples¶
- ResNet-50 - PyTorch to CGIR (experimental) walks through the complete Hugging Face PyTorch → ONNX → CGIR build, performance, and evaluation workflow.
- YOLO11 - ONNX to CGIR (experimental) provides an end-to-end conversion journey: export a checkpoint to ONNX, build CGIR, collect GPU performance results, compare raw output tensors, and try the WinMLCG EP alternative.
Command references¶
winml exportdocuments--target cgirand CGIR export options.winml optimizedocuments ONNX optimization.winml perfdocuments.mlir,winml-runtime, and WinMLCG performance measurement.winml evaldocuments evaluation of supported CGIR models with compatible preprocessing metadata.winml configandwinml builddocument configuration-driven CGIR conversion.