Simplifies ONNX models by folding constants, running optimizer passes, and inferring shapes. Available as Python CLI, library, browser WASM UI, C API, Rust wrapper, and npm package.
Overview
ONNX Simplifier (onnxsim) takes ONNX models that contain redundant shape and arithmetic nodes and reduces them through repeated shape inference, graph optimization, and constant folding until the graph stabilizes. It was created after exports from frameworks sometimes produced bulky graphs for simple operations.
The core loop can validate simplified models against the original on random inputs, honor dynamic shapes via overwrite options, keep custom operators intact, inline model-local functions, convert opset versions, and skip optimizations selectively. Additional tooling described in the project covers export paths toward Core ML, TensorFlow Lite, and MLIR, quantization-aware fine-tuning helpers, Hugging Face and Detectron2 export shortcuts, and safetensors or GGUF archives.
Consumers can run the same engine through a zero-install browser page where models stay local, a Python package with the onnxsim CLI, native bindings, or a WebAssembly npm build for JavaScript pipelines. Custom operator schemas registered with ONNX can be imported so simplification proceeds around vendor or plugin ops such as TensorRT nodes or selected QONNX families.
Optional integrations include onnxruntime for faster checks, rich for styled terminal reports, and various ML deployment stacks when emitting converted artifacts.
Key features
- Constant folding and graph cleanup
- onnx-optimizer fusion passes
- Shape and data propagation inference
- Optional numerical equivalence checks
- Custom operator preservation
- Opset conversion while simplifying
- Browser WASM and Python interfaces
- Export hooks for several deployment formats
Use cases
- Shrinking exported ONNX vision or NLP models
- Preparing graphs for mobile or edge converters
- Cleaning models before onnxruntime deployment
- Interactive simplification in the browser