[ET-VK] Synthesize the layer_norm affine parameters that are absent - #22506
Open
msluszniak wants to merge 1 commit into
Open
[ET-VK] Synthesize the layer_norm affine parameters that are absent#22506msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
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.
🔗 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.
|
This PR needs a
|
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.
Fixes #22504.
add_native_layer_norm_nodealready synthesizes a zero bias fornn.LayerNorm(bias=False), but still throws on a missing weight.F.layer_normcalled 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_shapewhen there is no weight tensor to take a shape from. A unit weight and a zero bias reproduceout = (x - mean) * rstdexactly. The two paths now share one helper.Verified on device: kokoro's duration predictor, whose
AdaLayerNormnormalizes with no affine parameters, aborts onmainand runs to completion with this change on an Adreno 840.cases.pygains threenative_layer_normcases covering weight-only, bias-only and neither.