Skip to content

Merge upstream main - #122

Merged
plotarmordev merged 269 commits into
mainfrom
feat/171-merge-upstream-main
Nov 21, 2026
Merged

plotarmordev merged 269 commits into
mainfrom
feat/171-merge-upstream-main

Conversation

@plotarmordev

Copy link
Copy Markdown
Owner

laudney and others added 30 commits November 21, 2026 15:39
The API guide named one reader. It now lists GLM-OCR with its
single page block, the header and footer refusal for a reader
without boxes, and the context a dense page needs under GLM-OCR's
default window; the changelog line stays with the maintainer.
…f the visual-token budget (ashhart#2510)

The default stays the per-request split, so replies without the flag are unchanged. With fixed, each image takes --vision-image-tokens / --vision-max-images whatever the request's image count, so a turn that adds an image leaves earlier images' rows where they were and the prompt cache resumes from the first image. A share of 0 is refused naming both flags.
… idle manager can take the lock and park on a busy runner
…, every weight byte read once the server is ready
…reads hash_failed when it cannot stamp; excluded servers never read the weights, and --kv-cache, --prompt-precision and --rope-yarn are excluded
…nd engine info they now take, and the changelog keeps ashhart#2956's line
DeepSeek-V4.1's LaneHost set no .structures, so the server answered response_format, the guided_* fields and
required or named tool calls with HTTP 400 (ashhart#847).

The lane backend now passes each window's grammar bits to the target in Segment.masks, and before a prompt's pick it
passes the first token's bits from the stream's own grammar (Target.first_mask). first_masked checks the prompt's
pick against the bits the lane core asks for. With TF_DSV41_TAIL_JOIN, a joined prompt's first draft keeps only a
count of held drafts, so the first round's plan has held drafts, and windows.constrain walks them with the grammar
through Backend.held. Lanes.heldChain gives them: the held chain's drafts, the same tokens that `verify` puts in a
window's held rows. Only constrain reads `held` here (dsv41 sets no context_copies).

On the GPU target, grammar_gpu.zig fills the Forward.grammar hook. Before each forward's picks, rank 0 stages the
masked rows and sends their row ids and bits to the other ranks on the plan link (op_grammar). Before a greedy or
keyed pick reads "w.logits", every rank copies those rows to pinned memory, sets the logits of disallowed tokens in
its vocabulary part to -inf and writes them back. Each run of adjacent masked rows is one copy each way. The pinned
buffer (64 rows of the rank's part) is allocated at load, so a pick allocates nothing after rank 0 sends its op.
A request without a grammar, and a row that allows every token, send and copy nothing. Tree windows give each chain
row its tree row's bits; row windows stage once per forward.

A nucleus row (top_p without top_k) whose grammar masks a rank's whole vocabulary part gave that rank the
statistics (-inf, NaN), and keepCount sent the row to the whole-row gather. keepCount now leaves such a rank out of
the sum: every logit it holds is -inf, so it adds 0. No finite sum changes, and a row without a grammar never has
such a rank.

With ignore_eos the server kept every end token in the reply's text, so a grammar's stop token came back at the end
of the content: '{"key": "value"}<|end▁of▁sentence|>' on the GPUs. The lane core already ends the reply on it.
The server's Generation now follows the request's grammar, from the token after `</think>` with thinking on. Under
it an end token is the grammar's stop token, so it ends the reply as without ignore_eos: finish reason stop, and out
of the text and the stream. The commit loop moves the grammar's phase token by token, so each end token is judged at
its own phase. The stream still scans the whole landed round, and eos_phase.zig replays the phase from the round's
start: an end token in the reasoning and the grammar's stop can land in one round, and judged at the round's last
phase the first one would end the stream. End tokens before the grammar starts, and all end tokens without a
grammar, stay in the text.

draft/lanes_grammar_test.zig runs the lane engine over the CPU twin with a test grammar: greedy and keyed replies
equal the twin's masked serial decode, drafted, with drafts off and four at once. A third test runs the prompts in
pieces with a `tail` that leaves the last row to the first round, as the GPU target does, and joins them with one
draft call or one each. A sampling_test.zig case masks one rank's whole part of two nucleus rows: the picks equal
one rank's and the whole rows', and no row is gathered whole (2 before the keepCount change). grammar_gpu_test.zig
covers the staged rows, the plan-link message, a rank's mask and the copy runs. hf_eos_http_test.zig sends a
json_object chat request with ignore_eos on the DeepSeek-V4.1 test tokenizer, thinking off and on, whole and
streamed, in rounds of every size from one token to the whole reply. Each round's reasoning and content stream with
it: judged at the round's last phase, the whole-reply round streams its reasoning in 2 pieces, not 1.
The structured output section gains a line for dsv41-cuda beside GLM's CUDA backend: rank 0 sends each pick's
grammar rows to the other ranks, and every rank masks its own vocabulary columns before the pick. The ignore_eos
paragraph says that a grammar's stop token still ends the reply, out of the text.
The followers take the mask bits rank 0 sends, so op 28 has no bind, step
or release sub-op any more. The note says so, and it no longer claims 29-31.
The new `grammar` phase covers one pick's masked rows: the copy out, the
host mask and the copy back. With TF_DSV41_PHASES=sync it syncs at both
ends, so with drafts off its ms_avg is the cost of one masked row.
…rallel walk

The lanes grammar test now also runs its cases with first-position siblings (TF_DSV41_TREE 2-4) on the CPU twin,
four at once and alone: every reply equals its masked serial decode, and the twin counts the tree windows it ran
(more than 0 in each run).

The test grammar gains an optional early stop and a grammar_budget hook that keeps only the stop token once a
longer reply could not end within the draws left. With the budget armed and max_new below the full length, the
drafted, "draft": false, tree, four-at-once and solo replies all end on the stop token within max_new and equal the
serial decode under the same budget. The same grammar without the bound runs past max_new.

The test grammar's matchers are independent, so it sets parallel_walk, and four constrained streams take the lane
core's worker pool (ashhart#1455). The four-at-once case now checks that the pool ran.
… bits

The lane core calls Backend.first_masked after the prompt pass to draw the first token among the grammar's bits.
DeepSeek's lanes draw it in the pass itself: before `prefill`, `finish` or `join` they take the stream's first-token
bits (Constraint.next), and the target draws the prompt's last row among them. lanes_first.zig now states this
contract and first_masked checks it. The grammar takes no token between that call and Engine.drawFirst, so
drawFirst passes the same bits. first_masked compares them word for word with the bits the pass drew under
(error.FirstMaskChanged when they differ, and when the pass drew without bits), checks that the pick is among them
(error.FirstNotMasked), and returns the pass's pick as `first` does. It runs no forward, writes no KV row and calls
no drafter. Before, it only checked the pick against the bits it was given. The pass's bits are a copy in the
stream's St (first_bits), freed with it.

The pick stays in the pass, and is not drawn in the callback from a kept row as Gemma 4's CUDA backend does, because
on DeepSeek it is the TP=2 forward's own pick: rank 0 sends the row's bits on the plan link and every rank masks its
part of the vocabulary first. A later draw would need its own plan-link op and a logits row kept per slot on every
rank. With TF_DSV41_TAIL_JOIN the first token comes from the first round's window, under the lane core's mask for
its pending row, so first_masked is not called; when the target runs the tail row anyway (`tail` returns its pick),
it is.

lanes_first_test.zig drives the backend over the CPU twin with a target that runs prompts as the GPU target does:
whole, in pieces, after a prefix that `begin` puts in place as a cache hit does, and joined with the tail row run.
On each path, under a grammar that refuses the twin's unmasked first token, greedy and keyed: the pick equals the
masked serial decode's first token; the KV rows, taps and drafter rings equal the unmasked pass's, so the bits
changed only the pick; first_masked leaves them and the lanes' state as they were and adds one handle; other bits
are refused with error.FirstMaskChanged, and the state stays the same. That includes bits one token away from the
pass's that still allow its pick: with the pick-only check the test fails, because it takes them. A target that
draws the pick without the bits is refused with error.FirstNotMasked. Through the lane engine, three replies at once
whose prompts came whole, in pieces, cached, joined or tail-run equal their masked serial decode.
TF_DSV41_TREE resolves each tree window as chain windows (branches.zig), and its counts reached only the gates. Rank
0 now logs them as it logs piece and replay runs, at the first tree window, at the first one with a row its grammar
narrows and at every 256th: "tree windows: N (M under a grammar), C chains, R rows run again". M counts a window
only when a row's bits refuse a token, so a grammar that allows everything at that point does not count. A
structured-output run with trees on can then show that tree windows ran under its grammar.
This branch made the reply's content tokens keep a trailing end token only
when no grammar was on, and left server/logprobs.zig on the older rule. On
main the two agreed, so the branch opened the gap: with logprobs, ignore_eos
and a grammar, a streamed reply's last logprob row would carry the stop token
that the content dropped.

No request reaches it today. openai.zig refuses logprobs together with
structured output, tools, stop strings or a thinking budget, and that is the
only place a request sets logprobs. The rule still belongs in one place.

eos_phase.Phase gains keepsTrailing, the negation of the condition ends
applies. The content tokens and both logprob delta calls now read it from one
place, beside the rule that decides whether the token ends the reply at all.
eos_phase.zig: keepsTrailing's comment on one line. forward_follow.zig: drop the history note on op_grammar.
bjornmonnens and others added 28 commits November 21, 2026 21:24
Main 7948cc4 routes GLM launches through cuLaunchKernelEx.
Forward that entry through main's pdl.forwardEx in the new recording fixtures and keep the merged code in zig fmt style.
First world-4 Flash Next receipt on HIP: Qwen3.8-Flash-Next-MLX-oQ2-MTP
at --tp 4 on four Radeon AI PRO R9700, with a same-binary world-2 control
run isolating the world effect. Decode 122.9 tok/s, concurrent code
123.8/242.0, chat 103.5/205.2, cold prefill 1412/1358/1263 tok/s; all
alone and serial comparisons equal. Refs ashhart#2401.
Point the build note at provenance.json (build.log is the build's quiet
output), reference ashhart#3608 for the tp 2 receipt until it lands, and
regenerate the README.md line in SHA256SUMS.
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.
…for gate 5

The 14 'glm moe rows' records (9e52d73) fell to the generic 'glm ' branch of the Metal limits resolver, whose key,
'moe', names no generated kernel: the device pass stopped at error.UnknownLaunch after glm_rows_wide_q8. They take
the gather source the loader builds them from (glm/wide.zig), as 'glm rows ' does.
…r adds

ashhart#3921 made kernels.zig put `#define TF_GLM_M3_FAST 1` before the KDA prompt
passes and glm_index_nax.metal on a GPU without tensor units. The KDA and
index contracts still built those texts without it, so on an M3 the loader
check refused them ("GLM contract text is not one the loader compiles") and
the whole GLM contract stopped before its first case. Both texts now follow
the loader, and gate 5's pre-M5 texts carry the define too.
…oes; its record declares 18432 bytes

On a GPU without tensor units the case compiles glm_index_nax.metal with TF_GLM_M3_FAST (ashhart#3921, ashhart#4397), whose
threadgroups cover 32 rows with 4 simdgroups, but encode launched it as on M5: scoreRows' 64 or 128 rows a group and
2 x rows threads. Rows past 32 x the groups' count were never written (256 x 128 x 16384: rows 64 on, byte 1065728),
so the shapes gate compared unwritten floats against main's scores. The case now launches it as selectKeys does
(glm/prompt.zig: 32 rows, 128 threads); rows it wrote matched main's bytes already, and the kernel is unchanged.
Before M5 the planted control moves into the pre-M5 branch (both simdgroups of a row pair on the same 32 blocks),
since the M5 branch it edited is not compiled there. The pre-M5 kernel stages 128 x 72 bf16 (18432 bytes) of keys;
the record declared 17408 (the M5 tile, 64 x 136), so gate 5's limit now declares 18432.
…ream-main

# Conflicts:
#	docs/recipes/README.md
#	zig/build/h3_image_encoder.zig
#	zig/src/core/contract/registry_joins.zig
#	zig/src/core/picture/resample.zig
#	zig/src/families/h3/geometry_test.zig
#	zig/src/families/h3/h3.zig
#	zig/src/families/qwen27/decode_round.zig
#	zig/src/families/qwen27/forward.zig
#	zig/src/families/qwen27/gpu_weights.zig
#	zig/src/families/qwen27/mtp.zig
#	zig/src/native/cuda.zig
#	zig/src/native/metal.zig
#	zig/src/native/qwen27_lanes.zig
#	zig/src/native/qwen27_served.zig
#	zig/src/server/cli.zig
#	zig/tests/cuda/contract_compile.zig
#	zig/tests/cuda/contract_tests.zig
#	zig/tests/cuda/main.zig
#	zig/tests/h3_image_encoder.zig
…nd with serve --cache-salt-per-key the API key it matched, is hashed with HMAC-SHA-256 under the server's tool-call id key and masks the first four words of the lane host's cache key. A kept state is then resumed only by a request with the same salt; with no salt the request is keyed exactly as before, and tokens never change.

Salted states stay in RAM: the disk writer, reader and --learn already
refuse high-bit words, so the disk format is unchanged. A salted request
neither drafts from nor adds to Recall's record and neither reads nor
writes --compact-memory notes; the server's own requests for a salted
conversation (warm pass, compaction notes, Cortheon's planner and kept
rounds) keep the salt, and a salted /v1/imprint ask looks up its own
states. Engines whose cache is not the lane host's store refuse a salted
request with 400 and refuse to start with --cache-salt-per-key. The request
log redacts the salt, and /v1/models publishes capabilities.cache_salt.

Fixes ashhart#3196
@plotarmordev
plotarmordev merged commit e0c33d4 into main Nov 21, 2026
@plotarmordev
plotarmordev deleted the feat/171-merge-upstream-main branch November 21, 2026 23:35
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.