Skip to content

Fix type/shape inferencing double recursion for subgraphs#29617

Open
skottmckay wants to merge 2 commits into
mainfrom
skottmckay/FixSubgraphTypeShapeInferencingRecursion
Open

Fix type/shape inferencing double recursion for subgraphs#29617
skottmckay wants to merge 2 commits into
mainfrom
skottmckay/FixSubgraphTypeShapeInferencingRecursion

Conversation

@skottmckay

Copy link
Copy Markdown
Contributor

Description

The secondary recursion in VerifyNodeAndOpMatch results in recursion on top of recursion for operators that do subgraph recursion via the ONNX type/shape inferencing path.

For a model with deep nesting this results in model load taking an extreme amount of time.

Memoize the subgraphs that have been processed to avoid this.

Motivation and Context

…on top of recursion for operators that do subgraph recursion via the ONNX type/shape inferencing path.

For a model with deep nesting this results in model load taking an extreme amount of time.

Memoize the subgraphs that have been processed to avoid this.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 reduces pathological model-load time for deeply nested control-flow subgraphs by memoizing which subgraphs have already been type/shape-inferred (and therefore verified) during a Resolve pass, so the later “verify subgraphs” sweep can skip redundant VerifyNodeAndOpMatch recursion.

Changes:

  • Track subgraphs that were processed via ONNX subgraph type/shape inference (e.g., Scan/If/Loop) in ResolveContext.
  • Skip redundant VerifyNodeAndOpMatch calls for those already-processed subgraphs to avoid exponential re-traversal.

Reviewed changes

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

File Description
onnxruntime/core/graph/graph.cc Records subgraphs inferred via InferAndVerifySubgraphTypes and skips redundant subgraph verification during VerifyNodeAndOpMatch.
include/onnxruntime/core/graph/graph.h Extends ResolveContext with an inferred_subgraphs set and clears it as part of context reset.

Comment thread onnxruntime/core/graph/graph.cc
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.

2 participants