flashinfer.gemm.bmm_mxfp8

flashinfer.gemm.bmm_mxfp8(A: Tensor, B: Tensor, A_scale: Tensor, B_scale: Tensor, dtype: dtype, out: Tensor | None = None, backend: Literal['cudnn', 'cutlass', 'cute-dsl', 'auto'] = 'auto', out_scale: Tensor | None = None) → Tensor

BMM MXFP8

Parameters:
  • A (torch.Tensor) – Input tensor, shape (b, m, k), fp8 e4m3 or fp8 e5m2 ("cute-dsl": e4m3 only).

  • B (torch.Tensor) – Mat2 tensor, shape (b, k, n), must be column major, fp8 e4m3 or fp8 e5m2 ("cute-dsl": e4m3 only). Quantize the contiguous [b, n, k] weight (so the 32-element scale blocks run along k, the reduction dim) and pass the transpose of the quantized tensor, e.g. B = mxfp8_quantize(weight)[0].transpose(-2, -1) (do NOT call .contiguous() on the transpose).

  • A_scale (torch.Tensor) – Scale tensor for A, uint8 (fp8 e8m0 format), in the F8_128x4 swizzled layout produced by mxfp8_quantize(..., is_sf_swizzled_layout=True).

  • B_scale (torch.Tensor) – Scale tensor for B, uint8 (fp8 e8m0 format), in the F8_128x4 swizzled layout, as returned by quantizing the [b, n, k] weight (see B).

  • dtype (torch.dtype) – out dtype, bf16 or fp16; "cute-dsl" also takes float8_e4m3fn (MXFP8 output, with out_scale).

  • out (Optional[torch.Tensor]) – Out tensor, shape (b, m, n), of dtype, defaults to None.

  • backend (Literal["cudnn", "cutlass", "cute-dsl", "auto"]) – The backend to use for the operation. Defaults to "auto". "cute-dsl" runs on SM107 only (see below); "auto" picks it only when no other backend can run the call, e.g. float8_e4m3fn output. On SM120/121 GPUs, "auto" selects the CUTLASS backend; scales must be 1D swizzled (SfLayout.layout_128x4). Pass B in the standard shape [b, k, n] (column-major); the CUTLASS path transposes internally. Both the cuDNN and CUTLASS backends read the scale tensors in the F8_128x4 swizzled layout; linear-layout scales are not supported. Both layouts are flat 1D buffers, so a linear scale whose length happens to match the padded swizzled length cannot be detected at runtime. Ensure the scale was produced with the swizzled layout rather than relying on a warning.

  • out_scale (Optional[torch.Tensor]) – Only for dtype=torch.float8_e4m3fn (backend="cute-dsl", SM107): uint8 buffer that receives the UE8M0 scale of every 32 output columns, in the F8_128x4 swizzled layout of the 2-D row-major matrix that stores out (out.stride(1) elements per row; batch i starts i * out.stride(0) elements in). For a contiguous out this is mxfp8_quantize(out_bf16.view(b * m, n), is_sf_swizzled_layout=True)’s scale layout; for out = y.view(m, b, n).transpose(0, 1) it is the scale of y.view(m, b * n). For finite outputs the values match a bf16 bmm_mxfp8 followed by mxfp8_quantize bit for bit (an infinite accumulator becomes NaN here, where mxfp8_quantize saturates).

  • launch (The "cute-dsl" backend (SM107) runs the batch in one)

  • as (takes A and out)

  • batch (strided views (row-major per)

  • be (16-byte-aligned strides) and needs m and n to)

  • ``B.transpose(1 (multiples of 128 and) –

  • contiguous. (2)`` to be)

Returns:

out – Out tensor, shape (b, m, n), bf16, fp16 or (cute-dsl) float8_e4m3fn.

Return type:

torch.Tensor