Skip to content

Add ONNX GraphSurgeon transformer block surgery example#4753

Draft
KOKOSde wants to merge 1 commit intoNVIDIA:mainfrom
KOKOSde:kokosde/ogs-transformer-block-example
Draft

Add ONNX GraphSurgeon transformer block surgery example#4753
KOKOSde wants to merge 1 commit intoNVIDIA:mainfrom
KOKOSde:kokosde/ogs-transformer-block-example

Conversation

@KOKOSde
Copy link
Copy Markdown

@KOKOSde KOKOSde commented May 10, 2026

Summary

  • add a runnable ONNX GraphSurgeon example for conservative transformer-block graph cleanup
  • generate a small transformer-like ONNX graph with an Identity and canceling Transpose pair
  • show how to remove those no-op structures while keeping the graph in standard ONNX operators
  • register the example in the existing ONNX GraphSurgeon example test list

Validation

  • python3 -m py_compile tools/onnx-graphsurgeon/examples/13_transformer_block_surgery/generate.py tools/onnx-graphsurgeon/examples/13_transformer_block_surgery/surgeon.py tools/onnx-graphsurgeon/tests/test_examples.py
  • git diff --check
  • In a temporary virtualenv with numpy/onnx/onnxruntime/colored installed: generated model.onnx, ran surgeon.py, checked both ONNX models, and ran CPU inference on both outputs

Note: pytest tools/onnx-graphsurgeon/tests/test_examples.py -k 13_transformer_block_surgery could not be run directly in this local checkout because the test harness invokes bare python3 and the system Python is externally managed without ONNX installed. The README commands were validated manually in a virtualenv using the local ONNX GraphSurgeon source via PYTHONPATH.

Signed-off-by: Fahad Alghanim <163377666+KOKOSde@users.noreply.github.com>
@KOKOSde KOKOSde force-pushed the kokosde/ogs-transformer-block-example branch from 11a0c49 to 2841ccd Compare May 10, 2026 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant