Fix missing ReLU in GLM-MOE-DSA indexer scoring#44690
Closed
gambletan wants to merge 1 commit intohuggingface:mainfrom
Closed
Fix missing ReLU in GLM-MOE-DSA indexer scoring#44690gambletan wants to merge 1 commit intohuggingface:mainfrom
gambletan wants to merge 1 commit intohuggingface:mainfrom
Conversation
The DSA indexer was missing a ReLU activation on the per-head dot-product scores before the weighted sum across heads. The reference DeepSeek V3.2 implementation applies ReLU inside the fp8_index kernel via `T.max(logits, 0)` before multiplying by head weights. Without this, negative attention scores incorrectly contribute to the index scoring, which can affect top-k token selection for sparse attention. Fixes huggingface#44360 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: glm_moe_dsa |
Member
|
Running a code agent to spam our notifications with a redundant PR when there's a maintainer PR already at #44564 is a good way to get blocked - be careful! |
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.
Summary
Fixes #44360
The
GlmMoeDsaIndexeris missing a ReLU activation on the per-head dot-product scores before the weighted sum across heads. The reference DeepSeek V3.2 implementation applies ReLU inside thefp8_indexkernel:The computation flow in the kernel is:
logits = q @ k^T(per-head dot products)logits = relu(logits) * weights(ReLU, then multiply by head weights)index_score = sum_h(logits)(reduce across heads)The HF bf16 equivalent was missing step 2's ReLU. Without it, negative attention scores incorrectly contribute to index scoring, which can affect top-k token selection for sparse attention.
Change
Added
torch.nn.functional.relu(scores)after the per-headq·k^Tcomputation and before the weighted sum, in bothmodular_glm_moe_dsa.pyandmodeling_glm_moe_dsa.py:scores = torch.einsum("bshd,btd->bsht", q.float(), k_cached.float()) * self.softmax_scale + + # ReLU matches the reference fp8_index kernel: T.max(logits, 0) before weighting + scores = torch.nn.functional.relu(scores) + index_scores = torch.einsum("bsht,bsh->bst", scores, weights)Test plan