--- id: spo4onnx version: "1.0.5" license: MIT License license_treatment: permissive maintenance: dormant --- # 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. License: permissive · Maintenance: dormant · Downloads: 82.7K/mo ## 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 above — 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 pip install spo4onnx uv add spo4onnx 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_current - Install friction: low - Maintenance: dormant - Downloads: 82.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags onnx model optimization, einsum optimization, neural network model compression, onnx simplification, model size reduction, onnx graph optimization, deep learning model optimization, model-optimization, onnx, neural-networks [View on SkillFed](https://skillfed.io/packages/spo4onnx) · [View on PyPI](https://pypi.org/project/spo4onnx/)