Skip to content

train 1119104839: #3268 #2950 #3728 (CI only) - #3946

Closed
ashhart wants to merge 23 commits into
mainfrom
lead/train-1119104839
Closed

ashhart wants to merge 23 commits into
mainfrom
lead/train-1119104839

Conversation

@ashhart

@ashhart ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

CI for a landing train: #3268 #2950 #3728 stacked on main in that order. Nothing merges from this PR: each PR above lands on its own once this tip is green, and this PR is then closed.

cshintov and others added 23 commits November 19, 2026 10:48
…es (#2761)

`tensorfold info MODEL [--context N] [--parallel N|auto]` prints the startup budget (weights, every stream's KV and state, the prompt scratch) and whether it fits this Mac's Metal working set beside the 8 GiB margin. The charge comes from native/qwen27_reserve.zig, which serve now calls for its fit and prompt rows, so the two cannot drift. hub.modelType returns its string in the caller's allocator instead of a parse it has freed.
Put the KV-size note above the assertion as one line within 120 columns and credit @cshintov on the Unreleased line.
…in / piece / finish)

The Metal target implements the lane core's chunked hooks over its whole-prompt path:
`begin` clears the slot or restores a kept state, each `piece` runs encoder chunks from
the slot's tail position, and `finish` runs the rows the pieces left, the decoder's cone
once over the prompt's end, and the choice and keep exactly as `prefill` does. An
`encode` that stops short of the prompt's end prepares the next call's first chunk
(keyed by the slot's tail and rows), so a lone prompt in pieces of the chunk size runs
the same chunks, inputs and host overlap as one call.

A mid-prompt state is never kept: a released, cancelled or failed prompt is abandoned
(nothing saved, the prepared chunk dropped) and the slot's next prompt starts cleared.

The lanes backend fills prompts a step at a time (Backend.prefill_step over the
pieces, draft/lane_steps.zig) only when Options.steps is set; serve_lanes turns it on
for Metal with TF_DSV41_PREFILL_PIECES=1, TENSORFOLD_PREFILL_ORDER=srpt or a LaneHost
prompt policy, share or budget. With none of them set prompts run whole at admission,
as before; the CUDA backend never sets it.

Tests: pieces of 1, 7, 64, 100 and 300 rows equal the whole prompt (every state byte,
the first choice and 8 greedy tokens) with a decode stream running between pieces; two
prompts' pieces taking turns at the same positions; refused and released mid-prompt
prefills; kept prompts resumed in pieces; served replies in steps equal serial; a short
request during a long prompt gets its first token first in steps (after it as whole
prompts); a cancel mid-prompt keeps nothing; host tests over a stepped CPU twin for the
step adapter, its failure and cancel paths and the switch.
…pt's steps

With prompts in steps the lane host ran one decode round after each 4,096-row piece,
so a reply beside a long prompt drew one token a piece. The DeepSeek served lanes now
use LaneHost's own share: `--decode-share` reaches LaneHost (its share and, while
replies decode, its row cap on a step), else TENSORFOLD_PREFILL_SHARE, else replies
get 0.25 of wall time beside a prompt in steps. A step taken while a reply decodes owes
it a third of the step's time in rounds before the next step; with no reply decoding
nothing is owed, so a lone prompt runs as before. `--decode-share` on Metal turns
steps on. With steps off the share stays the host's default (whole prompts).

The target counts the most launches between two of a prompt's pieces (Stats).
Tests: on the device, a share of 0.75 gives a decoding reply at least 3 rounds between
two pieces (37 here) where a share of 0 gives at most 1, replies equal serial; host
tests of the same over the stepped twin and of which share applies (flag, env,
default, whole prompts).
…refused by name, docs

`serve_lanes.stepsFor` takes --decode-share: above 0 it turns prompt steps on (its
share then reaches LaneHost), outside [0, 1) it is refused, and otherwise the
environment decides as before. The Metal entry reports either refusal by name at open:
the flag's range, or TF_DSV41_PREFILL_PIECES's expected forms when its text is
malformed (blank keeps the default).

Docs: TF_DSV41_PREFILL_PIECES's row in environment.md names what it does on each
backend; api.md lists DeepSeek-V4.1 on Metal among the servers that apply
--decode-share; profiles.md notes the Metal reader; the optimization ledger's
DeepSeek cell for prompt chunk interleaving is open on Metal.

Test: --decode-share 0.5 with no environment turns steps on at that share (and the
row cap); 0 and unset keep whole prompts; 1, 1.5, -0.1 and NaN are refused; a blank
switch keeps its default and malformed text fails.
…nk at its own size

When a step stopped short of the prompt's end, `encode` prepared the next full chunk.
Under a capped step (TENSORFOLD_PREFILL_POLICY=fcfs with _TOKENS, or the row cap
beside replies with --decode-share) the next call asks for fewer rows, so that stage
never matched and the call read its inputs again. The stage now takes the rows the
next call will ask for when it repeats this one's size, which is the next full chunk
for an uncapped step (the same as before) and for the rows a finish has left.

`Prompt.stage_hits` counts calls that start on a staged chunk. Tests: on the device,
pieces of 1, 7, 64, 100 and 300 rows each start every later call on a staged chunk
(1 and 7 rows found one before this change) with state equal to the whole prompt; a
served fcfs prompt in 128- and 100-row steps beside a decoding reply starts its steps
on staged chunks (8 of 8 and 10 of 10; 1 before) and replies equal serial.
…hare in steps, as unset does

applyShare skipped the steps default whenever TENSORFOLD_PREFILL_SHARE was present, blank included,
while the lane host reads a blank value as unset and so as its own default share of 1: with steps on
and the variable blank, a prompt kept all the time and replies were back to one round a step. A
blank value now counts as unset here too. The share test gains the blank case (it read 1 before).
Main's whole-prompt path keeps a state before the first user turn and before a thinking
prompt's closing <think> as the prompt passes them (Target.keepPoints), and skips keeping
the whole thinking prompt. The rebased steps path ran pieces straight to the end, so with
steps on those states were never kept and a thinking prompt kept nothing. A piece or
`finish` that passes a keep point now runs the prompt to it, the decoder's cone there, its
taps and that state kept (Target.keepAt, shared with `prefill`), then goes on.

Tests: (c2) and (c3) run with whole prompts and in steps; (i)'s long prompt carries no
user or think tag, so its cancel still keeps nothing.
…ines

serve_test.zig reached 676 lines with #2950's served tests in steps. Those five tests and
their stat wait move to steps_serve_test.zig, named "serve in steps: (a)" to "(e)" so their
letters no longer repeat main's (g), (h) and (j); they use serve_test.zig's reply helpers,
now pub. serve_test.zig's test block brings the new file in, as it does steps_test.zig and
tree_test.zig, so test-dsv41-metal-serve runs it; the step's description says so. No test
changes what it checks.
…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
(#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 #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 #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 #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 #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 #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 #3390
…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.
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner Author

Landed: #3268 #2950 #3728 as main 32c4e3d. This PR only carried their CI.

@ashhart ashhart closed this Nov 19, 2026
@ashhart
ashhart deleted the lead/train-1119104839 branch November 19, 2026 13:00
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