onnxsim/onnxsim
Simplify your onnx model
What it solves
ONNX Simplifier reduces the complexity of ONNX models by eliminating redundant operators and simplifying the computation graph. This is particularly useful when exporting models from frameworks like PyTorch, which can often produce overly complicated graphs with unnecessary reshape or shape-manipulation operations that make the model harder to analyze or deploy.
How it works
The tool runs a fixed-point iteration of shape inference, graph optimization, and constant folding. It evaluates constant parts of the graph and replaces them with their computed outputs. It also integrates with onnx-optimizer for fusions (like merging BatchNorm into Conv) and can propagate tensor shapes through the graph to unlock further simplifications. For large models, it can utilize the CUDA execution provider via ONNX Runtime to speed up the constant-folding process.
Who it’s for
It is designed for developers and ML engineers who deploy ONNX models to various runtimes or compiler stacks (such as MLIR-based stacks like torch-mlir or onnx-mlir) and need a cleaner, more efficient graph representation.
Highlights
- Constant Folding: Replaces redundant operators with their pre-computed constant outputs.
- Graph Optimization: Performs fusions and eliminations to reduce node count.
- Correctness Checking: Validates the simplified model against the original using random inputs.
- Broad Compatibility: Supports custom operators, opset conversion (upgrading/downgrading), and function inlining.
- MLIR Export: Provides a bridge to export simplified models directly to Torch or ONNX dialects of MLIR.
- Flexible Deployment: Available as a Python package, CLI, C API, Rust wrapper, and a zero-install web version.
相关
- 项目
- 项目
- 项目
- 项目
- 项目