[Refactor] Pass GLM DSA top-k IDs explicitly - #1988
Open
jayhenry wants to merge 2 commits into
Open
Conversation
jayhenry
marked this pull request as ready for review
July 30, 2026 05:01
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 herefeat/dsa-topk-selective-checkpoint→feat/unify-offloadSummary
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, removing the mutableSequenceContextcache and manual cross-layer lifecycle runtime.xtuner/v1/model/moe/glm52/:GLM52AttnOutputs, GLM dense/MoE decoder layers, DSA MLA, and GLM MTP layers/blocks. Generic attention, decoder, and MTP APIs no longer expose DSA fields or parameters._call_decoder_layerextension point to the main MoE and MTP loops. GLM-5.2 overrides it to arrange DSA inputs/results and contain the saved-tensor offload window without duplicating the full decoder stack.Checkpoint-stack adaptation
TypedDictdecoder contract, list-based micro-batch API, and keyword checkpoint inputs instead of restoring the old reentrant-compatible flattened tuples.dsa_topk_ids; common outputs remain model-agnostic.Validation
xtuner.v1.model.moe.glm52package are included.Performance evidence from #1978
These measurements are from the original isolated implementation in #1978; this stacked port reran the functional coverage above.
Follow-up
PR #1989 keeps DSA top-k selection resident with selective checkpointing so backward replay does not recompute it.
Result
GLM-5.2 retains explicit, offloadable DSA top-k dataflow while the common attention, decoder, MTP, and checkpointing paths stay free of model-specific DSA APIs.