flashinfer.cake_rmsnorm_train.cake_rmsnorm_train_backward¶
- flashinfer.cake_rmsnorm_train.cake_rmsnorm_train_backward(g: Tensor, x: Tensor, w: Tensor, rstd: Tensor, *, deterministic: bool = True, g_residual: Tensor | None = None, workspace: Tensor | None = None, dx: Tensor | None = None, dw: Tensor | None = None) tuple[Tensor, Tensor]¶
Fused BF16 RMSNorm backward:
dxand the FP32 weight gradientdw.- Parameters:
g (torch.Tensor) – BF16
[T, H]gradient ofyof any layout. Views with a contiguous feature dimension, 16-byte aligned storage and a row stride that is a multiple of 16 bytes (expanded or sliced autograd gradients included) are read in place; other layouts are materialized once.x (torch.Tensor) – The BF16
[T, H]tensor that was normalized (xof the plain forward,h_newof the residual forward); same layout rules asg.w (torch.Tensor) – BF16
[H]weight (copied when not contiguous).rstd (torch.Tensor) – FP32
[T]reciprocal RMS returned by the forward.deterministic (bool) – Only the deterministic fixed-order
dwreduction is exported;Falseis rejected.g_residual (torch.Tensor, optional) – BF16
[T, H]gradient flowing directly throughh_new(residual forward), any layout. It is added once so that the returneddxis the gradient of both residual-add inputs.workspace (torch.Tensor, optional) – Caller-owned
uint8buffer fromcake_rmsnorm_train_backward_workspace(); allocated when omitted.dx (torch.Tensor, optional) – Preallocated outputs: BF16
[T, H]and FP32[H]. Contiguous aligned buffers are written directly; any other layout receives a copy after the launch.dw (torch.Tensor, optional) – Preallocated outputs: BF16
[T, H]and FP32[H]. Contiguous aligned buffers are written directly; any other layout receives a copy after the launch.
- Returns:
(dx, dw)withdwin FP32; the caller decides whether to cast it.For a fixed token count and architecture
dwis bitwise reproducible.