Skip to content

vllm.models.inkling2.nvidia.ops.moe_sm120

SM120/121 expert GEMMs with native NVFP4 MMA and dequantized MXFP8.

Weights remain row-major, while activations retain Inkling2's tile-padded R8c4/R128c4 layout and its four-or-six quantization and outer row scales.

Functions:

  • bmm –

    Multiply quantized expert rows, returning bf16 [plan.rows, N].

bmm(act, act_scale, row_scale, weight, weight_scale, ones, tiles, plan, projection)

Multiply quantized expert rows, returning bf16 [plan.rows, N].

Source code in vllm/models/inkling2/nvidia/ops/moe_sm120.py
def bmm(
    act: torch.Tensor,
    act_scale: torch.Tensor,
    row_scale: torch.Tensor | None,
    weight: torch.Tensor,
    weight_scale: torch.Tensor,
    ones: torch.Tensor,
    tiles: torch.Tensor,
    plan: ExpertPlan,
    projection: int,
) -> torch.Tensor:
    """Multiply quantized expert rows, returning bf16 `[plan.rows, N]`."""
    del projection
    if weight.dtype == torch.float8_e4m3fn:
        n, k = weight.shape[1:]
        assert k % 128 == 0
        if plan.tile <= 16:
            block_n, block_t, num_warps = 128, 16, 4
        elif plan.tile <= 64:
            block_n, block_t, num_warps = 128, 64, 4
        else:
            block_n, block_t, num_warps = 256, 128, 8
        out = torch.empty((plan.rows, n), dtype=torch.bfloat16, device=act.device)
        _mxfp8_gemm[
            (triton.cdiv(n, block_n), plan.max_ctas * triton.cdiv(plan.tile, block_t))
        ](
            act,
            act_scale,
            weight,
            weight_scale,
            ones,
            out,
            tiles,
            MAX_CTAS=plan.max_ctas,
            N=n,
            K=k,
            TILE=plan.tile,
            BN=block_n,
            BT=block_t,
            BK=128,
            num_warps=num_warps,
            num_stages=3,
            launch_pdl=True,
        )
        return out
    assert weight.dtype == torch.uint8
    n, k = weight.shape[1], weight.shape[2] * 2
    block_m, block_n, num_warps = 32, 64, 4
    if plan.tile >= 128 and n == 2304 and k in (1152, 2304):
        # Mini's prefill tiles reuse each weight load across more routed rows.
        block_m = 128
        block_n = 128 if plan.tile >= 256 else 64
        num_warps = 8
    out = torch.empty((plan.rows, n), dtype=torch.bfloat16, device=act.device)
    _expert_gemm[
        (plan.max_ctas, triton.cdiv(plan.tile, block_m), triton.cdiv(n, block_n))
    ](
        act,
        act_scale,
        row_scale,
        weight,
        weight_scale,
        ones,
        out,
        tiles,
        MAX_CTAS=plan.max_ctas,
        N=n,
        K=k,
        TILE=plan.tile,
        BM=block_m,
        BN=block_n,
        BK=512,
        num_warps=num_warps,
        num_stages=2,
    )
    return out