onnx-graphsurgeon
ONNX GraphSurgeon
What it is and what it does
ONNX GraphSurgeon is a Python library for creating and modifying ONNX neural network models. It provides an intermediate representation (IR) layer that abstracts away ONNX's low-level details, letting you work with graphs, nodes, and tensors as Python objects. You can import ONNX models, manipulate their structure by adding, removing, or rewiring nodes and tensors, and export the result back to ONNX format.
The library is organized around three main components: importers (to load ONNX models into the IR), the IR itself (where all modifications happen), and exporters (to write modified graphs back to ONNX). It handles both in-memory models and models with externally stored data. Common operations include topological sorting, cleanup of unused nodes, and direct manipulation of tensor values and node attributes.
Use it for:
- Remove unused layers or nodes from ONNX models before deployment to reduce size
- Programmatically build custom ONNX models from scratch without writing raw protobuf
- Debug and visualize neural network graphs by inspecting nodes, tensors, and their connections
- Adapt models by inserting, removing, or rewiring layers for transfer learning workflows
- Automate model transformations as part of a model compilation or optimization pipeline
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ONNX GraphSurgeon lets you programmatically create and modify ONNX neural network models by working with an intermediate representation of graphs, nodes, and tensors.
Yes. The package is actively maintained, has no known vulnerabilities, installs with minimal friction, and solves a real problem for anyone working with ONNX models programmatically. The permissive Apache 2.0 license poses no restrictions. Install it if you need to create or modify ONNX graphs in code.
Install
onnx-graphsurgeon on PyPI
pip
pip install onnx-graphsurgeonuv
uv add onnx-graphsurgeonpoetry
poetry add onnx-graphsurgeonInstalling onnx-graphsurgeon
Before you install
Installation is straightforward with low friction; the package is a pure Python wheel with only three runtime dependencies (numpy, onnx, ml-dtypes). The project shows active maintenance with a recent release and steady repository activity.
License in practice
Apache 2.0 is a permissive license, allowing you to use, modify, and distribute the package freely in both open-source and commercial projects, provided you include a copy of the license and state any significant changes.
Quickstart
import onnx_graphsurgeon as gs
import onnx
# Load an ONNX model
graph = gs.import_onnx(onnx.load("model.onnx"))
# Modify the graph (e.g., cleanup unused nodes)
graph.cleanup()
# Export back to ONNX
onnx.save(gs.export_onnx(graph), "modified_model.onnx")
Verify before relying
- Whether the package supports all ONNX operator types and opset versions
- Performance characteristics when working with very large models
- Whether external data handling works seamlessly with all model types
Package facts
| License | Apache 2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — ml-dtypes, numpy, onnx |
| Maintenance | actively maintained — 128 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 751,950/month — #5,155 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: onnx_graphsurgeon-0.6.1-py2.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
onnx-ironnx-ir provides an in-memory intermediate…
permissive · top 5,000 on PyPI
snd4onnxRemoves specified nodes from ONNX model graphs…
permissive · top 15,000 on PyPI
soa4onnxAdds or modifies output nodes in ONNX model…
permissive · top 15,000 on PyPI
onnxsimSimplifies ONNX neural network models by…
permissive · top 15,000 on PyPI
sor4onnxRenames input, output, and operator nodes in…
permissive · top 15,000 on PyPI
sog4onnxGenerates minimal ONNX operation graphs by…
permissive · top 15,000 on PyPI
tf2onnxConverts TensorFlow, Keras, TensorFlow.js, and…
permissive · top 15,000 on PyPI
onnx2torchConverts ONNX models to PyTorch modules with a…
permissive · top 15,000 on PyPI
onnxscriptWrite ONNX functions and models in Python…
permissive · top 5,000 on PyPI
cotengraCotengra optimizes the contraction order of…
permissive · top 15,000 on PyPI