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.
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 sam4onnxuv
uv add sam4onnxpoetry
poetry add sam4onnxInstalling 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
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
onnxscriptWrite ONNX functions and models in Python…
permissive · top 5,000 on PyPI
sng4onnxAutomatically generates and assigns operation…
permissive · top 15,000 on PyPI
sed4onnxEncodes and decodes Base64-formatted constant…
permissive · top 15,000 on PyPI
soc4onnxChanges the opset version of an ONNX model…
permissive · top 15,000 on PyPI
sna4onnxAdds new operations (nodes) to ONNX model…
permissive · top 15,000 on PyPI
sio4onnxModifies the input and output shapes of ONNX…
permissive · top 15,000 on PyPI
soa4onnxAdds or modifies output nodes in ONNX model…
permissive · top 15,000 on PyPI
sor4onnxRenames input, output, and operator nodes in…
permissive · top 15,000 on PyPI
sod4onnxsod4onnx removes specified output operations…
permissive · top 15,000 on PyPI
sog4onnxGenerates minimal ONNX operation graphs by…
permissive · top 15,000 on PyPI