Repository navigation
Studio: gate the MTP target-KV reserve to MTP spec mode, not just MLA - #6449
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the MTP overhead estimation logic in llama_cpp.py to distinguish between true MTP draft modes and separate-drafter speculative modes (such as draft-simple and draft-eagle3). It introduces the mtp_keeps_target_ctx parameter to avoid charging the duplicated target KV context overhead to separate-drafter modes, which do not maintain this copy. Additionally, a new unit test has been added to verify this behavior, and a minor lambda cleanup was performed. There are no review comments, so no further feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
_estimate_mtp_overhead_bytes is also reached for the separate-drafter spec modes (draft-simple / draft-eagle3) through _user_draft_via_extras. Those modes load a small distinct drafter with its own KV -- already counted in the draft KV + weights -- and keep no duplicated full target context; only MTP runs a second context over the target model's own KV geometry (llama.cpp ctx_tgt). Charging the ~main-KV-sized f16 copy there over-reserved by tens of GiB on an MLA model and needlessly shrank the advertised context, the same under-advertising #6312 set out to fix. Thread mtp_keeps_target_ctx through _estimate_mtp_overhead_bytes (True for MTP, False for separate-drafter modes) and derive _engaged_is_mtp at the fit call site so the target copy is added only when the engaged mode is actually MTP. MLA + MTP (GLM-5.2 / DeepSeek / Kimi) is unchanged, so the GLM-5.2 OOM fix is preserved; non-MLA and the draft-simple / draft-eagle3 paths no longer pay the copy. test_mtp_mla_target_ctx.py adds a case asserting the separate-drafter reserve collapses to the draft KV (no target copy) while the default MTP path keeps it.
e402555 to
2698f31
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Summary
Follow-up to #6447. That PR reserves a duplicated f16 copy of the target model's KV context for MLA models under MTP speculative decoding (llama.cpp's
ctx_tgt), which fixed the GLM-5.2 first-decode OOM. The reserve was gated only on MLA (kv_lora_rankpresent), but_estimate_mtp_overhead_bytesis also reached for the separate-drafter spec modes (draft-simple/draft-eagle3) via_user_draft_via_extras. Those modes load a small distinct drafter with its own KV (already counted in the draft KV + drafter weights) and keep no duplicated full target context; only MTP runs a second context over the target model's own KV geometry.So on an MLA model, selecting
--spec-type draft-simpleordraft-eagle3through the extra-args field charged a full ~main-KV-sized f16 copy (tens of GiB) that those modes never allocate, needlessly backing off the advertised context. That is the same under-advertising #6312 set out to fix, just in the opposite direction. It is in the safe direction (over-reserve, never OOM) but a real regression for that configuration.Fix
Thread
mtp_keeps_target_ctxthrough_estimate_mtp_overhead_bytes(True for MTP draft modes, False for the separate-drafter modes) and derive_engaged_is_mtpat the fit call site, so the target copy is added only when the engaged spec mode is actually MTP.kv_lora_rank) and stays so.draft-simple/draft-eagle3no longer pays the target copy.Test
test_mtp_mla_target_ctx.pyaddstest_separate_drafter_mode_drops_target_copy: on an MLA backend the separate-drafter reserve collapses to exactly the draft KV (no target copy), while the default MTP path keeps draft KV + the full f16 target copy.Addresses the Codex review on #6447 (
r3437715720). Existing MTP budget + MLA reserve suites pass (134 tests).