GGUF ONNX
File conversion

Convert GGUF to ONNX

QUICK ANSWER
Is it possible to convert GGUF to ONNX?
Yes - GGUF converts to ONNX.

There is no direct GGUF-to-ONNX exporter. The realistic path is to convert the .gguf back to a Hugging Face model (safetensors) with a GGUF-to-safetensors tool, load it in Transformers, then run optimum-cli export onnx to produce the .onnx. Expect large files, since dequantizing removes GGUF's size savings.

Also to ONNX: H5

On this page

Tested on macOS, Windows & Linux
Last verified Sep 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert GGUF to ONNX?

People want GGUF as .onnx to run a model in ONNX Runtime, DirectML or other cross-platform accelerators that don't read GGUF. Because ONNX needs a standard computation graph and GGUF is a llama.cpp-specific quantized container, you first reconstruct a normal PyTorch model and then export it.

How to convert GGUF to ONNX

Dequantize GGUF to safetensors OPEN-SOURCE

Use a converter such as the ungguf tool or a gguf-reader script to turn the .gguf back into full-precision safetensors that Transformers can load.

Export to ONNX with Optimum FREE

Point Optimum at the reconstructed model: optimum-cli export onnx --model ./model-dir onnx-out/ writes the .onnx file.

Export manually with PyTorch OPEN-SOURCE

For unsupported architectures, load the model in PyTorch and call torch.onnx.export(model, dummy_input, "model.onnx") yourself.

About these formats

Quality & what to watch

  • Dequantizing a quantized GGUF cannot recover the precision lost during quantization, and complex quant types (like IQ variants) may not round-trip cleanly.
  • The resulting ONNX is full-precision, so it can be several times larger than the compact GGUF you started from.
  • Optimum only supports certain architectures out of the box; niche or custom models may need a manual export config or fail.

Frequently asked questions

Can I export GGUF straight to ONNX?
No. You must first convert the GGUF to a PyTorch/safetensors model, then export that to ONNX.
Will the ONNX model be as small as the GGUF?
No. Dequantization restores full precision, so the ONNX file is typically much larger unless you re-quantize it afterward.
Does dequantizing restore the original accuracy?
No. Quantization is lossy, so the recovered weights carry the same errors as the quantized GGUF.
What tools do I need?
A GGUF-to-safetensors converter plus Hugging Face Transformers and Optimum (or PyTorch for a manual export).