PcieAuto refines the decode PCIe share (which of a layer's missed experts the GPU computes after a PCIe copy, the
rest on the CPU, which rounds differently) at fixed window counts, but the value it picks comes from the measured
CPU pool time. On an RTX A6000 (IQ3_S, DFlash2 Auto, frozen table, prompt share 0.5) two of 18 starts settled one
reading later (0.10 -> 0.15 at window 144 instead of 48) and gave other tokens from the second request on; with the
share fixed at 0.15 12 of 12 traced starts were identical, and identical to the 16 other starts.
- The table file gets an optional "pcie" line (0..1). The start that writes the table stores the share PcieAuto has
then (its third reading, or what it reached by that request's end) and fixes it from the next request; a start
that loads a file with the line runs with that share and PcieAuto off.
- A file written before this has no pcie line: it loads as before, PcieAuto refines as today, and once it has settled
(three readings, or it gave up) the share is written into the same file and fixed; the next start loads it.
- One GPU only (a layer split keeps PcieAuto's per-stage refinement). Same key, same ignore-and-relearn rules; without
--draft-costs nothing changes.
- draft_policy_test: the pcie round trip, an old file without it, out-of-range and malformed values refused.
The default CPU prompt share (prompt chunks under the share's limit, CUDA one card and gfx12) picks
which streamed experts the CPU computes from measured CPU and GPU times (an EMA) and decides per
layer, from measured layer times, whether to share at all. On an RTX A6000 that streams experts
(DFlash2 Auto configuration, frozen draft table, STRATA_ADAPT_NOWAIT=0) two starts gave identical
tokens in 7 of 24 requests with the share balancing and in 24 of 24 with it fixed at 0.25 or 0.5
or off; the fixed 0.5 read the one short chunk the share helps (981 tokens) in 1,001-1,009 ms against
995-997 ms balancing and 1,070-1,074 ms off.
- Prefill::fix_cpu_share(v): the default-armed share at a fixed value, used like a fixed
STRATA_PREFILL_CPU_SHARE (the EMA and the per-layer gate are skipped); the variable, when set,
still wins. Prefill::cpu_share_balancing() says whether it is still balancing; PrefillStats
gains the last balanced value and the number of readings.
- The table file gets an optional "share" line (0..1). With --draft-costs the engine stores the
balanced share, to a 0.05 step (0.5 when no short prompt measured it yet), when it writes the
table, and fixes it from the next request; a loaded file with a share fixes it from the start.
Same key, same ignore-and-relearn rule; without --draft-costs nothing changes.
- draft_policy_test: the share round trip and an out-of-range share refused. Settings register
regenerated (moved lines only).
The draft policy picks each verify window from round times it measures (an EMA), so two runs with the
same tokens can pick different windows and print different tokens. This adds what a frozen table needs;
nothing calls it on the default path yet.
- DraftPolicy::set_fixed_costs(ms, n, bucket): the table replaces the measured costs; no round time
changes a cost afterwards, and the first-use probes and the stale-size retry are off. The token
statistics keep learning. STRATA_SPEC_FIXED=1 (+ STRATA_SPEC_FIXED_TABLE) applies it in the
constructor, as the f-spec-frozen prototype did.
- CostLearner: the raw round times of a learning stretch per context bucket and window size; the
table is the 10 % trimmed mean per size (sizes not seen filled between measured neighbours or by
the prior shape). Plain means, not the EMA: three calibrations agreed within 0.3-1.8 % with means
and 3.5-21.8 % with the EMA's last value (RTX A6000, RTX PRO 5000). check() says when a stretch
is long enough and whether it looks disturbed: a size whose first and second half differ by more
than 15 %, more than 5 % of its rounds above twice its median, or a wider window cheaper than a
narrower one by more than 10 %.
- DraftPolicy::set_learning(true) feeds the learner from observe, observe_chain and held times.
- read_cost_file / write_cost_file: a small text file valid for one key; a missing, cut-short,
malformed or foreign file is refused with a reason, a write replaces the file whole.
draft_policy_test covers all of it (PASS, g++ -std=c++20 -Werror).
Removes AdaptiveGate, df2_gate_on() and df2_gate_row_ms() (window_rule.hpp), their three
sites in generate.cpp and their block in window_rule_test.cpp. The opt-in gate measured
2.7-4.9% slower; with it off (the default) the window rule is unchanged. The register
marks both retired in 0.2.13.
With DFlash2 as the drafter the MTP stays loaded as the fallback (use_mtp stays true), and three decisions tested use_mtp where they meant
"the MTP chain drew this round's candidates":
- STRATA_SPEC_COST=1 (a GB10 default): T = clamp(chain_rows, 1, S_mtp), but chain_rows is only written by the MTP chain callback, so with DFlash2
and no --draft-conf the window stayed at one row (CLI and serve; code_py 175 vs 258 tok/s on an RTX PRO 6000, serve 166-230 vs 283-397).
- STRATA_SPEC_PROB=1, sampled requests: ver.set_spec_q(mtp.spec_q()) judged DFlash2's deterministic candidates against the MTP's stale q lists
(CLI: 107 of 137 windows), and serve's gated path was not declined for DFlash2.
- the lookup choice read mtp.prob() for the same reason.
spec/window_rule.hpp holds the window rule and the q rule, both loops call it. The default path is unchanged: window_rule_test compares the new
rule with a copy of the old code over 9216 inputs (only the DFlash2 + cost rule + no --draft-conf cases differ). The CLI stats also print the
window histogram for any rule that sets the width and, when STRATA_SPEC_PROB judged windows, their count and source.
With DFlash2 as the drafter the MTP stays loaded as the fallback (use_mtp stays true), and three decisions tested use_mtp where they meant
"the MTP chain drew this round's candidates":
- STRATA_SPEC_COST=1 (a GB10 default): T = clamp(chain_rows, 1, S_mtp), but chain_rows is only written by the MTP chain callback, so with DFlash2
and no --draft-conf the window stayed at one row (CLI and serve; code_py 175 vs 258 tok/s on an RTX PRO 6000, serve 166-230 vs 283-397).
- STRATA_SPEC_PROB=1, sampled requests: ver.set_spec_q(mtp.spec_q()) judged DFlash2's deterministic candidates against the MTP's stale q lists
(CLI: 107 of 137 windows), and serve's gated path was not declined for DFlash2.
- the lookup choice read mtp.prob() for the same reason.
spec/window_rule.hpp holds the window rule and the q rule, both loops call it. The default path is unchanged: window_rule_test compares the new
rule with a copy of the old code over 9216 inputs (only the DFlash2 + cost rule + no --draft-conf cases differ). The CLI stats also print the
window histogram for any rule that sets the width and, when STRATA_SPEC_PROB judged windows, their count and source.
Port of PR 4040 by merbanan (rebased onto f-0291-int-trial, bitwise by the author's checks).
--lookup-max-t N (up to 16) lifts only the prompt-lookup windows to N tokens; the MTP drafts keep --spec. A window
past kVerifyMaxT tokens runs as two token groups of at most kVerifyMaxT (the --spec-split layout), the head runs in
column chunks, the batched GDN commit takes up to 16 kept rows, MtpDrafter::draft_long catches the drafter up past its
window, and every lookup size is its own window graph (--lookup-sizes A,B picks them; one that finds no VRAM is dropped).
A build whose windows already hold 16 rows (STRATA_WINDOW_MAX_T=16, the HIP default) runs the 16 as one group.
Batch, pipelined and layer-split windows stay at kVerifyMaxT. Without the flag nothing changes.
Port notes: kVerifyLongT = 16 for both window widths, the per-window-size graph arrays keep the trunk's
[sel_long_][T] layout, the head chunk loop keeps fused_gr_read_multi's own slicing, the penalty history is sized for
the widest window only when --lookup-max-t is past 8, and draft_long forwards the gated-proposal view.
Problem (KeyanHu-git): the gated proposal needs the choice between the MTP window and a
lookup window to be fixed by the history, not by the draws of the rounds it will verify.
Freezing the policy for the whole request (the first commit) does that, but also freezes
the cost table, so a repeat-heavy request kept the window sizes it inherited. In the
author's diagnostic workload the frozen policy chose mean lookup windows of 5.87 and 3.38
on two repeat requests; with this change 4.31 and 4.05 (from the PR text; not
reproduced here).
Change: the request's copy of the DraftPolicy (source_policy) gets three calls, used only
when gated_proposal is on:
- observe_committed(): the round's accept and probe counts, applied at once. A lookup
window counts as a probe of its size (tried_), so a size whose cost is only guessed is
tried kProbes times, not every round.
- defer_cost(end, t, ms): the round's time is held. A time covers the window and the next
MTP draft, so it depends on every Philox counter up to
max(p + T - 1, p + a + 1 + S_mtp).
- apply_costs(committed): applies, in order, the held times whose end is behind the
committed position, with the same update observe() makes (including the STRATA_SPEC_COST
clamp), in the context bucket the round ran in; delayed_n_ keeps a held time from
counting as a second probe.
choose() counts the probes as cost_n_ - delayed_n_ + tried_.
Port note: the DraftPolicy on the current tree keeps its costs per context bucket
(STRATA_SPEC_COST), so tried_, delayed_n_ and the held times carry the bucket. A gated
request does not run with STRATA_SPEC_COST (it falls back to the older rule), so its
copy stays in bucket 0.
Default path: unchanged. choose() reads two new terms; on any path that never calls the new
functions tried_ and delayed_n_ are +0.0 and cost_n_ - 0.0 + 0.0 == cost_n_ exactly.
Checked by driving the old DraftPolicy (namespace-renamed copy of f-027-gh-eng) and the
new one with the same random call sequences (observe, observe_chain, observe_probs,
set_context, seed_costs, set_robust, choose, chain, keep_draft; 400 sequences of 3000
steps): 25,983,538 bitwise comparisons of picks, costs and rates, 0 mismatches; one
observe_committed call makes the same harness report 60,528 mismatches. generate.cpp:
nothing calls the new functions when gated_proposal is false.
Tests: draft_policy_test (the PR's added assertions, on the bucketed class) and
spec_admission_test pass on z440 and on the owner PC.
Not covered: the sampling argument for the delay boundary (that a held time cannot steer
a window through a counter that is drawn again) is the author's; a unit test cannot show
it, only the distribution run (gate script 3416-spec-prob-dist.sh, arm NEWLK) can.
A window size's cost was updated only when that size was chosen, and the re-probe covered only sizes seen fewer than
three times. A size priced high during one slow stretch (a prompt's cache refill) could stay priced out for the life
of the process. A size not measured for 300 rounds is now tried again when a confident lookup could use it, one
round per stretch. Output is unchanged (the policy only picks which drafts to verify); draft_policy_test gains a case
that fails without the change.
Measured on Strix Halo (UD-IQ4_XS, 1-2K contexts) a verify row costs ~9 ms on a ~61 ms window, so chaining
every 3+-token match (49% of chained drafts accepted) gave +6.4% tokens per step for +7% window time. The
policy now picks the number of chained tokens k with the best expected tokens per ms: the MTP window's
measured tokens + p_mtp (c + c^2 + .. + c^k) at the measured cost of the longer window, where p_mtp is the
product of the draft layer's own draft probabilities and c the chained drafts' acceptance by match length
(their own decayed counts, learned only from rounds that reached the chain). Unmeasured sizes are probed a
few times when p_mtp * c >= 0.6. STRATA_LOOKUP_CHAIN_FIXED=1 takes every proposal as before.
All opt-in; with none of them given the engine runs exactly as before.
- --lookup-chain K [--lookup-chain-min M]: after the MTP's drafts, the suffix drafter matches the context
plus those drafts and appends up to K of the tokens that followed the match to the same verify window
(the window grows to at most 8). Greedy verification keeps the output. Own counts: a stderr line per
request and five more DONE fields when on.
- include/strata/spec/draft_source.hpp: a DraftSource interface (the request's own text is
PromptLookupSource; other sources register in extra_draft_sources() and the longest match wins).
- --mtp-hnorm stream: the draft layer's pre_fc_norm_hidden as one RMS per hyper-connection stream
(llama.cpp's qwen4exp MTP graph) instead of one over all four (vLLM's qwen4_exp MTP, the default).
New kernel native_qsa_rms_norm_grouped; the batched prompt K/V pass follows the switch.
- Diagnostics: STRATA_MTP_FULL_HEAD=1 drafts over the whole vocabulary; STRATA_MTP_TOP2=1 counts how often
the draft layer's runner-up is the token verify picked where a draft was rejected.
- Prompt lookup on by default: the suffix drafter's windows are taken only where a learned policy (measured
acceptance per match length, measured window cost) expects more tokens per ms than the MTP window; lookup windows
up to --spec + 2. Code edits +6-11%, other text unchanged, verified output identical. --suffix-draft 0 = off.
- Per-request sampling (#19) keeps greedy requests on the in-graph sampler (no extra launch per window), and draws
row t of a window with Philox(seed, pos0 + t), so a seed replays the same text whatever the drafts were.
- tools: a shallow install (G:\Strata) no longer crashes the MTP packer and the pack tools (IndexError, #20).
- setup: says at step 1 when the PC has less RAM than the smallest model needs; requires engine 0.1.7.
Inference engine, OpenAI/Anthropic API on localhost, optional image input, one-file setup
(START-HERE.bat / setup.sh). Model files are downloaded from Hugging Face by the setup.