Make ScalelessRMSNorm a torch.nn.RMSNorm; fix SDPACustom view -> reshape (#19376)#19376
Open
navsud wants to merge 1 commit intopytorch:mainfrom
Open
Make ScalelessRMSNorm a torch.nn.RMSNorm; fix SDPACustom view -> reshape (#19376)#19376navsud wants to merge 1 commit intopytorch:mainfrom
navsud wants to merge 1 commit intopytorch:mainfrom
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19376
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 3 PendingAs of commit 07aa7e5 with merge base 91aef57 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Contributor
|
@navsud has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104258950. |
billmguo
approved these changes
May 7, 2026
…ape (pytorch#19376) Summary: Pull Request resolved: pytorch#19376 Two related changes that together unblock the QNN export path for VLM/STITO: (1) ScalelessRMSNorm: re-implement as torch.nn.RMSNorm subclass ScalelessRMSNorm was previously implemented as a hand-rolled RMS normalization (decomposed into mean / rsqrt / mul). On the QNN export path, this decomposition fails to lower for an LLM. Using torch.nn.RMSNorm() directly works. Re-implement ScalelessRMSNorm as a torch.nn.RMSNorm subclass whose weight is hardcoded to ones and frozen (requires_grad=False). This keeps the public interface (ScalelessRMSNorm(dim, eps)) unchanged while letting backends see a proper RMSNorm op so it composes/decomposes cleanly for QNN. (2) SDPACustom / QuantizedSDPA: replace .view() with .reshape() Switching to torch.nn.RMSNorm changes how strides propagate through the export graph compared to the hand-rolled decomposition, exposing a latent bug in source_transformation/sdpa.py. The output of torch.ops.llama.custom_sdpa retains the non-contiguous (transposed) strides of its inputs, so output.view(bsz, seqlen, self.dim) — which merges the last two dims (n_heads, head_dim) — fails during torch.export with: Cannot view a tensor with shape (1, s0, 32, 64) and strides (2048*s0, 64, 64*s0, 1) as a tensor with shape (1, s0, 2048) Switching to .reshape() inserts .contiguous() only when needed and matches the pattern already used elsewhere in this file (SDPASimple, SDPAFlex, SDPACoreML, and attention.py). Reviewed By: billmguo, telgamal-1 Differential Revision: D104258950
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Two related changes that together unblock the QNN export path for VLM/STITO:
(1) ScalelessRMSNorm: re-implement as torch.nn.RMSNorm subclass
ScalelessRMSNorm was previously implemented as a hand-rolled RMS normalization
(decomposed into mean / rsqrt / mul). On the QNN export path, this decomposition
fails to lower for an LLM. Using torch.nn.RMSNorm() directly works.
Re-implement ScalelessRMSNorm as a torch.nn.RMSNorm subclass whose weight is
hardcoded to ones and frozen (requires_grad=False). This keeps the public
interface (ScalelessRMSNorm(dim, eps)) unchanged while letting backends see a
proper RMSNorm op so it composes/decomposes cleanly for QNN.
(2) SDPACustom / QuantizedSDPA: replace .view() with .reshape()
Switching to torch.nn.RMSNorm changes how strides propagate through the export
graph compared to the hand-rolled decomposition, exposing a latent bug in
source_transformation/sdpa.py. The output of torch.ops.llama.custom_sdpa retains
the non-contiguous (transposed) strides of its inputs, so
output.view(bsz, seqlen, self.dim) — which merges the last two dims
(n_heads, head_dim) — fails during torch.export with:
Switching to .reshape() inserts .contiguous() only when needed and matches the pattern already used elsewhere in this file (SDPASimple, SDPAFlex, SDPACoreML, and attention.py).
Reviewed By: billmguo, telgamal-1
Differential Revision: D104258950