flashinfer.cake_mhc_train.cake_mhc_train_head_backward¶
- flashinfer.cake_mhc_train.cake_mhc_train_head_backward(dY: Tensor, *, dX: Tensor | None = None, accumulate: bool = False) Tensor¶
Gradient of the head:
dX[t, i, d] = BF16(dY[t, d] * 0.25)for each of the four streams.Bit for bit torch’s
MeanBackwardofX.mean(dim=1)(the quarter is exact unless it is subnormal, and then rounds once). Withaccumulate=Truethe kernel adds instead,dX[t, i, d] = BF16(dX[t, i, d] + BF16(dY[t, d] * 0.25)), bit for bit torch’s BF16dX.add_(...)of that gradient (autograd’s accumulation into an existingX.grad).- Parameters:
dY (torch.Tensor) – BF16
[T, H]contiguous gradient ofY,Hin 4096, 5120 or 7168, 32-byte aligned;T == 0launches nothing.dX (torch.Tensor, optional) – BF16
[T, 4, H]contiguous gradient ofXto write (defaultNone: a new tensor) or, withaccumulate=True, to add into (then required); it must not overlapdY.accumulate (bool) – Add into
dXinstead of overwriting it (defaultFalse).
- Returns:
BF16
dXof shape[T, 4, H](the caller’s tensor when given).The launch runs on the current torch stream of
dY’s device.