Skip to content

Merge upstream main - #67

Merged
plotarmordev merged 80 commits into
mainfrom
feat/77-merge-upstream-main
Nov 17, 2026
Merged

plotarmordev merged 80 commits into
mainfrom
feat/77-merge-upstream-main

Conversation

@plotarmordev

Copy link
Copy Markdown
Owner

devopsfortunato and others added 30 commits November 17, 2026 00:00
…ts source once, so an M4 run sees a stale M5 edit
Jinja's float(value, default=0.0) for numbers, booleans and numeric text.
Anything else gives the default, an undefined value raises, and an
argument Jinja does not have is an error, as in Jinja. Inkling 2's chat
template reads its thinking effort through it.
Model.load reads every shard span through core's checked read-ahead before the first forward, so missing or short shards fail the load. TF_LOAD_PREFETCH=0 leaves page faults to the mapping. zig build test-h3-read-ahead covers 16 readers and 0, and the nightly macOS adapter target runs it.
…low the origin no longer overflows

On main a copy-drafts-only server (ReleaseSafe) panics at its first one-row step graph: offsets computed
m.k[i] + at - m.origin in u64, and attach's sliding rings can be allocated below origin. The kernel reads the
offsets as long long, so a negative one is valid.
…grouped experts read it, routed arrays are freed

TF_FLASHNEXT_SCALE_INDEX is now on by default on GPUs without tensor units. The loader indexes every 4-bit group-32
expert projection once at load, on up to eight threads. The routed gate, up and down projections, which only expert
kernels read, release their stored scales and biases and keep the index and table in those slots; the shared
projections keep theirs beside the index, since kernels outside the expert set read them direct.

The prompt gathers (32, 64 and 128-row tiles and the fused gate/up) and the grouped expert kernels now read each
group's pair through the index, as the per-row expert kernels already did: the same two values into the same sums,
so replies keep their tokens. An index is keyed by its projection's codes buffer, and a kernel takes the indexed
form only for a projection that has one. A tensor with more pairs than a 16-bit index holds turns the index off
with a warning, as before.

The indexed gathers and the indexed grouped launches register with the kernel contract as bit-preserving
replacements of the direct reads, each with a planted control and launch records.

