Skip to content

feat: add reset-aware KDA recursive doubling and Ulysses CP - #1027

Merged
github-actions[bot] merged 1 commit into
mindspore-ai:masterfrom
xuxl1008:feat/kda-cached-rd-cp
Nov 3, 2026
Merged

github-actions[bot] merged 1 commit into
mindspore-ai:masterfrom
xuxl1008:feat/kda-cached-rd-cp

Conversation

@xuxl1008

@xuxl1008 xuxl1008 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Related issue: #1220.

Kimi Delta Attention (KDA) represents a local sequence segment by an affine state summary, H_out = S + M @ H_in. A sequential P2P chain has a dependency depth linear in the state-group size. This PR adds ordered recursive doubling (RD), including Ulysses × RD, and prunes communication and summary production across real packed-document resets.

RD is explicitly selected with backend: triton and state_cp_method: recursive_doubling. The default remains P2P. The configuration examples use the current plan_overrides.replace schema; forward method replacement already defaults to region_dispatch: false, so the examples omit that redundant field.

Implementation

  • The forward pass performs an ordered inclusive scan followed by an adjacent exchange to obtain each rank's exclusive input state. Earlier rounds carry S/M; the final doubling round and adjacent exchange carry only the state.
  • Each autograd invocation owns compact pre-round M caches. Backward traverses the same graph in reverse, applying the cached transposed transitions without regenerating or gathering backward transition matrices.
  • Packed TND metadata determines the live rounds, peers and summary consumers after Ulysses. Real document resets remove unrelated communication, composition, empty-round packing and unused S/M production. Head input dependencies and tail output dependencies are handled separately.
  • Immutable document metadata and bounded CPU plans can be reused across layers. Dense and TND share local round construction, without building a global per-round receive table or creating process groups per batch.
  • Public torch.distributed.batch_isend_irecv handles communication. Buffer lifetimes remain protected by completion dependencies. Pointwise kernels fuse packing, addition and compact cache writes while retaining matrix arithmetic and composition order.
  • The implementation integrates with the existing Layer/Core entry points, model adapter and Ulysses mesh split. Invocation-local caches support multiple live forwards, reverse-order backward and non-reentrant checkpointing. Unused qg and w/u/kg references are released before later phases.

Supported scope: Ascend NPU/HCCL, BF16, K=V128, lower-bounded gates, and equally sized contiguous nonempty rank shards in sequence order. Dense and TND tails need not be multiples of 64 tokens. Ordered DP×CP submeshes and Ulysses × RD are supported. NCCL, production CPU/Gloo execution, zigzag or unequal rank shards, TP×CP, graph capture and inference caches are outside this PR.

Cost and memory

Let R = CP / U and let one FP32 state occupy W = 4 × B × (H/U) × 128² bytes. A single long document requires at most ceil(log2 R) + 1 stages per direction; real TND resets can remove stages and messages. The worst rank retains up to W × ceil(log2 R) transition-cache bytes per invocation. Live layers and microbatches accumulate these caches independently.

For B1/H96/U1, W is 6 MiB: the worst-rank cache is 18 MiB at CP8 and 48 MiB at CP256. These are tensor-size and schedule estimates, not large-CP hardware measurements. Fewer stages do not guarantee a faster complete layer: summary production, composition, handoff and concurrent communication remain relevant.

Validation

This update: rebased onto upstream master; 35 existing CPU tests passed for RD planning, packed metadata and KDA/GDN model/configuration contracts. The YAML fixtures verify the default execution mode and its serialized form. No new test files or numerical-threshold changes were introduced. This documentation/configuration update does not change RD runtime or kernel arithmetic, and does not claim a new NPU run.

Retained NPU evidence was collected on 910B3 with Torch/Torch-NPU 2.10.0, CANN 9.1.0-beta.3, Triton-Ascend 3.2.2+gitc22984ba and FLA commit 6b6f546f9bd10a97be1e8cf2f0120de70cfca482:

Check Reference and acceptance Coverage
State protocol arithmetic Independent CPU FP64 ordered recurrence with identical supplied S/M/G; both L2(error) <= 1e-6 × L2(reference) + 1e-12 and maximum absolute error <= 2e-6 NPU CP8 and interleaved DP2×CP4; forward input states and backward terminal-state gradients; noncommuting transitions and a zero-M mathematical reset
Complete-layer regression Bitwise equality of output, hidden gradients and reduced FP32 parameter gradients against the frozen previous RD implementation CP4, local4K, H96/K=V128, hidden projection size 32; U1/U2; one long document and mixed non-64-aligned TND documents
Invocation lifecycle Independent caches, unchanged saved matrices and compact storage; reverse-order backward and non-reentrant checkpointing Two live invocations; document-gradient isolation in packed layer checks
Plan preservation Identical peers, rounds and cache requirements against the frozen previous planner 4,000 dense plans and 11,031 packed rank plans

The zero-M boundary test validates reset arithmetic; real TND execution and pruning are covered separately by packed-layer and planner checks. Remote CI status is reported by the checks on the current commit.

Numerical scope

The fixed-summary FP64 checks validate the distributed affine scan and its reverse accumulation. The complete-layer regression validates changes against the previous RD implementation. Neither is a full-model FP64 comparison or a long-training convergence result.

On a previously recorded sensitive CP8/local4K dense input with H96/K128 and hidden size 512, RD versus P2P reached maximum relative L2 differences of 0.484164% for hidden gradients and 0.427030% for individual reduced parameter gradients. These exceed the existing 0.003 screening threshold, which has not been relaxed. This is a local compatibility threshold, not a universal training-accuracy standard.

RD and P2P use different floating-point composition orders, and native nonzero-state mixed-precision feedback is not strictly affine. The historical comparison is therefore retained as a limitation rather than reported as passed. RD remains opt-in, and P2P remains the default.

@xuxl1008
xuxl1008 marked this pull request as draft October 19, 2026 07:28
@xuxl1008
xuxl1008 force-pushed the feat/kda-cached-rd-cp branch from 775564e to 751ecd6 Compare October 19, 2026 07:29
@xuxl1008 xuxl1008 changed the title feat: add cached recursive doubling for KDA context parallelism feat: add KDA recursive doubling and Ulysses hybrid CP Oct 19, 2026
@xuxl1008
xuxl1008 force-pushed the feat/kda-cached-rd-cp branch 2 times, most recently from ce0c545 to 6fb380a Compare October 26, 2026 15:32
@xuxl1008

Copy link
Copy Markdown
Contributor Author

/check-pr

@xuxl1008

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1127 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 72%/33% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1127
Smoke_Ascend910b_Torch FAILURE 1127

@xuxl1008
xuxl1008 force-pushed the feat/kda-cached-rd-cp branch from 6fb380a to 3f53b2b Compare October 29, 2026 16:59
@xuxl1008 xuxl1008 changed the title feat: add KDA recursive doubling and Ulysses hybrid CP feat: add reset-aware KDA recursive doubling and Ulysses CP Oct 29, 2026
@xuxl1008
xuxl1008 marked this pull request as ready for review October 31, 2026 08:58
@xuxl1008
xuxl1008 force-pushed the feat/kda-cached-rd-cp branch from 3f53b2b to 3efec7b Compare October 31, 2026 09:34
@xuxl1008

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@xuxl1008

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- shard 242.208s 300.0s
- fully_shard 440.684s 600.0s
- pipeline_parallel 928.261s 600.0s
- optimizer 443.408s 300.0s
- auto_models 123.941s 150.0s
- accuracy 112.693s 120.0s
- clip_grad 117.879s 120.0s
- swap_optimizer 349.367s 300.0s
- init_weights 92.155s 118.75s
- distributed_checkpoint 88.801s 120.0s
- llama3_examples 92.167s 120.0s
- expert_parallel 158.92175s 120.0s
- activation_memory 112.38875s 120.0s
- tensor_parallel 266.93s 300.0s
- process_group 86.951s 90.0s
- dtensor 92.319s 120.0s
- context_parallel 92.206s 120.0s
- multicore 111.68812s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1348

@xuxl1008

xuxl1008 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1351 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 73%/77% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- shard 200.655s 300.0s
- optimizer 340.898s 300.0s
- pipeline_parallel 752.196s 600.0s
- fully_shard 403.268s 600.0s
- auto_models 110.777s 150.0s
- clip_grad 117.905s 120.0s
- accuracy 117.822s 120.0s
- swap_optimizer 327.557s 300.0s
- activation_memory 113.51575s 120.0s
- tensor_parallel 279.618s 300.0s
- dtensor 97.117s 120.0s
- context_parallel 107.393s 120.0s
- llama3_examples 107.852s 120.0s
- init_weights 97.224s 118.75s
- expert_parallel 139.26962s 120.0s
- distributed_checkpoint 87.212s 120.0s
- process_group 87.264s 90.0s
- multicore 123.91612s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1351

@xuxl1008

xuxl1008 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@mindspore-ai-bot

Copy link
Copy Markdown

🔵 The pipeline #1353 is running. Please wait a moment... (Link)

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details(Full/Incremental) Detail
Coverage Line Coverage ❌ FAILURE 73%/77% Link

@mindspore-ai-bot

Copy link
Copy Markdown
Platform Type Module Excution Time Time Limit
- shard 250.261s 300.0s
- optimizer 309.835s 300.0s
- auto_models 102.77s 150.0s
- pipeline_parallel 754.628s 600.0s
- clip_grad 128.993s 120.0s
- fully_shard 423.051s 600.0s
- activation_memory 122.28175s 120.0s
- distributed_checkpoint 106.448s 120.0s
- context_parallel 102.566s 120.0s
- llama3_examples 84.898s 120.0s
- tensor_parallel 277.729s 300.0s
- process_group 98.967s 90.0s
- dtensor 98.696s 120.0s
- swap_optimizer 343.038s 300.0s
- multicore 136.58125s 120.0s
- expert_parallel 161.11325s 120.0s
- init_weights 91.356s 118.75s
- accuracy 104.897s 120.0s

@mindspore-ai-bot

Copy link
Copy Markdown
Project Name Build_Stage Build Result Details
Hyper-parallel_Github_Gate - ❌ FAILURE 1353
Smoke_Ascend910b_Torch FAILURE 1353

@github-actions
github-actions Bot merged commit 8abb8e9 into mindspore-ai:master Nov 3, 2026
12 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants