skillfed

onnx-graphsurgeon

ONNX GraphSurgeon

onnx-graphsurgeon v0.6.1 752.0K downloads/30d#5,155 on PyPI13,250
Permissive license Apache 2.0 Active released

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-graphsurgeon

uv

uv add onnx-graphsurgeon

poetry

poetry add onnx-graphsurgeon

Installing 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

Intended Audience :: DevelopersProgramming Language :: Python :: 3

Tags

onnx model editinggraph modification libraryneural network model manipulationonnx ir intermediate representationcreate onnx models programmaticallyonnx graph transformationmodel graph surgery
model-optimizationonnx-toolsgraph-manipulation

More Artificial Intelligence packages