flashinfer.comm.trtllm_mnnvl_ar.trtllm_mnnvl_fused_allreduce_add_rmsnorm_quant¶
- flashinfer.comm.trtllm_mnnvl_ar.trtllm_mnnvl_fused_allreduce_add_rmsnorm_quant(input: Tensor, residual_in: Tensor, gamma: Tensor, workspace: MNNVLAllReduceFusionWorkspace, epsilon: float | None = None, output: Tensor | None = None, residual_out: Tensor | None = None, quant_out: Tensor | None = None, scale_out: Tensor | None = None, output_scale: float | Tensor | None = None, layout_code: int = 0, quant_type: int = 0, launch_with_pdl: bool = False, strategy: MNNVLAllreduceFusionStrategy = MNNVLAllreduceFusionStrategy.AUTO, weight_bias: float = 0.0, block_quant_group_size: int | None = None) Tuple[Tensor, Tensor | None, Tensor, Tensor | None]¶
Perform MNNVL AllReduce + Residual + RMSNorm + quantization.
Quantization is applied after RMSNorm.
outputis optional; pass it only when the normalized non-quantized tensor is also needed. The quantized result is always returned asquant_out.- Parameters:
input – Input tensor with shape
[num_tokens, hidden_dim].residual_in – Residual tensor with the same shape as
input.gamma – RMSNorm gamma tensor with shape
[hidden_dim].workspace – MNNVL workspace for the tensor-parallel group.
epsilon – RMSNorm epsilon. Defaults to
torch.finfo(input.dtype).eps.output – Optional normalized output tensor with shape
[num_tokens, hidden_dim].residual_out – Optional residual output tensor with shape
[num_tokens, hidden_dim].quant_out – Optional quantized output. For FP8 and MXFP8, shape must be
[num_tokens, hidden_dim]and dtypetorch.float8_e4m3fn. For NVFP4, shape must be[num_tokens, hidden_dim // 2]and dtypetorch.uint8ortorch.float4_e2m1fn_x2.scale_out – Optional scale output. Dynamic FP8 uses
[num_tokens, 1]float32. MXFP8 uses a contiguous 1-D uint8 tensor of UE8M0 scales (one per 32 elements) sized asmxfp8_quantizereturns it for the layout; the scales of the swizzled layout’s padding rows are not written. NVFP4 uses[num_tokens, hidden_dim // 16]forLINEARlayout, or a 1-D tensor large enough for the paddedSWIZZLED_128x4layout. Per-token-group FP8 uses packed UE8M0 scales with shape[num_tokens, ceil(groups_per_row / 4)], dtypetorch.int32, and stride(1, ceil(num_tokens / 4) * 4). Static FP8 ignores this argument.output_scale – Scalar float or float32 tensor used as the quantization output scale. Defaults to
1.0. Not used by dynamic FP8, MXFP8, or packed per-token-group FP8.layout_code – NVFP4/MXFP8 scale layout. MNNVL supports
SWIZZLED_128x4andLINEAR;SWIZZLED_8x4is not supported.quant_type –
MNNVLQuantType.FP8,MNNVLQuantType.NVFP4,MNNVLQuantType.DYNAMIC_FP8,MNNVLQuantType.MXFP8, orMNNVLQuantType.PER_TOKEN_GROUP_FP8_PACKED.launch_with_pdl – Whether to launch with PDL.
strategy – MNNVL execution strategy.
AUTOuses internal heuristics.weight_bias – Bias added to gamma before scaling.
0.0for standard RMSNorm;1.0for Gemma / Qwen3.5 RMSNorm.block_quant_group_size – Group size along the hidden dimension for per-token-group FP8 quantization. MNNVL requires an exact row partition into at most eight CTAs, with at most 1024 vector threads per CTA and an integral number of groups owned by each CTA.
- Returns:
A tuple
(quant_out, scale_out, residual_out, output).scale_outisNonefor static FP8;outputisNoneunless requested.