Skip to content

perf(cake_gdn_det_kcp): chain-aware walk widths in the deterministic KCP GDN package - #8538

Merged
yyihuang merged 2 commits into
flashinfer-ai:mainfrom
yyihuang:cake-gdn-det-r23-vhrule
Nov 3, 2026
Merged

yyihuang merged 2 commits into
flashinfer-ai:mainfrom
yyihuang:cake-gdn-det-r23-vhrule

Conversation

@yyihuang

@yyihuang yyihuang commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

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)

CP Pack Layout Walk forms Boundary A ms s1 B ms s1 B/A s1 A ms s2 B ms s2 B/A s2
2 P1 C unchanged B1 7.884 7.898 1.002 7.863 7.865 1.000
2 P1 C changed B3 23.793 23.611 0.992 23.778 23.580 0.992
2 P1 Z unchanged B1 7.753 7.751 1.000 7.757 7.758 1.000
2 P1 Z changed B3 23.728 23.471 0.989 23.740 23.487 0.989
2 P1 D changed B1 7.919 7.913 0.999 7.919 7.916 1.000
2 P1 D changed B3 23.999 23.942 0.998 24.014 23.949 0.997
2 P2 C unchanged B1 8.441 8.449 1.001 8.438 8.443 1.001
2 P2 C changed B3 25.784 25.516 0.990 25.786 25.504 0.989
2 P2 Z unchanged B1 8.383 8.378 0.999 8.398 8.394 1.000
2 P2 Z changed B3 25.590 25.186 0.984 25.609 25.219 0.985
2 P2 D unchanged B1 8.553 8.555 1.000 8.552 8.550 1.000
2 P2 D changed B3 26.260 25.933 0.988 26.249 25.923 0.988
2 P3 C unchanged B1 7.386 7.379 0.999 7.376 7.373 1.000
2 P3 C unchanged B3 25.264 25.261 1.000 25.250 25.240 1.000
2 P3 Z unchanged B1 9.289 9.277 0.999 9.296 9.291 0.999
2 P3 Z changed B3 28.269 27.966 0.989 28.271 27.982 0.990
2 P3 D unchanged B1 8.248 8.237 0.999 8.240 8.245 1.001
2 P3 D changed B3 25.282 24.942 0.987 25.306 24.968 0.987
2 P4 C unchanged B1 8.273 8.284 1.001 8.271 8.253 0.998
2 P4 C changed B3 25.198 24.996 0.992 25.140 24.916 0.991
2 P4 Z unchanged B1 8.463 8.461 1.000 8.454 8.451 1.000
2 P4 Z changed B3 25.718 25.421 0.988 25.734 25.436 0.988
2 P4 D unchanged B1 8.516 8.521 1.001 8.509 8.510 1.000
2 P4 D changed B3 25.838 25.559 0.989 25.839 25.549 0.989
2 P5 C unchanged B1 8.076 8.080 1.000 8.126 8.080 0.994
2 P5 C changed B3 24.852 24.492 0.986 24.835 24.456 0.985
2 P5 Z unchanged B1 8.721 8.712 0.999 8.729 8.724 0.999
2 P5 Z changed B3 26.660 26.375 0.989 26.633 26.332 0.989
2 P5 D unchanged B1 8.199 8.193 0.999 8.233 8.218 0.998
2 P5 D changed B3 25.025 24.737 0.988 25.056 24.753 0.988
4 P1 C unchanged B1 4.360 4.366 1.001 4.352 4.357 1.001
4 P1 C changed B3 12.985 12.987 1.000 12.984 12.985 1.000
4 P1 Z unchanged B1 4.211 4.204 0.998 4.199 4.193 0.999
4 P1 Z changed B3 12.616 12.542 0.994 12.597 12.500 0.992
4 P1 D changed B1 4.325 4.326 1.000 4.321 4.326 1.001
4 P1 D changed B3 13.005 12.996 0.999 13.005 12.999 1.000
4 P2 Z unchanged B1 4.493 4.495 1.000 4.486 4.471 0.997
4 P2 Z unchanged B3 13.538 13.529 0.999 13.518 13.511 0.999
4 P2 D unchanged B1 4.837 4.840 1.000 4.840 4.844 1.001
4 P2 D changed B3 14.439 14.259 0.988 14.464 14.294 0.988
4 P3 C unchanged B1 4.364 4.368 1.001 4.369 4.366 0.999
4 P3 C changed B3 13.225 13.056 0.987 13.213 13.069 0.989
4 P3 Z unchanged B1 4.360 4.356 0.999 4.360 4.352 0.998
4 P3 Z changed B3 13.184 13.018 0.987 13.183 13.016 0.987
4 P3 D unchanged B1 4.691 4.689 1.000 4.685 4.686 1.000
4 P3 D changed B3 14.156 14.080 0.995 14.162 14.082 0.994
4 P4 D unchanged B1 4.427 4.438 1.002 4.426 4.424 1.000
4 P4 D unchanged B3 13.239 13.217 0.998 13.226 13.213 0.999
4 P5 C unchanged B1 4.229 4.218 0.998 4.228 4.229 1.000
4 P5 C changed B3 12.783 12.638 0.989 12.790 12.654 0.989
4 P5 Z unchanged B1 4.253 4.254 1.000 4.257 4.255 0.999
4 P5 Z changed B3 12.862 12.666 0.985 12.859 12.672 0.985
4 P5 D changed B1 4.360 4.358 0.999 4.341 4.341 1.000
4 P5 D changed B3 13.211 13.046 0.988 13.187 13.016 0.987
8 P1 C unchanged B1 2.504 2.536 1.013 2.526 2.527 1.000
8 P1 C unchanged B3 7.880 7.868 0.998 7.880 7.888 1.001
8 P1 D changed B1 2.651 2.649 0.999 2.650 2.647 0.999
8 P1 D changed B3 7.756 7.785 1.004 7.655 7.662 1.001
8 P2 Z unchanged B1 2.692 2.689 0.999 2.695 2.701 1.002
8 P2 Z unchanged B3 7.770 7.767 1.000 7.751 7.751 1.000
8 P3 C changed B1 2.636 2.575 0.977 2.616 2.553 0.976
8 P3 C changed B3 7.973 7.971 1.000 7.830 7.839 1.001
8 P4 D unchanged B1 2.752 2.758 1.002 2.759 2.765 1.002
8 P4 D unchanged B3 8.348 8.380 1.004 8.189 8.210 1.003
8 P5 D changed B1 2.585 2.583 0.999 2.579 2.579 1.000
8 P5 D changed B3 7.550 7.492 0.992 7.533 7.482 0.993

