Skip to content

Qualcomm AI Engine Direct - Move QCOM_AXIS_ORDER pop into LayoutTransform pass - #21932

Merged
psiddh merged 2 commits into
pytorch:mainfrom
CodeLinaro:dev1/boru/layoutTransform-refactor-v2
Oct 6, 2026
Merged

psiddh merged 2 commits into
pytorch:mainfrom
CodeLinaro:dev1/boru/layoutTransform-refactor-v2

Conversation

@paul1106

@paul1106 paul1106 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Context

This PR supersedes #21630.

The original PR was closed due to CLA issues.
This new PR is created from a new branch to track CLA status and continue the review process.

Please refer to #21630 for previous review comments and discussion.

Summary:

  • The pop of QCOM_AXIS_ORDER was previously done in
    QnnBackend._build_op_wrappers before calling
    transform_for_preprocess_pipeline. Moving it into
    LayoutTransform.call() when insert_permute=True keeps the cleanup
    logic co-located with the code that depends on it.

  • The pop is necessary because the delegated subgraph is created via
    deepcopy, which carries over the QCOM_AXIS_ORDER tags written by the
    to-edge LayoutTransform run. Without clearing them, is_transformed_node()
    returns True for every sensitive node in the
    main for-loop, causing all traversals to be skipped and no permute
    nodes to be inserted.

Test plan

python -m backends.qualcomm.tests.test_qnn_delegate TestQNNQuantizedOperator  --device ${SERIAL_NUM}   --soc_model ${SOC_MODEL}   --build_folder build-android   --executorch_root .

cc @cccclai @winskuo-quic @shewu-quic @haowhsu-quic @DannyYuyang-quic @cbilgin @abhinaykukkadapu @psiddh

Copilot AI lite review requested due to automatic review settings August 19, 2026 03:35
@pytorch-bot

pytorch-bot Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21932

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Unrelated Failure

As of commit e209ca4 with merge base 273cb33 (image):

NEW FAILURE - The following job has failed:

  • Cadence Build & Test / Resolve CI docker image / resolve (gh)
    ##[error]Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla

meta-cla Bot commented Aug 19, 2026

Copy link
Copy Markdown

Hi @paul1106!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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 relocates cleanup of the QCOM_AXIS_ORDER node metadata from QnnBackend._build_op_wrappers into the LayoutTransform pass itself (specifically when insert_permute=True), so the metadata invalidation happens next to the logic that depends on it. This prevents inherited QCOM_AXIS_ORDER tags (carried via deepcopy) from making LayoutTransform.is_transformed_node() incorrectly treat all sensitive nodes as already-processed, which would otherwise suppress permute insertion during preprocessing.

Changes:

  • Remove the QCOM_AXIS_ORDER metadata pop from backends/qualcomm/qnn_preprocess.py preprocessing entrypoint.
  • Add a targeted QCOM_AXIS_ORDER metadata pop inside LayoutTransform.call() when running the permute-inserting mode (insert_permute=True).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
backends/qualcomm/qnn_preprocess.py Removes early QCOM_AXIS_ORDER meta cleanup from _build_op_wrappers, delegating it to the pass that relies on it.
backends/qualcomm/_passes/layout_transform.py Clears inherited QCOM_AXIS_ORDER tags before the main sensitive-node traversal when insert_permute=True, ensuring permute insertion logic executes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@paul1106

paul1106 commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor Author

This PR supersedes #21630.

The original PR was closed due to CLA issues.
This new PR is created from a new branch to track CLA status and continue the review process.

Please refer to #21630 for previous review comments and discussion.

Copilot AI review requested due to automatic review settings August 19, 2026 06:35

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@executorch-triage executorch-triage Bot added the community: contribution PRs coming from community (excluding hardware partners) label Sep 22, 2026
@nil-is-all nil-is-all removed the community: contribution PRs coming from community (excluding hardware partners) label Sep 24, 2026
…form pass

Summary:
      - The pop of QCOM_AXIS_ORDER was previously done in
      QnnBackend._build_op_wrappers before calling
      transform_for_preprocess_pipeline. Moving it into
      LayoutTransform.call() when insert_permute=True keeps the cleanup
      logic co-located with the code that depends on it.

      The pop is necessary because the delegated subgraph is created via
      deepcopy, which carries over the QCOM_AXIS_ORDER tags written by the
      to-edge LayoutTransform run. Without clearing them, is_transformed_node()
      returns True for every sensitive node in the
      main for-loop, causing all traversals to be skipped and no permute
      nodes to be inserted.
…es_helper

The manual QCOM_AXIS_ORDER strip loop in PassPipeline.lower_preprocess_gm()
was added to mirror qnn_preprocess.py. Now that the pop is handled inside
LayoutTransform.call() when insert_permute=True, this block is dead code.

Generated with Claude Code
@paul1106
paul1106 force-pushed the dev1/boru/layoutTransform-refactor-v2 branch from f701d62 to e209ca4 Compare September 30, 2026 03:19
Copilot AI lite review requested due to automatic review settings September 30, 2026 03:19

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

@shewu-quic

Copy link
Copy Markdown
Contributor

Hi @psiddh,
@paul1106 is our intern and will be assisting us with related tasks.
He has rebased PR and signed EasyCLA.
Could you please check whether he has any CLA issues?

@psiddh psiddh added the module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/ label Oct 5, 2026
@psiddh

psiddh commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

MetaCLA Is no longer needed, merginf

@psiddh
psiddh merged commit ba8b711 into pytorch:main Oct 6, 2026
7 of 8 checks passed
meta-codesync Bot pushed a commit that referenced this pull request Oct 7, 2026
…ransform

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0) (oldest at bottom):
* __->__ #23528

D123733351 (#21932) moved the `QCOM_AXIS_ORDER` pop from `QnnBackend._build_op_wrappers` into `LayoutTransform`. `test_qnn_backend_draw_graph` calls `transform_for_preprocess_pipeline` directly, so it previously never cleared the stale to-edge tags and `LayoutTransform` inserted no permutes. Its goldens captured that graph, which real lowering never produces.

The test now sees the same graph as `preprocess`: an NCHW->NHWC `permute_copy` feeding both convs, the graph input at its original `[1, 32, 28, 28]` shape, and (quantized only) an NHWC->NCHW `permute_copy` before the output dequantize. Update both goldens to match.

Authored with Claude Code.

Differential Revision: D123874998

Pull Request resolved: #23528
SS-JIA added a commit that referenced this pull request Oct 7, 2026
…ransform

D123733351 (#21932) moved the `QCOM_AXIS_ORDER` pop from `QnnBackend._build_op_wrappers` into `LayoutTransform`. `test_qnn_backend_draw_graph` calls `transform_for_preprocess_pipeline` directly, so it previously never cleared the stale to-edge tags and `LayoutTransform` inserted no permutes. Its goldens captured that graph, which real lowering never produces.

The test now sees the same graph as `preprocess`: an NCHW->NHWC `permute_copy` feeding both convs, the graph input at its original `[1, 32, 28, 28]` shape, and (quantized only) an NHWC->NCHW `permute_copy` before the output dequantize. Update both goldens to match.

Authored with Claude Code.

Differential Revision: [D123874998](https://our.internmc.facebook.com/intern/diff/D123874998/)


ghstack-source-id: 443606972
Pull-Request: #23528
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants