From cc703b5e484cf869abcc8dfded010f3d0e2a4b3d Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Sun, 1 Nov 2026 09:48:05 +0100 Subject: [PATCH] #4040 --lookup-max-t 12 by default (serve, 8-row CUDA build, one GPU, no batch/DFlash2/layer split/chain); --lookup-max-t 0 or STRATA_LOOKUP_MAX_T=0 turns it off (owner 11-01) --- docs/DETAILS.md | 2 +- src/program/generate.cpp | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/DETAILS.md b/docs/DETAILS.md index d755037071..36fd9a0e52 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1047,7 +1047,7 @@ them on your own card. | `STRATA_NO_AVXVNNI=1` | CPUs with AVX-VNNI | Turns the AVX-VNNI row forms off (they give the same bits, 4-25% faster rows). | A diagnostic. | | `STRATA_PREFILL_EQUAL=1` | CUDA | A prompt segment is read in chunks of equal size, not full chunks and a short last one. Changes rounding. | | | `STRATA_OWNED_PRICE=exact` | CUDA | The cache sizing prices the prompt path's own buffers by their real allocation. | | -| `--lookup-max-t N` (up to 16), `--lookup-sizes A,B` | CUDA, one conversation on one GPU (a layer split, batch and pipelined windows stay at 8) | Prompt-lookup windows up to N tokens while the MTP keeps `--spec`. A window past 8 tokens runs as two groups of 8; each size is a CUDA graph of its own (about 20-35 MiB), a size that finds no VRAM is dropped. Same answers on file rewrites. Use 12: `--lookup-max-t 12`. | File rewrites and the edit turns of an agent loop decode +11 to +14% (RTX A6000 IQ3_S, greedy and sampled), +13 to +18% on a Tesla P100 IQ3_XXS; ordinary prose and code are within 1% at 12. 16 gains 1-3 points more on rewrites and costs 3-4% on some prose. A wide-window build (`-DSTRATA_WINDOW_MAX_T=12` or 16) gains less (+7 to +9%) and is not needed. Off by default. | +| `--lookup-max-t N` (up to 16), `--lookup-sizes A,B` | CUDA, one conversation on one GPU (a layer split, batch and pipelined windows stay at 8) | Prompt-lookup windows up to N tokens while the MTP keeps `--spec`. A window past 8 tokens runs as two groups of 8; each size is a CUDA graph of its own (about 20-35 MiB), a size that finds no VRAM is dropped. Same answers on file rewrites. On by default at 12 in the serve engine of the 8-row CUDA build on one GPU (no batch, DFlash2 or layer split); `--lookup-max-t 0` or `STRATA_LOOKUP_MAX_T=0` turns it off. | File rewrites and the edit turns of an agent loop decode +11 to +14% (RTX A6000 IQ3_S, greedy and sampled), +13 to +18% on a Tesla P100 IQ3_XXS; ordinary prose and code are within 1% at 12. 16 gains 1-3 points more on rewrites and costs 3-4% on some prose. A wide-window build (`-DSTRATA_WINDOW_MAX_T=12` or 16) gains less (+7 to +9%) and is not needed. | | `STRATA_PF_GROUP_SCRATCH=1`, `STRATA_PF_HC_REGION=1` | CUDA, prompt path on MMQ (not the fused int8 experts) | The prompt path's gate/up output, SwiGLU and q8_1 copy hold one expert group's rows, and the hyper-connection read's scratch shares the attention/MoE region. Same bits at an equal chunk. A line at start says when they took effect or why GROUP_SCRATCH is ignored. | Frees 0.3-0.5 GiB of borrowed cache slots so `--prefill auto` can pick a bigger chunk; the speed gain showed only with `STRATA_PREFILL_CPU_SHARE=0` (+7 to +11% on an emulated 8 GB card), because the bigger chunk leaves the CPU-share range. | | `STRATA_PW_WITH_BATCH=1` | CUDA/HIP layer split with `--pipeline-windows 2` and `--batch` slots | A request that is alone keeps the pipelined windows beside the batch slots; batch windows run without them. | 2x RTX A6000 IQ3_S: lone request +14% on code, +9% on a file rewrite, +3% on a long decode; two requests at once not slower. The second verifier takes about 270 MiB of the first card. | | `STRATA_MTP_ROOM_MIN=TOKENS` | CUDA, `--serve` with `--mtp`, no `--batch` | A request that reads at least TOKENS prompt tokens uses the draft layer's 512 decode-only experts (about 675 MiB) as extra ring slots while it is read, then gets them back. | The author measured +17 to +23% prompt on an 8 GB RTX 2060 SUPER; on a P100 limited to 8 GB (ring 8 to 311 slots) it gave +0.5% (CPU share off) and nothing with defaults. Off by default. | diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 3b54802228..1091fa9f49 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -910,11 +910,12 @@ struct Options { /// verify window (the window grows to at most 8). Greedy verification keeps the output; its own counts are kept. int lookup_chain = 0; int lookup_chain_min = 3; ///< --lookup-chain-min M: the shortest match (in tokens, drafts included) it extends on - /// --lookup-max-t N (opt-in, 0 = the --spec + 2 rule): prompt-lookup windows up to N tokens (<= kVerifyLongT) while + /// --lookup-max-t N (-1 = not given: 12 on a build whose windows hold 8 rows, one GPU, no batch / DFlash2 / lookup chain, owner decision + /// 11-01 for #4040; 0 = off, the --spec + 2 rule): prompt-lookup windows up to N tokens (<= kVerifyLongT) while /// the MTP keeps its --spec windows. A copy-heavy turn (an edit that rewrites a file) accepts nearly every lookup /// draft, so its decode is bound by the window length. Each window size is a graph of its own (~20-35 MiB of /// VRAM), so only --lookup-sizes get one past the MTP's sizes; a size whose graph finds no VRAM is dropped. - int lookup_max_t = 0; + int lookup_max_t = -1; /// --lookup-sizes A,B,.. : the lookup window sizes above the MTP's (default with --lookup-max-t N: MTP+1, MTP+2, N) std::string lookup_sizes; /// --mtp-hnorm stream (opt-in): the draft layer's pre_fc_norm_hidden normalizes each hyper-connection stream on @@ -1075,8 +1076,8 @@ void usage() { " --suffix-draft N prompt lookup: draft from an earlier repeat of the last N+ tokens of context\n" " when it pays (default 3; 0 = MTP only)\n" " --mtp-max-t M cap the MTP's windows at M tokens (0 = --spec; longer ones come from suffixes)\n" - " --lookup-max-t N opt-in: prompt-lookup windows up to N (<= 16) tokens (the MTP keeps --spec); copy-heavy\n" - " edits gain, each extra window size costs a graph (~20-35 MiB of VRAM)\n" + " --lookup-max-t N prompt-lookup windows up to N (<= 16) tokens (default 12 on one GPU in the 8-row build; 0 = off);\n" + " copy-heavy edits gain, each extra window size costs a graph (~20-35 MiB of VRAM)\n" " --lookup-sizes A,B the lookup window sizes past the MTP's (default: MTP+1, MTP+2 and N)\n" " --spec N the MTP drafter's verify window: how many tokens it proposes per check (setup\n" " writes 4; --suffix-draft lets it grow by 2, up to 8, where a repeat is likely)\n" @@ -4040,7 +4041,16 @@ int main(int argc, char** argv) { o.mtp_max_t = o.spec; o.spec = std::min(o.spec + 2, 8); // kVerifyMaxT } - // --lookup-max-t N (opt-in): lookup windows up to N tokens, the MTP's stay at --spec + // --lookup-max-t N: lookup windows up to N tokens, the MTP's stay at --spec. Not given: 12 where the pr-nv2 runs measured it (serve, one GPU, the 8-row + // build: rewrites and agent edit turns +11..14%, prose and code within noise); --lookup-max-t 0 or STRATA_LOOKUP_MAX_T=0 turns it off. The wide + // builds (HIP, 16 rows), a layer split, --batch, DFlash2 and --lookup-chain keep the old windows. + if (o.lookup_max_t < 0) { + const char* lme = std::getenv("STRATA_LOOKUP_MAX_T"); + const bool env_off = lme != nullptr && lme[0] == '0'; + const bool narrow = strata::kernels::kVerifyMaxT == strata::kernels::kVerifyNarrowT; + o.lookup_max_t = !env_off && narrow && o.serve && !multi_gpu && o.layer_split.empty() && o.batch <= 1 && o.draft != "dflash2" && + o.lookup_chain <= 0 && o.suffix_draft > 0 && o.spec >= 2 ? 12 : 0; + } if (o.lookup_max_t > 0 && o.suffix_draft > 0 && o.spec >= 2) { if (o.mtp_max_t == 0) o.mtp_max_t = o.spec; o.spec = std::max(o.spec, std::min(o.lookup_max_t, strata::kernels::kVerifyLongT));