flashinfer.cake_moe_grouped_gemm_det_train.cake_moe_grouped_gemm_det_train_dgrad

flashinfer.cake_moe_grouped_gemm_det_train.cake_moe_grouped_gemm_det_train_dgrad(g: Tensor, w: Tensor, offs: Tensor, out: Tensor | None = None) → Tensor

dX[offs[e-1]:offs[e]] = G[offs[e-1]:offs[e]] @ W[e] for every group e.

The slice lower bound is 0 for e == 0 and offs[e-1] for e > 0. For m_indptr input, offs in these formulas means m_indptr[1:].

g is [sum_m, N] bfloat16, w is [E, N, K] bfloat16 and is read in place (no transpose copy), offs is [E] int32 device end offsets (or m_indptr [E + 1]) and out is [sum_m, K] bfloat16. K % 256 == 0 and N % 64 == 0 are required. See cake_moe_grouped_gemm_det_train_forward for the prepared form.

Parameters:
  • g (torch.Tensor) – BF16 [sum_m, N] packed output-gradient rows.

  • w (torch.Tensor) – BF16 [E, N, K] expert weights, read in place.

  • offs (torch.Tensor) – int32 device cumulative end offsets [E], or leading-zero m_indptr [E + 1].

  • out (torch.Tensor, optional) – Caller-owned BF16 [sum_m, K] output; allocated when omitted.