skillfed

sam4onnx

A very simple tool to rewrite parameters such as attributes and constants for OPs in ONNX models. Simple Attribute and Constant Modifier for ONNX.

sam4onnx v2.0.0 83.0K downloads/30d#14,113 on PyPI15
Permissive license MIT License AGING released

What it is and what it does

sam4onnx is a lightweight utility for modifying operator attributes and constant inputs in ONNX models. It accepts either a file path to an .onnx model or an in-memory onnx.ModelProto object, locates a specified operator by name, and rewrites its attributes or the constants feeding into it. The tool operates on a single operator at a time and includes support for recursive modification within If operator subgraphs.

The package provides both a command-line interface and a Python API. It does not validate the overall graph integrity after modifications—that responsibility falls to the user. It is designed for simple, targeted edits rather than comprehensive model transformation, making it useful for quick parameter adjustments, debugging, or preparing models for deployment with modified hyperparameters.

Use it for:

  • Adjust operator attributes (e.g., transpose permutation, reshape dimensions) in an exported ONNX model without retraining.
  • Modify constant tensor values feeding into operators to test different hyperparameters or thresholds.
  • Batch-edit multiple models' parameters via CLI for deployment pipeline automation.
  • Recursively update parameters in conditional branches (If operators) across a model's subgraph structure.
  • Prepare quantized or pruned models by rewriting shape metadata or operator-specific configuration.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Rewrites attributes and constants in ONNX model operators via CLI or Python API, supporting both file-based and in-memory graph modifications.

Yes, if you need to edit ONNX operator parameters post-export. Low install friction, no dependencies, permissive license, and straightforward API make it a practical choice for model tweaking. Aging maintenance (189 days since last release) is a minor concern but not a blocker for a stable utility tool. Verify that graph-level side effects of your edits are acceptable before relying on it in production pipelines.

Install

sam4onnx on PyPI

pip

pip install sam4onnx

uv

uv add sam4onnx

poetry

poetry add sam4onnx

Installing sam4onnx

Before you install

Low friction: pure Python wheel with no runtime dependencies. Maintenance status is aging—last release 189 days ago—but the repository remains active and targets current Python versions.

License in practice

MIT License permits commercial and private use, modification, and distribution with minimal restrictions, making it suitable for most projects.

Quickstart

pip install sam4onnx

from sam4onnx import modify

modified = modify(
    input_onnx_file_path='model.onnx',
    output_onnx_file_path='modified.onnx',
    op_name='Transpose_17',
    attributes={'perm': [0, 1]}
)

Verify before relying

  • Whether graph integrity validation is performed after modifications beyond the documented single-OP scope.
  • Performance characteristics when working with large models or deeply nested subgraph structures.
  • Compatibility with ONNX opset versions beyond what the fact sheet documents.

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 aging — 189 days since the last release
Last repo commit
First released
Downloads 82,975/month — #14,113 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: sam4onnx-2.0.0-py3-none-any.whl

Tags

onnx model attribute modifierrewrite onnx operator parametersonnx constant editormodify onnx graph attributesonnx op parameter tuningonnx model parameter adjustmentsimple onnx editing tool
onnx-toolsmodel-editingml-ops

More Artificial Intelligence packages