Skip to content

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

❌ 8 Tests Failed:

Tests completed Failed Passed Skipped
7678 8 7670 4113
View the top 3 failed test(s) by shortest run time
onnxscript.ir.passes.common.graph_extration_test.TestExtractGraphPass::test_extract_subgraph
Stack Traces | 0.002s run time
.../passes/common/graph_extration_test.py:34: in test_extract_subgraph
    self.assertEqual(len(result.model.graph.nodes), 2)
E   AttributeError: 'Graph' object has no attribute 'nodes'
onnxscript.ir.passes.common.graph_extration_test.TestExtractGraphPass::test_extract_subgraph_with_initializers
Stack Traces | 0.003s run time
.../passes/common/graph_extration_test.py:65: in test_extract_subgraph_with_initializers
    self.assertEqual(len(result.model.graph.nodes), 3)
E   AttributeError: 'Graph' object has no attribute 'nodes'
onnxscript.ir.passes.common.graph_extration_test.TestExtractGraphPass::test_extract_subgraph_with_subgraph
Stack Traces | 0.004s run time
.../passes/common/graph_extration_test.py:119: in test_extract_subgraph_with_subgraph
    self.assertEqual(len(result.model.graph.nodes), 1)
E   AttributeError: 'Graph' object has no attribute 'nodes'

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

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