[Feature] Keep DSA top-k out of checkpoint replay - #1989
Conversation
74cb1fd to
985442d
Compare
|
Heads-up: #1988 was rebased onto the rewritten SAC stack (new head Your commit is written against APIs that no longer exist:
A unit now declares what it resolves to, via
Two things stopped me from just writing that:
Guessing would put code you did not write, and that I cannot verify, into your PR. Your call on the mapping; happy to do the mechanical part once you have decided. |
985442d to
81d2b2f
Compare
81d2b2f to
4511a97
Compare
4511a97 to
557e635
Compare
557e635 to
f9b4b32
Compare
Stack (bottom to top):
feat/sac-nonlegacy-base→mainfeat/sac-engine→feat/sac-nonlegacy-baserecompute_cfgand per-model recompute declarations (3/3) #1981feat/sac-recompute-cfg-v2→feat/sac-enginefeat/unify-offload→feat/sac-recompute-cfg-v2feat/dsa-topk-selective-checkpoint→feat/unify-offload← you are here (top of stack)Summary
This PR implements the selective-checkpoint follow-up from #1978 on top of the current non-reentrant checkpoint stack.
save_dsa_indexerselective checkpointing around only the mutation-free DSA top-k selection kernel.SAVE_DSA_INDEXERis selected; an unsetrecompute_cfgpreserves the original compiled path.torch.compile.RECOMPUTE_CFG=save_dsa_indexerin the GLM SFT example.Selective interval
RecomputeUnit.SAVE_DSA_INDEXERresolves to the half-open intervaldsa.indexer.begin→dsa.indexer.end. The markers enclose only the actual top-k selection, which is mutation-free and safe for selective-checkpoint caching.flowchart LR A["Compiled index projection and RoPE"] --> B["Compiled SP gather"] B --> C["dsa.indexer.begin"] C --> D["Eager mutation-free top-k selection"] D --> E["dsa.indexer.end"] E --> F["Compiled sparse MLA"] G["Checkpoint replay"] -. "SAC cache hit: skip top-k execution" .-> DValidation
DSA top-k selective-checkpoint regression (2026-07-29)
Summary
The narrow interval is functionally correct and bounded: checkpoint replay does not execute the top-k selection again, the default path remains unchanged, and the 16K production-style run needs less than 1 GB of additional peak allocated memory. On this workload the opt-in path costs about 3.15% aggregate TGS, so it remains an explicit memory-for-replay policy rather than a default.
Configuration and methodology
2.9.1+cu128; CUDA 12.8;conda activate pt29_glm1.GLM-5.2-30B-MTP-new, 5 main decoder layers + 1 MTP layer, 32.797B trainable parameters.SAMPLE_MAX_LENGTH=4096;PACK_MAX_LENGTH=16384; GBS8.1e-6; activation offload, DSA top-k offload, optimizer swap, and explicit GC disabled to isolate selective checkpointing.control → selective → selective2 → control2, yielding 256 all-rank steady-state records and 32 paired rank-0 steps per variant.RECOMPUTE_CFG; selective usedRECOMPUTE_CFG=save_dsa_indexer. Tokens were identical rank-by-rank and step-by-step.Results
save_dsa_indexer, 2 runs>=1.8 s)The two order-balanced aggregate TGS comparisons were:
control → selectiveselective2 → control2Across the 32 paired rank-0 steady steps, selective step time was +3.31% on average and +3.68% at the median; the approximate 95% interval was +2.53% to +4.09%. The repeat confirms that the slowdown is not an execution-order artifact.
Functional regression
aten.topkexecution during backward replay before the interval existed.torch.compile(fullgraph=False)tests both observe zero backward top-k executions and finite gradients.[('dsa.indexer.begin', 'dsa.indexer.end')]and emit no missing/inert marker warning..scratch/dsa_indexer_sac_regression/results/16k_kernel_{control,selective,selective2,control2}/.Conclusion
save_dsa_indexernow provides the requested mutation-safe selective interval without changing the default compiled graph. It reliably removes the top-k selection from checkpoint replay and is compatible with non-reentrant checkpointing, MTP, FP8, compile, SP/EP, micro-batching, and offload. The measured 16K trade-off is +0.90 GB maximum peak allocation and -3.15% aggregate TGS, which is why the policy is opt-in.