Triton RMSNorm Optimizations#593
Open
Micky774 wants to merge 5 commits into
Open
Conversation
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.
Description
Optimizes the Triton RMSNorm forward and backward kernels and adds an LDS-tiled FP8 transpose path. Measured 10%-50% improvements across a representative shape sweep for bf16 w/ no quantization or FP8 quant, and improvements of 3x-8x on FP8 Transpose outputs.
Benchmarks generated by this script.
Results
Note that below A refers to the baseline implementation on
devwhile B is the PR's implementation.Type of change
Changes
Please list the changes introduced in this PR:
dgaccumulation refactor. Shrunk thedg_tmppartial buffer from(M, N)to(NUM_PRGMS, N)fp32 with per-program HBM RMW accumulation. The smaller buffer is L2-resident on typical workloads, turning the RMW into a near-free op.gammaload +ZERO_CENTERED_GAMMAadjustment +1/n_colshoisted outside the persistent row loop.gammahoist;inv_n_colshoisted.c_scalar = nf*nf*grad_sum*inv_n_colscomputed once before the dx/dg loop;dxexpression refactored tonf * (dz*g - c*x)(saves one multiply per element)._rmsnorm_bwd_tritonand_rmsnorm_bwd_dg_reduce_tritonnow follow the impl + autotune-wrapper dispatch pattern already used by the fwd kernel.te_rmsnorm_bwd_tritontakes anautotune: bool = Truekwarg; when off it uses the previously-hardcodednum_warps=8+ fixedBLOCK_SIZE_M/N=128/64reduce tile._fp8_transpose_2d_impl(+ autotune wrapper) replaces the in-kernelout_transpose_ptr + cols * stride + row_idxstrided byte stores that were uncoalesced (one byte per thread to a different cache line). The new kernel does a coalesced(BLOCK_M, BLOCK_N)read,tl.trans()for LDS-staged transpose, then coalesced strided write. Gated by env varNVTE_RMS_EXTERNAL_TRANSPOSE(default on); set to0to fall back to the in-kernel path.Checklist: