[Feature] Support GLM-5.2 source-layer DSA indexer training - #2022
Open
sjyouuuuug wants to merge 6 commits into
Open
[Feature] Support GLM-5.2 source-layer DSA indexer training#2022sjyouuuuug wants to merge 6 commits into
sjyouuuuug wants to merge 6 commits into
Conversation
jayhenry
reviewed
Aug 19, 2026
| weights = self.weights_proj(hidden_states).float() * (self.index_n_heads**-0.5) | ||
|
|
||
| # Top-k 索引是整数,不需要梯度,所以整个 indexer 都放在 no_grad 下。 | ||
| raw_weights = self.weights_proj(hidden_states) |
Author
There was a problem hiding this comment.
已经统一了,现在 weights_proj 只计算一次,并在 DSAIndexerFeatures 中保存一份 raw weights,不再维护 selection_weights 和 training_weights 两份张量。
| seq_ctx, | ||
| ), | ||
| ) | ||
| ) |
Collaborator
There was a problem hiding this comment.
对于 share layer 则不训练 indexer?
Author
There was a problem hiding this comment.
现在只训练 source layer 的 indexer,后面只复用,不算 kl
| debug_name: str | None = None, | ||
| debug_interval: int = 0, | ||
| ) -> Tensor: | ||
| """Convenience wrapper for one attention teacher and one indexer.""" |
Author
There was a problem hiding this comment.
主要参考 https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/core/transformer/experimental_attention_variant/dsa.py 中的compute_dsa_indexer_loss,算法的逻辑上是比较近似的,主 attention 的 query 计算 teacher attention distribution,通过 KL(teacher || indexer) 训练 indexer。sparse 模式下使用 Top-k mask 限制 token。
…o feat/glm52-indexer-training
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.
Motivation
Enable training of GLM-5.2 source-layer DSA indexers with attention-derived KL supervision.
Changes
Validation
Current limitations
SP_SIZE=1INTRA_LAYER_MICRO_BATCH=1cudnn_dsabackendResults