[Refactor] Pass GLM DSA top-k IDs explicitly - #1988
Draft
jayhenry wants to merge 1 commit into
Draft
Conversation
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-v2← you are here (top of stack)Summary
This is the stack-compatible port of #1978. The explicit DSA top-k dataflow and offload design stay the same, while the integration is adapted to the non-reentrant and selective-checkpointing APIs introduced by #1979–#1981.
torch.int32dsa_topk_idsexplicitly through GLM decoder layers, intra-layer micro-batches, and MTP inputs/results, removing the mutableSequenceContextcache and manual cross-layer lifecycle runtime.TypedDictdecoder contract, list-based micro-batch API, and keyword checkpoint inputs instead of restoring the old reentrant-compatible flattened tuples.save_dsa_indexerselective checkpointing around only the mutation-free DSA top-k selection kernel, leaving index projections and the SP gather compiled and replayable.Checkpoint-stack adaptation
AttnOutputs, dense decoder outputs, and MoE decoder outputs exposedsa_topk_idsas an optional keyed field, which non-reentrant checkpointing can replay without input/output flattening.RecomputeUnit.SAVE_DSA_INDEXERresolves to the half-opendsa.indexer.begin→dsa.indexer.endinterval. Its eager island is enabled only when that unit is selected, so an unsetrecompute_cfgpreserves the original compiled path.Validation
Performance evidence from #1978
These measurements are from the original isolated implementation in #1978; this stacked port reran the functional coverage above.
Follow-ups
fullgraph=Trueseparately.save_dsa_indexeras a default.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.
flowchart LR A["Compiled index projections"] --> 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" .-> DConfiguration 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.