flashinfer.cake_rmsnorm_train.cake_rmsnorm_train_backward_workspace_bytes

flashinfer.cake_rmsnorm_train.cake_rmsnorm_train_backward_workspace_bytes(rows: int, hidden: int, device: device, *, residual: bool = False, deterministic: bool = True) → int

Bytes of the caller-owned backward workspace of width hidden on device for up to rows tokens.

deterministic is resolved as the backward resolves it (see cake_rmsnorm_train_backward()), so the buffer fits the kernels the backward call with the same flag runs. Under torch.use_deterministic_algorithms(True, warn_only=True), deterministic=False warns and returns the deterministic package’s size; the backward call of that fallback does not use a caller’s workspace (it passes none to the deterministic package, which allocates its own). The deterministic package’s workspace holds its chunk-claim counters and one FP32 dw partial row per chunk and grows with rows (flashinfer.cake_rmsnorm_det_train.cake_rmsnorm_det_train_backward_workspace_bytes()). The non-deterministic workspace has one layout for every call (cake_jit.workspace_layout, offsets fixed by the package): the deterministic pairs’ uint32 counters (cake_jit.COUNTERS_BYTES), the single kernel’s counters (cake_jit.SINGLE_COUNTERS_BYTES at cake_jit.SINGLE_COUNTERS_OFFSET), its FP64 column sums (cake_jit.SUMS_BYTES at cake_jit.SUMS_OFFSET, the largest workspace_bytes of the package’s single kernels) and, when a window up to rows of the width runs the deterministic pair, that pair’s FP32 partial rows at cake_jit.PAIR_ROWS_OFFSET, which grow with rows. The size returned is the largest layout of the records the width’s backward routes (hidden, residual, both weight dtypes) run for up to rows tokens. The buffer must be zero on first use (allocate with torch.zeros or use cake_rmsnorm_train_backward_workspace()); after every launch the kernels leave the counters at rest and the sums at zero, so with no host write one buffer serves any sequence of deterministic=False backward calls – hidden sizes, residual flags, weight dtypes, token counts, windows and CUDA Graph replays – whose sizes it covers. It serves calls of one mode: do not pass it to a deterministic=True call (that package’s workspace has another layout). Zeroing it again between calls is harmless. Backward calls that may run at the same time (on different streams) need one buffer each.