Registry / ai-ml / sng4onnx

sng4onnx

JSON →
library2.0.1pypypiunverified

sng4onnx is a Python library and CLI tool designed to automatically generate and assign an operation (OP) name to each operation within an ONNX (Open Neural Network Exchange) file, particularly useful for older format models lacking explicit OP names. The library is currently active, with version 2.0.1, and maintains a frequent release cadence, often rolling out updates for bug fixes and minor feature enhancements.

pip install -U onnx sng4onnx
INSTALL
IMPORT
SIG · SNG4ONNX
S
sng4onnx
ai-mlpythonv2.0.1
Install
6.7s avg
Import
574ms
Disk
193MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
installs and imports cleanly · install 6.7s · import 0.574s · 190MB
193MB installed
● package 193MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generate
from sng4onnx import generate
The primary function for processing ONNX models.

This quickstart demonstrates how to use `sng4onnx` to process an ONNX model. It begins by programmatically creating a simple ONNX model, then passes it to the `generate` function to automatically assign operation names. Finally, it saves and verifies the processed model.

import onnx from onnx import helper, TensorProto import numpy as np from sng4onnx import generate import os # 1. Create a dummy ONNX model for demonstration def create_dummy_onnx(path): # Define graph inputs X = helper.make_tensor_value_info('X', TensorProto.FLOAT, [1, 2, 3]) Y = helper.make_tensor_value_info('Y', TensorProto.FLOAT, [1, 2, 3]) # Define graph outputs Z = helper.make_tensor_value_info('Z', TensorProto.FLOAT, [1, 2, 3]) # Create a node (Mul operator) node_def = helper.make_node( 'Add', ['X', 'Y'], ['Z'], name='MyAddOperation' # Can be empty in an 'old format' model ) # Create the graph graph_def = helper.make_graph( [node_def], 'simple_graph', [X, Y], [Z] ) # Create the model model_def = helper.make_model(graph_def, producer_name='dummy-model') # Save the model onnx.save(model_def, path) input_onnx_path = 'input_model.onnx' output_onnx_path = 'output_model_renamed.onnx' create_dummy_onnx(input_onnx_path) # 2. Use sng4onnx to generate/assign OP names print(f"Processing {input_onnx_path}...") renamed_model = generate( input_onnx_file_path=input_onnx_path, output_onnx_file_path=output_onnx_path, non_verbose=False ) # 3. Verify the output (optional) if os.path.exists(output_onnx_path): print(f"Successfully generated {output_onnx_path}") loaded_model = onnx.load(output_onnx_path) print(f"Nodes in renamed model: {[node.name for node in loaded_model.graph.node]}") else: print("Error: Output model not found.") # Clean up dummy files os.remove(input_onnx_path) os.remove(output_onnx_path)
sng4onnx --version
Debug
Known issues
breakingVersion 2.0.0 removed the `onnx_graphsurgeon` dependency. If your project or other tools implicitly relied on `sng4onnx` installing `onnx_graphsurgeon` or expected its presence, you will encounter `ModuleNotFoundError`.
fix
Explicitly install `onnx_graphsurgeon` if your workflow requires it: `pip install -U onnx_graphsurgeon --index-url https://pypi.ngc.nvidia.com`.
affects: >=2.0.0
gotchaOlder versions (prior to 1.0.5) had a bug where running `onnx.shape_inference.infer_shapes()` on ONNX models with external data could corrupt the model file.
fix
Upgrade to `sng4onnx` version 1.0.5 or newer to ensure correct handling of external data during shape inference.
affects: <1.0.5
gotchaVersions prior to 1.0.2 had issues preserving critical ONNX model metadata, such as `domain` and `ir_version`, during processing, potentially leading to models that behave unexpectedly or are incompatible with other tools.
fix
Ensure you are using `sng4onnx` version 1.0.2 or later to correctly preserve ONNX graph metadata.
affects: <1.0.2
Upgrade
Version history
2.0.1latest on PyPI · released Feb 24, 2026
Audit
Dependencies
onnxrequiredCore dependency for ONNX model manipulation.
Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
sng4onnx — pip install sng4onnx · libregistry