Refs ashhart#2751
At widths other than 4/64, wide.moe ran each (row, pick) slot in its own
threadgroup, so a window of R rows read each routed expert once per pick
and the shared expert once per row. glm_moe_rows_u runs one threadgroup a
unique expert (the route's uids, members and count) with a simdgroup per
pick, and the shared expert with a simdgroup per row, so their weights
come from memory once for every row that picked them. Each pick's sums are
the same tf_rp_rows call, so the bits are too. Windows of 2+ rows take it;
one row keeps the per-pick launch.

tf-glm-rows-check: by unique expert == by pick at q8, q4 and q2 for 2, 4
and 16 rows (456,192 bit-equal values).
A checkpoint may store layers.45.shared_head.head (a lighter copy of
lm_head, e.g. 4-bit beside an 8-bit backbone). On one Mac the loader
loads it beside lm_head and the MTP drafts project through it; lm_head
still produces every verified token, so replies are unchanged. Without
the tensor nothing changes.

8-bit GLM-5.3-Flash with the 4-bit MTP layer and head, 6 bench prompts:
12/12 replies equal to the 8-bit alone; greedy 53.0 -> 53.2-53.5 tok/s,
sampled 48.4 -> 50.1-50.3, 3.5 GB less memory.
EugeneClaw and others added 28 commits November 17, 2026 09:29
… the completed prefix

A warm pass ran to the end of the prompt instead of stepping aside when
foreground work arrived: the loop checked cancellation but never the yield
hook its background passes wire. The pass now keeps its completed prefix
and returns error.Yielded at the boundary; the next pass resumes the kept
mark.
A planned store kept a warm end off the grid, and under a one-snapshot
budget the unusable end evicted the usable mark: the next request resumed
at zero. The rules now set warm_usable, and the one-snapshot regression
stays.
…prose

Tool-call openers quoted inside Markdown inline code spans (`...`) or fenced code blocks (```...``` or ~~~...~~~) in generated assistant prose were treated as live call openers. Quoted `<tool_call>` tags paired with a following real call's `</tool_call>` and rejected it, quoted `<tool_call>NAME<arg_key>...` fragments naming an offered tool streamed bogus arguments, and complete quoted calls inside prose or code blocks executed as tool calls.

Add a linear-time Markdown code-span and fence scanner (reply_code.zig) and wire it into whole parsing (tool_parse.zig), streaming call deltas (tool_stream.zig), single-call prose filtering (tool_policy.zig), prose hiding and thinking-tail lifting (reply_text.zig, reply_tool_tail.zig), LFM2 rewrites (tool_lfm2.zig), logprob ranges (logprob_parts.zig), and EOS call closing (chat_generation.zig). While streaming, an inline backtick span containing a tool opener waits until a matching closer confirms code or a paragraph break or end proves it literal.

zig build test-tool-parse-host test-tool-visibility-http-host test-thinking-tail-host, zig build test test-golden dev-tools -Dcpu=apple_m1, zig fmt --check build.zig zig, and python3 tools/pr_check.py --base origin/main pass.
… a 4096-row-multiple end

The Qwen3.5 CUDA family declared no warm pass, so the server never ran one for
it. Both entry points now declare `warm_quiet` (150 ms) and `warm_usable`,
`cuda_snaps.cacheRules` reads a family's `warm_usable`, and a CUDA host takes
the family's own wait instead of Nemotron's. What the pass keeps is the narrow
part: a request's chunk starts never reach its own end, and this family's grid
is 4096 rows, so the end survives only when the prompt is an exact multiple of
it. A turn under 4096 rows keeps nothing and is cancelled before it runs; a
5000-row turn keeps its 4096 mark but not its end.

`prefillFn`'s whole text pass is fixed on main (ashhart#2838); this branch carries the
enablement only, and ashhart#2873's foreground yield goes first.

Host tests: the declarations on both entry points, and a family's warm rules
and its own wait.

Refs ashhart#2812
Share the existing chat chunk-start expression through Plan.request. A warm pass computes its own system prefix and uses that same plan, so request-starts caching does not skip the system cut on the background path.

The host regression compares warm-prefix and later-request cuts with a 600-token system prefix. Skipping the cut fails the test; preserving it gives the same starts below the warm end.

Refs ashhart#2812
…ack, the model's repetition past about 300K, and omp's replayReasoningContent
The lane host tests run hand-picked orders; their seeds pick samples, not
schedules. test-lane-explore-host wraps the fake target and, before each
prompt call, prompt step, batched pass, first draw, one-token step and
verified round, lets a seed pick the next arrival, a cancel, the backend's
room for live lanes or the memory pressure the host reads. The seed also
picks the setup: lanes, requests, a draft head or none, pipelined or
verified one-token rounds, early or late speculation, batched or per-stream
head drafts, sampled or greedy requests, and for chunked prompts the chunk
count and the prompt-row budget.

After each schedule every request has finished exactly once with no event
after it, ended `length` with all its tokens or `cancelled` only when
cancelled, and its tokens are a solo run's (or their prefix); no reply
passes max_tokens, the backend never holds more lanes than the host, prompt
steps beside a decoder stop at the row budget, a stream's chunks run in
order, and no lane or stream is left. A third test replays 16 seeds of each
scenario and compares a digest of every yield point's act and every reply.

A failure prints its seed and `zig build test-lane-explore-host
-Dexplore-seed=S` replays it; -Dexplore-seeds=N sets the sweep (default
200 a scenario) and -Dexplore-tally=true prints what the schedules did.
The test binary runs in about 2 s. A planted skipped release on cancel and
a removed budget stop each fail at a printed seed that replays. No engine
code changes. The nightly Linux host list runs the step.
…ords (value change)

Both target loaders (load.zig: load and loadGptq) and the DFlash2 drafter (drafter.zig, Drafter.init) take their
inverse frequencies from xpu/rope_table.zig: rope_freq.inverseFrequencies(1e7, 64) for the target's 32 words
(attn_prep: 64 rotated dims of 256), (1e7, 128) for the drafter's 64 (dprep: full 128-dim heads). Every word that
moves moves by exactly 1 ulp.

Target, theta 1e7 over 64: 15 of 32 differ; largest |old - new| 2.980e-8 (word 2), largest relative 1.181e-7.
  word  2 0x3ebaf81a -> 0x3ebaf81b   word 16 0x39a5cb5f -> 0x39a5cb60   word 22 0x37812dac -> 0x37812dab
  word  3 0x3e61f836 -> 0x3e61f835   word 18 0x38f22ce3 -> 0x38f22ce2   word 26 0x3609cf4b -> 0x3609cf4a
  word  5 0x3da50957 -> 0x3da50956   word 19 0x3892587f -> 0x3892587e   word 28 0x35494c56 -> 0x35494c57
  word  7 0x3cf11176 -> 0x3cf11177   word 20 0x3830df51 -> 0x3830df52   word 29 0x34f3499c -> 0x34f3499d
  word 10 0x3bd4ca14 -> 0x3bd4ca15   word 21 0x37d5c442 -> 0x37d5c441
  word 13 0x3abbd3ec -> 0x3abbd3ed

Drafter, theta 1e7 over 128: 18 of 64 differ; largest |old - new| 2.980e-8 (word 4), largest relative 1.181e-7.
  Even words 2j equal the target's word j, old and new, so 15 are the target's above at twice the index:
  4 6 10 14 20 26 32 36 38 40 42 44 52 56 58. Three odd words also move:
  word 25 0x3af19f03 -> 0x3af19f02   word 35 0x391bc44d -> 0x391bc44e   word 39 0x3863872d -> 0x3863872c

Why the words differ:
- Formula order: the loaders computed f32(1e7^(-i / 32)), a negative exponent with no reciprocal; transformers and
  rope_freq compute 1 / 1e7^(2i / d).
- Precision: both old forms kept everything in f64 and rounded to fp32 once (the drafter's f32(1 / 1e7^(2i / 128))
  took its reciprocal in f64). transformers rounds 1e7^e to fp32, then takes an fp32 reciprocal: two roundings.
  Every moved word is a case where those two roundings land 1 ulp from the single one. On all 18 moved words the
  old word is the nearer one to the exact 1e7^(-2i / d) (checked in 60-digit decimal). So this is a move to
  transformers' bits, not an accuracy fix.
- Theta and exponent handling contribute nothing: 1e7 is exact in fp32 and f64, and 2i / 64 and 2i / 128 are exact
  in both, so old and new raise the same base to the same exponent.

Test (zig build test, through the XPU host tests): rope_table.zig prints the old and new tables side by side with
each table's largest absolute and relative difference. The replaced expressions live only in the tests, as
references. The target's words are pinned to the transformers 5.22.1 literals that rope_freq's own test holds for
1e7/64. The drafter's are pinned to new 1e7/128 literals, each step correctly rounded in 60-digit decimal; their
even words are the 1e7/64 transformers words, and their odd words are not yet checked against torch. The tests
also assert exactly the moved indices and at most 1 ulp.

Not run on an XPU. Before landing it needs a token A/B of old and new xpu-qwen27 builds on the same ids, and
drafted == serial on the new build (XPU_VERIFY_TEST, XPU_DRAFTER with XPU_TREE=15, XPU_MULTI_TEST).

Refs ashhart#1852.
xpu/rope_table.zig's two tests (the target's and the drafter's words against their old expressions) ran only
under the aggregate test step. test-rope-xpu-host runs them alone, without devices or ocloc; the aggregate step
still depends on them.

Refs ashhart#1852.
xgrammar's compile grows with the square of the grammar's text and the server holds one lock across it.
A grammar over 512 KiB now gets HTTP 400 before the compiler sees it.
…al of their own

A sent grammar is checked where it is read, before compiling. A tool grammar is measured as the grammar for one call,
which holds each tool's name and schema once, so the repeat a parallel-call grammar adds no longer refuses tools under
the limit (300 KiB of required tools is served); names and many small tools still count. Its 400 names tools. The docs
say a JSON schema or a choice list is measured as the server re-serializes it.
…eam-main

# Conflicts:
#	zig/build/h3_host.zig
#	zig/build/metal_targets.zig
#	zig/src/families/h3/h3.zig
#	zig/src/families/h3/read_ahead.zig
#	zig/src/families/h3/tensors.zig
@plotarmordev
plotarmordev merged commit 3e445ab into main Nov 17, 2026
@plotarmordev
plotarmordev deleted the feat/77-merge-upstream-main branch November 17, 2026 12:03
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.