NVIDIA GB200 (sm_100a)

CP Pack Layout Walk forms Boundary A ms s1 B ms s1 B/A s1 A ms s2 B ms s2 B/A s2
2 P1 C unchanged B1 8.016 8.012 0.999 8.032 8.033 1.000
2 P1 C changed B3 24.233 24.104 0.995 24.238 24.106 0.995
2 P1 Z unchanged B1 7.890 7.892 1.000 7.908 7.904 1.000
2 P1 Z changed B3 24.176 23.980 0.992 24.205 24.016 0.992
2 P1 D changed B1 8.072 8.065 0.999 8.073 8.077 1.001
2 P1 D changed B3 24.448 24.438 1.000 24.498 24.517 1.001
2 P2 C unchanged B1 8.600 8.600 1.000 8.606 8.606 1.000
2 P2 C changed B3 26.247 26.035 0.992 26.265 26.046 0.992
2 P2 Z unchanged B1 8.555 8.542 0.998 8.548 8.555 1.001
2 P2 Z changed B3 26.113 25.777 0.987 26.141 25.797 0.987
2 P2 D unchanged B1 8.709 8.716 1.001 8.715 8.720 1.001
2 P2 D changed B3 26.728 26.464 0.990 26.733 26.471 0.990
2 P3 C unchanged B1 7.524 7.525 1.000 7.543 7.545 1.000
2 P3 C unchanged B3 26.088 26.093 1.000 26.127 26.160 1.001
2 P3 Z unchanged B1 9.440 9.433 0.999 9.443 9.445 1.000
2 P3 Z changed B3 28.722 28.493 0.992 28.719 28.500 0.992
2 P3 D unchanged B1 8.386 8.401 1.002 8.397 8.396 1.000
2 P3 D changed B3 25.754 25.473 0.989 25.767 25.503 0.990
2 P4 C unchanged B1 8.418 8.412 0.999 8.415 8.428 1.002
2 P4 C changed B3 25.649 25.585 0.997 25.636 25.567 0.997
2 P4 Z unchanged B1 8.594 8.596 1.000 8.606 8.597 0.999
2 P4 Z changed B3 26.209 25.977 0.991 26.223 25.997 0.991
2 P4 D unchanged B1 8.651 8.656 1.001 8.648 8.654 1.001
2 P4 D changed B3 26.299 26.056 0.991 26.317 26.081 0.991
2 P5 C unchanged B1 8.245 8.230 0.998 8.251 8.251 1.000
2 P5 C changed B3 25.309 24.990 0.987 25.348 25.042 0.988
2 P5 Z unchanged B1 8.840 8.836 1.000 8.847 8.848 1.000
2 P5 Z changed B3 27.040 26.783 0.990 27.068 26.800 0.990
2 P5 D unchanged B1 8.340 8.334 0.999 8.344 8.342 1.000
2 P5 D changed B3 25.501 25.251 0.990 25.529 25.282 0.990
4 P1 C unchanged B1 4.475 4.477 1.000 4.442 4.436 0.999
4 P1 C changed B3 13.335 13.341 1.000 13.274 13.268 1.000
4 P1 Z unchanged B1 4.291 4.296 1.001 4.254 4.252 0.999
4 P1 Z changed B3 12.857 12.799 0.996 12.797 12.765 0.997
4 P1 D changed B1 4.412 4.410 1.000 4.432 4.424 0.998
4 P1 D changed B3 13.268 13.283 1.001 13.272 13.265 0.999
4 P2 Z unchanged B1 4.586 4.590 1.001 4.579 4.581 1.000
4 P2 Z unchanged B3 13.855 13.848 1.000 13.865 13.866 1.000
4 P2 D unchanged B1 4.916 4.915 1.000 4.899 4.899 1.000
4 P2 D changed B3 14.685 14.523 0.989 14.667 14.505 0.989
4 P3 C unchanged B1 4.446 4.454 1.002 4.460 4.472 1.003
4 P3 C changed B3 13.470 13.334 0.990 13.484 13.327 0.988
4 P3 Z unchanged B1 4.451 4.448 0.999 4.457 4.455 1.000
4 P3 Z changed B3 13.428 13.295 0.990 13.431 13.286 0.989
4 P3 D unchanged B1 4.773 4.771 0.999 4.787 4.793 1.001
4 P3 D changed B3 14.415 14.363 0.996 14.446 14.392 0.996
4 P4 D unchanged B1 4.500 4.496 0.999 4.541 4.543 1.000
4 P4 D unchanged B3 13.480 13.479 1.000 13.511 13.511 1.000
4 P5 C unchanged B1 4.296 4.294 1.000 4.310 4.314 1.001
4 P5 C changed B3 13.008 12.890 0.991 13.017 12.908 0.992
4 P5 Z unchanged B1 4.330 4.335 1.001 4.352 4.349 0.999
4 P5 Z changed B3 13.086 12.944 0.989 13.091 12.945 0.989
4 P5 D changed B1 4.428 4.438 1.002 4.467 4.470 1.001
4 P5 D changed B3 13.454 13.315 0.990 13.483 13.354 0.990
8 P1 C unchanged B1 2.538 2.540 1.001 2.599 2.579 0.992
8 P1 C unchanged B3 7.925 7.933 1.001 7.975 7.979 1.001
8 P1 D changed B1 2.671 2.677 1.002 2.685 2.666 0.993
8 P1 D changed B3 7.769 7.776 1.001 7.800 7.789 0.999
8 P2 Z unchanged B1 2.720 2.722 1.001 2.788 2.789 1.000
8 P2 Z unchanged B3 7.933 7.936 1.000 7.923 7.918 0.999
8 P3 C changed B1 2.635 2.576 0.978 2.636 2.585 0.981
8 P3 C changed B3 7.907 8.031 1.016 7.959 8.008 1.006
8 P4 D unchanged B1 2.753 2.753 1.000 2.780 2.770 0.997
8 P4 D unchanged B3 8.311 8.283 0.997 8.200 8.227 1.003
8 P5 D changed B1 2.604 2.604 1.000 2.605 2.608 1.001
8 P5 D changed B3 7.652 7.600 0.993 7.642 7.588 0.993

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

  • Performance Improvements
    • Improved walk-width selection for forward and backward operations using launch-chain length, GPU architecture, and execution scheduling characteristics.
    • Added architecture-specific handling for long walks to help select an appropriate execution strategy.
  • Testing
    • Expanded coverage for width selection across architectures, walk types, and execution paths.

