pass-writing

Guide creation of custom transformation passes for ONNX IR graphs.

45|20|Updated May 14, 2025
One-click install
npx skills add https://github.com/onnx/ir-py --skill pass-writing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pass-writing
Source: https://github.com/onnx/ir-py/tree/main/.github/skills/pass-writing
Command: npx skills add https://github.com/onnx/ir-py --skill pass-writing

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive guidance and best practices for developing transformation passes within the ONNX IR project, enabling users to effectively modify and optimize ONNX graphs.

Core Features & Use Cases

  • Pass Infrastructure: Understand base classes (InPlacePass, FunctionalPass) and pass lifecycle.
  • Graph Manipulation: Learn safe node and value manipulation, including replacement and removal.
  • Use Case: A developer needs to implement a new optimization pass to fuse specific ONNX operations. This Skill provides the necessary patterns, code examples, and best practices to build and test such a pass efficiently.

Quick Start

Use the pass-writing skill to learn how to implement a new InPlacePass for ONNX IR.

Frequently Asked Questions about pass-writing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a custom optimization pass for ONNX IR?

To write a custom ONNX IR optimization pass, you implement a transformation by extending base classes like InPlacePass or FunctionalPass, then manipulate nodes and values to modify the graph structure safely.

What is the difference between InPlacePass and FunctionalPass in ONNX graph transformation?

InPlacePass modifies the ONNX graph directly during transformation, whereas FunctionalPass returns a new modified graph, offering different lifecycle patterns for ONNX graph optimization and analysis development.

How do I safely replace or remove nodes during ONNX graph manipulation?

Safe ONNX graph manipulation requires using the pass infrastructure's specific patterns for node replacement and removal, ensuring value references and initializer handling are correctly updated during the transformation pass.

How do you handle subgraphs and opset version management in ONNX IR passes?

Handling subgraphs and opset version management in ONNX IR passes involves specific graph traversal techniques to process nested structures and ensuring opset compatibility when modifying operations within the ONNX graph.

Does ONNX pass development require managing initializers separately from graph values?

Yes, ONNX pass development requires explicit initializer handling, as initializers represent constant tensors that must be managed separately from dynamic graph values during node and value manipulation.

What's the best way to debug a custom ONNX IR transformation pass?

The best way to debug a custom ONNX IR transformation pass involves utilizing the pass infrastructure's built-in debugging features to inspect graph traversal, verify node manipulation, and validate subgraph processing outcomes.