GLM-DSA: improve TG performance#2067
Merged
Merged
Conversation
ikawrakow
pushed a commit
that referenced
this pull request
Jul 2, 2026
) The batch >8 indexer path in build_deepseek2_dsa_indexer accumulates the per-head scores with ggml_add_inplace into an accumulator that is seeded from a view of KQ_mask. On -fa 0, KQ_mask is the raw F32 input tensor, so the in-place writes land in the shared KQ_mask buffer and corrupt the causal mask that build_deepseek2_dsa_sparse_mask and the later softmax layers read back, which gives garbage perplexity. -fa 1 is unaffected (its F16 mask is cast to a private F32 buffer), and the small-batch path added in #2067 is unaffected (it uses a non-inplace add). Take a private copy of the seed in the batch >8 -fa 0 path (raw F32 mask) before the accumulation, matching what those two paths already do. 4K -fa 0 --dsa PPL goes from thousands to 2.7134 (dense 2.6972, -fa 1 --dsa 2.7111). -fa 1 and non-DSA builds are byte-identical. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ikawrakow
pushed a commit
that referenced
this pull request
Jul 3, 2026
#2071) - fix incorrect reshape in the small-batch (n_tokens <= 8) indexer path - anchor inp_dsa_sink in the graph with ggml_build_forward_expand
4 tasks
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.
As part of the effort to reduce the compute buffer sizes required for GLM-DSA, the indexer computation was done in a loop over indexer attention heads.
This PR changes the approach for small batches (<=8) to compute the indexer score via a single matrix multiplication. RELU, and sum over attention heads. The change is limited for batch sizes <=8 to preserve the compute buffer reduction of the loop over attention heads.
The change improves GLM-DSA TG performance by nearly 10%.
DSA is still slower than no-DSA, but hopefully we can improve that in follow up PRs.
Below are some
sweep-benchresults with this PR compared to no-DSA. GLM-5.2-Q4_K_M, 13x3090 (limited to 200W each), Ryzen-3995WX CPU. Command line iswhich results in routed experts in 37 layers being left in RAM.
No DSA
DSA, this PR