spo4onnx
Simple tool for partial optimization of ONNX. Further optimize some models that cannot be optimized with onnx-optimizer and onnxsim by several tens of percent. In particular, models containing Einsum and OneHot.
What it is and what it does
spo4onnx is a specialized ONNX model optimizer designed to handle cases where standard tools like onnx-optimizer and onnxsim reach their limits. It focuses on models containing Einsum and OneHot operations, which are common bottlenecks in neural network graphs. The tool works by temporarily downgrading onnxsim to version 0.4.30, applying its own optimization sequence to reduce redundant operations, then restoring the original environment. It can be used as a command-line tool or imported as a Python module.
The optimization strategy preserves Einsum operations rather than expanding them into MatMul chains, which can lead to significant reductions in model complexity—documented examples show reductions from 9,988 operations to 3,927. However, the tool has important limitations: it cannot safely process models with non-deterministic output shapes (like NonZero or NonMaxSuppression), and not all models benefit equally. The package requires onnx and onnxruntime as peer dependencies and is permissively licensed under MIT.
Use it for:
- Optimize large computer vision models with Einsum operations for deployment on resource-constrained devices.
- Reduce model complexity and file size for models that onnxsim alone cannot adequately simplify.
- Pre-process ONNX models before quantization or conversion to other inference formats.
- Improve inference latency by reducing the operation count in models with OneHot layers.
- Prepare models with fixed input dimensions for edge deployment after manual shape specification.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Applies specialized optimization techniques to ONNX neural network models, particularly those with Einsum and OneHot operations that standard optimizers cannot effectively reduce.
Yes, if you have ONNX models with Einsum or OneHot operations that standard optimizers leave largely unchanged and you can verify the model contains no non-deterministic operations. The low install friction and permissive license make it a low-risk addition to a model optimization pipeline. However, the dormant maintenance status means no active support for new onnxsim versions or bug fixes—treat it as a specialized tool for a specific problem, not a general-purpose optimizer.
Install
spo4onnx on PyPI
pip
pip install spo4onnxuv
uv add spo4onnxpoetry
poetry add spo4onnxInstalling spo4onnx
Before you install
Low friction installation with no runtime dependencies. The package is dormant (last release 2024-05-07, 829 days ago), so expect no active maintenance or bug fixes.
License in practice
MIT License permits free use, modification, and distribution with minimal restrictions, making this safe for commercial and open-source projects.
Quickstart
pip install spo4onnx
from spo4onnx import partial_optimization
optimized_model = partial_optimization(
input_onnx_file_path='model.onnx',
output_onnx_file_path='model_optimized.onnx'
)
Requires onnx and onnxruntime to be installed separately; models with non-deterministic output shapes (NonZero, NonMaxSuppression) will be corrupted by optimization.
Verify before relying
- Whether the tool's optimization gains (claimed 30%-60% reduction) are reproducible across model architectures beyond the documented examples.
- Current compatibility with recent onnxsim versions beyond the default 0.4.30 target.
- Whether models with dynamic shapes can be reliably optimized without manual intervention.
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.6) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 829 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 82,697/month — #14,143 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: spo4onnx-1.0.5-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
scs4onnxCompresses ONNX model files by deduplicating…
permissive · top 15,000 on PyPI
onnxsimSimplifies ONNX neural network models by…
permissive · top 15,000 on PyPI
onnxoptimizerApplies graph-level optimizations to ONNX…
permissive · top 15,000 on PyPI
opt-einsum-fxOptimizes PyTorch einsum operations and…
permissive · top 15,000 on PyPI
sne4onnxExtracts subgraphs from ONNX model files by…
permissive · top 15,000 on PyPI
sde4onnxRemoves embedded doc_strings from ONNX model…
permissive · top 15,000 on PyPI
snd4onnxRemoves specified nodes from ONNX model graphs…
permissive · top 15,000 on PyPI
cotengraCotengra optimizes the contraction order of…
permissive · top 15,000 on PyPI
opt-einsumOptimizes the contraction order of einsum…
permissive · top 1,000 on PyPI
sbi4onnxModifies ONNX model files to initialize or…
permissive · top 15,000 on PyPI