Skip to content

Qualcomm: skip higher-order ops in LiftConstantScalarOperands - #22252

Open
psiddh wants to merge 2 commits into
pytorch:mainfrom
psiddh:qnn-liftconst-skip-hop
Open

psiddh wants to merge 2 commits into
pytorch:mainfrom
psiddh:qnn-liftconst-skip-hop

Conversation

@psiddh

@psiddh psiddh commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

The pass inspects node.target._schema to lift scalar operands, but higher-order ops (e.g. wrap_with_set_grad_enabled from a torch.no_grad block) have no OpOverload schema, so the pass crashed with AttributeError on a valid exported program (surfaced exporting Mamba2 / Mixtral MoE via the QNN backend). Skip non-OpOverload targets.

cc @cbilgin

Copilot AI lite review requested due to automatic review settings August 28, 2026 07:08
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ 2 Pending, 1 Unrelated Failure

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

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 added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 28, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: psiddh / name: Siddartha Pothapragada (e9a0b00)

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

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

@psiddh
psiddh marked this pull request as draft August 28, 2026 07:10
@psiddh
psiddh marked this pull request as ready for review September 24, 2026 15:55
Copilot AI review requested due to automatic review settings September 24, 2026 15:55

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

The fix is covered by regression tests and has no unresolved blocking issues.

Review effort: Lite
Findings: None

@psiddh psiddh added the module: qnn Issues related to Qualcomm's QNN delegate and code under backends/qualcomm/ label Sep 24, 2026
Copilot AI review requested due to automatic review settings September 24, 2026 16:00

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

🔵 Needs a closer look

Preserve scalar lifting for EdgeOpOverload targets instead of excluding all non-OpOverload targets.

Review effort: Lite
Findings: None

@shewu-quic shewu-quic 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.

Thanks for looking into this issue. Could you please add a test to our new test framework?

diff --git a/backends/qualcomm/tests/rework/src/pattern.py b/backends/qualcomm/tests/rework/src/pattern.py
index f6ea8c2fae..3f44d8b786 100644
--- a/backends/qualcomm/tests/rework/src/pattern.py
+++ b/backends/qualcomm/tests/rework/src/pattern.py
@@ -4456,6 +4456,12 @@ class LiftConstantScalarOperands:
     class _Where(torch.nn.Module):
         def forward(self, x):
             return torch.where(x > 0, 1.0, 0.0)
+
+    class _HigherOrderOps(torch.nn.Module):
+        def forward(self, x):
+            with torch.no_grad():
+                y = x + 1
+            return y * 2

     @staticmethod
     @unpack_pass_fixtures
@@ -4526,6 +4532,10 @@ class LiftConstantScalarOperands:
                     f"got {n.meta['val'].dtype} (use_self_dtype broken?)"
                 )

+        with subtests.test(msg="skip_higher_order_ops"):
+            gm = lower(LiftConstantScalarOperands._HigherOrderOps())
+            assertions.assert_target_count(gm, torch.ops.higher_order.wrap_with_set_grad_enabled, 1)
+

 class LpaiPartitionFallbackSupport:
     _SKIP_NODE_ID_SET = {"aten_add_tensor", "aten_mean_dim"}

…ands

LiftConstantScalarOperands reads node.target._schema to decide which scalar
operands to lift. A torch.no_grad() region is captured as a higher-order op
(wrap_with_set_grad_enabled) whose target carries no schema, so the pass raised
AttributeError on an otherwise valid program. This blocks quantization for any
model that traces a no_grad block, which includes the transformers decoder-only
LLMs going through the ExecuTorch exporter.

Skip nodes whose target has no _schema. Testing for the attribute the pass
actually reads, rather than for the OpOverload type, keeps EdgeOpOverload
targets lifting should the pass ever move into the capture pipeline.

Adds a unit test in tests/test_passes.py and the requested subtest in the
rework framework; both fail before the change and pass after.
Copilot AI lite review requested due to automatic review settings September 29, 2026 20:38
@psiddh
psiddh force-pushed the qnn-liftconst-skip-hop branch from 563428a to e9a0b00 Compare September 29, 2026 20:38
@psiddh

psiddh commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

@shewu-quic added the subtest to the rework framework as suggested : _HigherOrderOps + skip_higher_order_ops in pattern.py. pytest backends/qualcomm/tests/rework/passes/test.py::test_lift_constant_scalar_operands gives 16/16 with the fix, 12/16 without

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 comments; the schema guard and regression coverage address the reported crash.

Review effort: Lite
Findings: None

@shewu-quic shewu-quic 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.

LGTM. Thanks

Copilot AI lite review requested due to automatic review settings September 30, 2026 00: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.

Copilot review overview

🟢 Approval recommended

No unresolved issues were identified, and regression coverage is included.

Review effort: Lite
Findings: None

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. 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.

4 participants