Skip to content

[QNN EP] Add Support for If Op using Graph Transformation #24906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

quic-ashwshan
Copy link
Contributor

  • Currently Onnx graph transform handles only static If Op cases.
    1. When If op input is static and both branches are also static
    2. When if Op input is statifc but branches are dynamic.
  • Extend If Op handling to support dynamic condition and dynamic branches.
  • Lower both subgraphs to the main graph and select output using ONNX Where op.
  • Added unit tests in graph transformer to test dynamic if conditions and ensure that a Where Op is added

Description

This change adds support for lowering ONNX If operations where both the condition and the branches are dynamic. Previously, the ORT transformation logic handled only two cases:

  1. Fully static If nodes were folded to constants.
  2. Semi-dynamic If nodes (static condition, dynamic branches) were partially lowered by selecting the active branch at compile time.

This change now includes the case -
When both the condition and branches are dynamic, both subgraphs are lowered into the main graph, and a Where op is used to select the correct output at runtime.

Motivation and Context

  1. Enables support for dynamic control flow in ONNX models where the condition and both branches of an If node are not statically known.
  2. This also helps offload the op to the NPU for QNN backend.

- Currently Onnx graph transform handles only static If Op cases.
  1. When If op input is static and both branches are also static
  2. When if Op input is statifc but branches are dynamic.
- Extend If Op handling to support dynamic condition and dynamic
  branches.
- Lower both subgraphs to the main graph and select output using ONNX
  Where op.
- Added unit tests in graph transformer to test dynamic if conditions
  and ensure that a Where Op is added
@HectorSVC HectorSVC added the ep:QNN issues related to QNN exeution provider label May 29, 2025
@HectorSVC
Copy link
Contributor

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline,Windows x64 QNN CI Pipeline

Copy link

Azure Pipelines successfully started running 5 pipeline(s).

@HectorSVC HectorSVC removed the ep:QNN issues related to QNN exeution provider label May 29, 2025
@HectorSVC HectorSVC requested a review from skottmckay May 29, 2025 22:03
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