[Feature] Keep DSA top-k out of checkpoint replay - #1989
Open
jayhenry wants to merge 1 commit into
Open
Conversation
jayhenry
force-pushed
the
feat/dsa-topk-selective-checkpoint
branch
from
July 30, 2026 07:15
74cb1fd to
985442d
Compare
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.
Stack (bottom to top):
feat/sac-nonlegacy-base→mainfeat/sac-engine→feat/sac-nonlegacy-baserecompute_cfgand per-model marker 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.