[PR #4040] [Engine] --lookup-max-t: prompt-lookup windows up to 16 tokens while the MTP keeps --spec, bitwise, edits +19% decode #4889

Open
opened 2026-11-07 16:31:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4040
Author: @merbanan
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: pr/lookup-max-t


📝 Commits (5)

  • ec14b55 serve: --lookup-max-t N - prompt-lookup windows up to N tokens while the MTP keeps --spec
  • 999e504 verify: one-conversation windows up to 16 tokens (--lookup-max-t 16)
  • 419efbb serve: --lookup-max-t - the prompt's verify windows take the allowed sizes too; a layer split stops at 8
  • 176d3e8 verify: 16-token windows - the q8_1 scratch holds one token group, the GDN recurrence takes 16 tokens
  • 4dd7b48 docs: --lookup-max-t and --lookup-sizes in DETAILS.md

📊 Changes

11 files changed (+303 additions, -55 deletions)

View changed files

📝 docs/DETAILS.md (+6 -0)
📝 include/strata/core/mtp.hpp (+6 -0)
📝 include/strata/core/verify.hpp (+15 -9)
📝 include/strata/kernels/verify_kernels.hpp (+5 -0)
📝 include/strata/spec/draft_policy.hpp (+14 -1)
📝 src/core/mtp.cpp (+21 -0)
📝 src/core/verify.cpp (+77 -31)
📝 src/kernels/cuda/verify_kernels.cu (+6 -3)
📝 src/program/generate.cpp (+99 -5)
📝 src/spec/draft_policy.cpp (+22 -6)
📝 src/spec/draft_policy_test.cpp (+32 -0)

📄 Description

Problem and result

On a copy-heavy turn (an edit that rewrites a file), almost every prompt-lookup draft is accepted (1477 of 1487 on a 142-line rename, RTX 2060 SUPER), so decode is bound by the window cap of --spec + 2 tokens. Raising --spec to lift it makes the MTP's own windows longer too, which costs on ordinary turns.

--lookup-max-t N (up to 16) lifts only the prompt-lookup windows to N tokens. The MTP keeps --spec. Edits decode faster with the same tokens.

Approach

  • kVerifyLongT = 16 for the serial (one-conversation) decode window. Batch, pipelined and layer-split windows stay at kVerifyMaxT = 8.
  • A window past 8 tokens always runs as two token groups of at most 8 (the --spec-split layout). Every per-group kernel (fused hyper-connection reads, GDN, QSA, the router and resident plan), the CPU experts and the drafter keep their 8 rows. Only the window-wide parts take more:
    • the final mixer and the head matvec run in column chunks of 8 (one chunk, the same launches as before, for every window up to 8);
    • the batched GDN commit takes up to 16 kept rows (the per-layer commit fallback refuses windows past 8);
    • the PLE rows, NaN flags, window graphs, group counts and penalty history are sized for 16;
    • the q8_1 scratch holds one token group.
  • The drafter stays at 8 rows. MtpDrafter::draft_long catches up the accepted rows past its window through prefill() and drafts from the last one, so its K/V holds every accepted cell.
  • Every window size is a CUDA graph of its own (~20-35 MiB of VRAM), so past the MTP's sizes only --lookup-sizes A,B,... get one (default MTP+1, MTP+2 and N). A lookup window's graph is captured before its round; one that finds no VRAM is dropped for good (DraftPolicy::disable), and the round takes the next smaller allowed size instead of the engine exiting on verify: instantiate: out of memory.
  • The prompt tail's verify windows also take only allowed sizes (they used to be min(--spec, rest)). A layer split caps at 8.

Without --lookup-max-t nothing changes. Documented in docs/DETAILS.md; draft_policy_test covers the new size rules.

Validation

Environment: RTX 2060 SUPER 8 GB (sm_75), Ryzen 9 3900X, 92 GB RAM, Linux 7.0, CUDA build with gcc-13, Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS native pack, --kv k8v4 --spec 3 --mtp ... --expert-cache auto --prefill auto --max-context 131072. Baseline: main 7dd5cf18, built and run the same way.

Passed:

  • Default path byte-identical: without the flag, six greedy probes (two file edits, a 142-line rename, needle recalls at 10K / 30K / 60K) give the same output bytes as main.
  • --lookup-max-t 16 --lookup-sizes 8,16: the same six outputs, byte-identical to main (2 loads).
  • Speed (decode tokens/s), main (2 loads) vs this (2 loads):
    • edit-rename 40.5 / 40.3 -> 48.0 / 48.1
    • edit-log 40.8 / 40.5 -> 48.6 / 48.6
    • big-rename 40.4 / 40.3 -> 48.7 / 48.6 (+19%)
    • needle 10K 38.4 / 38.7 -> 43.3 / 43.3 (+12%)
    • prompt speed unchanged (4K / 16K / 32K: 336 / 370 / 380 vs 336 / 370 / 379)
  • Built and ran on this branch: draft_policy_test (PASS), verify_parity (PASS), spec_verify_parity (1296 rows, 0 mismatches), verify_batch_parity (PASS), prefill_plan_test, prefill_mmq_scatter_test; the same as main.

Failed: none observed.

Not run:

  • HIP and SYCL builds (no such toolchain here). The change touches src/core/verify.cpp, src/core/mtp.cpp, src/kernels/cuda/verify_kernels.cu and src/program/generate.cpp.
  • Layer split and batched serving with the flag (they keep 8 by design; not exercised on hardware here).
  • Other GPUs.

Limits

It helps turns where lookup drafts are long and mostly accepted (edits, rewrites, repeated text). Each extra window size costs a graph's VRAM, which is why --lookup-sizes exists; on a card with no room left, the larger sizes are dropped at run time and decode falls back to the smaller ones.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4040 **Author:** [@merbanan](https://github.com/merbanan) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/lookup-max-t` --- ### 📝 Commits (5) - [`ec14b55`](https://github.com/Niko1221/Strata/commit/ec14b5572f4a0cd67e4c91244c75fc070015168a) serve: --lookup-max-t N - prompt-lookup windows up to N tokens while the MTP keeps --spec - [`999e504`](https://github.com/Niko1221/Strata/commit/999e50465723e3b7e7856220ef0acd4d043aa9c8) verify: one-conversation windows up to 16 tokens (--lookup-max-t 16) - [`419efbb`](https://github.com/Niko1221/Strata/commit/419efbba98c3ba8e1bd1d8a2217df01191af39c6) serve: --lookup-max-t - the prompt's verify windows take the allowed sizes too; a layer split stops at 8 - [`176d3e8`](https://github.com/Niko1221/Strata/commit/176d3e8ee77e8e5c6d173cc15361af50c4d73ba3) verify: 16-token windows - the q8_1 scratch holds one token group, the GDN recurrence takes 16 tokens - [`4dd7b48`](https://github.com/Niko1221/Strata/commit/4dd7b4812d7f15b6d6a49e6ba7961f154183ee94) docs: --lookup-max-t and --lookup-sizes in DETAILS.md ### 📊 Changes **11 files changed** (+303 additions, -55 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+6 -0) 📝 `include/strata/core/mtp.hpp` (+6 -0) 📝 `include/strata/core/verify.hpp` (+15 -9) 📝 `include/strata/kernels/verify_kernels.hpp` (+5 -0) 📝 `include/strata/spec/draft_policy.hpp` (+14 -1) 📝 `src/core/mtp.cpp` (+21 -0) 📝 `src/core/verify.cpp` (+77 -31) 📝 `src/kernels/cuda/verify_kernels.cu` (+6 -3) 📝 `src/program/generate.cpp` (+99 -5) 📝 `src/spec/draft_policy.cpp` (+22 -6) 📝 `src/spec/draft_policy_test.cpp` (+32 -0) </details> ### 📄 Description ## Problem and result On a copy-heavy turn (an edit that rewrites a file), almost every prompt-lookup draft is accepted (1477 of 1487 on a 142-line rename, RTX 2060 SUPER), so decode is bound by the window cap of `--spec` + 2 tokens. Raising `--spec` to lift it makes the MTP's own windows longer too, which costs on ordinary turns. `--lookup-max-t N` (up to 16) lifts only the prompt-lookup windows to N tokens. The MTP keeps `--spec`. Edits decode faster with the same tokens. ## Approach - `kVerifyLongT = 16` for the serial (one-conversation) decode window. Batch, pipelined and layer-split windows stay at `kVerifyMaxT = 8`. - A window past 8 tokens always runs as two token groups of at most 8 (the `--spec-split` layout). Every per-group kernel (fused hyper-connection reads, GDN, QSA, the router and resident plan), the CPU experts and the drafter keep their 8 rows. Only the window-wide parts take more: - the final mixer and the head matvec run in column chunks of 8 (one chunk, the same launches as before, for every window up to 8); - the batched GDN commit takes up to 16 kept rows (the per-layer commit fallback refuses windows past 8); - the PLE rows, NaN flags, window graphs, group counts and penalty history are sized for 16; - the q8_1 scratch holds one token group. - The drafter stays at 8 rows. `MtpDrafter::draft_long` catches up the accepted rows past its window through `prefill()` and drafts from the last one, so its K/V holds every accepted cell. - Every window size is a CUDA graph of its own (~20-35 MiB of VRAM), so past the MTP's sizes only `--lookup-sizes A,B,...` get one (default MTP+1, MTP+2 and N). A lookup window's graph is captured before its round; one that finds no VRAM is dropped for good (`DraftPolicy::disable`), and the round takes the next smaller allowed size instead of the engine exiting on `verify: instantiate: out of memory`. - The prompt tail's verify windows also take only allowed sizes (they used to be min(--spec, rest)). A layer split caps at 8. Without `--lookup-max-t` nothing changes. Documented in docs/DETAILS.md; draft_policy_test covers the new size rules. ## Validation Environment: RTX 2060 SUPER 8 GB (sm_75), Ryzen 9 3900X, 92 GB RAM, Linux 7.0, CUDA build with gcc-13, Qwen3.8-Flash-Next GSQ-RCO IQ3_XXS native pack, `--kv k8v4 --spec 3 --mtp ... --expert-cache auto --prefill auto --max-context 131072`. Baseline: main 7dd5cf18, built and run the same way. Passed: - Default path byte-identical: without the flag, six greedy probes (two file edits, a 142-line rename, needle recalls at 10K / 30K / 60K) give the same output bytes as main. - `--lookup-max-t 16 --lookup-sizes 8,16`: the same six outputs, byte-identical to main (2 loads). - Speed (decode tokens/s), main (2 loads) vs this (2 loads): - edit-rename 40.5 / 40.3 -> 48.0 / 48.1 - edit-log 40.8 / 40.5 -> 48.6 / 48.6 - big-rename 40.4 / 40.3 -> 48.7 / 48.6 (+19%) - needle 10K 38.4 / 38.7 -> 43.3 / 43.3 (+12%) - prompt speed unchanged (4K / 16K / 32K: 336 / 370 / 380 vs 336 / 370 / 379) - Built and ran on this branch: draft_policy_test (PASS), verify_parity (PASS), spec_verify_parity (1296 rows, 0 mismatches), verify_batch_parity (PASS), prefill_plan_test, prefill_mmq_scatter_test; the same as main. Failed: none observed. Not run: - HIP and SYCL builds (no such toolchain here). The change touches src/core/verify.cpp, src/core/mtp.cpp, src/kernels/cuda/verify_kernels.cu and src/program/generate.cpp. - Layer split and batched serving with the flag (they keep 8 by design; not exercised on hardware here). - Other GPUs. ## Limits It helps turns where lookup drafts are long and mostly accepted (edits, rewrites, repeated text). Each extra window size costs a graph's VRAM, which is why `--lookup-sizes` exists; on a card with no room left, the larger sizes are dropped at run time and decode falls back to the smaller ones. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4889
No description provided.