Repository navigation
model : fix MTP context kv cache allocation for deepseek2, glm4moe, c… - #28630
Merged
Merged
Conversation
…ohere2moe architectures (ggml-org#28626)
CISC
reviewed
Sep 9, 2026
… testing for mtp layer filtering
CISC
reviewed
Sep 10, 2026
Comment on lines
10
to
13
| // TODO: replace with #include "llama-ext.h" in the future | ||
| #include "../src/llama-arch.h" | ||
| #include "../src/llama-ext.h" | ||
| #include "../src/llama-model-saver.h" |
Member
There was a problem hiding this comment.
Hummm, not sure what exactly this TODO refers to and if it is stale/can be resolved now? @ggerganov
Member
There was a problem hiding this comment.
The idea of the TODO is to properly expose libllama internals through the llama-ext.h header only. It's still relevant.
For this PR, don't make any changes to test-llama-archs.cpp. The proposed changes are hard to follow and not generic enough.
CISC
approved these changes
Sep 11, 2026
ggerganov
approved these changes
Sep 11, 2026
Patt92
pushed a commit
to Patt92/llama.cpp
that referenced
this pull request
Sep 11, 2026
…ggml-org#28630) * model : fix MTP context kv cache allocation for deepseek2, glm4moe, cohere2moe architectures (ggml-org#28626) * model: add inverse architecture gating and comprehensive architecture testing for mtp layer filtering * model : slim NextN filter comment, drop test-llama-archs changes (cherry picked from commit 5cdd3d1)
5 tasks
6 tasks done
fencerJP
pushed a commit
to fencerJP/llama-apu
that referenced
this pull request
Sep 16, 2026
…ggml-org#28630) * model : fix MTP context kv cache allocation for deepseek2, glm4moe, cohere2moe architectures (ggml-org#28626) * model: add inverse architecture gating and comprehensive architecture testing for mtp layer filtering * model : slim NextN filter comment, drop test-llama-archs changes
quimmedes
pushed a commit
to quimmedes/cafe-llama.cpp
that referenced
this pull request
Sep 16, 2026
…ggml-org#28630) * model : fix MTP context kv cache allocation for deepseek2, glm4moe, cohere2moe architectures (ggml-org#28626) * model: add inverse architecture gating and comprehensive architecture testing for mtp layer filtering * model : slim NextN filter comment, drop test-llama-archs changes
x1250
pushed a commit
to x1250/llama.cpp
that referenced
this pull request
Sep 22, 2026
…ggml-org#28630) * model : fix MTP context kv cache allocation for deepseek2, glm4moe, cohere2moe architectures (ggml-org#28626) * model: add inverse architecture gating and comprehensive architecture testing for mtp layer filtering * model : slim NextN filter comment, drop test-llama-archs changes (cherry picked from commit 5cdd3d1)
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.
Overview
Fixes #28626. MTP draft contexts on DEEPSEEK2, GLM4_MOE and COHERE2MOE allocate KV for every layer instead of only the appended NextN block. This commit adds the three architectures to the existing NextN filter condition and includes a corresponding regression test. This allows for correct kv cache allocation in both the main and draft contexts.
Additional information
test-llama-archs gains a '--mtp-kv' flag. It builds all architectures that are MTP-capable as a synthetic model with an appended NextN block. It tests with a 2-layer and an 8-layer trunk, and checks the MTP context's KV cache is the same size at both depths. The MTP graph only runs one NextN block regardless of depth, so filtered draft context kv cache allocation is depth-invariant.
Adding a NextN block raises block_count and different architectures disagree on the resulting per-layer array length (cohere2moe/mimo2 read the SWA pattern at n_layer(), step35 at n_layer_all). The test matches how their respective loader and converters handle it.
Requirements