Skip to content

[ET-VK] Synthesize the layer_norm affine parameters that are absent - #22506

Open
msluszniak wants to merge 1 commit into
pytorch:mainfrom
msluszniak:ms/vulkan-layer-norm-optional-affine
Open

[ET-VK] Synthesize the layer_norm affine parameters that are absent#22506
msluszniak wants to merge 1 commit into
pytorch:mainfrom
msluszniak:ms/vulkan-layer-norm-optional-affine

Conversation

@msluszniak

Copy link
Copy Markdown
Contributor

Fixes #22504.

add_native_layer_norm_node already synthesizes a zero bias for nn.LayerNorm(bias=False), but still throws on a missing weight. F.layer_norm called with no affine parameters at all is an ordinary call, used whenever a module applies its own scale and shift afterwards, and it currently makes the model abort at prepack.

This synthesizes a unit weight the same way, sizing it from normalized_shape when there is no weight tensor to take a shape from. A unit weight and a zero bias reproduce out = (x - mean) * rstd exactly. The two paths now share one helper.

Verified on device: kokoro's duration predictor, whose AdaLayerNorm normalizes with no affine parameters, aborts on main and runs to completion with this change on an Adreno 840.

cases.py gains three native_layer_norm cases covering weight-only, bias-only and neither.

The layer_norm shader reads a weight and a bias binding unconditionally, and
add_native_layer_norm_node already synthesized a zero bias for
nn.LayerNorm(bias=False). A missing weight was still a hard error, so any model
that calls F.layer_norm with no affine parameters at all aborts at prepack with
"native_layer_norm requires weight to be non-None".

That call is not unusual: kokoro's AdaLayerNorm normalizes with no affine
parameters and applies its own style-conditioned scale and shift afterwards.

Synthesize a unit weight the same way, sized from normalized_shape when there
is no weight tensor to take a shape from. A unit weight and a zero bias
reproduce out = (x - mean) * rstd exactly. The two paths now share one helper.
@msluszniak
msluszniak requested a review from SS-JIA as a code owner September 3, 2026 06:50
@pytorch-bot

pytorch-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⚠️ 15 Awaiting Approval

As of commit 11519e8 with merge base a6b115b (image):

AWAITING APPROVAL - The following workflows need approval before CI can run:

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 Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026

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.

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ET-VK] native_layer_norm rejects a missing weight, so affine-free F.layer_norm cannot run

2 participants