…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.
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

KCP walk-width selection now considers LPT chain-fit and long-chain decisions in addition to walk count and SM count. DHU selection also uses walk type and architecture. The plan derives and caches these decisions, then passes them into launch resolution.

Changes: KCP walk-width selection

Layer / File(s) Summary
Width rules and conditions
flashinfer/experimental/cake_gdn_det_train_kcp/cake_kcp.py, flashinfer/experimental/cake_gdn_det_train_kcp/README.md, flashinfer/experimental/cake_gdn_det_train_kcp/cake_options.py, tests/experimental/test_cake_gdn_det_train_kcp_api.py
Forward width 64 is selected when the one-wave condition or the LPT chain-fit condition holds. DHU width selection uses architecture, walk type, and the SM100 long-chain condition. Tests cover the selection boundaries and pinned vectors.
Plan metadata and launch selection
flashinfer/experimental/cake_gdn_det_train_kcp/cake_kcp.py, tests/experimental/test_cake_gdn_det_train_kcp_api.py
The plan memoizes chain-fit and long-chain decisions and passes them, with architecture data, to launch resolution. Tests check launch records and grids across forward, checkpoint recompute, and recompute-handle paths.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Other

Sequence Diagram(s)

sequenceDiagram
  participant CallDetKcp
  participant Tables
  participant LaunchResolver
  participant WidthRules
  CallDetKcp->>Tables: query chain-fit or long-chain decision
  Tables-->>CallDetKcp: return walk decision
  CallDetKcp->>LaunchResolver: pass walk decision and launch data
  LaunchResolver->>WidthRules: select fwdh_vh or dhu_vh width
