vllm.model_executor.layers.fused_allreduce_gemma_rms_norm
¶
Manual fusion of tensor-parallel all-reduce with the following GemmaRMSNorm.
Under tensor parallelism a RowParallelLinear (e.g. attention o_proj)
produces a per-rank partial sum that is all-reduced, and the result is then fed
into a GemmaRMSNorm that adds the residual and normalizes. flashinfer ships a
kernel that fuses all-reduce + residual-add + RMSNorm into a single launch; this
helper drives it directly (no torch.compile pass) for models that run eager.
Scope: attention output only, no quantization. When the flashinfer fast path is
not applicable (TP==1, flashinfer/NVSwitch unavailable, unsupported dtype, or an
oversize batch) it falls back to all_reduce + GemmaRMSNorm, which is
numerically identical to the unfused model path.
Functions:
-
allreduce_gemma_rms_norm_mxfp8–All-reduce + residual add + GemmaRMSNorm with MXFP8-quantized output.
-
fused_allreduce_gemma_rms_norm–All-reduce
hidden_states+ addresidual+ GemmaRMSNorm, fused.
_can_use_flashinfer(hidden_states, tp_size)
¶
Whether the flashinfer fused path applies; returns (ok, max_token_num).
Source code in vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py
_max_token_num(tp_size, hidden_size, dtype)
¶
Workspace token budget for flashinfer fused all-reduce, or None if the
current world size / device is unsupported. Mirrors FlashInferAllReduce.
Source code in vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py
allreduce_gemma_rms_norm_mxfp8(hidden_states, residual, norm, return_normed=False)
¶
All-reduce + residual add + GemmaRMSNorm with MXFP8-quantized output.
fused_allreduce_gemma_rms_norm followed by an MXFP8 activation quant,
with the quant as an epilogue of the Triton norm instead of its own launch.
The fused all-reduce + norm kernels have no quantized output, so this only
covers the plain collective + Triton norm; when one of them would run it
returns None and the caller keeps the unfused path.
Returns (x_q, x_scale, normed, residual_out): float8_e4m3fn values
[M, N], row-major E8M0 scales [M, N // 32], the bf16 normed rows
(only if return_normed, else None) and the new residual.
Source code in vllm/model_executor/layers/fused_allreduce_gemma_rms_norm.py
fused_allreduce_gemma_rms_norm(hidden_states, residual, norm)
¶
All-reduce hidden_states + add residual + GemmaRMSNorm, fused.
hidden_states is the per-rank partial (un-reduced) output of a
row-parallel linear; norm is the GemmaRMSNorm applied right after.
Returns (normed_output, new_residual), equivalent to
norm(all_reduce(hidden_states), residual).