fix: apply x_stride1 in the rmsnorm normalize pass - #1468
Open
truong-v wants to merge 1 commit into
Open
Conversation
_rms_norm_fwd_fused honours x_stride1 when accumulating the variance and y_stride1 when storing, but the normalize pass loads X + cols, so an input whose last-dim stride is not 1 is normalised from the wrong elements.
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 #1467
_rms_norm_fwd_fusedhonoursx_stride1when it accumulates the variance, and honoursy_stride1when it stores, but the normalize pass readsX + cols. For any input whose last-dim stride is not 1 the row's RMS is therefore computed from the right elements while the values it scales come from elsewhere, and the output is silently wrong.rmsnorm_forwardreaches the kernel with such a tensor without complaint:x.view(-1, x.shape[-1])is shape-preserving for a 2-D input and succeeds whatever the strides are, andtorch.empty_like(x)gives the output matching strides.The
gemma4,deepseek3_2andNormWeightcall sites all pass last-dim-contiguous tensors today, so no shipped model is affected —deepseek3_2'scache_kv[:, :, :kv_lora_rank]slice keeps stride 1 on the last dim. This makes the kernel consistent with the strides it already accepts.Testing
New
unit_tests/common/basemodel/triton_kernel/test_rmsnorm.py, 12 cases (3 shapes × with/without weight × contiguous/strided). All 12 pass with this change. Reverting the kernel and keeping the tests fails the 6 strided cases and passes the 6 contiguous ones.Against
torch_rms_normfrom the same module, atM=64, N=256float32:Performance
triton.testing.do_benchon an NVIDIA B200, three interleaved before/after rounds:No measurable cost — the kernel is memory-bound and the variance pass already does the same multiply.
black --line-length=120andflake8with the repo's pre-commit arguments are clean on both files.Environment
ModelTC/lightllmatfe9bdabfc331b990124f1ec27daf6bb7945cf7ee