flashinfer.gemm.bmm_bf16

flashinfer.gemm.bmm_bf16(A: Tensor, B: Tensor, out: Tensor | None = None, out_dtype: dtype = torch.bfloat16, backend: Literal['cudnn', 'cutlass', 'cutile', 'tgv', 'cake', 'auto'] = 'cudnn') → Tensor

BMM BF16

Parameters:
  • A (torch.Tensor) – Input tensor, shape (b, m, k), bf16 in row-major layout.

  • B (torch.Tensor) – Weight tensor, shape (b, k, n), bf16 in column-major layout.

  • out (Optional[torch.Tensor]) – Out tensor, shape (b, m, n), bf16, fp16, or fp32, defaults to None.

  • out_dtype (torch.dtype) – Output dtype, bf16 (default), fp16, or fp32.

  • backend (Literal["cudnn", "cutlass", "cutile", "tgv", "cake", "auto"]) – Backend to use, defaults to “cudnn”. "cake" selects the frozen SM100a/SM103a CAKE-generated dispatcher for contiguous A/output, exact transposed column-major B, 16-byte-aligned tensor data, N divisible by 8, and K in {64, 256, 1024}. The output must not overlap either input. On a few decode shapes with K 1024 it runs generated tcgen05 programs (flashinfer.jit.cake_bf16_bmm_swap_ab) instead; set FLASHINFER_DISABLE_CAKE_BF16_BMM_SWAP_AB=1 to keep the dispatcher on every shape. "auto" lists "cake" as the last candidate when the call meets the "cake" requirements above and at least one other backend is listed and "cake" serves every M of the tuning bucket of M with one program. The default buckets put each swap-AB row above together with M that run the dispatcher, so "auto" lists "cake" for such a row only when the effective tuning buckets give the row a bucket of its own. Without tuning, "auto" runs the first candidate as before, and lists "cake" only while the autotuner holds a "cake" result (see AutoTuner.may_select_runner_class). Under flashinfer.autotune(), "cake" is measured with the other candidates and runs only when it is the fastest; tuning under flashinfer.autotuner.set_autotune_process_group does not list it. FLASHINFER_DISABLE_CAKE_AUTO_CANDIDATES=1 removes it from "auto"; backend="cake" is not affected.

Returns:

Out tensor, shape (b, m, n), bf16, fp16, or fp32 in row-major layout.

Return type:

torch.Tensor

Examples

>>> import torch
>>> import flashinfer
>>> # Using the CUTLASS backend
>>> input = torch.randn([16, 48, 64], device="cuda", dtype=torch.bfloat16)
>>> weight = torch.randn([16, 80, 64], device="cuda", dtype=torch.bfloat16).transpose(-2, -1)
>>> fp16_out = torch.empty([16, 48, 80], device="cuda", dtype=torch.float16)
>>> out = flashinfer.bmm_bf16(input, weight, out=fp16_out, out_dtype=torch.float16, backend="cutlass")
>>> out.shape
torch.Size([16, 48, 80])
>>> out.dtype
torch.float16
>>> # using the cuDNN backend
>>> out = flashinfer.bmm_bf16(input, weight, backend="cudnn")
>>> out.shape
torch.Size([16, 48, 80])
>>> out.dtype
torch.bfloat16
>>> # using the TGV (cute_ext) backend
>>> out = flashinfer.bmm_bf16(input, weight, backend="tgv")
>>> out.shape
torch.Size([16, 48, 80])