Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
bbaa792 to
ccc7b1a
Compare
Signed-off-by: why1te <youngtingwang@gmail.com>
Keep the RMSNorm gain in FP32 as confirmed with the maintainer. Previously the BF16 storage path discarded gain bits before the operator's FP32 math. Implementation: - Change NormParams validation and seeded fixtures to FP32 gamma. - Read gamma through float pointers in CUDA forward and input-gradient kernels; update Triton dtype validation without changing reduction order. - Preserve BF16 activations, upstream gradients, normalized/residual outputs, and FP32 explicit dx/dgamma. Autograd returns BF16 x.grad and FP32 gamma.grad. - Update gtest/benchmark input generation and record benchmark gamma dtype. - Adapt direct callers to the oracle backward signature without x; keep provider/backend interfaces with explicit x through the reference adapter. - Add tests using gamma=1+2**-10 to detect premature BF16 rounding in both forward and backward, plus dtype validation and gradient-precision checks. Golden migration: - Regenerate the CPU-oracle manifest for the approved FP32 input contract. - Update 59 hashes: normalized outputs and gamma-dependent upstream gradients in five block fixtures, plus y/grad.dx in rms_edges. - Leave Sinkhorn-edge, residual, and dgamma hashes unchanged and retain strict manifest equality; no candidate output is used as a golden value. - The migration validation recorded in the original refresh commit rounded gamma through BF16 in a diagnostic process and reproduced the entire old manifest. No diagnostic rounding was added to production code or tests. H100 PCIe validation (PyTorch 2.8.0+cu128, Triton 3.4.0, CUDA 12.8): - uv run --no-sync python -m pytest tests/test_rmsnorm_residual.py tests/test_rmsnorm_residual_triton.py -q -rs: 28 passed in 7.89s. - uv run --no-sync python -m pytest tests/test_rmsnorm_residual_gamma_precision.py -q: 4 passed in 2.63s. - uv run --no-sync python -m pytest tests/test_p1_oracle.py tests/test_p1_provider.py tests/test_operator_inputs.py tests/test_kernel_registry.py -q: 77 passed in 2.16s, including the anchor. - check_operator.py for cuda and triton at T=16/D=4096 with --check-grad: both passed, zero reported errors, gamma gradient FP32. - check_p1.py for both providers: all boundaries byte-equal in all five cases. - Benchmark at T=32768/131072/262144, D=4096, 50 warmup/1000 iterations: both candidates byte-equal to the oracle before timing; CUDA combined speedup 1.27-1.31x versus torch-native on these measured workloads. Squashes the FP32 implementation and reviewed golden refresh into one atomic contract migration. The source tree is unchanged from 6b24500. Signed-off-by: why1te <youngtingwang@gmail.com>
Document public and explicit APIs, FP32 gamma and gradient boundaries, fixed-order arithmetic, backend dispatch, validation commands, H100 results, and rank-local limitations. Add the operator page to the documentation index and navigation. Validation: Python and shell example syntax, YAML navigation, and git diff checks passed. Full MkDocs build not run because MkDocs is not installed in the local environment. Signed-off-by: why1te <youngtingwang@gmail.com>
Signed-off-by: Zhang Jian <jianmusings@gmail.com>
zhangj1an
left a comment
There was a problem hiding this comment.
LGTM. Thank you!
This PR implements rmsnorm_residual using CUDA and Triton backends.
Forward: y = (x · r) · gamma, whereby r = rsqrt(mean(x²) + eps).
Backward: since y = x · r · gamma, need to calculate dx and dgamma.
for dx: dx = r · (dy · gamma) − x · r³ · Σ_d(dy · gamma · x) / D + d_residual. (i asked against gpt to understand this formula derivation).
for dgamma: Σ_t (dy · x · r), whreby t means tokens, as every token uses the same gamma.
Both backends are byte-equal to the oracle (fixed-order reductions, mul/add separated, rsqrt not 1/sqrt).
We agreed via dm to use FP32 gamma. So the oracle was updated accordingly.
[DSv4][P1-5] rmsnorm_residual
Summary
Implements P1-5
rmsnorm_residualfrom #383, targetingdsv4-p1-dev. Adds CUDA/Triton forward and backward, autograd, registry fallback, and P1 providers.The operator returns RMS-normalized output plus a copy of the original input—not
RMSNorm(x + residual). Both backends pass bitwise oracle alignment and P1 acceptance on H100.Implementation
dx/dgamma. Autograd returns BF16x.gradand FP32gamma.grad.D=4096in production;D=128for fixtures;eps=1e-6.rsqrt(mean(x²) + eps),(x * r) * gamma, ascending FP32 reductions, and separate rounding. No atomic reductions, Split-K, or Stream-K. Residual copying does not change the reduction layout.Operator documentation:
docs/operators/rmsnorm-residual.md.Validation environment
Correctness / Tests
Coverage:
T={1,7,16},D={128,4096}; byte-equal forward/backward and saved state, edge values, strided inputs, repeatability, batch/padding invariance, both autograd branches, invalid inputs, and FP32 gamma rounding regressions.gtest
Both report
passed=True pass_rate=1.0000. Maximum absolute and relative errors are 0 for both outputs, BF16x.grad, and FP32gamma.grad.P1 acceptance
Both report
RESULT: PASS (all boundaries byte-equal)for all five cases:one_row,packed_t16,packed_t7_odd,fused_pre_norm, andmixer_frozen.Benchmarks
H100 PCIe,
D=4096, BF16 activations, FP32 gamma/explicit gradients; CUDA-event mean, eager execution, no CUDA Graphs. The script runs all three backends; both candidates pass pre-timing bitwise checks. CUDA versus torch-native forward + backward results:CUDA forward speedup is 1.62–1.63×; combined peak extra allocated memory is approximately 71.4% lower. Memory is the allocator peak above the live baseline, not total GPU usage. Torch-native uses vectorized reductions and is a performance baseline, not the fixed-order oracle. Results apply to these measured workloads.
Kernel PR checklist
Follow PR #204.
MHCProvidercheck_p1.pypassing result