Skip to content

pin Triton RMSNorm/LayerNorm launch configs instead of autotuning - #792

Open
matthiasdiener wants to merge 2 commits into
devfrom
mdiener/rmsnorm-pin-num-warps
Open

matthiasdiener wants to merge 2 commits into
devfrom
mdiener/rmsnorm-pin-num-warps

Conversation

@matthiasdiener

@matthiasdiener matthiasdiener commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #790 (related PRs: #646, #615, #593).

Triton's autotuner picks a launch config per process by timing. For the
RMSNorm and LayerNorm kernels, num_warps (and the RMSNorm dgamma-reduce block
shape) sets the reduction order, so processes running identical
shapes can produce slightly different results.

Launch configs are now fixed by row width:

  • RMSNorm fwd num_warps: 1 (<= 1024), 4 (<= 8192), else 16
  • RMSNorm bwd num_warps: 1 (<= 1024), 4 (<= 2048), else 16
  • RMSNorm dgamma reduce: BLOCK_SIZE_M=128, BLOCK_SIZE_N=64, num_warps=8
  • LayerNorm fwd num_warps: 1 (<= 2048), 4 (<= 6144), else 8; num_stages=1

On gfx950 these are within ~1% geomean of the per-shape best. LayerNorm fwd
is 1.2-2.4x faster at widths <= 2048, which the old config space missed.
The autotune kwargs remain for API compatibility. The FP8 transpose stays
autotuned because its output does not depend on the config.

Also adds a test.

cc @jbelofamd

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

Please list the changes introduced in this PR:

  • Change A
  • Change B

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes


# triton drop-in replacement for transformer_engine::pytorch::rmsnorm_bwd
def te_rmsnorm_bwd_triton(dz, x, rsigma, gamma, sm_margin, zero_centered_gamma, autotune: bool = True):
del autotune # Kept for API compatibility; the bwd launch configs are fixed by width.

@Micky774 Micky774 Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a TE-only API I think we can deprecate this parameter, e.g. set the default to "deprecated" and then warn on usage, and internally force-set it to false.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, thanks. Done (in spirit) in 15d8189; te_rmsnorm_fwd_triton still uses autotuning in part (for the FP8 transpose kernel).

@Micky774 Micky774 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jbelofamd

Copy link
Copy Markdown

Re-checked at 15d8189. The new commit only changes how the autotune argument is handled (deprecation warnings) and the tests. The launch-config tables and the kernels are the same as at 0ec0e4a, which is the head we validated above, so that result still holds.

On CI: both red sGPU jobs (mi30x and mi35x) fail only in the examples group, in the JAX MNIST example (examples/jax/mnist/test_single_gpu_mnist.py). Its call to datasets.load_dataset dies while hashing the config: TypeError: Pickler._batch_setitems() takes 2 positional arguments but 3 were given, which comes from dill 0.3.8 running under Python 3.14. The torch, jax and core groups pass on both, so the failure is unrelated to this PR.

Thanks again, @matthiasdiener, and @Micky774 for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-level 1 CI test level 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Triton RMSNorm autotune picks differ across processes and ranks, so the numerics differ; no knob pins or disables them

3 participants