Repository navigation
Conversation
Default OPUS_FP32_to_BF16_DEFAULT to 0 (RNE) for module_rmsnorm_quant, module_rmsnorm and module_fused_qk_rmsnorm_group_quant. Truncation biased bf16 outputs and residuals toward zero on targets without a hardware bf16 cvt (e.g. gfx942), where RNE runs in software and costs extra latency on small shapes.
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
|
Thanks @Arist12. We verified this on MI300X (gfx942) with vLLM 0.29.0: PR head Accuracy. Stock rounds ~50% of RMSNorm outputs 1 ulp toward zero (bias -2.8e-3), and the residual stream shrinks 7.1% over Qwen3-1.7B's 56 fused add+norm calls. Patched outputs are 99.999% exact and
Cost. RMSNorm kernel time at decode sizes (1-1024 rows): +12-21% norm and +27-34% fused add at hidden 2048, +33-64% fused add at hidden 4096, in line with your table. End-to-end vLLM decode on Qwen3-1.7B: -1.1% to -1.9% (batch 1-128). One outlier we haven't explained: +83% for norm at 4096 rows × hidden 4096, where your table shows +4%. Same truncation as #5151. |
|
Thanks @lohiaj for the independent verification, and for pointing to #5151. @xiaohong42 reported the same bug a month earlier with verl evidence; I'll add We reran on your setup: The 4096 × 4096 outlier. We couldn't reproduce it. At this shape,
Our full graph-replay sweep gives +7% here on both 0.1.19 and aiter main, one of the smaller norm slowdowns. If you can share your script, happy to take a look. End to end. vLLM 0.29, Qwen3-1.7B, On gating by
Gating would avoid the RNE overhead on the quant kernels at decode. On aiter main at M ≤ 256, that overhead is +13–49% for i8 / fp8 dynamic quant and +10–27% for group-128 fp8. But FP8 / INT8 models would keep the drift. The bf16 path, which pays more (+22–108%), needs RNE either way. I'd keep RNE on all paths. Recovering the kernel cost (follow-up). The bf16 conversion in On the HIP path it removes most of the cost: fused add at 1 × 8192 drops from +108% to +32%, and norm at 1 × 4096 from +20% to −1%. On the opus kernels (hidden > 8192) the result is mixed:
It needs per-kernel work and touches a shared helper, so I'd do it in a separate PR once this one lands. |
|
Helllo, could you help to test #6300 on top of this PR to check whether rollout-versus-trainer accuracy meets your requirements? |
|
PR #6300 has already been merged and addresses the BF16 truncation issue discussed here by switching the affected RMSNorm and residual-add paths to round-to-nearest-even (RNE). It also introduces a faster software RNE conversion to reduce the performance overhead compared with the original RNE implementation. On the common HIP path, the measured overhead relative to truncation is approximately 0–7.1% for RMSNorm and 0–11.0% for fused residual-add. Since the fix has landed in #6300, I’ll close this PR for now. Please rebuild the affected JIT modules with AITER_REBUILD=1 before testing. |
Summary
The RMSNorm kernels behind
rmsnorm2d_fwdandrmsnorm2d_fwd_with_add, andfused_qk_rmsnorm_group_quant, store bf16 by truncating fp32 on targets without a hardware bf16 cvt, such as gfx942 (MI300X / MI325X). That rounds every inexact output toward zero, includingresidual_out(input + residual).This PR switches them to round-to-nearest-even, which is what PyTorch does and what the hardware cvt does on gfx950 / gfx12. It's a trade: on gfx942, decode-size calls get slower (see Performance).
Motivation
#4059 chose truncation for two reasons: software RNE costs about 6 ops per element on gfx942, and truncation matched the CK/HIP reference bit for bit. But the error from truncation is one-sided, so it accumulates through the residual stream.
We hit this in miles, an RL framework. sglang (using these kernels) generates the rollouts; Megatron / Transformer Engine trains. The metric is the mean per-token |logp_rollout − logp_train|, measured with miles' Qwen2.5-0.5B GRPO test (
tests/e2e/short/test_qwen2.5_0.5B_gsm8k_short.py). Hidden size is 896, so onlymodule_rmsnorm_quantruns.module_rmsnorm_quantbuilt withOPUS_FP32_to_BF16_DEFAULT=0Switching only RoPE to native, or attention to triton, leaves the diff unchanged. cc @carlushuang
Changes
Change the default of
OPUS_FP32_to_BF16_DEFAULTfrom 2 (truncate) to 0 (RNE, the existingfp32_to_bf16_rtn_raw) in three places:module_rmsnorm_quantrmsnorm2d_fwd*for 2-D bf16/fp16 inputs with hidden ≤ 8192, non-T5optCompilerConfig.json(env override kept)module_rmsnormrmsnorm2d_fwd*case (see_use_hip_commoninaiter/ops/rmsnorm.py)rmsnorm_opus_kernel.hppmodule_fused_qk_rmsnorm_group_quantfused_qk_rmsnormwith per-token or group quant; affects its bf16q_out_unquantized,k_outandq_res_outoptCompilerConfig.json(env override kept)rmsnorm2d_fwd*picks between them by shape.aiter.rmsnorm, andop_tests/test_fused_qk_rmsnorm_per_token_quant.pychecks itsk_outbit-exactly. Left on truncation, q/k norm and the residual stream would round differently.fused_qk_rmsnormpath, are left for follow-ups.Behavior change: this affects targets without a hardware bf16 cvt: gfx942, and gfx950 / gfx12 built with clang < 20.
Performance
MI300X, GPU time per call, measured with HIP graphs:
fused_qk_rmsnorm_group_quant: +6–10% at m = 8192 / 16384, per the test's own timing. Smaller shapes are within noise.The compiler's native conversion,
static_cast<bf16_t>, is cheaper. opus already uses it on gfx950, and it gives bit-identical RNE results: the 1 × 4096 fused add drops to 2.2 µs and the 1 × 16384 one to 10.1 µs. It changes the shared helper inopus.hpp, though, so we'd put it in a follow-up.Testing
On MI300X, the three residual checks in
op_tests/test_rmsnorm2d.pynow require an exact match with PyTorch'sinput + residual(rtol=0, atol=0, tol_err_ratio=0):Before / after on related tests:
test_rmsnorm2dFusedAddQuant(vs PyTorch, atol=0.01)test_fused_qk_rmsnorm_per_token_quantmodule_rmsnorm_quantflipped:k_outfails)test_fused_qk_rmsnorm_group_quanttest_gated_rmsnorm_fp8_quantTo reproduce, rebuild with
AITER_REBUILD=1. Otherwise a cachedmodule_*.sokeeps the old rounding.