Skip to content

perf(lanes): price a lone stream's copy windows from its own timed rounds - #3728

Merged
ashhart merged 9 commits into
ashhart:mainfrom
AbrahamCete:fix/lanes-lone-copy-pricing
Nov 19, 2026
Merged

ashhart merged 9 commits into
ashhart:mainfrom
AbrahamCete:fix/lanes-lone-copy-pricing

Conversation

@AbrahamCete

Copy link
Copy Markdown
Contributor

What this changes

A lone stream's copy window (a suffix match from the prompt or the reply, up to 15 rows on HIP) was never priced or timed: the round loop verified it whenever the proposer matched, and a pending copy held the head at one draft. At a long context every verified row walks the whole cache, so copies that miss cost about a plain round a row. That is why the served default decodes 9% to 39% slower than "draft": false from 131K tokens on HIP (#3390). Now a lone stream's copies are priced the way its head windows already are on HIP, from its own timed rounds, so the depth rule leaves copies off where they lose.

  • Rule.copyRows runs Rule.depth's loop (now Rule.bestRows, same arithmetic) over the copy's landing chances, from the stream's own copiedRate history, and the stream's own round times. The plan keeps the best prefix through window_cut.prefix, never wider than the proposal (no first_copy_rows change, as you asked on Lanes: a lone stream's copy windows are never priced or timed; from 131K tokens of context the served default decodes 9-38% slower than "draft": false on HIP #3390), or drops the copy so the head's drafts or a plain round take the round.
  • Copy rounds are timed into the stream's own copy table (copy_price.zig), so they carry the real context. A width not timed yet lies on the line from the stream's plain round to its nearest timed copy; before any copy is timed, each row costs its forward's step plus the plain round's time past its forward. Copied rows are charged no head step. Head windows' times and prices are untouched.
  • A copy priced off is tried again at its best prefix after a backoff, as plain rounds are (8 copies, doubling up to 128, reset on a win).
  • copyAhead reads the same price, so a copy left off no longer holds the head at one draft.
  • A new fact, Model.copy_guard, turns this on; unset, it follows plain_guard. HIP's Qwen facts set it whenever the forwards are timed, so a copies-only stream (the 27B, or --mtp-drafts 0) times its plain and copy rounds too, while HIP's plain_guard, and with it every shared round, stays as on main.
  • On a stream with a head, a copy round is timed by its verify alone: the round's time is read before the head drafts the next one (the clock is read as often as before; head windows keep their own timing). Otherwise the copy's time carried the head's drafting while the plain price it meets at a request's start does not, and copies were cut where they win.
  • The copy prices outlive the request, as CUDA's lone window prices do (lone_costs.keep): a finished stream leaves its copy rounds' times, its copies' landing history (by source), and its plain rounds' times when only copy pricing reads them (without plain_guard). One entry a sampling mode and context band, filed under the band of the stream's first priced round (its first plain round on a copies-only stream, its first copy on a stream with a head), so the next request of the same start reads it; it is replaced only by a stream that timed at least two copy rounds of its own and never shared a round, so a reply of a few tokens (a warm-up) does not stand for the requests after it. The next stream's first priced round starts from it, each table and each source's history only while it has none of its own. Without this, every reply priced its first copies by the untimed estimate and the prior landing rate (0.94), which at a short context, or on a dense model where a row costs most of a plain round, cut them short. A head's own round times stay its depth rule's; backoff counters start fresh with each request. CUDA's lone window prices keep their keying.
  • Off as on main: root copies, context copies, node probabilities, lone_cost_tile, family trims and shared rounds. own_copy_rates keeps its history as before. New trail events: copy-price, copy-cost, plain-cost; and a priced stream's depth state now exists from its first priced round, so a copies-only stream's first state line shows it where main shows null (decisions unchanged).
  • One bias I know of and did not remove: under plain_guard, a stream's own timed plain rounds are read after the head drafts the next round, while its copy rounds are now verify-only, so where a stream has timed plain rounds its copies can look slightly cheaper than they are. The receipts below include it.

A copy window only changes which rows are verified, never the reply: the new tests compare every reply with drafts-off decode, and the served replies below equal main's request by request.

Size: 931 lines (+907/-24) in 11 files, 647 of them tests, in six commits: the pricing; a fix for a stream with priced copies whose head has no plain_guard (from review; no family sets that combination today); the copy prices kept across requests; their keying by the band a stream started in; a head stream's copy round timed without the head's drafting; and the landing rate kept with the prices (the last four from the receipts below).

Reach beyond HIP Qwen

copy_guard defaults to plain_guard, so this is the core change for every lone stream where plain_guard is on, its rounds are timed, and its head windows are priced by the depth rule's chain, not only for HIP. By the code on this head, with each family's default facts, the gate is on for:

  • HIP: Qwen3.5 family with and without the MTP head (the target); Nemotron with a head and timed forwards.
  • Metal: LFM3, LFM2-MoE, GLM (with MTP, and in some configurations without it), GLM-DSA, MiniMax with DSpark or DFlash2, Gemma4 with the MTP assistant.
  • CUDA: Gemma4 with the assistant (unless TF_GEMMA4_COPIES=1).
  • XPU: copy-only engines (LFM3, Gemma4) and Nemotron with a head.
  • A drafter turns it on by itself (Drafter.Facts.plain_guard defaults to true), wherever its target meets the other conditions.

Off, as on main: CUDA Qwen3.5 (with or without a drafter; lone_cost_tile), the dense 27B's root copies, GLM with own_copy_rates, Metal Qwen3.5 and Qwen 27B, FlashNext, HIP Nemotron without a head, every shared round, and every engine without timed rounds.

I could only run gfx1151. If you would rather take it for HIP alone first, copy_guard defaulting to false in config.zig makes it opt-in, and only hip_lanes.zig sets it; the other backends would then keep main's behavior until each is checked.

Checks on this head

  • Head commit: 461133b, on main 9489c38. Every line below was built from git archive trees of the base and the head.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head (the head's checker on both): 221 and 221, 0 new (tools/zig/lean_new.py). depth.zig is 560 lines and engine.zig 545; no touched file passes 600.
  • Tests run, with the command and pass, fail and skip counts (--summary all, main -> this head):
    • zig build test-shared-lane-regressions-host: 406 of 407 passed, 1 skipped -> 428 of 429 passed, 1 skipped (the 22 new tests in lone_copy_price_test.zig and copy_price_test.zig; CI reaches this step through test-host-a/test-host-b).
    • test-root-copy-host 52/52, test-qwen35-copies-host 8/8, test-lane-api-host 667/667, test-family-copies-host 18/18, test-lane-lone-host 38/38, the same on both.
    • zig build test test-golden -Dhip=true: 778 of 782 steps, 10,234 of 10,314 tests passed, 78 skipped, 2 failed, the same on both. The 2 fail on main on this machine too: stage_hip_test "every staged call on HIP memory equals the reference, whole and in parts" and cli_config_test "serve --config: expand reads the file, passes other commands through and names what it cannot read".
    • zig fmt --check build.zig zig and git diff --check: clean.
  • New tests fail before the change and pass after it (the first two commits' tests on their first base, e7e2424; the branch was rebased since without conflicts, and its commits are unchanged): the three pricing tests fail on main (1,304 copied rows verified for 96 tokens with a head, and every early round a copy, on a clock where each row costs most of a plain round) and pass on this head (25-26 copied rows; copies come back once they land); the pin of HIP's shared rounds without a head, at two and four streams, fails on the first version of this change and passes now; the plain-price test of the second commit fails on the first commit (27 rounds, 32 copied rows) and passes on the second (7 rounds, 87 rows). Each later commit's test fails on the commit before it: two requests in a row, the second's first copy cut to 4 rows (15 expected); a warm-up timing one copy, then two requests from 8,150 tokens past 8,192, the warm-up's copy steering both (11 copy windows of 40 rows against 5 of 55); a head stream on a clock where each drafting costs 30 ms, its kept 15-row copy at 41.6 ms against its verify's 11.6; a dense model's clock, the second request's first copy cut to 11 rows like the first's. The trail of two requests in a row on engines with unpriced copies (CUDA's lone_cost_tile facts, and HIP's with copy_guard off, with and without a head) is pinned from the second commit and unchanged on every later one. The other new tests pin behavior that must not move (unpriced paths byte for byte, replies equal to drafts-off decode).
  • An independent check of the last four commits, from probes compiled on main 9489c38 and on this head: the whole decision trail is identical to main in 9 of 9 configurations where the gate is off (CUDA's lone_cost_tile facts, HIP with copy_guard off with and without a head, root and context copies, untimed costs, a drafter without plain_guard; 90 of 90 requests), and in 3 of 3 where copies are never proposed; the shared phase makes the same decisions as main in 16 of 16 two- and four-stream runs, also after lone copying requests on the same engine; 106 of 106 requests equal drafts-off over 903 copy windows; and 202 of 202 head-stream copy timings equal the verify alone while head windows' own timings still include the drafting.
  • CI: runs on this pull request.
  • Not run, and why: Metal, CUDA and XPU (no such hardware here); HIP chips other than gfx1151; HIP Nemotron with a head (in reach, not measured for this change); sampled requests.

Receipt

  • Main against branch: main 9489c38 against this head 461133b, both built from git archive trees (ReleaseFast, gfx1151, system hipcc), one fresh server a run on the same machine, runs alternated (main, head, head, main, main, head where a cell has six). Every server started only after the GPU read 0% busy for 10 s with no other /dev/kfd holder.

Long context, the case of #3390. The turn client of #3390: a conversation kept at K tokens, then 8 turns of 200 fresh tokens asking 128 at temperature 0, --parallel 1, --prompt-cache-gib 18, the request's draft field on, off, off, on over two text stretches. Decode tok/s, each value the mean of four requests. On over off is drafts on divided by "draft": false.

model kept tokens drafts on, main -> head "draft": false, main -> head on over off, main -> head
Qwen3.6-35B-A3B (MTP + copies) 131,072 21.75 -> 26.09 (+20.0%) 29.33 -> 29.47 (+0.5%) 0.741 -> 0.885
Qwen3.6-35B-A3B (MTP + copies) 258,048 12.25 -> 17.03 (+39.0%) 18.06 -> 18.08 (+0.1%) 0.679 -> 0.942
Qwen3.8-27B (copies only) 131,072 6.87 -> 7.90 (+15.0%) 7.62 -> 7.63 (+0.1%) 0.902 -> 1.036
Qwen3.8-27B (copies only) 258,048 4.06 -> 5.28 (+30.1%) 5.22 -> 5.23 (+0.2%) 0.778 -> 1.010

From 131K tokens drafts on recover most of the gap to "draft": false on the 35B-A3B and pass it on the 27B, whose drafts are copies only. Drafts off is level: a plain round is not priced. At 258K the 35B-A3B's drafts-on replies verify 13-23 proposed rows for 3-12 accepted, against 71-115 for 16-17 on main.

Mid context (same client): the 35B-A3B at 8,192 kept tokens, drafts on 78.37 -> 81.23 (+3.7%), "draft": false 73.17 -> 73.41 (+0.3%).

A copy-heavy prompt (a 4,000-token stretch of the corpus twice, then its first 32 tokens, so the reply copies the passage; 512 reply tokens; the lab's warm-up request, a cold request, then drafts on, off, off, on twice on the resumed prompt; --context 16384 --parallel 1; runs main, head, head, main). Medians of 8 requests:

model drafts on, main -> head "draft": false, main -> head rounds a drafts-on reply, main -> head
Qwen3.6-35B-A3B 194.33 -> 194.74 (+0.2%) 73.00 -> 73.27 (+0.4%) 43 -> 43
Qwen3.8-27B 65.78 -> 65.67 (-0.2%) 13.50 -> 13.50 (0.0%) 32 -> 32 (a fresh server's cold first reply: 33)

Short context, one stream and four (tools/bench_concurrent.py --tokens 256 --reps 3 --temperatures 0 --levels 1,4 --alone --serial, its code and chat prompts, --context 8192 --parallel 4 --prompt-cache-gib 0). Per-stream decode tok/s, median of each build's runs:

engine code x1 code x4 chat x1 chat x4
Qwen3.6-35B-A3B, MTP + copies (two sets, six runs a build) 123.75 -> 124.95 (+1.0%) 60.60 -> 61.90 (+2.1%) 97.45 -> 98.40 (+1.0%) 52.35 -> 52.35 (0.0%)
Qwen3.6-35B-A3B, --mtp-drafts 0 (copies only) 97.5 -> 97.4 (-0.1%) 57.4 -> 57.4 (0.0%) 83.9 -> 83.9 (0.0%) 51.4 -> 51.4 (0.0%)
Qwen3.8-27B (copies only) 14.4 -> 14.5 (+0.7%) 11.8 -> 11.8 (0.0%) 14.8 -> 14.8 (0.0%) 11.8 -> 11.8 (0.0%)

The 35B-A3B's served default at code x1 runs in two regimes on main itself (about 83 or about 100 rounds a 256-token reply, by server), so that cell is the twelve-run comparison: main 122.7-129.5, this head 123.1-125.0, Mann-Whitney U 18.5 of 36. Four streams are level: shared rounds keep main's path.

  • Boxes it reaches: the lane core's round plan for a lone stream with priced copies (copy_guard): which copied rows are verified, and when a copy is left out for the head's drafts or a plain round; the copy prices and landing rates an engine keeps between such streams; and, on a stream with a head, where its copy rounds are timed. Decode only; prompt processing and shared rounds are not reached.
  • New switch? No user switch. A family fact, Model.copy_guard (?bool, unset: plain_guard); HIP's Qwen facts set it when the forwards are timed.
  • Environment: TensorFold 9489c38 (main) and 461133b (this head); Zig 0.17.0; hipcc HIP 7.1.52801 (Ubuntu clang 21.1.8); Ryzen AI Max+ 395 (Strix Halo, gfx1151), unified memory; Ubuntu 26.04.1, kernel 7.0.0-38; Qwen3.6-35B-A3B-MLX-4bit-MTP (with its MTP head) and Qwen3.8-27B-MLX-4bit (no head on HIP). Binaries: main tensorfold-native fc57239f1ba9, head 20d4faa5dae2 (sha256 prefixes).
  • Paths and platforms the change reaches, which I ran and which I could not: ran HIP gfx1151, Qwen3.6-35B-A3B served default and --mtp-drafts 0, Qwen3.8-27B, one stream and four, greedy, contexts from a 14-token prompt to 258,048 kept tokens. Not run: the other backends and families under "Reach" above (no hardware), other HIP chips, HIP Nemotron with a head, sampled requests.
  • Exactness: every reply's token_sha equals main's request by request, and within each build drafts on equal "draft": false: the turn cells 9 of 9 a cell (45 of 45), the copy-heavy prompt one hash a model over every request of both builds, and in the short-context runs one hash a prompt across both builds' alone, --serial ("draft": false) and four-stream replies (alone 3/3 and 12/12, serial 1/1 in every run).
  • Main against this branch, same machine and checkpoint: the tables above.
  • Decode speed before and after: the tables above; the short-context table is tools/bench_concurrent.py's per-stream decode (it has tools/bench_openai.py's prompts). Clients, scripts and raw files: https://gist.github.com/AbrahamCete/b1ead4bd9fa5d9d0e61bcf4882875477 (local paths read $LAB, $MODELS, $WT and $SCRATCH)
  • Prompt speed before and after: n/a: the change prices decode rounds only. The resumed first token in the turn cells is level (for example 1.845 -> 1.846 s for the 27B at 131K, 1.355 -> 1.356 s for the 35B-A3B at 258K); at 131K on the 35B-A3B one of main's eight turns took 1.031 s against 0.78-0.79 s for every other turn on both builds.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack. (Tick after the push.)

  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (Host-only tests; no dependency to skip.)

  • Comments and docstrings are one line. No measurements or history in the source. (Lean checker: 0 new problems.)

  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (The change only picks which copied rows a lane round verifies.)

  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Served hashes equal main's and equal across drafts on and off; the copy-heavy prompt gives one hash cold and resumed; four streams equal one alone in every short-context run.)

  • No precision traded for speed. If the bits change, the description says which sums change and why. (No arithmetic changes.)

  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (Greedy at one stream and four, every cell inside main's spread or faster; sampled requests were not run; --drafter is n/a: the HIP engine runs no drafter.)

@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @AbrahamCete. The own-round prices, backoff and calibration lifetime have useful regressions. Please make unqualified families opt in rather than inheriting plain_guard, as you offered, and add seeded-sampled coverage for shortened/off copies and kept prices. The enabled native paths still need exact-token comparison with main and drafts-off, including sampling; the supplied device runs cover greedy only.

  • Synthena

@ashhart
ashhart force-pushed the fix/lanes-lone-copy-pricing branch from 461133b to d14bdb7 Compare November 19, 2026 02:20
ashhart added a commit to AbrahamCete/TensorFold that referenced this pull request Nov 19, 2026
…plain_guard

Answers review ask 1 on ashhart#3728: make families that are not qualified opt in
rather than inheriting plain_guard, as the author offered.

Model.copy_guard is now a plain bool that defaults to false, and
Config.init reads it as is. Only HIP's Qwen facts set it (hip_lanes.zig,
unchanged), so their lone copies are priced exactly as on the branch. Every
other family, and a drafter's plain_guard, keeps main's unpriced copies
until it is checked and opts in.

The config test now pins that copy_guard stays off with plain_guard on or
off unless the family sets it.
ashhart added a commit to AbrahamCete/TensorFold that referenced this pull request Nov 19, 2026
…nd kept

Answers review ask 2 on ashhart#3728: add seeded-sampled coverage for shortened
and off copies and kept prices.

lone_copy_sampled_test.zig runs a seeded sampled lone stream on the fake
target, whose copier proposes the target's keyed draws, with and without a
head:
- shortened: on a dense model's clock the first copy is cut below 15 rows;
- off: at a long context, copies that miss are priced off;
- kept: a second sampled request's first copy is whole from the prices the
  first one kept, filed under the sampled mode, not the greedy one.
Each reply equals drafts-off decode and the same request with copies
unpriced, token for token; the sampled reply differs from the greedy one.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @AbrahamCete. To get this moving, we finished our two asks on your branch ourselves, keeping your six commits as they were (author and message):

  1. Model.copy_guard is now opt-in (false by default), and only the HIP Qwen line in hip_lanes.zig sets it, so every other family keeps main's behaviour, as you offered.
  2. lone_copy_sampled_test.zig adds seeded sampled tests for shortened copies, copies priced off, and kept prices.

We also rebased it onto current main. We will run the Strix Halo device check on our side and post the result here; nothing else is needed from you.

  • Synthena

@AbrahamCete

Copy link
Copy Markdown
Contributor Author

@ashhart thanks for finishing the two asks and the rebase. Two things from this side, in case they save you time.

1. An exact-token check on gfx1151, on the head as it stands. B = f5765b5 (its base), C = d14bdb7. Four arms a cell: B with drafts on, B with drafts off, C with drafts on, C with drafts off; greedy and seeded-sampled (seed 7, temperature 0.8). Every request's token hash is the same across the four arms in all 12 cells.

cell greedy sampled draft and copy rows proposed with drafts on, B → C
short context, 35B-A3B, 1 and 4 streams equal (2 solo, 60 concurrent) equal (8 solo, 20 concurrent) greedy 4,849 → 4,670; sampled 2,092 → 2,112
short context, 27B, 1 and 4 streams equal (2 solo, 60 concurrent) equal (8 solo, 20 concurrent) greedy 228 → 164; sampled 87 → 47
35B-A3B, resumed turns at 131,072 tokens equal, 16 of 16 equal, 16 of 16 greedy 90, 90, 130, 130 → 36, 36, 52, 25; sampled 62, 62, 157, 157 → 18, 21, 47, 54
35B-A3B, resumed turns at 258,048 equal, 16 of 16 equal, 16 of 16 greedy 71, 71, 115, 115 → 21, 14, 11, 11; sampled 69, 69, 61, 61 → 14, 16, 16, 16
27B, resumed turns at 65,536 equal, 16 of 16 equal, 16 of 16 greedy 0, 0, 15, 15 → 0, 0, 3, 3; sampled none on either
27B, resumed turns at 131,072 equal, 16 of 16 equal, 16 of 16 greedy 72, 72, 62, 62 → 19, 24, 26, 23; sampled 105, 105, 75, 75 → 13, 13, 33, 36

A turn cell is two stretches asked on, off, off, on with the request's draft field, on both builds, after one cold request that also matches across builds. The last column is there to show the gate is at work in these cells; it comes from the server's done lines, which give the rows a request proposed, not which copies were shortened or left off. The 27B at 65,536 sampled proposed no copies on either build, so that one cell proves little. Not run: the 27B at 258,048, --mtp-drafts 0, other chips and other backends.

2. A drafted pair inherits the gate. Drafted.facts (core/lanes/drafted.zig) starts from the target's Model, so a drafter over a target that sets copy_guard keeps lone copy pricing on. A host probe on d14bdb7 reads: target alone copy_guard=true plain_guard=false; drafted pair copy_guard=true plain_guard=true. No engine builds that pair on main today, but #3665 will (HIP --drafter on the 27B), and that pair has not been measured with these prices. If you want drafted pairs to opt in as well, it is one line in Drafted.facts and a test. I have both locally and can send them here or with part 6, whichever you prefer.

@AbrahamCete

Copy link
Copy Markdown
Contributor Author

@ashhart the red zig-b on d14bdb7 does not come from this pull request: the same failure reproduces on its base.

The failing test is in lane_host_explore_test, "explore: a seed replays its schedule, every yield point's act and every reply the same": lane host explore (service): seed 1592590343 failed (ScheduleNotReplayed) (run 44443614896). That seed is first_seed + 7, a fixed one, so it is the run that differs, not the seed.

Here, on a 32-thread host, I ran the test binary of zig build test-lane-explore-host (default options) directly, from clean trees of both commits:

how it ran main f5765b5 this head d14bdb7
one at a time, 60 runs 0 failed 0 failed
6 at a time on two cores (taskset -c 0,1), 120 runs 0 failed 1 failed
4 at a time on one core, 60 runs 0 failed 0 failed
96 at a time, 288 runs 3 failed 3 failed

All seven failures print the same line: the service kind, seed 1592590343, ScheduleNotReplayed. The counts are too small to compare the two trees; they only show it happens on main too, and only on a loaded machine. With -Dexplore-seed=1592590343 alone it passed 700 of 700 on each tree (300 one at a time, 400 at 16 at a time), so it seems to need the default sweep as well.

I have not looked for the cause. If an issue is more useful than a note here, I can open one.

AbrahamCete and others added 9 commits November 19, 2026 12:59
…unds

A lone stream's copy window was never priced or timed: the round loop
verified up to 15 copied rows whenever the proposer matched, and a copy
ahead held the head at one draft. At a long context every row walks the
whole cache, so a copy that misses costs about a plain round a row
(ashhart#3390).

Price it the way the depth rule prices a lone head window on HIP:
- Rule.copyRows runs Rule.depth's loop (now Rule.bestRows) over the
  copy's chances, from the stream's own copiedRate history, and the
  stream's own round times; the plan keeps the best prefix through
  window_cut.prefix, never wider than the proposal, or drops the copy so
  the head's drafts or a plain round take the round.
- Copy rounds are timed into the stream's own copy table. A width not
  timed yet lies on the line from the stream's plain round to its nearest
  timed copy; before any copy is timed, each row costs its forward's step
  plus the plain round's time past its forward. Copied rows are charged
  no head step, and head windows' times and prices are untouched.
- A copy priced off is tried again at its best prefix after a backoff,
  as plain rounds are (8 copies, doubling up to 128).
- copyAhead asks the same price, so a copy left off no longer holds the
  head at one draft.
- A new fact, Model.copy_guard, turns this on and defaults to
  plain_guard. HIP sets it whenever its forwards are timed, so a
  copies-only stream (no head) times its plain and copy rounds too, while
  HIP's plain_guard, and with it every shared round, stays as before.

Only lone streams with copy_guard and timed rounds whose head windows are
priced by the depth rule's chain are priced: root copies, context
copies, node probabilities, lone_cost_tile, family trims and shared
rounds keep their paths, and own_copy_rates keeps its history as before.
A copy only changes which rows are verified, so every token stays the
same; the new tests compare each reply with drafts-off decode and pin
the unpriced paths, and the shared rounds of HIP's facts without a head
at two and four streams, to their values on main.

Refs ashhart#3390
A lone stream whose copies are priced (copy_guard) but whose head has no
plain_guard never kept its own round times: the round loop times a
head's and plain rounds into the stream's own table only under
plain_guard. Its copies were then weighed against the startup forward,
timed on a short scratch context, while their own cost came from real
timed copy rounds, so at a long context even copies that land were
priced off. No family sets that combination today (HIP's head and
plain_guard both follow drafting), but copy_guard allows it.

- lone_copy.time keeps such a stream's head and plain rounds in its own
  table, and copy_price.plain reads it through roundCost's model
  (Rule.roundCostIn), as plain_guard's streams already do. What heads
  and shared rounds record under plain_guard is unchanged.
- A copy's cost, its plain round and their observations move from
  depth.zig into copy_price.zig, with direct tests of the three
  estimates: a timed width, the line from plain to the nearest timed
  copy (a tie takes the narrower), and the forward plus the plain
  round's excess on each of n + 1 rows before any copy is timed.
- A test checks that copyAhead reads the decision the plan then takes,
  backoff probes included, and that only the plan's take counts.
- Those rounds log as plain-cost, not cost, so the trail's cost lines
  stay the head's depth timing alone.

Refs ashhart#3390
A lone stream's copy times lived in its depth state, which release
drops with every request, so each reply priced its first copies by the
untimed estimate: each row charged the whole excess of a plain round
over its load-time forward. At a short context that excess is mostly
fixed, so a reply's first copies were cut to a few rows until one was
timed, and short replies paid it each time.

The engine now keeps them as it keeps CUDA's lone window prices
(lone_costs.keep), in the same slots and under the same rules:
- A finished stream leaves its copy rounds' times, and its plain
  rounds' times when only copy pricing reads them (no plain_guard). A
  head's own round times stay its depth rule's and are not carried.
- One entry a sampling mode and context band; the newest stream that
  timed a copy and never shared a round replaces it.
- A stream's first priced round starts from it, each table only while
  the stream has timed none of its own, and its own rounds then blend
  in as before. Backoff counters and copy rate history start fresh.
- Engines whose copies are unpriced keep nothing new: copy_guard off,
  or lone_cost_tile on (CUDA keeps its own calibration as before).

Tests: two requests in a row on one engine, where the second's first
copy is whole (cut to 4 rows before this change); the kept tables'
rules; and the trail of two requests in a row on engines with unpriced
copies, pinned from the previous commit.

Refs ashhart#3390
The kept copy prices were filed under the context band a stream ended
in and read from the band it started in, as lone_costs.slot computes
both from the stream's length at the time. A prompt just under a band
edge, whose reply crossed it, therefore never read the prices of the
request before it, only what another shape of request had left there.
On HIP an 8-token warm-up's single timed copy priced a run of
8,032-token copy-heavy requests: every one cut its copies until it had
timed its own.

- A stream's copy prices are kept in the band its first priced round
  started in, the one it seeded from, so the next request of the same
  start reads them.
- A stream replaces the kept prices only after timing two copy rounds
  of its own: a reply of a few tokens times one at most, and its prices
  no longer stand for the requests after it.
- CUDA's lone window prices keep lone_costs.slot's keying.

Tests: a warm-up that times one copy at another clock, then two
requests that start below 8,192 tokens and end above it; the long
requests decide as on an engine that never served the warm-up, and the
second one's first copy is whole (a one-row probe before this change).
The kept-price rules' test now also covers the two-round minimum; the
trail pins of engines with unpriced copies are unchanged.

Refs ashhart#3390
On a stream with a head, the round loop timed a copy round after the
head had drafted the next one, so the copy's recorded time carried the
head's drafting. The plain price a copy is weighed against at a
request's start is the load-time forward, which carries none, so kept
copy times made copies look dearer than they are and cut them.

familyRound now reads the round's time after its verify and keep,
before the head drafts, on the rounds lone copy pricing records, and
lone_copy.time records that reading. The clock is read as many times
as before; on a stream without a head the reading point is unchanged.
Head windows keep their own timing.

Test: a head stream on a clock where each drafting costs 30 ms keeps
whole copies at their verify time (11.6 ms), not 41.6 ms as before.

Refs ashhart#3390
A copy's rows are priced by the stream's own landing history, which
starts each request at the prior (four rows of copy_rate, 0.94). On a
dense model every verified row costs most of a plain round, so at that
rate the best prefix of a request's first copy stops short of the
whole window: on HIP the 27B cut one landing copy a reply, 33 rounds
against main's 32 on a copy-heavy prompt, kept prices or not.

The kept copy prices now carry the stream's landing history by source
(context and Recall), kept and seeded under the same rules: the band
the stream started in, two timed copy rounds, and a source only while
the new stream has seen none of its own copies.

Test: on a dense model's clock, a request's first copy is cut to 11
rows at the prior rate, and the next request's first copy is whole (11
rows before this change).

Refs ashhart#3390
…plain_guard

Answers review ask 1 on ashhart#3728: make families that are not qualified opt in
rather than inheriting plain_guard, as the author offered.

Model.copy_guard is now a plain bool that defaults to false, and
Config.init reads it as is. Only HIP's Qwen facts set it (hip_lanes.zig,
unchanged), so their lone copies are priced exactly as on the branch. Every
other family, and a drafter's plain_guard, keeps main's unpriced copies
until it is checked and opts in.

The config test now pins that copy_guard stays off with plain_guard on or
off unless the family sets it.
…nd kept

Answers review ask 2 on ashhart#3728: add seeded-sampled coverage for shortened
and off copies and kept prices.

lone_copy_sampled_test.zig runs a seeded sampled lone stream on the fake
target, whose copier proposes the target's keyed draws, with and without a
head:
- shortened: on a dense model's clock the first copy is cut below 15 rows;
- off: at a long context, copies that miss are priced off;
- kept: a second sampled request's first copy is whole from the prices the
  first one kept, filed under the sampled mode, not the greedy one.
Each reply equals drafts-off decode and the same request with copies
unpriced, token for token; the sampled reply differs from the greedy one.
@ashhart
ashhart force-pushed the fix/lanes-lone-copy-pricing branch from d14bdb7 to ef4b050 Compare November 19, 2026 13:00
@ashhart
ashhart merged commit 32c4e3d into ashhart:main Nov 19, 2026
ashhart added a commit that referenced this pull request Nov 19, 2026
…plain_guard

Answers review ask 1 on #3728: make families that are not qualified opt in
rather than inheriting plain_guard, as the author offered.

Model.copy_guard is now a plain bool that defaults to false, and
Config.init reads it as is. Only HIP's Qwen facts set it (hip_lanes.zig,
unchanged), so their lone copies are priced exactly as on the branch. Every
other family, and a drafter's plain_guard, keeps main's unpriced copies
until it is checked and opts in.

The config test now pins that copy_guard stays off with plain_guard on or
off unless the family sets it.
ashhart added a commit that referenced this pull request Nov 19, 2026
…nd kept

Answers review ask 2 on #3728: add seeded-sampled coverage for shortened
and off copies and kept prices.

lone_copy_sampled_test.zig runs a seeded sampled lone stream on the fake
target, whose copier proposes the target's keyed draws, with and without a
head:
- shortened: on a dense model's clock the first copy is cut below 15 rows;
- off: at a long context, copies that miss are priced off;
- kept: a second sampled request's first copy is whole from the prices the
  first one kept, filed under the sampled mode, not the greedy one.
Each reply equals drafts-off decode and the same request with copies
unpriced, token for token; the sampled reply differs from the greedy one.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. 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.

ashhart added a commit that referenced this pull request Nov 21, 2026
On an M3 Ultra it made Qwen3.8-27B with the DFlash2 drafter verify more
drafted rows that do not land: 108 rows for 54 accepted drafts on a 16K
prompt against 99 before, the same tokens, decode 3.7% slower. 1.3.0 ships
without it; this brings main back to the same lane code until the pricing
is fixed for every family.
ashhart added a commit that referenced this pull request Nov 21, 2026
On an M3 Ultra it made Qwen3.8-27B with the DFlash2 drafter verify more
drafted rows that do not land: 108 rows for 54 accepted drafts on a 16K
prompt against 99 before, the same tokens, decode 3.7% slower. 1.3.0 ships
without it; this brings main back to the same lane code until the pricing
is fixed for every family.
ashhart added a commit that referenced this pull request Nov 21, 2026
On an M3 Ultra it made Qwen3.8-27B with the DFlash2 drafter verify more
drafted rows that do not land: 108 rows for 54 accepted drafts on a 16K
prompt against 99 before, the same tokens, decode 3.7% slower. 1.3.0 ships
without it; this brings main back to the same lane code until the pricing
is fixed for every family.
ashhart added a commit that referenced this pull request Nov 21, 2026
On an M3 Ultra it made Qwen3.8-27B with the DFlash2 drafter verify more
drafted rows that do not land: 108 rows for 54 accepted drafts on a 16K
prompt against 99 before, the same tokens, decode 3.7% slower. 1.3.0 ships
without it; this brings main back to the same lane code until the pricing
is fixed for every family.
ashhart added a commit that referenced this pull request Nov 22, 2026
On an M3 Ultra it made Qwen3.8-27B with the DFlash2 drafter verify more
drafted rows that do not land: 108 rows for 54 accepted drafts on a 16K
prompt against 99 before, the same tokens, decode 3.7% slower. 1.3.0 ships
without it; this brings main back to the same lane code until the pricing
is fixed for every family.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants