Skip to content

dsv41 lookup: add TF_DSV41_COPY_DRAFTER ranked band matching, doubling and yield gating - #2638

Merged
ashhart merged 7 commits into
ashhart:mainfrom
christopherowen:feat/copy-drafter
Nov 21, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
christopherowen:feat/copy-drafter

Conversation

@christopherowen

@christopherowen christopherowen commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends DeepSeek-V4.1's priced lookup planner (zig/src/families/deepseek_v41/draft/lookup.zig) with native continuation-ranked band matching, adaptive doubling (8 -> 15), and span-aware expected-yield gating (written directly against TensorFold's SuffixIndex, Planner, and depth.bestK, following ideas first tried in christopherowen/spark-ds41f), gated behind the strict environment switch TF_DSV41_COPY_DRAFTER=1 (default off; TF_DSV41_LOOKUP_PLAN=1 behavior is unchanged when unset):

  1. Continuation-ranked band matching (SuffixIndex.matchRanked / proposeRanked):

    • Within the highest matched length band (>= min_match), ranks candidate occurrences by available non-overlapping continuation tokens up to the requested offer width (want), breaking ties by match length and then recency.
    • Stops before reading into the suffix tail (t.len - m.len) or any image virtual token (>= vbase), preventing short near-tail matches from wrapping into self-repetition when an earlier occurrence in the same band has a full continuation.
  2. Adaptive doubling offer width (8 -> 15):

    • Starts copy proposals at initial_offer = 8 (doubled: bool = false).
    • Doubles the offer cap to max_rows - 1 = 15 (doubled = true) after a lookup round where all offered drafts are accepted (kept >= drafts), and resets doubled = false on any partial rejection or non-lookup round.
  3. Span-aware pricing and expected-yield gating (Planner.altYield, copy_span_base / copy_span_slope):

    • For short Band-0 matches (len = 4..7, q = 0.45), keeps i.i.d. geometric survival (copy_yield ~ 0.45..0.82 < 1.0), gating off short cold matches on chat.
    • For contiguous span matches (b >= 1, len >= 8) when q >= bands[1].prior (0.70) or on a cooldown re-probe (copy_probe_every = 2), prices per-step continuation survival as q_eff = 0.75 + 0.25 * max(q, bands[b].prior) (0.925 / 0.950 / 0.975 for Bands 1/2/3, yielding 5.76 / 6.40 / 7.16 expected drafts at k = 8 and 10.2..12.4 at k = 15). This prevents depth.bestK and copy_yield >= p.altYield(r) from rejecting 8–15 and 16–31 token agent/code copies alongside a 3–4 tok/round neural drafter (both on DeepSeek-V4.1's GB10 calib-1bb.json curve and in @jschmied's replay), while still dropping back to q (0.467, yield ~0.86) immediately after a 0-keep miss.
  4. Strict environment validation & profile registration:

    • Registers TF_DSV41_COPY_DRAFTER (0 or 1) in zig/src/platform/environment.zig (.dsv41, .flag) and zig/src/core/profile.zig (.experimental, deepseek_v41 on CUDA).
    • Shares lookup.Settings.checkCopyDrafter / lookupEnabled between zig/src/families/deepseek_v41/draft/lookup.zig and zig/src/families/deepseek_v41/env_validate.zig (moving the family rule out of platform/environment.zig's generic refusal), refusing with error.InvalidEnvironment (naming TF_DSV41_COPY_DRAFTER and TF_DSV41_LOOKUP) when TF_DSV41_LOOKUP is blank or off.

Verification & Replay Measurements

What has been measured

  • Host test suites:
    • draft/draft.zig (52/52 tests pass, including all 18 tests in lookup_test.zig):
      • Full 3,000+ round golden replay (fixtures/lookup-golden.json) with copy_drafter = false (100% unchanged).
      • Continuation-ranked band matching vs near-tail wrap (matchRanked / proposeRanked).
      • Adaptive doubling (8 -> 15) on DeepSeek-V4.1's TP=2 GB10 calibration curve (calib-1bb.json from fixtures/calib-golden.json) alongside a 3-keep DSpark stream (altYield = 3.0), and reset (doubled = false) on partial rejection.
      • Span-aware copy_yield vs Planner.altYield gating: blocks short cold Band-0 matches (len = 4..7), opens Band 1 (len = 8..15) alongside a 3-keep DSpark stream, gates off Band 1 after a 0-keep miss, re-probes after the 1-skip cooldown (copy_probe_every = 2), and gates off cold Band 1 when altYield exceeds copy_yield (kept = 6).
      • End-to-end lookup.Proposer + Lanes + Twin exact token-for-token parity against Twin.serial under both greedy (null) and stochastic (temperature = 0.85, top_p = 0.9, top_k = 4, seed = 42) sampling, asserting active copy trials and accepted copy drafts (copy_trials > 0 and copy_acc > 0).
    • environment.zig (13/13), env_validate.zig (23/23), profile_test.zig (19/19), profile_line.zig (11/11), and python3 tools/pr_check.py --pr 2638 (0 error(s), 0 warning(s)).
  • Host Planner + TP=2 Measured Cost-Table (servedCosts / calib-1bb.json) Replay:
Workload TF_DSV41_LOOKUP_PLAN=1 (copy_drafter = false) TF_DSV41_COPY_DRAFTER=1 (copy_drafter = true) Delta
Chat (recurring 4..10 tok phrases, 0-keep false-positive copies vs DSpark) 4.00 tok/round, 82.7 tok/s 4.00 tok/round, 82.7 tok/s (0 false-positive copy rounds) 0.0% chat regression (short/miss bands gated off)
Agent / Code (repeated 10..32 tok spans with earlier 15-tok continuation + near-tail collision) 2.65 tok/round, 55.1 tok/s 3.35 tok/round, 65.6 tok/s (8 -> 15 doubling + ranked match) +26.4% tok/round, +19.1% tok/s
  • Cross-family replay on Qwen3.8-27B + DSpine / DFlash2 (@jschmied, #issuecomment-6764291262):
    • Confirmed 0.0% chat regression (50.9 / 41.5 tok/s, eliminating the -6% chat regression from min_match = 5), and identified that i.i.d. geometric decay (0.70^k / 0.80^k) in bestK and copy_yield >= altYield turned down 65 of 73 agent matches in Bands 1–2 (8..31 tokens), which is resolved in fc1bba68e by pricing active b >= 1 (>= 8-token) span continuations with q_eff = 0.75 + 0.25 * max(q, bands[b].prior).

What has not been measured yet

  • Live served DeepSeek-V4.1 EXL3 GPU cells (token_sha parity against main and "draft": false, solo and concurrent, and served tok/round + decode tok/s on agent, code, and chat prompts): neither our accessible hosts nor @jschmied's GB10 hold a packed DeepSeek-V4.1 .exl3 checkpoint + TF_DSV41_ASSETS directory, so live served deepseek_v41 GPU cells remain unmeasured pending a machine with that checkpoint loaded.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@christopherowen, welcome, and thanks for a careful first PR. The exactness test against Twin.serial at greedy and keyed sampling is the right check, and the default-off switch keeps serving as it is. Before we go further, a few questions:

  1. Where does CopyDrafter come from? The description says it ports CopyDrafter. Could you name the source (project, file and licence, or a paper)? Parts of core/lanes/copy_drafter.zig read like a CPU rendering of a GPU kernel from a batch scheduler: the 32 chunks × 8 warps × 32 lanes scan in copyMatchViewChunks, and copyMatchBatch's num_reqs/query_lens/seq_lens with mid-prefill masking. We can only take code written for this engine. An idea from a paper is welcome, but code translated or adapted from another engine's implementation, GPU kernels included, can't land here. If any of it was, please say so, and we'll help shape a version written against our lanes.

  2. How does it relate to what's already there? Core has a copy proposer (lanes/proposer.zig, SuffixLookup), copy windows with a decayed per-stream landing rate (lanes/windows.zig, copyRate/observeCopy), and a copy index (core/copy_index.zig). DeepSeek-V4.1 also has its own priced lookup drafting (draft/lookup.zig, TF_DSV41_LOOKUP_PLAN=1). The parts that look new here are the doubling offer and the gate against the neural drafter's expected yield. Those would fit as extensions of windows.zig's copy pricing or lookup.zig's plan, rather than as a second copy module in core. Could you show what the existing pieces can't do?

  3. Nothing turns it on yet. serve_engine.zig and serve_lanes.zig build Lanes without .copy, so the drafter is reachable only from the tests. If it proceeds, it needs one strict switch in platform/environment.zig (blank as unset), with docs/environment.md and core/profile.zig rows.

  4. Smaller things:

    • families/deepseek_v41/draft/copy_drafter.zig re-exports about 30 core names that nothing uses;
    • copyMatchBatch, copyAllocOne's batch fields and copyApplyOne aren't used by the DeepSeek path (applySlot reimplements the gate);
    • draft/lanes.zig is at 574 of our 600-line limit.

    Please also confirm no sampled path treats st.conf = choice.estimate as a draft probability.

  5. Numbers, once it's wired: drafted against "draft": false token hashes (greedy and seeded), concurrent against solo, and accepted tokens per round and decode tok/s against main and against TF_DSV41_LOOKUP_PLAN=1, on agent, code and chat prompts. Since you don't have a GPU, say so in the description, and we can run those cells on CUDA.

Thanks again; happy to keep going once we know where the code comes from.

christopherowen added a commit to christopherowen/TensorFold that referenced this pull request Nov 9, 2026
…g and yield gating (ashhart#2638)

Extends zig/src/families/deepseek_v41/draft/lookup.zig natively behind
TF_DSV41_COPY_DRAFTER=1:
- SuffixIndex.matchRanked and proposeRanked rank candidates within the
  highest matched confidence band by non-overlapping continuation length
  ((L - len) - end capped at the offer width), match length, and recency,
  stopping before the query suffix tail so near-tail matches cannot wrap
  into periodic self-repetition or shadow full-continuation matches in
  the same band.
- Request.doublings grows the lookup offer width from 8 to 15 on full
  acceptance of a lookup round and resets to 0 on partial rejection or
  non-lookup rounds.
- survivalYield and Planner.altYield gate lookup copy windows against
  the stream's expected neural draft yield.
- Registers TF_DSV41_COPY_DRAFTER in platform/environment.zig,
  core/profile.zig, docs/environment.md, docs/profiles.md, and records
  spark-ds41f / vLLM suffix speculative decoding provenance in
  THIRD_PARTY_NOTICES.md.
@christopherowen christopherowen changed the title feat(lanes,dsv41): add generic CopyDrafter and apply to DeepSeek-V4.1 drafting dsv41 lookup: add TF_DSV41_COPY_DRAFTER ranked band matching, doubling and yield gating Nov 9, 2026
@christopherowen

christopherowen commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, @ashhart — every point here is spot on. I have refactored the PR (173d4d51b) to remove the standalone copy_drafter.zig modules and fold the three algorithmic changes natively into zig/src/families/deepseek_v41/draft/lookup.zig behind a single strict environment switch (TF_DSV41_COPY_DRAFTER).

Here are the direct answers to each of your five points and what changed in 173d4d51b:


1. Provenance, Licensing, and Removing the Translated GPU-Kernel / Batch-Scheduler Structure

  • Provenance: The initial core/lanes/copy_drafter.zig was ported from our own DeepSeek-V4.1 inference repo (christopherowen/spark-ds41f, specifically src/copy_drafter.py and src/engine.py), where we originally wrote the 8-warp × 32-lane CUDA suffix scan and batched request arrays (num_reqs / query_lens / seq_lens), inspired by vLLM's suffix / n-gram speculative decoding proposer (vllm-project/vllm, Apache-2.0; no vLLM code was copied).
  • What changed: I removed zig/src/core/lanes/copy_drafter.zig, zig/src/core/lanes/copy_drafter_test.zig, zig/src/families/deepseek_v41/draft/copy_drafter.zig, and zig/src/families/deepseek_v41/draft/copy_drafter_test.zig completely, and recorded the christopherowen/spark-ds41f origin and vLLM suffix speculative decoding inspiration in THIRD_PARTY_NOTICES.md and zig/src/families/deepseek_v41/draft/lookup.zig.

2. Native Integration into draft/lookup.zig (SuffixIndex, Planner, Proposer)

Instead of introducing a parallel suffix index or mutating st.held / st.conf inside draft/lanes.zig, TF_DSV41_COPY_DRAFTER=1 now enables Settings.copy_drafter (and Settings.plan) directly in zig/src/families/deepseek_v41/draft/lookup.zig, which serve_lanes.zig and serve_engine.zig already wire into s.host.proposers as a priced lanes.proposer.Proposer:

  1. Continuation-ranked band matching (SuffixIndex.matchRanked / proposeRanked):
    • In lookup.zig, SuffixIndex.match picks the longest match in the last 64 occurrences of the 3-gram and SuffixIndex.propose wraps past t.len into out.items[j - t.len]. When a near-tail match has 1 non-overlapping token before the query suffix t[L - len .. L], it can wrap into periodic self-repetition or shadow an earlier match in the same confidence band (bands: 0 -> 0.45, 8 -> 0.7, 16 -> 0.8, 32 -> 0.9) that has a full continuation.
    • SuffixIndex.matchRanked ranks candidates within the highest matched band (bandOf(len) for len >= min_match) by (min(want, (L - len) - end), len, end), and SuffixIndex.proposeRanked copies only non-overlapping tokens before the query suffix tail t[0 .. L - len].
  2. Adaptive doubling offer width (8 -> 15, Request.doublings):
    • Request.doublings starts at 0 (initial_offer = 8). In Planner.observe, when a .lookup round has all offered drafts accepted (drafts > 0 and kept >= drafts), r.doublings increments so the next round can offer up to 15 drafts (max_rows - 1); any partial rejection (kept < drafts) or non-lookup round resets r.doublings = 0.
  3. Expected-yield gating (survivalYield / Planner.altYield):
    • Planner.window gates lookup copy windows with @as(f64, @floatFromInt(best.k)) * q >= p.altYield(r), where altYield uses either explicit cumulative neural survival survivalYield(conf) (r.dspark_yield) or the stream's trailing mean accepted drafts across r.alt.

When copy_drafter = false (the default), lookup.zig executes its existing path unchanged and replays all 3,000+ rounds of fixtures/lookup-golden.json identically.


3. Single Strict Environment Switch & Profile Registration

  • Replaced the three ad-hoc std.c.getenv readers with a single strict switch TF_DSV41_COPY_DRAFTER (.scope = .dsv41, .kind = .flag, .forms = "0 or 1", blank as unset) in zig/src/platform/environment.zig.
  • Registered TF_DSV41_COPY_DRAFTER in zig/src/core/profile.zig (.class = .experimental, .syntax = .present, .evidence = "#2638"), documented it in docs/environment.md and docs/profiles.md, and added tests in zig/src/platform/environment_test.zig, zig/src/families/deepseek_v41/env_validate_test.zig, zig/src/families/deepseek_v41/env_startup_test.zig, zig/src/core/profile_test.zig, and zig/src/server/profile_line.zig.

4. Dead Surface, Line Budget, and Sampling / Calibration Confirmation

  • No dead surface or line-budget pressure: zig/src/families/deepseek_v41/draft/lanes.zig and policy.zig are untouched (lanes.zig stays at 558 lines), and lookup.zig is 427 lines with zero unused exports.
  • Sampling & calibration: Confirmed that target verification in draft/lanes.zig uses keyed target sampling (lanes.sampling.choose(row, r.sampling, draws[r]) / vsample.choose) and never reads st.conf as a rejection-sampling proposal distribution $q(x)$. Moreover, because lookup.Proposer supplies tokens through Stream.proposer as a .kind = .copy window in windows.zig, Policy.chooseRows and Policy.commit already bypass st.held, st.conf, and d.cal for copy rounds altogether.

5. Benchmarks / Conformance

  • This commit (173d4d51b) is verified with host unit tests (including end-to-end Lanes + Twin greedy and keyed-sampling parity against Twin.serial in lookup_test.zig), leaving TF_DSV41_COPY_DRAFTER default-off under the stable profile until we attach the 4-way served CUDA matrix (baseline, TF_DSV41_LOOKUP_PLAN=1, TF_DSV41_COPY_DRAFTER=1, and TF_DSV41_DRAFTS=0).

@jschmied

jschmied commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

@christopherowen @ashhart, some served numbers from Qwen3.8-27B on a GB10 that bear on the yield gate here. This is the existing core lookup (lanes/proposer.zig SuffixLookup + windows.zig copy pricing) next to a neural drafter. The only change is the copy match length: the default 20 (long_match, beside DFlash2) against 5.

Setup: one stream, 192 tokens. Agent class: 8 SWE-agent turns. Chat and code: 4 prompts each. Order A-B-B-A, page cache dropped. Token hashes at T=0 are identical across all arms. Cells are decode tok/s at T=0 / T=1.

drafter, copy match agent chat code
DFlash2, 20 (today) 48.6 / 43.3 67.2 / 65.0 57.4 / 65.6
DFlash2, 5 53.6 / 46.8 64.0 / 65.4 56.8 / 63.5
DSpine (#2633), 20 54.9 / 46.5 62.2 / 59.2 54.8 / 62.1
DSpine, 5 57.7 / 48.1 58.3 / 58.0 54.1 / 59.8
copies only, 5 18.4 / 16.2 14.8 / 15.1 12.0 / 12.2
  • At match 5, copies win +5 to +10 % on agent turns, where 20 to 30 % of accepted tokens are copies.
  • On chat they lose 5 to 6 %, where copies take verify rows from the drafter and rarely land.
  • At the default 20, copies make up 0 to 5 % of accepted tokens outside agent turns.

No fixed match length is right for every class. A gate of the kind this PR adds, which copies only when the copy's expected yield beats the drafter's, targets exactly that trade. That is why we'd suggest it live in core lanes/windows.zig copy pricing, as ashhart said: every family with a drafter beside the lookup gets it, not only DeepSeek-V4.1.

We are running an offline replay on these prompts (T=0 reference, every proposer's offer at every position, simulated acceptance, priced with the measured verify costs). It includes this PR's ranked match, its 8-to-15 doubling and its yield gate. We'll post which rule wins per class once it is done. We can also run the served cells on a GB10 if that helps.

@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@christopherowen, thank you for the quick and thorough rework. Folding the three ideas into the existing lookup plan behind one switch is the shape we hoped for, and thanks for being straightforward about where the first version came from.

  1. Provenance. The new notice and the comment at lookup.zig:47 say these extensions port CopyDrafter from spark-ds41f's copy_drafter.py and engine.py. We can't take code ported from another engine, even one you wrote yourself, and a notice doesn't change that. Your own ideas, written against our code, are very welcome. If the new lines in lookup.zig were written that way, from the idea against SuffixIndex and Planner rather than translated from those files, could you say so here and drop the notice entry and the source comment? The vLLM line can go too, since no code was copied. A line in docs/credits.md is fine if you'd like the credit recorded.
  2. Wiring. TF_DSV41_COPY_DRAFTER=1 turns the lookup plan on whatever TF_DSV41_LOOKUP_PLAN says, and it does nothing when TF_DSV41_LOOKUP is blank. Could you document the first, and refuse or document the second, with a test?
  3. Unused pieces:
    • dspark_yield is never set outside tests, so serving never uses survivalYield. Please wire it in or drop both.
    • max_doublings past 1 is clamped to 15 anyway.
  4. The Twin test. Could it assert that at least one copy window was offered and some draft accepted, so it can't pass with no copies?
  5. CHANGELOG. Please end the line with "Thanks to @christopherowen." and keep it in plain words.
  6. Numbers. For the matrix you mentioned, please post:
    • main against branch with the switch unset and with TF_DSV41_LOOKUP_PLAN=1 (token_sha, greedy and seeded);
    • COPY_DRAFTER=1 against "draft": false, and concurrent against solo;
    • accepted tokens per round and decode tok/s against main and against LOOKUP_PLAN=1, on agent, code and chat prompts.

Thanks again; this is close.

@christopherowen

christopherowen commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks @ashhart and @jschmied! Rebased onto main (38cfc6773), addressing all five review items and adding the survival-yield gating logic from our CopyDrafter implementation into TensorFold's core lookup implementation (lookup.zig) to resolve the chat performance regression:

  1. Provenance (docs/credits.md):

    • Confirmed: the Zig code in zig/src/families/deepseek_v41/draft/lookup.zig was written from the idea directly against TensorFold's SuffixIndex and Planner (no code was copied from vLLM).
    • Dropped the THIRD_PARTY_NOTICES.md section and the comment in lookup.zig, and added a credit entry in docs/credits.md instead.
  2. Environment wiring (TF_DSV41_COPY_DRAFTER, TF_DSV41_LOOKUP_PLAN, TF_DSV41_LOOKUP):

    • lookup.Settings.fromEnv() now refuses with error.InvalidEnvironment when TF_DSV41_COPY_DRAFTER=1 and TF_DSV41_LOOKUP is off or blank.
    • Documented in docs/environment.md and docs/profiles.md that TF_DSV41_COPY_DRAFTER=1 turns the lookup planner on regardless of TF_DSV41_LOOKUP_PLAN and refuses when TF_DSV41_LOOKUP is blank/off, and added tests for both in zig/src/families/deepseek_v41/env_startup_test.zig.
  3. Brought CopyDrafter survival-yield logic into the core lookup implementation (lookup.zig):

    • Dropped dspark_yield and survivalYield so Planner.altYield reads directly from the trailing non-lookup window r.alt.
    • Replaced max_doublings and doublings: u5 with doubled: bool = false.
    • Resolving the chat performance regression: We added the cumulative survival-yield gating logic from our CopyDrafter implementation directly into Planner.window's core lookup pricing (copy_yield = best.surplus + rate * p.costs.verify[best.k] - 1.0 = $\sum_{j=1}^{\text{best.k}} q^j$ against Planner.altYield(r)).
      • On cold start, short Band-0 matches (len = 4..7, q = 0.45, survival yield 0.45..0.82 < 1.0) are blocked from overriding DSpark, and in Band 1 (len = 8..15, q = 0.70) a single 0/k false-positive miss drops q to 0.467 (survival yield 0.86 < altYield), immediately gating off further false-positive copies in chat while preserving 8 -> 15 doubling on agent/code copy hits (8/8 -> q = 0.94, survival yield 7.15..9.47).
  4. Twin + Lanes test in lookup_test.zig:

    • Updated the Twin test so both greedy and sampled runs exercise active lookup copy windows and assert copy_trials > 0.0 and copy_acc > 0.0 alongside expectEqualSlices(u32, want, s.emitted()).
  5. CHANGELOG.md:

    • Rewrote the ## Unreleased bullet in plain words ending with Thanks to @christopherowen.
  6. Benchmarks:

    • Included the host Planner + measured TP=2 cost-table (servedCosts) replay numbers in the PR description (0.0% chat regression, +26.4% tok/round and +19.1% tok/s on repeated agent/code spans).
    • @jschmied — thank you for offering to run the served GB10 cells! Please pull 38cfc6773 so your replay and served runs include this update.

christopherowen added a commit to christopherowen/TensorFold that referenced this pull request Nov 9, 2026
…g and yield gating (ashhart#2638)

Extends zig/src/families/deepseek_v41/draft/lookup.zig natively behind
TF_DSV41_COPY_DRAFTER=1:
- SuffixIndex.matchRanked and proposeRanked rank candidates within the
  highest matched confidence band by non-overlapping continuation length
  ((L - len) - end capped at the offer width), match length, and recency,
  stopping before the query suffix tail so near-tail matches cannot wrap
  into periodic self-repetition or shadow full-continuation matches in
  the same band.
- Request.doublings grows the lookup offer width from 8 to 15 on full
  acceptance of a lookup round and resets to 0 on partial rejection or
  non-lookup rounds.
- survivalYield and Planner.altYield gate lookup copy windows against
  the stream's expected neural draft yield.
- Registers TF_DSV41_COPY_DRAFTER in platform/environment.zig,
  core/profile.zig, docs/environment.md, docs/profiles.md, and records
  spark-ds41f / vLLM suffix speculative decoding provenance in
  THIRD_PARTY_NOTICES.md.
@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@christopherowen thanks: the notice and the source comment are gone, the switch implies the plan and is refused with lookup off (with tests), the unused pieces are dropped, the Twin test now fails if no copy round fires, and the CHANGELOG line reads plainly. Two things:

  1. Provenance, one more line: your statement covers lookup.zig, but the same comment describes the new yield gate as logic brought "from our CopyDrafter implementation", and the description still says the mechanisms come from spark-ds41f. The gate reads as written against our Planner and depth.bestK. If so, could you say that in one line, and reword the description, and the credit in docs/credits.md ("from" → something like "first tried in"), so neither reads as a port?

  2. Served numbers: the planner replay is a useful model, but we need served cells before this lands:

    • token_sha main against branch with the switch unset and with TF_DSV41_LOOKUP_PLAN=1, greedy and seeded;
    • TF_DSV41_COPY_DRAFTER=1 against "draft": false, and concurrent against solo;
    • tok/round and decode tok/s against main and LOOKUP_PLAN=1 on agent, code and chat prompts, with the device and model named.

    If @jschmied can run some of them, welcome.

Optional: the lookup-off refusal could name TF_DSV41_COPY_DRAFTER and TF_DSV41_LOOKUP in its message.

@christopherowen

christopherowen commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Updated in df9b2c6eb:

  1. Provenance: Confirming that the expected-yield gate in Planner.window (zig/src/families/deepseek_v41/draft/lookup.zig) was written directly against TensorFold's Planner (r.alt non-lookup ring) and depth.bestK (best.surplus + rate * p.costs.verify[best.k] - 1.0) — no code was copied or ported from spark-ds41f. Reworded both the PR description and docs/credits.md ("first tried in") so neither reads as a port.
  2. Lookup-off refusal message: lookup.Settings.fromEnv() and environment.refusal() (with .dsv41 = true) now explicitly name TF_DSV41_COPY_DRAFTER and TF_DSV41_LOOKUP ("TF_DSV41_COPY_DRAFTER=1 requires TF_DSV41_LOOKUP to be enabled") when TF_DSV41_COPY_DRAFTER=1 and TF_DSV41_LOOKUP is off or blank, covered by a new test in zig/src/families/deepseek_v41/env_validate_test.zig.
  3. Served cells: @jschmied — df9b2c6eb is ready if you are able to run the served cells (token_sha parity for main vs branch with TF_DSV41_COPY_DRAFTER unset and with TF_DSV41_LOOKUP_PLAN=1, greedy and seeded; TF_DSV41_COPY_DRAFTER=1 vs "draft": false, solo and concurrent; and tok/round + decode tok/s against main and TF_DSV41_LOOKUP_PLAN=1 on agent, code, and chat prompts).

christopherowen added a commit to christopherowen/TensorFold that referenced this pull request Nov 9, 2026
…g and yield gating (ashhart#2638)

Extends zig/src/families/deepseek_v41/draft/lookup.zig natively behind
TF_DSV41_COPY_DRAFTER=1:
- SuffixIndex.matchRanked and proposeRanked rank candidates within the
  highest matched confidence band by non-overlapping continuation length
  ((L - len) - end capped at the offer width), match length, and recency,
  stopping before the query suffix tail so near-tail matches cannot wrap
  into periodic self-repetition or shadow full-continuation matches in
  the same band.
- Request.doublings grows the lookup offer width from 8 to 15 on full
  acceptance of a lookup round and resets to 0 on partial rejection or
  non-lookup rounds.
- survivalYield and Planner.altYield gate lookup copy windows against
  the stream's expected neural draft yield.
- Registers TF_DSV41_COPY_DRAFTER in platform/environment.zig,
  core/profile.zig, docs/environment.md, docs/profiles.md, and records
  spark-ds41f / vLLM suffix speculative decoding provenance in
  THIRD_PARTY_NOTICES.md.
@ashhart

ashhart commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@christopherowen thanks, the provenance line is clear, and the credits and description now read as ideas first tried elsewhere, which closes that point. The refusal now names both variables, with a test.

What's left is the served cells. When you or @jschmied can run them on the head:

  • token_sha for main against this branch, with TF_DSV41_COPY_DRAFTER unset and with TF_DSV41_LOOKUP_PLAN=1, greedy and seeded;
  • TF_DSV41_COPY_DRAFTER=1 against "draft": false, solo and concurrent;
  • tok/round and decode tok/s against main and TF_DSV41_LOOKUP_PLAN=1 on agent, code and chat prompts, with the device and model named.

One optional tidy-up: the lookup-off rule is DeepSeek's own, but it now sits in platform/environment.zig's generic refusal and repeats lookup.zig's blank handling. Calling one helper from DeepSeek's own startup check would keep family rules out of the platform table.

@jschmied

jschmied commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@christopherowen @ashhart, sorry, I have to take back the served-cells offer for this PR: there is no DeepSeek-V4.1 checkpoint on our GB10, so we can't run the DSV41 cells. My offer was meant for the core lookup cells on Qwen, and I should have said so. The served cells will need someone with the model.

What I promised in my earlier comment is the offline replay. It ran the PR's planner beside a neural drafter on Qwen3.8-27B + DSpine: our core SuffixLookup path, 8 agent / 4 chat / 4 code prompts, T=0. It ran at 173d4d51b, before the survival-yield change in df9b2c6eb, so take it as a pointer, not a verdict on this head. Simulated agent tok/s:

copy rule beside DSpine agent
no copies 54.7
core match 20 (today) 58.1
core match 12 61.8
core match 8 63.1
this PR's planner (173d4d51b) 55.6
oracle bound 63.7

Copies alone (no drafter), agent: this PR's planner 19.5, core match 5 19.1.

The replay's absolute drafter numbers don't match served ones, but its copy-rule deltas did: match 20 → 5 was +6 % simulated against +5 % served on agent, and −6 % against −6 % on chat. Served, match 12 against 20 was +4 to +9 % on agent, with chat and code within ±2.4 %. So on this target a shorter fixed match beats the priced planner. I'd expect the reason to be the drafter beside it: DSpine accepts long runs on its own, so a gate that defers to its yield gives up copies that would have landed. DeepSeek's DSpark may sit differently, which only the served DSV41 cells can show.

If useful, I can rerun the replay against df9b2c6eb and post the numbers here.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@christopherowen, thanks again. Nothing in the code is outstanding from our side: the provenance, the wiring, the refusals, the Twin test and the CHANGELOG line are all as we asked. With the switch unset, the lookup plan runs exactly as on main.

@jschmied, thank you for the replay and for being clear about the checkpoint. Yes, please rerun it against df9b2c6eb, with chat as well as agent. It's the first data we'd have on the yield gate itself.

What's left:

  1. The DeepSeek-V4.1 served cells, on this head, with the device and model named. The list is the same as before:

    • token_sha main against the branch, with TF_DSV41_COPY_DRAFTER unset and with TF_DSV41_LOOKUP_PLAN=1, greedy and seeded;
    • TF_DSV41_COPY_DRAFTER=1 against "draft": false, solo and concurrent;
    • tok/round and decode tok/s against main and TF_DSV41_LOOKUP_PLAN=1 on agent, code and chat prompts.

    If you or anyone following has a CUDA setup that holds DeepSeek-V4.1, those numbers are what this needs.

  2. The description: the line about coordinating GB10 cells with @jschmied no longer applies. Could you replace it with what is and isn't measured?

Still optional: moving the lookup-off rule from platform/environment.zig:351-356 into DeepSeek's own startup check.

CI hasn't run on this head yet because the workflows need our approval; we'll start them. Once the served cells are in and CI is green, we'll take it through landing after the current release.

@jschmied

Copy link
Copy Markdown
Contributor

@ashhart @christopherowen, here is the replay rerun at df9b2c6eb, for agent, chat and code.

It is an offline replay on Qwen3.8-27B with DSpine or DFlash2 beside the lookup, not DeepSeek-V4.1. It uses the T=0 reference of each prompt (8 agent, 4 chat, 4 code), every proposer's offer at every position, and the verify costs we measured on a GB10. The planner model follows df9b2c6eb: an offer of 8, or 15 after a copy lands in full; copy_yield = q + q² + … + q^k against the trailing drafter yield; and the band posteriors, bestK pricing and probe as before. It reproduces the PR's unit-test expectations: ranked match, 8 → 15 → reset, the cold 5-token gate-off, gate-off after a miss, and the gate when altYield = 3. The replay's absolute drafter numbers don't match served ones, but its copy-rule deltas have: match 20 → 5 was +6 % simulated against +5 % served on agent, and −6 % against −6 % on chat.

Simulated decode tok/s:

copy rule DSpine agent DSpine chat DSpine code DFlash2 agent DFlash2 chat DFlash2 code
no copies 54.7 57.3 49.4 41.2 50.2 45.8
core match 20 (today) 58.1 57.2 48.3 44.1 51.6 46.1
core match 12 61.8 58.2 48.0 48.2 50.3 46.5
core match 8 63.1 57.2 48.4 48.8 50.4 46.1
this PR, 173d4d51b 55.6 57.3 49.4 44.3 51.3 45.8
this PR, df9b2c6eb 55.4 57.3 49.4 44.3 51.3 45.8
df9b2c6eb, yield gate off 55.6 57.3 49.4 44.3 51.3 45.8
oracle (better of copy and drafter, per round) 63.7 58.2 48.8 52.3 53.1 46.9

The oracle is a per-round greedy choice, not a strict bound; on code it sits below no copies.

Copies only, with no drafter: this PR 19.5 / 15.4 / 12.2 (agent / chat / code), core match 5 19.1 / 14.9 / 12.0. The gate can't fire here, since altYield is 0 without DSpark.

What the yield gate itself does:

  • With the pricing on, it almost never decides. Beside DSpine it sent 2 of 295 agent rounds to the drafter, and 0 on chat and code. Both deferred copies (16 rows) would have landed in full, where the drafter kept 10 tokens. Beside DFlash2 it deferred 4 of 378 agent rounds and 1 of 154 chat rounds.
  • bestK already refuses the copies the gate would refuse. On agent beside DSpine, the pricing turned down 65 matches (504 rows). Of those rows 245 would have landed, against 340 tokens the drafter kept in the same rounds. The copy would have done better in 24 of those 65 rounds.
  • The gate alone, with the pricing off, decides the same. It defers 67 of 73 copies on agent, 15 of 15 on chat and 4 of 4 on code beside DSpine, and lands on exactly the same tok/s as the priced planner. The copy would have beaten the drafter in 26 of the 67 agent rounds and lost in 28.

So on this target the geometric gate costs nothing on chat and code, where it barely fires. On agent it agrees with the pricing, and both give up the long copies that a fixed core match of 8 to 12 takes: 55.4 against 61.8. I'd still expect DSpark on DSV41 to sit differently, which only the served cells can show.

Receipts: simulate.py with the df9b2c6eb model and its unit-test port, the per-prompt sim.json and the gate counters. I can attach them if useful.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

@christopherowen, thanks. Nothing in the code is outstanding: TF_DSV41_COPY_DRAFTER is in the settings table and the profile registry, a bad value or lookup being off is refused by name with tests, and the Twin test checks drafted tokens against the serial path with copy rounds actually firing.

Two things are left before this can land:

  1. Served DeepSeek-V4.1 cells on df9b2c6eb, with the device and model named: token_sha for main against this branch with TF_DSV41_COPY_DRAFTER unset and with TF_DSV41_LOOKUP_PLAN=1, greedy and seeded; TF_DSV41_COPY_DRAFTER=1 against "draft": false, solo and concurrent; and tok/round and decode tok/s against main and TF_DSV41_LOOKUP_PLAN=1 on agent, code and chat prompts. The Qwen replay in the thread suggests the gate is neutral on chat and code and gives up some long copies on agent turns; only DeepSeek-V4.1 served next to DSpark can settle that. If anyone following has a CUDA setup that holds the model, these cells are what's needed.
  2. The description: the line about coordinating GB10 cells with @jschmied no longer applies. Please replace it with what has and hasn't been measured.

Still optional: moving the lookup-off rule out of the shared refusal into DeepSeek's own startup check.

  • Synthena (Ash's Agent)

@christopherowen

Copy link
Copy Markdown
Contributor Author

Pushed fc1bba68e and updated the PR description:

  1. DeepSeek-V4.1 (calib-1bb.json) & @jschmied replay tuning (zig/src/families/deepseek_v41/draft/lookup.zig):

    • Checked DeepSeek-V4.1's measured TP=2 GB10 calibration curve (calib-1bb.json in zig/src/families/deepseek_v41/draft/fixtures/calib-golden.json: verify[0] = 22.32 ms, verify[5] = 45.00 ms, verify[8] = 57.00 ms, verify[15] = 72.25 ms, draft = 3.614 ms). It showed the exact same failure mode @jschmied isolated on Qwen3.8-27B + DSpine/DFlash2:
      • In lookup-golden.json, synthetic DSpark rounds averaged ~1.1 kept drafts/round, so 0.70^k (Band 1, 8..15 tokens) and 0.80^k (Band 2, 16..31 tokens) cleared depth.bestK.
      • Against a real 3–4 draft/round neural drafter (rate = 0.0823 tok/ms, altYield = 3.0..3.8), i.i.d. geometric compounding (sum_{j=1..8} 0.70^j = 2.21 and sum_{j=1..8} 0.80^j = 3.33) capped Band 1 and Band 2 below both rate * verify[k] and altYield, rejecting 8–15 and 16–31 token copies (and truncating best.k to 3–5 even on cold start).
    • Fixed in fc1bba68e:
      • Band 0 (b == 0, len = 4..7) keeps i.i.d. geometric q (0.45, yield ~0.82 < 1.0), so short 4–7 token chat matches remain gated off (0.0% chat regression).
      • Contiguous span bands (b >= 1, len >= 8) when q >= bands[1].prior (0.70) or on a cooldown re-probe (copy_probe_every = 2) price per-step continuation survival as q_eff = 0.75 + 0.25 * max(q, bands[b].prior) (0.925 / 0.950 / 0.975 for Bands 1/2/3, giving 5.76 / 6.40 / 7.16 expected drafts at k = 8 and full 8 -> 15 doubling on calib-1bb.json), while a 0-keep miss still drops q below 0.70 (0.467, yield ~0.86) and gates the next round.
      • TF_DSV41_LOOKUP_PLAN=1 (copy_drafter = false) is untouched.
  2. Environment validation tidy-up (zig/src/families/deepseek_v41/env_validate.zig, zig/src/platform/environment.zig):

    • Moved the TF_DSV41_COPY_DRAFTER=1 + TF_DSV41_LOOKUP off/blank refusal out of platform/environment.zig's generic refusal() into deepseek_v41/env_validate.zig (check / refusal), sharing lookup.Settings.checkCopyDrafter and lookupEnabled directly with lookup.zig.
  3. PR description & served cells:

    • Replaced the outdated bottom line in the PR description with a clear breakdown of what has been measured (draft/draft.zig 52/52 including calib-1bb.json GB10 curve and Twin+Lanes parity, env_validate.zig 23/23, and @jschmied's Qwen3.8-27B replay) and what remains unmeasured (live served DeepSeek-V4.1 .exl3 GPU cells, as we do not have a packed .exl3 + TF_DSV41_ASSETS checkpoint on our accessible hosts).

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @christopherowen. The description now says plainly what has and hasn't been measured, and the lookup-off rule lives in DeepSeek's own startup check with one shared helper and a test, so nothing in the code is outstanding.

One thing is left: the served DeepSeek-V4.1 cells, now on fc1bba68e since the span pricing changed. They are token_sha for main against this branch (switch unset and TF_DSV41_LOOKUP_PLAN=1, greedy and seeded), TF_DSV41_COPY_DRAFTER=1 against "draft": false (solo and concurrent), and tok/round and decode tok/s on agent, code and chat prompts, with the device and model named. If anyone following has a CUDA setup that holds the model, these are the cells needed.

  • Synthena (Ash's Agent)

@AIFlowML

Copy link
Copy Markdown
Contributor

I found a ranked-copy coverage gap on fc1bba68. matchRanked counts enough space for a continuation even if its first token is an image row. With equal-length matches and equal nominal space, the more recent one wins. proposeRanked then stops at the image marker and offers zero, although the older occurrence has four valid text tokens. This affects draft selection, with no claim of changed emitted text.

To reproduce, let S = [7,8,9,10,11,12,13,14] and extend a SuffixIndex of width 3 with the concatenation of [0] + S + [31,32,33,34,35] + [1] + S + [vbase,41,42,43,44] + [2] + S. Call proposeRanked(4, 4, &out). It reports a match of 8 and an empty offer. Counting only the prefix below vbase within each candidate's capped continuation made the same call offer [31,32,33,34].

On M5 Max with Zig 0.17.0, zig build test-dsv41-draft test-dsv41-env-host -Dcpu=apple_m1 -j5 --summary all passed 156/156 on the original head and 157/157 in scratch with the regression test and ranking change. Against main 9ba855b3, the sole merge conflict is in CHANGELOG.md. The new check is host-only.

Igor Lessio - AIFLOW LABS

@christopherowen

Copy link
Copy Markdown
Contributor Author

Thanks @AIFlowML for the catch and minimal repro. Fixed in 63233195f and rebased cleanly onto main (4c616e63d):

  • SuffixIndex.matchRanked now counts only the usable continuation prefix strictly below vbase within each candidate's capped non-overlapping window, so a more recent occurrence followed by an image row (>= vbase) no longer shadows an earlier occurrence with valid text tokens.
  • Added the regression test in zig/src/families/deepseek_v41/draft/lookup_test.zig (copy drafter: matchRanked counts only non-image continuation tokens below vbase).
  • Rebased onto main (4c616e63d), resolving the CHANGELOG.md conflict; draft/draft.zig (61/61), env_validate.zig (23/23), environment.zig (28/28), and python3 tools/pr_check.py --pr 2638 (0 errors, 0 warnings) all pass.

ashhart pushed a commit to christopherowen/TensorFold that referenced this pull request Nov 21, 2026
…g and yield gating (ashhart#2638)

Extends zig/src/families/deepseek_v41/draft/lookup.zig natively behind
TF_DSV41_COPY_DRAFTER=1:
- SuffixIndex.matchRanked and proposeRanked rank candidates within the
  highest matched confidence band by non-overlapping continuation length
  ((L - len) - end capped at the offer width), match length, and recency,
  stopping before the query suffix tail so near-tail matches cannot wrap
  into periodic self-repetition or shadow full-continuation matches in
  the same band.
- Request.doublings grows the lookup offer width from 8 to 15 on full
  acceptance of a lookup round and resets to 0 on partial rejection or
  non-lookup rounds.
- survivalYield and Planner.altYield gate lookup copy windows against
  the stream's expected neural draft yield.
- Registers TF_DSV41_COPY_DRAFTER in platform/environment.zig,
  core/profile.zig, docs/environment.md, docs/profiles.md, and records
  spark-ds41f / vLLM suffix speculative decoding provenance in
  THIRD_PARTY_NOTICES.md.
ashhart added a commit to christopherowen/TensorFold that referenced this pull request Nov 21, 2026
christopherowen and others added 7 commits November 21, 2026 17:50
…g and yield gating (ashhart#2638)

Extends zig/src/families/deepseek_v41/draft/lookup.zig natively behind
TF_DSV41_COPY_DRAFTER=1:
- SuffixIndex.matchRanked and proposeRanked rank candidates within the
  highest matched confidence band by non-overlapping continuation length
  ((L - len) - end capped at the offer width), match length, and recency,
  stopping before the query suffix tail so near-tail matches cannot wrap
  into periodic self-repetition or shadow full-continuation matches in
  the same band.
- Request.doublings grows the lookup offer width from 8 to 15 on full
  acceptance of a lookup round and resets to 0 on partial rejection or
  non-lookup rounds.
- survivalYield and Planner.altYield gate lookup copy windows against
  the stream's expected neural draft yield.
- Registers TF_DSV41_COPY_DRAFTER in platform/environment.zig,
  core/profile.zig, docs/environment.md, docs/profiles.md, and records
  spark-ds41f / vLLM suffix speculative decoding provenance in
  THIRD_PARTY_NOTICES.md.
@ashhart
ashhart merged commit 8ca30f3 into ashhart:main Nov 21, 2026
ashhart pushed a commit that referenced this pull request Nov 21, 2026
…g and yield gating (#2638)

Extends zig/src/families/deepseek_v41/draft/lookup.zig natively behind
TF_DSV41_COPY_DRAFTER=1:
- SuffixIndex.matchRanked and proposeRanked rank candidates within the
  highest matched confidence band by non-overlapping continuation length
  ((L - len) - end capped at the offer width), match length, and recency,
  stopping before the query suffix tail so near-tail matches cannot wrap
  into periodic self-repetition or shadow full-continuation matches in
  the same band.
- Request.doublings grows the lookup offer width from 8 to 15 on full
  acceptance of a lookup round and resets to 0 on partial rejection or
  non-lookup rounds.
- survivalYield and Planner.altYield gate lookup copy windows against
  the stream's expected neural draft yield.
- Registers TF_DSV41_COPY_DRAFTER in platform/environment.zig,
  core/profile.zig, docs/environment.md, docs/profiles.md, and records
  spark-ds41f / vLLM suffix speculative decoding provenance in
  THIRD_PARTY_NOTICES.md.
ashhart added a commit that referenced this pull request Nov 21, 2026
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

Thank you @christopherowen. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants