Repository navigation
refactor: migrate V4.1 CSA2 to the module family architecture - #1606
Merged
xingleixu123 merged 1 commit intoNov 21, 2026
Merged
Conversation
xuxl1008
requested review from
kisnwangg,
liuchongming74,
suteng,
yangzhenzhang02 and
yaoyifanx
as code owners
November 18, 2026 06:08
xuxl1008
force-pushed
the
refactor/v41-csa2-module-family
branch
from
November 18, 2026 06:50
ebef8f2 to
1e8b366
Compare
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
commented
Nov 18, 2026
xuxl1008
force-pushed
the
refactor/v41-csa2-module-family
branch
from
November 19, 2026 07:58
1e8b366 to
4d9726a
Compare
Contributor
Author
|
/check-pr |
Contributor
Author
|
/retest |
|
|
@xuxl1008, your gate pipeline failed at the code check stage. You can configure some code check tools locally following the (pre-push quick guide), to enable automatic checking when you push your code every time. Tools included are: Check_CMakelint, Check_Codespell, Check_Cpplint, Check_Lizard, Check_Pylint, Check_ClangFormat, Check_ShellCheck. |
xuxl1008
force-pushed
the
refactor/v41-csa2-module-family
branch
from
November 19, 2026 09:29
4d9726a to
6672b27
Compare
Contributor
Author
|
/retest |
|
🔵 The pipeline #1889 is running. Please wait a moment... (Link) |
|
|
|
|
Contributor
Author
|
/retest |
|
🔵 The pipeline #1895 is running. Please wait a moment... (Link) |
|
yaoyifanx
approved these changes
Nov 20, 2026
xingleixu123
enabled auto-merge
November 21, 2026 06:45
xingleixu123
disabled auto-merge
November 21, 2026 06:45
This was referenced Nov 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paired: GitHub #1606 ↔ GitCode !1980
What type of PR is this?
/kind refactor
What does this PR do / why do we need it:
Migrate DeepSeek-V4.1 CSA2 to the common module-family architecture. Split attention, compression, Indexer selection, auxiliary KL, document layout and parallel scheduling out of
shared_compressed_dsa_attention.py, and remove the model adapter's second wrapper around attentionforward.The public entry point is
hyper_parallel.components.modules.CompressedSparseAttention2. The family selects local/CP implementations from the topology and reference/fused implementations throughuse_fused_ops. Common TP/SP boundaries handle input/output redistribution; intermediate head reductions are bound separately. Fusion and Indexer load balancing still require TP=1 and reject unsupported configurations explicitly.Responsibilities and execution boundaries
compressed_sparse_attention2_family.pycompressed_sparse_attention2.pycompressor.pyindexer.pyCSA2Indexerprojections, shared-key production/consumption and discrete selectionindexer_kl_loss.pydocument_layout.pycp_compressed_sparse_attention2.pyExisting module-family builders, TP/SP boundaries, CPContext, collectives, sequence dispatch, Indexer balancing, functional operator adapters and checkpoint infrastructure remain part of the execution path. The architecture and diagrams are described in #1627.
Compressor and Indexer remain actual submodule calls, so their projections execute inside the scopes managed by FSDP and activation checkpointing. Source replacement preserves Parameter/buffer identity, buffer persistence, trainability, child training modes and checkpoint keys. Direct construction retains the HF V4 parameter construction order; this family implements the V4.1 algorithm.
Additional changes:
publish_*methods. Validation traces record actual publications only._DeferredBankLaunch: launch main KV explicitly after Index K submission, store the actual handle and wait at consumption. Preserve the existing communication dependencies.Configuration
Remove the old attention
*.self_attn.forwardreplacement andtp_divide_attrs: [num_groups]to avoid duplicate wrapping and sharding. Full/Reindex/Reuse roles, natural-document isolation, candidate restrictions, teacher/KL formulas and Q chunking retain their existing semantics.Position and runtime-validation fixes from #1553
Which issue(s) this PR fixes:
Refs #1627 and #1553. Module-family foundation: #1523. MLA/GQA comparison: #1587. Related optimizer-state issue: #1585.
Test Plan and Test result: What scenarios were tested, and what were the verification results (function, performance, reliability, etc.)?
Module and distributed numerical checks
none+AG+r2,zigzag+A2AV+r2,greedy+AG+r1andhybrid+A2AV+r2, plus CPU TP2 with SP off/on. Outputs, TopK, input gradients and all parameter gradients matched withrtol=0, atol=0.Trainer, TP and multi-source role chains
The following comparisons used pre-refactor master
7db2d93fb734a216e3e3580bb63e800534d5fc51and the measured PR revision7a040f386bd622b016ee6cab30d1489e2e6b924a, with identical topology, weights, data and precision.Trainer checks compared every input, actual parameter gradient, updated parameter/buffer, loss, gradient norm and learning rate using raw tensor-byte hashes. Text covered 4,080 gradient pairs and 4,720 parameter/buffer pairs; VLM covered 5,120 and 5,920 respectively. Experts, routers, Engram, vision encoder and aligner produced nonzero gradients. All final runs exited normally. KL was not recorded as a separate scalar; all Indexer gradients and updates were compared.
The candidate used this PR's runtime contract directly. The old-master baseline received only equivalent validation-condition and checkpoint-wrapper recognition fixes, without changes to attention, communication or optimizer mathematics.
TP runs used the supported reference path (
use_fused_ops=false). Native TP score/teacher reduction was not added. The Trainer's existing full checkpoint policy still excludes Full source attention; whole-attention checkpointing was tested separately in the role-chain experiment.Environment: Torch/Torch-NPU 2.12.0, CANN 9.2.0, Transformers 5.13.1 and Ascend 910B3. The fused adapters used the existing
v41_training_transformervendor dated 2026-09-23. This is not evidence that the CANN 9.2 built-in SMLA metadata supports ratio 2. These diagnostic runs included CPU tensor copies/hashing and are not performance measurements.Rebase and follow-up checks
Rebased onto
master@9d9d06539700f0088ba3f9722a0ce9efdd52a8d4without conflicts. At that revision the production Python code matched the measured revision above; the additional change was the sharding README. Thirty real-module layout configurations (five roles × TP1/2/4 × SP off/on), 100 related CPU tests, documentation links and catalog checks passed. Test counts from separate rounds overlap and should not be added together.The 2026-11-20 follow-up rebases onto
master@1d489a70(including the public EP cleanup). Local execution of the CPU CP8 smoke test exposed an obsoletedeepcopy(model)in the test setup: public RMSNorm family members retain immutable build metadata that is not pickleable. The test now constructs an independent model and strictly loads the same state before conversion. Output, gradient and optimizer-update assertions and the gate level are unchanged. The launcher passed locally with both Torch 2.10 and 2.12. The remote build's earlier pytest exit code 4 did not include worker-level diagnostics, so the remote rerun is still required to establish whether it has an additional collection/environment failure. Common torchrun/logging utilities were not changed.Remote build #1882 subsequently passed that CPU smoke stage, code checks and compilation. Its UT stage reported three additional legacy whole-module deepcopy failures in the V4.1 compressor, shifted-mHC/DSpark, and native auxiliary-loss tests. These setups now also construct independent modules and strictly load matching state. All 21 tests in the two affected test files pass locally, with all existing output/gradient assertions retained. The final revision includes both the CP8 setup fix and these three setup fixes; the remote rerun remains the final gate check.
Validation boundaries
The full 40-layer training model, released deep Reindex layers in an end-to-end run, joint TP with nontrivial FSDP parameter sharding, MegaMoE/MegaGate, encoder parallelism, static graphs and full distributed checkpoint save/resume remain outside the completed matrix. No new performance claim is made.
Issue #1585 F3 is a pre-existing training-parameter/checkpoint problem: with KL disabled, Indexer parameters remain in optimizer groups without initialized state. A CPU Full→Reindex→Reuse probe trained three steps, restored into a fresh model/optimizer and compared the fourth update. The original implementation failed for both nested and flattened state formats; excluding or statically freezing inactive Indexer parameters restored both formats with bitwise-identical subsequent updates and unchanged model checkpoint keys. This is not a full NPU/FSDP restore result. The permanent-KL-off fix is submitted separately in #1639; this refactor does not change trainability or relax strict loading.
Self-checklist: