--- id: onnx-graphsurgeon version: "0.6.1" license: Apache 2.0 license_treatment: permissive maintenance: active --- # onnx-graphsurgeon — ONNX GraphSurgeon License: permissive · Maintenance: active · Downloads: 752.0K/mo ## 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 above — 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 pip install onnx-graphsurgeon uv add onnx-graphsurgeon 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: unspecified - Install friction: low - Maintenance: active - Downloads: 752.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags onnx model editing, graph modification library, neural network model manipulation, onnx ir intermediate representation, create onnx models programmatically, onnx graph transformation, model graph surgery, model-optimization, onnx-tools, graph-manipulation [View on SkillFed](https://skillfed.io/packages/onnx-graphsurgeon) · [View on PyPI](https://pypi.org/project/onnx-graphsurgeon/)