Loading

Possibly related issues

Suggested labels: op: linear attention, run-ci

Suggested reviewers: yzh119

Merge Risk: Minimal · up to 77aa4

The chain-aware launch-width changes have no demonstrated actionable defect in the supplied evidence and are mergeable subject to normal checks. Performance on unmeasured shapes remains unproven, not a demonstrated regression.

Pre-merge checks: Passed 3 · Failed 2

Failed Failed checks: 2 warnings

Check name Status Explanation Resolution
Description check Warning The description gives a detailed and relevant summary, implementation rationale, benchmark data, and test scope. However, it does not follow the required template: it omits the Related Issues, Pull Re… Add the missing template sections. Complete the pre-commit and test checkboxes, provide the experimental tracking issue and required experimental metadata, and add the tests under the experimental-tests fence.
Docstring Coverage Warning Docstring coverage is 73.91% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly identifies the performance change and the affected deterministic KCP GDN package.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description gives a detailed and relevant summary, implementation rationale, benchmark data, and test scope. However, it does not follow the required template: it omits the Related Issues, Pull Request Checklist, Pre-commit Checks, Tests checklist, and required Experimental Track section with a tracking issue and experimental-tests targets.

Resolution

Add the missing template sections. Complete the pre-commit and test checkboxes, provide the experimental tracking issue and required experimental metadata, and add the tests under the experimental-tests fence.

Full details: Docstring Coverage

Explanation

Docstring coverage is 73.91% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 23 functions across 3 files. (1 skipped: 1 unsupported.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cc186340-b629-4b7c-aa15-94fb8b43f7f2
Commits

Reviewing files that changed from the base of the PR and between a1b4ed3 and 77aa454.

Files selected for processing: 4
  • flashinfer/experimental/cake_gdn_det_train_kcp/README.md
  • flashinfer/experimental/cake_gdn_det_train_kcp/cake_kcp.py
  • flashinfer/experimental/cake_gdn_det_train_kcp/cake_options.py
  • tests/experimental/test_cake_gdn_det_train_kcp_api.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@yyihuang
yyihuang marked this pull request as ready for review November 3, 2026 17:36
@flashinfer-bot flashinfer-bot added the op: linear attention KDA, mamba, GDN, etc. review filtering. label Nov 3, 2026
@yyihuang

yyihuang commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

op: linear attention KDA, mamba, GDN, etc. review filtering. run-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants