Repository navigation
Add fused Allreduce + RMSNorm + MXFP4 quant - #3229
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
|
maybe we need a unified tensor_model_parallel_fused_allreduce_rmsnorm_quant API... |
@valarLip That makes sense. CC: @TennyWang1223 |
Route FP8 per-group and MXFP4 fused allreduce RMSNorm quantization through a generic quant_type selector while keeping compatibility wrappers intact.
Apply Black formatting after rebasing the fused quant API changes onto origin/main.
7a249be to
edff6b9
Compare
|
Hi @valarLip and @TennyWang1223, I have refactored the PR so that we can have an unified
Please help review it again. Thanks! |
Motivation
Quantized ROCm/AITER model paths often follow a layer-boundary pattern where the previous MLP / MoE output is tensor-parallel all-reduced and RMS-normalized before the next attention or MLP block consumes a quantized activation:
Today this runs as three sequential kernels with bf16 traffic between them. AITER already has a fused allreduce + RMSNorm + per-group FP8 quantization path from #2823, and this PR adds an MXFP4 quantization epilogue for DeepSeek-R1-MXFP4. This PR reworks the Python API so both quantization schemes use one generic entry point that can be extended to future quantization formats.
Technical Details
Public API
Return values are
(quantized_out, residual_out, scale). Withemit_bf16=True, the API returns(quantized_out, residual_out, scale, bf16_normed), wherebf16_normedis the bf16-rounded RMSNorm output for shadow consumers such as NSA / indexer paths.The previous public functions remain as compatibility wrappers:
tensor_model_parallel_fused_allreduce_rmsnorm_quant_per_group(...)calls the generic API withquant_type="per_group".tensor_model_parallel_fused_allreduce_rmsnorm_mxfp4_quant(...)calls the generic API withquant_type="mxfp4".Behavior and dispatch
The generic API normalizes quantization aliases and dispatches to the matching implementation:
per_token: existing fused AR+RMSNorm + FP8 per-token quantization path.per_group/per_1x128: fused AR+RMSNorm + FP8 per-group quantization path from Add fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output #2823, with composed fallback tofused_allreduce_rmsnorm+ HIP per-group quantization.mxfp4/per_1x32: new fused AR+RMSNorm + MXFP4 quantization path, with composed fallback tofused_allreduce_rmsnorm+ Tritondynamic_mxfp4_quant.For MXFP4, the implementation auto-selects between specialized direct kernels and fallback based on shape, TP world size, and the kernel’s shared-memory budget. Callers do not need to know which path runs: semantics and the reference composed path match across direct and fallback routes.
AITER_AR_1STAGEis reserved as a test/benchmark override and should be left unset in production.Code map (AITER)
aiter/dist/communication_op.pyaiter/dist/parallel_state.pyaiter/dist/device_communicators/communicator_cuda.pyaiter/dist/device_communicators/custom_all_reduce.pyaiter/ops/custom_all_reduce.pycsrc/include/custom_all_reduce.cuhcsrc/include/custom_all_reduce.hcsrc/include/rocm_ops.hppcsrc/kernels/custom_all_reduce.cuop_tests/multigpu_tests/)test_fused_ar_rms_per_group_quant.py— validates the Add fused AR + RMSNorm + per-group FP8 quant: optional bf16 side-output #2823 FP8 per-group path through the generic APItest_fused_ar_rms_mxfp4_quant.py— CI smoke + local--fullmatrixbenchmark_fused_ar_rms_mxfp4_quant.py— correctness-gated CUDA-graph microbench for MXFP4 direct/fallback/API pathstest_fused_ar_rms_memory_order.py— cross-device memory-orderingregression (same memory-ordering pattern hardened in Fix 2-stage fused_allreduce_rmsnorm memory ordering #2890 for the per-group FP8 2-stage path)
SGLang integration (companion change)
A separate SGLang PR wires
LayerCommunicator.prepare_attnto call the generic API withquant_type="mxfp4"on the DeepSeek-R1-MXFP4 path. It is activated withSGLANG_USE_AITER=1and--enable-aiter-allreduce-fusion, and falls back to the existing fused AR+RMSNorm sequence when any gate (hardware, model, communicator support) fails.Profiling
A torch profiler trace during decode shows
allreduce_fusion_kernel_*_mxfp4active and the layer-boundary_dynamic_mxfp4_quant_kernelcost folding into the fused kernel. The standalone_fused_rms_mxfp4_quant_kernelon the local DeepSeek MLA Q/K RMSNorm+MXFP4 path remains as expected (no all-reduce to fuse).Risks and mitigations
quant_type.test_fused_ar_rms_memory_order.py.Test Plan
AITER unit correctness — FP8 per-group (
test_fused_ar_rms_per_group_quant.py)Validates the previously added #2823 feature through the generic API:
Focused smoke command used during this rework:
AITER unit correctness — MXFP4 (
test_fused_ar_rms_mxfp4_quant.py)CI smoke (picked up by
.github/scripts/aiter_test.sh, no flags): 3 shapes (one per dispatch path) ×tp_size in {2, 4, 8}via the user-facing dispatcher.Local full matrix (developer opt-in, pre-merge / pre-release):
Per row the test reports
mxfp4_dequant_err,residual_err, and optionalbf16_erragainst an fp32 reference of the composed path (tolerances as inTechnical Details).
Focused smoke command used during this rework:
Memory-ordering regression (
test_fused_ar_rms_memory_order.py)CUDA-graph microbench — MXFP4 (
benchmark_fused_ar_rms_mxfp4_quant.py)Dense sweep across
tp_size in {2, 4, 8}and 32 shapes per TP (decode andprefill-style regions for multiple
K). Example driver:Focused command used during this rework:
python3 op_tests/multigpu_tests/benchmark_fused_ar_rms_mxfp4_quant.py \ -t 2 --cuda-graph --warmup 3 --iters 10 \ --shapes "1,4096;16,7168;128,7168"SGLang E2E (companion stack; validates wiring + accuracy)
DeepSeek-R1-MXFP4-Preview at TP=4 with EAGLE,
fp8_e4m3KV, 200k context. Baseline: same server and benchmark commands without--enable-aiter-allreduce-fusion. Fused: add only that flag.Server launch (representative; fused adds
--enable-aiter-allreduce-fusion):SGLANG_ENABLE_OVERLAP_PLAN_STREAM=1 \ SGLANG_ENABLE_SPEC_V2=1 \ ROCM_QUICK_REDUCE_QUANTIZATION=NONE \ SGLANG_AITER_FP8_PREFILL_ATTN=1 \ SGLANG_AITER_MLA_PERSIST=1 \ AITER_MXFP4_MOE_SF=1 \ SGLANG_USE_AITER=1 \ SGLANG_INT4_WEIGHT=0 \ SGLANG_MOE_PADDING=1 \ SGLANG_SET_CPU_AFFINITY=1 \ SGLANG_ROCM_FUSED_DECODE_MLA=1 \ SGLANG_USE_ROCM700A=1 \ SGLANG_DISABLE_FUSED_AR_MXFP4_QUANT=false \ python3 -m sglang.launch_server \ --model-path /data2/deepseek-ai/DeepSeek-R1-MXFP4-Preview/ \ --tensor-parallel-size 4 --trust-remote-code \ --mem-fraction-static 0.9 --chunked-prefill-size 131072 \ --attention-backend aiter \ --speculative-algorithm EAGLE --speculative-num-steps 3 \ --speculative-eagle-topk 1 --speculative-num-draft-tokens 4 \ --max-running-requests 32 --context-length 200000 \ --kv-cache-dtype fp8_e4m3 \ --model-loader-extra-config '{"enable_multithread_load": true, "num_threads": 8}'GSM8K:
Test Result
Generic API rework validation
Focused local validation after the API rework:
py_compile, Black, Ruff, and IDE lints passed on the touched Python files.test_fused_ar_rms_per_group_quant.py -t 2 -s 1,4096 32,4096 --group-size 128 --skip-python-checkpassed throughtensor_model_parallel_fused_allreduce_rmsnorm_quant(..., quant_type="per_group")foremit_bf16=Falseandemit_bf16=True. Reportedper_group_err = 0for all rows.test_fused_ar_rms_mxfp4_quant.py -t 2 -s 1,4096 16,7168 128,7168 --skip-python-checkpassed throughtensor_model_parallel_fused_allreduce_rmsnorm_quant(..., quant_type="mxfp4")acrossdirect_1stage,direct_2stage, and fallback routes. Reportedmxfp4_dequant_err = 0andresidual_err = 0for all rows.1,4096;16,7168;128,7168,--warmup 3 --iters 10; all correctness checks passed and the generic API timing tracked the selected route.Microbench smoke rows:
1 x 409616.5415.2417.9215.6416 x 716823.84inf21.7022.15128 x 716856.60infinf56.92Post-run GPU/core check: no lingering benchmark/test processes and no
gpucore.*dumps found.Existing MXFP4 dense validation
test_fused_ar_rms_mxfp4_quant.py(CI smoke)Every row reported
mxfp4_dequant_err = residual_err = bf16_err = 0.0against the fp32 reference. Use-t Nto restrict to a single TP for debugging.test_fused_ar_rms_mxfp4_quant.py --full(local)Last full sweep on the author workstation: 0 hard failures and 0 non-zero err lines at TP=2 and TP=4 (82 rows each). TP=8 inherits the same kernels and is additionally covered by the microbench correctness matrix below.
Microbench (96 rows: 32 shapes × TP 2/4/8)
0 correctness failures. Aggregate fused vs composed fallback (
>= 1.05x= win,0.95–1.05x= tie,< 0.95x= loss):1.034x1.039x1.013xTP=8 gate-boundary behavior: e.g.
32 x 4096routes to 2-stage;1 x 8192in tie range. The TP=8 table includes a small post-crossover rerun for rows whose route changed after the dense sweep.Per-shape latency — TP = 2
1 x 28805 KiB15.0615.871.054x16 x 288090 KiB16.7917.431.038x32 x 2880180 KiB18.3322.531.229x64 x 2880360 KiB28.2928.270.999x80 x 2880450 KiB30.2130.160.998x128 x 2880720 KiB35.7335.690.999x1 x 40968 KiB15.2515.841.039x16 x 4096128 KiB17.2918.151.050x32 x 4096256 KiB19.5223.831.221x64 x 4096512 KiB26.7030.891.157x80 x 4096640 KiB33.9433.920.999x128 x 40961024 KiB40.8940.981.002x1 x 512010 KiB15.6816.231.035x16 x 5120160 KiB18.2722.371.224x32 x 5120320 KiB22.7825.621.125x80 x 5120800 KiB37.6137.741.003x1 x 614412 KiB15.8416.371.033x16 x 6144192 KiB18.6723.171.241x32 x 6144384 KiB23.9426.971.127x80 x 6144960 KiB40.6840.671.000x1 x 716814 KiB16.2916.521.014x4 x 716856 KiB16.7716.881.007x16 x 7168224 KiB21.5823.571.092x32 x 7168448 KiB25.8828.341.095x64 x 7168896 KiB39.4039.310.998x80 x 71681120 KiB43.4843.450.999x128 x 71681792 KiB56.4056.451.001x1 x 819216 KiB16.4616.641.011x16 x 8192256 KiB22.1724.071.086x32 x 8192512 KiB26.7629.201.091x64 x 81921024 KiB41.3141.240.998x80 x 81921280 KiB46.6746.731.001xPer-shape latency — TP = 4
1 x 28805 KiB17.3218.111.046x16 x 288090 KiB17.5318.371.048x32 x 2880180 KiB18.8621.621.146x64 x 2880360 KiB26.1426.080.998x80 x 2880450 KiB27.2227.611.014x128 x 2880720 KiB30.4130.080.989x1 x 40968 KiB16.1917.431.077x16 x 4096128 KiB18.6419.331.037x32 x 4096256 KiB20.2922.511.109x64 x 4096512 KiB22.1927.081.220x80 x 4096640 KiB29.2329.411.006x128 x 40961024 KiB33.5833.520.998x1 x 512010 KiB18.1919.231.057x16 x 5120160 KiB18.9621.801.150x32 x 5120320 KiB20.8123.701.139x80 x 5120800 KiB31.4331.531.003x1 x 614412 KiB18.2018.391.010x16 x 6144192 KiB20.9823.301.111x32 x 6144384 KiB21.4524.261.131x80 x 6144960 KiB33.0733.061.000x1 x 716814 KiB17.6717.911.014x4 x 716856 KiB18.3919.141.041x16 x 7168224 KiB21.7423.251.069x32 x 7168448 KiB22.4724.861.106x64 x 7168896 KiB31.9132.171.008x80 x 71681120 KiB34.9734.991.001x128 x 71681792 KiB41.7941.951.004x1 x 819216 KiB18.1018.151.003x16 x 8192256 KiB21.2822.401.053x32 x 8192512 KiB23.1125.381.098x64 x 81921024 KiB33.2033.391.006x80 x 81921280 KiB36.0836.231.004xPer-shape latency — TP = 8
1 x 28805 KiB17.6518.401.042x16 x 288090 KiB20.5522.291.085x32 x 2880180 KiB22.8222.921.004x64 x 2880360 KiB27.5827.280.989x80 x 2880450 KiB27.5227.941.015x128 x 2880720 KiB29.0529.081.001x1 x 40968 KiB19.9820.211.012x16 x 4096128 KiB20.5421.511.047x32 x 4096256 KiB21.5023.681.101x64 x 4096512 KiB22.7927.021.186x80 x 4096640 KiB28.9529.071.004x128 x 40961024 KiB31.0030.960.999x1 x 512010 KiB19.3120.091.040x16 x 5120160 KiB20.7122.851.103x32 x 5120320 KiB22.7225.281.113x80 x 5120800 KiB30.6830.691.000x1 x 614412 KiB19.3320.201.045x16 x 6144192 KiB22.1224.161.092x32 x 6144384 KiB22.1324.571.110x80 x 6144960 KiB31.3431.571.007x1 x 716814 KiB19.3021.481.113x4 x 716856 KiB21.4421.120.985x16 x 7168224 KiB22.6023.631.046x32 x 7168448 KiB24.4924.661.007x64 x 7168896 KiB29.7329.700.999x80 x 71681120 KiB32.2632.020.993x128 x 71681792 KiB34.5534.450.997x1 x 819216 KiB20.6320.510.994x16 x 8192256 KiB23.3724.421.045x32 x 8192512 KiB24.2625.091.034x64 x 81921024 KiB31.7232.051.010x80 x 81921280 KiB32.4432.240.994xSGLang E2E (companion)
GSM8K (three runs each; both configs pass
>= 0.94gate):--enable-aiter-allreduce-fusion)0.9410.94**Trace view

Unfused:
Fused:
