Repository navigation
perf(lanes): price a lone stream's copy windows from its own timed rounds - #3728
Conversation
|
Thanks @AbrahamCete. The own-round prices, backoff and calibration lifetime have useful regressions. Please make unqualified families opt in rather than inheriting
|
461133b to
d14bdb7
Compare
…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.
|
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):
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.
|
|
@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.
A turn cell is two stretches asked on, off, off, on with the request's 2. A drafted pair inherits the gate. |
|
@ashhart the red The failing test is in Here, on a 32-thread host, I ran the test binary of
All seven failures print the same line: the service kind, seed 1592590343, I have not looked for the cause. If an issue is more useful than a note here, I can open one. |
…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.
d14bdb7 to
ef4b050
Compare
…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.
…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.
|
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. |
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.
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.
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.
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.
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.
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": falsefrom 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.copyRowsrunsRule.depth's loop (nowRule.bestRows, same arithmetic) over the copy's landing chances, from the stream's owncopiedRatehistory, and the stream's own round times. The plan keeps the best prefix throughwindow_cut.prefix, never wider than the proposal (nofirst_copy_rowschange, 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": falseon HIP #3390), or drops the copy so the head's drafts or a plain round take the round.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.copyAheadreads the same price, so a copy left off no longer holds the head at one draft.Model.copy_guard, turns this on; unset, it followsplain_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'splain_guard, and with it every shared round, stays as on main.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 (withoutplain_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.lone_cost_tile, family trims and shared rounds.own_copy_rateskeeps 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 firststateline shows it where main showsnull(decisions unchanged).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)."draft": falseon HIP #3390 (the core shape you chose 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": falseon HIP #3390: a lone copy window priced like a head window, from timed rounds that carry the context; the device check on your side, and the other backends below, are the conditions you named).main9489c38. Commits: 3e86b6b, 25035c6, 8de388a, ec9037e, 9528ef0, 461133b.atc overlap --json(2026-11-17 20:26Z, basemain9489c38;mainhas moved 89 commits since, none touching these files, and the branch merges clean with it): incomplete (the repository's pull-request limits). It reports Host draw: greedy and masked rows scan 64-logit blocks and skip mask words that allow nothing #2846, which shareszig/src/core/lanes/lanes.zigand merges clean, and MiMo-V2.6-Flash on CUDA (2x GB10) with DFlash as the drafter #728 (MiMo-V2.6-Flash on CUDA), which also editscore/lanes/config.zig,depth.zig,engine.zigandwindows.zigand conflicts with this branch indepth.zigandengine.zig; whichever lands first, the other rebases. My open feat(hip): serve Qwen3.8-27B with its DFlash2 drafter #3665 shareship_lanes.zigand merges clean with this branch.Reach beyond HIP Qwen
copy_guarddefaults toplain_guard, so this is the core change for every lone stream whereplain_guardis 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:TF_GEMMA4_COPIES=1).Drafter.Facts.plain_guarddefaults 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 withown_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_guarddefaulting tofalseinconfig.zigmakes it opt-in, and onlyhip_lanes.zigsets it; the other backends would then keep main's behavior until each is checked.Checks on this head
main9489c38. Every line below was built fromgit archivetrees of the base and the head.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.zigis 560 lines andengine.zig545; no touched file passes 600.--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 inlone_copy_price_test.zigandcopy_price_test.zig; CI reaches this step throughtest-host-a/test-host-b).test-root-copy-host52/52,test-qwen35-copies-host8/8,test-lane-api-host667/667,test-family-copies-host18/18,test-lane-lone-host38/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" andcli_config_test"serve --config: expand reads the file, passes other commands through and names what it cannot read".zig fmt --check build.zig zigandgit diff --check: clean.lone_cost_tilefacts, and HIP's withcopy_guardoff, 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).main9489c38 and on this head: the whole decision trail is identical tomainin 9 of 9 configurations where the gate is off (CUDA'slone_cost_tilefacts, HIP withcopy_guardoff with and without a head, root and context copies, untimed costs, a drafter withoutplain_guard; 90 of 90 requests), and in 3 of 3 where copies are never proposed; the shared phase makes the same decisions asmainin 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.Receipt
git archivetrees (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/kfdholder.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'sdraftfield 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."draft": false, main -> headFrom 131K tokens drafts on recover most of the gap to
"draft": falseon 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": false73.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:"draft": false, main -> headShort 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:--mtp-drafts 0(copies only)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.
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.Model.copy_guard(?bool, unset:plain_guard); HIP's Qwen facts set it when the forwards are timed.Qwen3.6-35B-A3B-MLX-4bit-MTP(with its MTP head) andQwen3.8-27B-MLX-4bit(no head on HIP). Binaries: main tensorfold-nativefc57239f1ba9, head20d4faa5dae2(sha256 prefixes).--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.token_shaequals 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 (alone3/3 and 12/12,serial1/1 in every run).tools/bench_concurrent.py's per-stream decode (it hastools/bench_openai.py's prompts). Clients, scripts and raw files: https://gist.github.com/AbrahamCete/b1ead4bd9fa5d9d0e61bcf4882875477 (local paths read$LAB,$MODELS,$WTand$SCRATCH)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;--drafteris n/a: the HIP engine runs no drafter.)