Skip to content

fix: honor x_stride1 in rmsnorm normalize pass - #1782

Open
YuvrajSinghBhadoria2 wants to merge 1 commit into
ModelTC:mainfrom
YuvrajSinghBhadoria2:fix/rmsnorm-normalize-pass-stride
Open

YuvrajSinghBhadoria2 wants to merge 1 commit into
ModelTC:mainfrom
YuvrajSinghBhadoria2:fix/rmsnorm-normalize-pass-stride

Conversation

@YuvrajSinghBhadoria2

Copy link
Copy Markdown
Contributor

What

_rms_norm_fwd_fused accepts x_stride1 and uses it in the variance pass, and the store uses y_stride1, but the normalize pass loaded the input as if its last dim were contiguous:

x = tl.load(X + cols, mask=mask, other=0.0).to(tl.float32)

For an input with stride(-1) != 1 the row RMS was computed from the correct elements while the values scaled by that RMS were read from somewhere else, so the result was silently wrong rather than out of bounds.

This changes the load to X + cols * x_stride1, matching the variance pass above it and the store below it.

Tests

Adds unit_tests/common/basemodel/triton_kernel/test_rmsnorm.py covering:

  • contiguous 2-D input (baseline)
  • last-dim-strided 2-D input (x.t()), compared against the reference and against the same values laid out contiguously
  • out= as a strided view, including a check that padding outside the view is not written
  • fp32 / fp16 / bf16, with and without a weight

The tests require CUDA and I did not run them locally (this machine has no GPU and no torch/triton); they are written to pytest.skip without CUDA so the CPU test jobs stay green. The kernel change is a one-line index fix and does not alter the launch configuration.

Relation to #1468

This replaces #1468, which carries the identical one-line change but also adds an unrelated 232-line fused_moe/deepep_scatter_gather.py that the reviewer asked to remove; that PR has been untouched since August. This one contains only the fix and the regression tests. #1468 reported the strided fp32 max error going from 5.83 to 0.0 on a B200 for the same change, with no measurable perf cost.

Fixes #1467.

Signed-off-by: Yuvraj Singh Bhadoria yuvrajsinghbhado2030@gmail.com

The variance pass and the output store already honour x_stride1/y_stride1,
but the normalize pass loaded X + cols as if the last dim were contiguous.
For an input whose last-dim stride is not 1 the row RMS was computed from
the correct elements while the values scaled by that RMS were read from
somewhere else, so the output was silently wrong rather than out of bounds.

Read with cols * x_stride1 in the normalize pass, and add regression tests
covering contiguous, last-dim-strided and out= view inputs in fp32, fp16
and bf16, with and without a weight.

Fixes ModelTC#1467.

Signed-off-by: Yuvraj Singh Bhadoria <yuvrajsinghbhado2030@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] _rms_norm_fwd_fused drops x_stride1 in its normalize pass, so a non-unit last-dim stride gives wrong output

1 participant