Skip to content

[Pass] Graph extractor pass#2119

Closed
justinchuby wants to merge 18 commits intomainfrom
justinchu/graph-extractor-2
Closed

[Pass] Graph extractor pass#2119
justinchuby wants to merge 18 commits intomainfrom
justinchu/graph-extractor-2

Conversation

@justinchuby
Copy link
Collaborator

@justinchuby justinchuby commented Mar 22, 2025

  • Added a new pass for extracting subgraphs from a graph (ExtractGraphPass) in onnxscript/ir/passes/common/graph_extration.py. This pass allows for the extraction of a sub-model defined by specific input and output tensor names.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a new pass for extracting subgraphs from an ONNX model based on exact input and output tensor names. Key changes include:

  • Adding a new pass implementation in onnxscript/ir/passes/common/graph_extration.py.
  • Enhancing pre- and post-condition checks in the pass infrastructure in onnxscript/ir/passes/_pass_infra.py.
  • Exporting the new create_value_mapping function via the convenience modules.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
onnxscript/ir/passes/common/graph_extration.py Implements the new ExtractGraphPass for subgraph extraction.
onnxscript/ir/passes/_pass_infra.py Updates PassBase and PassManager for improved invariant checking.
onnxscript/ir/_convenience.py Exports create_value_mapping and replace_nodes_and_values.
onnxscript/ir/convenience.py Imports and re-exports create_value_mapping.
Comments suppressed due to low confidence (1)

onnxscript/ir/passes/common/graph_extration.py:1

  • The filename 'graph_extration.py' appears to be misspelled; consider renaming it to 'graph_extraction.py' for clarity.
# Copyright (c) Microsoft Corporation.

@codecov
Copy link

codecov bot commented Mar 22, 2025

Codecov Report

❌ Patch coverage is 82.67717% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.64%. Comparing base (6d33d22) to head (2e5191a).
⚠️ Report is 316 commits behind head on main.

Files with missing lines Patch % Lines
...nnxscript/ir/passes/common/graph_extration_test.py 81.53% 11 Missing and 1 partial ⚠️
onnxscript/ir/passes/common/graph_extration.py 83.87% 5 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2119      +/-   ##
==========================================
- Coverage   73.63%   67.64%   -5.99%     
==========================================
  Files         227      229       +2     
  Lines       29134    29261     +127     
  Branches     3338     3352      +14     
==========================================
- Hits        21453    19795    -1658     
- Misses       6551     8376    +1825     
+ Partials     1130     1090      -40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

justinchuby and others added 5 commits March 21, 2025 18:07
@justinchuby justinchuby marked this pull request as draft March 22, 2025 14:59
@justinchuby justinchuby marked this pull request as ready for review March 26, 2025 18:54
* **Test extract subgraph**: Add a test case to validate the extraction of a subgraph with basic operations (Add, Mul).
* **Test extract subgraph with initializers**: Add a test case to validate the extraction of a subgraph that includes initializers (Constant).
* **Test extract subgraph with subgraph**: Add a test case to validate the extraction of a subgraph that includes nested subgraphs (If node with then and else branches).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the copilot output

@@ -0,0 +1,154 @@
# Copyright (c) Microsoft Corporation.

Check warning

Code scanning / lintrunner

RUFF/format Warning

Run lintrunner -a to apply this patch.
@@ -0,0 +1,154 @@
# Copyright (c) Microsoft Corporation.

Check warning

Code scanning / lintrunner

RUFF-FORMAT/format Warning

Run lintrunner -a to apply this patch.
@@ -0,0 +1,154 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import unittest

Check warning

Code scanning / lintrunner

RUFF/I001 Warning

Import block is un-sorted or un-formatted.
See https://docs.astral.sh/ruff/rules/unsorted-imports
@justinchuby justinchuby marked this pull request as draft April 11, 2025 15:46
@justinchuby justinchuby mentioned this pull request Apr 1, 2025
3 tasks
@justinchuby justinchuby marked this pull request as ready for review April 23, 2025 02:03
@justinchuby justinchuby marked this pull request as draft April 23, 2025 02:03
@justinchuby
Copy link
Collaborator Author

Replaced by onnx/ir-py#294

justinchuby added a commit to onnx/ir-py that referenced this pull request Dec 30, 2025
Extract subgraphs with `onnx_ir.convenience.extract()`. Migrated from
microsoft/onnxscript#2119.

Requires #293

---------

Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

2 participants