Skip to content

train 1118185203: #3231 #3214 #3508 #3832 #2841 #3220 (CI only) - #3861

Closed
ashhart wants to merge 25 commits into
mainfrom
lead/train-1118185203
Closed

ashhart wants to merge 25 commits into
mainfrom
lead/train-1118185203

Conversation

@ashhart

@ashhart ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

CI for a landing train: #3231 #3214 #3508 #3832 #2841 #3220 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.

ashhart and others added 25 commits November 18, 2026 18:52
…t once

A grammar request compiled under the server-wide grammar lock with no time
bound. xgrammar's compile time grows faster than the square of an object's
optional properties, so one such schema held every other grammar request,
cached ones included, for as long as it took. A 207 KB schema takes minutes.

tf_grammar.cc now hands each compile to tfc::Cache in tf_compile.h. A hit
among the last 8 grammars that finished in time is served under its lock.
A miss runs on its own thread, with the 8 MiB stack the request threads
have, against the same long-lived xgrammar compiler, options and caches as
before. Identical pending requests share one compile. At most 4 compiles
run at once, and a request that finds all 4 busy waits for one. A request
waits at most 2,000 ms in all, then gets the 400 naming the limit.

xgrammar has no point at which a compile can be stopped. An abandoned
compile runs to the end in the background and keeps its slot until it
returns. The grammar it finishes goes into xgrammar's cache but never into
the in-time cache, so the same request sent after that is served. The Zig
caller drops its compile mutex. The C ABI is unchanged apart from
tfg_compiling, a slot count for tests, and an older library still compiles
without the time limit.

A grammar that compiles within the limit is the one main compiles, from the
same compiler object, calls and options. Masks over 14 grammars in all six
formats hash equal to main's library's at every step, and two invalid
inputs give the same errors.

Tests: tf_compile_test.cc drives the runner with fake compiles through the
deadline, late results kept out of the cache, a small compile passing a
running large one, shared jobs, slot waits, ownership past close, failures
and stack depth. It runs in zig build test and test-grammar-compile-host. A
lanes test shows one caller's slow compile no longer holds another's. A
server test checks the 400 for every format. Through a real libtfgrammar,
the 8,000-property schema is refused at 2 s while a small schema compiles,
a retry joins the running compile, and once that returns the grammar comes
from the cache.

Fixes #3209
…m 3)

qwen3_5/draw_topk.zig moves unchanged to core/lanes/sampling_row_topk.zig (lanes imports become
sampling.zig/grammar.zig, the Qwen error names become NonfiniteLogits/NoAllowedToken, the parameter
`sampling` is `settings`). sampling_row.draw tries it first for a sampled top_k of 1..128, as
qwen3_5/draw.zig did, so qwen3_5/draw.zig is core's draw with the errors mapped back to the Qwen names.
The three selection tests move with the code; a core test pins the heap-free path through sampling_row.draw.
…ests

The planned decode walk's score kernels (tf_plan_score*, the long-span
and the short-span ones, q fp32 and in the cache's kind) take a path
for head size 256, the Qwen3.6-35B-A3B and Qwen3.8-27B attention:

- every lane takes its eight elements without the `lane + 32 i < d`
  test, so a key's products form one plain chain;
- a wave's keys are scored in one basic block (no branch per key on
  `visible`), so their chains and folds interleave;
- lane 0 writes a head's scores of the wave in one 16-byte (long) or
  8-byte (short) store when the rows are aligned and the span is a
  multiple of the wave's keys, else one at a time;
- keys are read through global, not flat, pointers, so LDS waits do
  not also wait on the cache loads;
- a long-span block walks eight steps of its warps' keys and loads the
  next step's keys while the step before is summed; launches/plan.zig
  divides the score grid by the steps.

Stats, apply and the partial sums are unchanged, and other head sizes
keep the current path.

Why the bits hold: each score is the same sum in the same order. Lane
l adds its eight products in element order from 0.f, then the folds
run at xor 16, 8, 4, 2, 1 with each lane's own value as the first
operand, as before. Keys past the row's position are not loaded (their
registers hold zeros) and their scores are still -inf. A fused
v_add_f32_dpp fold (partner + x) was tried and dropped: on gfx1151 it
keeps the other operand's payload when both are NaN.

kernel_tests/plan_pin.zig pins every byte the walk writes (scores,
stats, partials, output) on keys and queries poisoned with NaNs of
distinct payloads and signs and with infinities, long and short spans,
q fp32 and bf16, by a digest recorded on the kernels this replaces.
The eight score records take the registers ROCm 10.1's hipcc reports
for each served chip, updated in place.

Refs #3429
…el contract

The contract's walk fixed d = 128, so it never entered the score's
d == 256 path. It now registers that path for both Qwen head groups
(16 query heads over 2 KV heads and 24 over 4), on short spans (two
keys a wave) and long ones (four keys, eight steps a block), with q
fp32 and in the cache's kind: eight kernels through gates 1-4.

- Rows end at causal cuts: inside a wave's keys, on a wave's, a step's
  and a block's edge, at the span's end, one key and all but the last;
  the float64 reference sums each row over the keys it sees.
- Spans past the 8- and 16-byte score stores (1023, 4093, 16386,
  16387, 16511, 16513) take the scalar tail, and served[0] of the
  24-head cases is one, so gate 2's guard bytes cover that tail.
- Gate 4's rows see every key, so its weights stay 1 / keys.
- A control launches the walk with the long-span score grid counted
  for 16 steps a block where the kernel walks 8; gate 3 must go red.

