skillfed

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.

spo4onnx v1.0.5 82.7K downloads/30d#14,143 on PyPI19
Permissive license MIT License DORMANT released

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 spo4onnx

uv

uv add spo4onnx

poetry

poetry add spo4onnx

Installing 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

onnx model optimizationeinsum optimizationneural network model compressiononnx simplificationmodel size reductiononnx graph optimizationdeep learning model optimization
model-optimizationonnxneural-networks

More Artificial Intelligence packages