Repository navigation
perf(cake_gdn_det_kcp): chain-aware walk widths in the deterministic KCP GDN package - #8538
Conversation
…KCP GDN package The forward state walk (#2) also takes the two-CTA vh = 64 form when its grid finishes within the longest walked segment (LPT of 2 * HV CTAs per segment over two CTAs per SM). The adjoint offset walk (#7) always takes vh = 64, and the adjoint tape walk takes vh = 64 on sm_100a and sm_103a; sm_107a keeps the two-wave rule. Both forms of each program write bitwise-identical results. The decision reads host plan integers only (walk list, segment chunk table, HV, SM count, device architecture), so the forward, the checkpoint recompute and the recompute-handle replay take the same form. This is the rule of the non-deterministic KCP package.
On sm_100a, a #7 walk (offset and tape) whose longest segment has at least 400 chunks and whose two-CTA grid has a larger LPT makespan than its one-CTA grid (both over 2 x SM slots) takes the two-wave rule again (vh = 64 iff 2 * n_walk * HV <= 4 * SM). The decision reads host plan integers only (walk_dhu_long_chain, memoized per walk list in _Tables) and is passed with each #7 launch. Other architectures keep their rules. This is the clause of the non-deterministic KCP package.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@flashinfer-bot run tests/experimental/test_cake_gdn_det_train_kcp.py tests/experimental/test_cake_gdn_det_train_kcp_api.py tests/experimental/test_cake_gdn_det_train_kcp_build.py tests/experimental/test_cake_gdn_det_train_kcp_cp1.py tests/experimental/test_cake_gdn_det_train_kcp_dist.py tests/experimental/test_cake_gdn_det_train_kcp_l2n.py tests/experimental/test_cake_gdn_det_train_kcp_ring.py tests/experimental/test_cake_gdn_train_kcp_api.py |
Cake's deterministic context-parallel GDN training kernel has one data-type variant: BF16 q/k/v/out/dout with FP32 scalar log-decay g and beta. The grouped Q/K head counts
(H_qk, HV)are runtime parameters with production shape (16, 48). The kernel has three partition layouts: contiguous (C), whole-buffer zigzag (Z) and per-document zigzag + ragged (D). This PR delivers the same variant. It changes the host-side rule that picks the value-head tile width for the cross-rank state-summary walk launches. A walk runs either 128 value columns per CTA or 64, and the 64 form runs two CTAs per segment and head. Forward walks still use the 64 form when the grid fits one wave. They now also use it when an LPT schedule of the walk's segment chain lengths shows that the two-CTA grid finishes within its longest chain. Backward offset walks always use the 64 form. Backward tape walks use it on sm_100a and sm_103a, while sm_107a keeps the previous two-wave rule. One exception applies on sm_100a: a backward walk keeps the previous two-wave rule when its longest chain is at least 400 chunks and its two-CTA schedule would take longer than the one-CTA schedule. The rule reads only host plan integers (segment lengths, head count, SM count and device architecture), never tensor contents. It takes the same decision in the forward, the checkpoint recompute and the recompute-handle replay. The non-deterministic KCP package (PR #8521) uses the same thresholds. The change is host-side Python only and the kernels are unchanged. Only launch widths differ, so outputs and gradients are bitwise identical to before on every measured row, and peak memory is unchanged. A is the previous Cake version of this package, as shipped after PR #8385. B is this PR on the same base. B/A < 1 means faster. Each GPU was measured on 66 rows: packs P1-P5 x CP 2/4/8 x layouts C/Z/D at B1 and B3. On 33 of these rows the launch form changes, and the other 33 are unchanged controls. On GB300 (sm_103a), changed rows range from 0.984 to 1.004 at B3 (median 0.989) and from 0.976 to 1.001 at B1 (median 0.999), though only 6 B1 rows change. Unchanged GB300 rows range from 0.994 to 1.013 (median 1.000). On GB200 (sm_100a), changed rows range from 0.987 to 1.016 at B3 (median 0.992) and from 0.978 to 1.002 at B1 (median 1.000). Unchanged GB200 rows range from 0.992 to 1.003 (median 1.000). Taking the median over both sessions, changed rows at CP 2 / 4 / 8 come to 0.989 / 0.990 / 0.999 on GB300 and 0.991 / 0.994 / 1.000 on GB200. That is about a 1 % gain at CP 2 and CP 4 and about parity at CP 8. The largest gain is CP 8 P3 C B1 on GB300 at 0.977 / 0.976. The slowest changed row is CP 8 P3 C B3 on GB200, at 1.016 in session 1 and 1.006 in session 2. R200 (sm_107a) rows were not measured.ms = slowest-rank median; B1 = module forward with autograd recording; B3 = forward + non-reentrant checkpoint replay + backward, including all communication and copies; Walk forms = changed (this PR launches a different width) or unchanged (same launches as A); s1/s2 = two sessions.
Packs: P1 241,817 tokens / 6 documents, P2 261,987 / 3, P3 259,174 / 2, P4 254,976 / 1 (one document spans the whole group), P5 249,856 / 4. Heads (16, 48); causal conv1d width 4 over 10,240 channels.
Software: CUDA 13.4 toolkit, torch 2.14.1+cu130.
NVIDIA GB300 (sm_103a)
NVIDIA GB200 (sm_100a)
Cake also ships these separately: a non-deterministic variant of this kernel, single-GPU GDN training packages without context parallelism (deterministic and non-deterministic), GDN inference kernels for chunked prefill and decode, and the KDA deterministic context-parallel training sibling, which covers the per-channel-gate form; this kernel ships on sm_100a, sm_103a and sm_107a.
Summary by CodeRabbit