Refs #3429
The d == 256 branch inside plan_score_body shared the register
allocation of tf_plan_score_*, so Nemotron's d = 128 walk ran at 107
VGPRs where main runs 48. The branch moves into its own entry points,
and every existing score kernel is main's source again.

- plan.hip: tf_plan_score256_{f16,bf16,act_f16,act_bf16} run
  plan_score256_body, which holds plan_score_d256's walk verbatim
  (eight steps of four keys a warp a block, keys loaded a step early,
  no element tests). plan_score_body and the eight tf_plan_score*
  kernels equal main's byte for byte; the file only adds lines.
- launches/plan.zig dispatches d == 256 on long spans to the new
  kernels and divides their grid by score_steps; other head sizes and
  short spans launch main's kernels, as on main.
- Records: hip_records.zig is main's again (in place, 600 lines); the
  four new kernels get records in hip_records_score.zig.
- Contract: the planted grid fault now targets tf_plan_score256_*,
  with a control for q fp32 and one for q in the cache's kind.
- plan_pin.zig pins Nemotron's shape too (32 heads over 2, d 128, a
  long span), with its own digest beside the d = 256 one.

Refs #3429
… their arrival order (#3775)

Flash Next's chat template renders each tool result as an anonymous <tool_response> block, so the model reads them
by position. When an assistant made several calls and the results arrived out of call order, each answer was read
as the wrong call's: two read_file calls answered production-first gave the defaults file's port as production's.

After normalizing, renderStarts now reorders, for flashnext-zig only, a contiguous run of tool results that follows
an assistant with two or more tool_calls: only when the run holds exactly one result for each call's id, with no
blank or repeated id. Any other run keeps arrival order. Every other request and backend renders as before.

The regression test renders AB, BA, BA with the ids swapped, and a repeated id through a template that emits
anonymous result blocks; it fails on main without the fix (BA renders 9137 first) and passes with it.

Reported, fixed and tested by @srh3877, ported to main.

Co-authored-by: srh3877 <84433664+srh3877@users.noreply.github.com>
…2833)

Every host save and disk-recall blank pinned new memory (cuMemHostAlloc) and
every drop unpinned it. A dropped copy's buffer now goes to a list of at most
two spares on the target, once no copy into or out of it can be queued: the
save synchronized, and no restore still reads it (a stuck one still goes to
the copy-source quarantine). The next save or blank of exactly that size takes
it instead of pinning. The prompt cache counts the spares inside its budget
(snap_spare), frees them when it needs the room (snap_trim, now wired through
cuda_snaps.zig) and keeps a state in a spare without evicting more
(snap_reuses); the dense and MoE entries both declare the hooks. The spares
are freed with the engine, after the host closes the prompt cache.

The bytes copied are the same; only their buffer changes. Host tests on a
mock driver that moves real bytes: reuse after a drain, none before, another
size pins, the cap, trim and teardown, byte-equal saves and restores in every
layout, a recall blank, and the store reusing an evicted state's buffer.
… stage

Main's stage geometry reads first and whole; a geometry built field by field from undefined left them unset,
so deltas() read past the layer table and every kept-spares test crashed on today's main.
…o spares

saveCache takes the spare list now; the checker's three saves passed five arguments, so the Linux checker
(compile-qwen35-rounds-host, and tf-qwen35-cuda on a device) no longer compiled.
…imported inline, so cuda_native.zig stays under 600 lines
POST /v1/responses with background: true answers at once with the response, status "queued", and runs the turn on
its own thread after the POST returns; leaving the connection does not cancel it. GET /v1/responses/{id} polls it:
queued, in_progress (no output yet), then the finished response as the same request sent normally returns it. The
job runs its own copy of the translated chat body through the same turn and chat path, on a connection that is gone
only when cancelled, so the same body and seed give the same tokens. Its end is an ordinary stored response, kept
before the job leaves the running list so a poll always finds one of the two. The store itself is unchanged.

POST /v1/responses/{id}/cancel goes through the request cancel route's registry: a running reply ends "cancelled"
with the text it had, as POST /v1/requests/{id}/cancel ends it, and either route takes the resp_ id; before the turn
registers, the gone hook stops it with nothing run. The route waits up to 2 s for the end and answers with it. A
second cancel answers the cancelled response again; any other ended background response, or one not created with
background, answers 400; an unknown id 404. DELETE of a running one stops it and keeps nothing.

Limits: 64 queued or running per server, 16 per API key, 256 MiB of copied requests; past them a create answers 429
background_limit_exceeded before any thread starts. A job takes the route's gate counts and lease (Held.take) and
releases them once its end is stored, so --max-inflight, idle unload and a stop's drain see it as a request in
progress; Server.deinit cancels and waits for any left. Refused with 400 by name: stream: true or store: false with
background, a non-boolean true value, background over a Responses socket, GET ?stream=true of a background
response, and a previous_response_id that names one still running. With keys only a full or [admin] key reaches
stored responses, as before; without keys the 128-bit id is the right to read, cancel or delete one, as for GET
and DELETE.

The golden refuse-background case now sends stream: true with background, which is still refused, so the frozen
answers stay deterministic; its expected body is the new refusal.

Fixes #3187
@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Landed: #3231 #3214 #3508 #3832 #2841 #3220 as main 0900b48. This PR only carried their CI.

@ashhart ashhart closed this Nov 18, 2026
@ashhart
ashhart deleted the lead/train-1118185203 branch November 18, 2026 20:46
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.

3 participants