Check dim order in the optimized layer_norm as the portable one does - #21866
Open
SuryanshSS1011 wants to merge 1 commit into
Open
Check dim order in the optimized layer_norm as the portable one does#21866SuryanshSS1011 wants to merge 1 commit into
SuryanshSS1011 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21866
Note: Links to docs will display an error until the docs builds have been completed.
|
Contributor
Author
|
@pytorchbot label "release notes: ops & kernels" |
SuryanshSS1011
force-pushed
the
fix/optimized-layer-norm-dim-order
branch
from
August 15, 2026 03:48
05bbe79 to
128d5cb
Compare
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
Related to #21828 and #21865 (same underlying assumption in the optimized kernel library).
aten.native_layer_normreturns wrong data on a channels-last input, off by 3.192 against eager PyTorch where it matches exactly on contiguous input. Nothing errors.The portable kernel is fine. It carries this, with the reason written down:
The optimized kernel has neither that check nor the matching
tensors_have_same_dim_order, andnative_layer_norm.outis mapped totorch::executor::opt_native_layer_norm_outinoptimized.yaml. So any build withEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ONgets the ungated one.It needs the guard rather than stride-aware indexing, because it splits the buffer into
Mrows ofNcontiguous elements:That layout only exists in the default dim order. This copies the two checks across from the portable kernel so the two agree.
Test plan
OpNativeLayerNormTest.NonDefaultDimOrderDiespasses a channels-last input without,meanandrstdall channels-last, so the same dim order check passes and only the default dim order check can reject.meanandrstdshare the input's rank with the normalized dims set to 1, which the kernel requires before it reaches any dim order check.The test file is shared by both kernel libraries, so it runs against the portable kernel too, where it already passes.