Skip to content

Merge upstream main - #141

Merged
plotarmordev merged 234 commits into
mainfrom
feat/190-merge-upstream-main
Nov 22, 2026
Merged

plotarmordev merged 234 commits into
mainfrom
feat/190-merge-upstream-main

Conversation

@plotarmordev

Copy link
Copy Markdown
Owner

gilby and others added 30 commits November 21, 2026 22:59
The depth rule priced Metal rounds with the CUDA-shaped defaults. Metal now
times dry windows of 1 to 16 rows, the second launch from row 17 and a DSpark
pass with its ingest at load, on a time budget, through the lane core's
calibration path. TF_DSV41_CALIB keeps its meaning; measure is the Metal
default, and TF_DSV41_CALIB_BUDGET_MS bounds the repeats. The prompt cache is
not fed and every slot is left as new.
…t table

The first measurement took 12.7 s and priced the pass at 62 ms. It now times
rows 1, 2, 4, 8 and 16, the 4 + 4 window, rows 17 and 32 and the pass once
each after an untimed window and pass, repeats the passes only while the
budget lasts, and interpolates the rows between. The startup line reports the
ingest share of the pass and the timed runs.
… table by device and weights

The Metal measurement now checks every TF_DSV41_CALIB* setting before it
times anything, so a malformed value stops the start naming the setting, its
text and the accepted forms; only a measurement that fails falls back to the
defaults. The settings have rows in platform/environment.zig and
docs/environment.md. A stored table carries the device and checkpoint
identity, so another chip or other weights never read it. dropWindow's
comment says it is for calibration, with wipe after.
…very window a lone stream can make

The measurement prefilled the calibration text into each slot twice and ran
thirty one-row windows to grow a continuation, which cost about nine seconds
on the release model outside the timed runs. It now prefills one short prompt
in each slot it needs once, takes the window tokens from the text itself,
and clears only the slots it used. Rows 1 to 6 are timed rather than
interpolated, since a lone stream's drafts make exactly those windows.
…t be one

The pass's entry was a single sample taken right after the largest windows,
so whatever the first ingest after them costs became the table's pass. The
pass is now run once untimed and five times back to back, as a round runs it,
and the fastest is kept; the first ingest after the windows is reported apart.
A table whose pass is dearer than twice its own 1-row window is refused when
measured and when read back from a stored file.
…budget

The slot term is the 4 + 4 window less the 8-row one, each a single sample
once the budget was spent. Both now run twice more side by side after the
passes, marked so the budget never drops them; only the other row counts are
optional.
…ults

On the M5 Ultra the measured table made code faster and sampled chat slower
in three cells, with the rule near-indifferent between the depths. The table
is still timed at start and reported, with its checks and settings, but the
default table prices the rounds unless TF_DSV41_CALIB names a source, so
served depths are unchanged. The lanes test and the Metal device test run
from the Metal test steps.
Unset or blank keeps the default table with nothing timed and no extra
startup line, so load time and behaviour are the base's. measure, zig,
cached and real time or read the table, check it, report it and price from
it. The table_prices switch is gone.
…ding binding

codec_net_test.zig runs codec_net.zig's decode (3 frames, two chunks) and encode (2 frames) over a binding
that records every kernel and clip-buffer call with its arguments, addresses named by weight and buffer.
The lists are pinned in fixtures/codec_{decode,encode}_calls.txt; a difference names the first changed call.
…tched to 64 rows

tf_attn_lo and tf_attn_hi widen through the bfloat type (the same values), so the
decode kernel's dots and sums spend fewer instructions a key; the prompt kernel's
own widening copy goes. With that, loading each step's keys a step ahead wins at
every row count measured, so decode launches take the prefetch pipeline up to 64
rows. A 72-row decode shape keeps the plain pipeline under the contract. Bits equal
main's.
… origin, the first commit, the decoder's time and late buffer starts
…ows, the first run's rows read first

The chunk's Engram row ids are hashed once for every layer. Before the first commit only the first run's layer-1 rows are queued; the second run's and layer 14's queue behind them once the GPU has layer 0. The first run (30% of the chunk's rows, chunks of 512 rows or more) goes through layers 1-13 as soon as its rows are in, the second as a later chunk would, from its first row's keys; layer 14 on runs all rows. Prompt tests compare chunks of 900 rows in two runs of 270, 9 and 450 rows, chunks of 64 in runs of 19 and 45, and every cold chunk in the prompt-then-decode check, against one run and against decode: 0 values differ.
At 65536 records a prompt's reads (more than a quarter of the cache) were read through, never kept. At 4M a 4096-row chunk's batches are kept, and the rows of common n-grams stay cached across requests.
The target gave the server's ticker only its idle tick. With the busy probe (as the Qwen3.8-27B server has) a tiny command buffer on the ticker's own queue uses the weights' set every interval of a request, under the owner's hold, so macOS keeps the layers a long prompt is not using wired. The served keepalive test runs the probe beside its ticks.
Main's stepped path starts the profile clock and times the decoder cone, so its first-commit and decoder rows are right.
No change in behavior. Keeps prompt.zig within the 600-line cap with main's image rows and staged chunks.
…hat allow nothing (ashhart#2832)

sampling_row.scan replaces the scalar first pass of the greedy and masked draw: every
block's exponents are checked finite before any mask test, a block whose two mask words
are zero is not ranked, and an allowed key replaces the best only when strictly larger,
taking the block's first lane at that key, so ties keep the lowest id and both zeros
rank equal. The sampled pass walks set mask bits in id order, so the same candidates
reach the fp64 sampler in the same order. The bf16 order keys move here from
qwen3_5/draw_topk.zig. Main's draw stays as the test oracle in sampling_row_test.zig.
…g in, and ranks only allowed logits (ashhart#2832)

After the unchanged finite check, a 32-logit block whose mask word is zero is skipped,
the full-selection skip ranks only the allowed lanes, and consider runs for set bits in
id order. Each skipped call would have returned at its mask check, so the selection is
unchanged. Structured sampled rows at top_k 1..128 take this path, including rows where
fewer than top_k ids are allowed. key and keys now come from core's sampling_row (an
order-equivalent encoding), and their order test moved there with them.
… row on the CPU (ashhart#2832)

Greedy, masked and sampled rows through qwen3_5/draw.zig at ReleaseFast, with a checksum
of every drawn token so two builds' tokens can be compared. Not part of test or any CI
shard; it runs only when asked for.
…rd core's bf16 keys (ashhart#2832)

The "bounded BF16 keys" filter matched nothing once that test moved to core's
sampling_row with the keys. The bounded keyed draws compare the top-k path against the
value-sorted reference, so the step again fails when the keys order -0 and +0 apart.
ashhart and others added 28 commits November 22, 2026 10:58
The ReleaseSafe serve's process gpa is SafeAllocator over page_allocator, whose
minimum bucket is 64 KiB on aarch64. Memo segments land in those buckets among a
request's short-lived allocations, so each request that keeps a new segment maps
about 64 KiB that stays until the segment evicts (ashhart#4389). Build the memo on
std.heap.smp_allocator instead: dense size classes, freed segment space reused by
later segments, so VmData tracks the memo's own 64 MiB count. overrideSplit
propagates the memo's allocator; the other create call sites (its own tests) are
unchanged.
longestShared picked the kept prompt sharing the longest prefix without
checking entry salt, so one salt's history could shape where another
salt's fork marks land. ashhart#4504 scoped every other prompt-cache lookup by
exact salt; filter the fork candidates the same way (e.salt == salt,
null matching null). No change to which KV is restored or to any single
salt's marks.
…ream-main

# Conflicts:
#	zig/src/server/speech.zig
Each text segment is tokenised on its own and cut to 4,096 tokens; references enter as a label and a vision
block whose rows are tagged 0. Positions follow Qwen-VL's M-RoPE, and the rotary table rounds to bf16. The Qwen
copy of a reference keeps or scales its short edge to 1,024 with Pillow's LANCZOS. The text encoder's and the
refiner's configs are checked at the released geometry.
tf-h3-image-prompt turns a prompt into the text rows tf-h3-image reads: Qwen3-VL's text model to the hidden
state leaving layer index 49, then condition_proj, the two token-refiner blocks over every row and the final
norm. Weights are bf16 read in place; products run in simdgroup matrices with fp32 sums, so chips without
tensor units run it too. The encoder also takes a reference's vision rows and DeepStack features at their image
pads, ready for the edit's tower.

Its selftest writes a tiny synthetic checkpoint, loads it as a real run does, and gates each kernel alone and
each whole run against a float64 host reference with the same bf16 rounding points.
…d rotary table, unpatchify

image_decoder.zig: the 297 decoder tensors MiniMax-H3-Image's VAE file holds
(F32, checked by name and shape, decoder.mask_token left unread), their
places in one bf16 buffer, a tile's sequence (its cells, 4 registers, one
zero token), the 2D rotary ids in bf16 arithmetic and their angles, the
proj_out rows unpatchified to pixels, and the tile geometry the attention
holds (at most 16 cells a side). Host tests run in test-h3-geometry.
… on the host

image_decoder_metal.zig runs the VAE's 2D ViT decoder on a batch of tiles
a command buffer, on any Apple GPU (its kernels compile from source at
load, no tensor units): post_quant_conv and x_embedder, the 24 blocks
(RMSNorm, grouped q | k | v, q and k normed and turned half-style over
their first 32 dims, softmax attention at 1/8, LayerScale residuals, the
gated SiLU FFN), norm_out in fp32 and proj_out. Products are bf16 with
fp32 sums, rounded where the reference rounds. decode() blends the tiles
in fp32 with picture_vae's Assembler. image_decoder_reference.zig is the
same forward on the host with float64 sums, for the self-test.
…self-test

tf-h3-image-decoder MODEL_DIR latent.f32 ROWS COLUMNS out.png [WIDTHxHEIGHT]
reads vae/config.json and the decoder's tensors, denormalises the latent,
decodes it in tiles of up to 16 a pass, blends them, truncates to bytes,
resizes with Pillow's LANCZOS when asked and writes a PNG.

`selftest` runs the kernels on synthetic weights against the float64 host
reference: the embedding and proj_out within 1 bf16 ULP, each block
teacher-forced, two and all 24 blocks chained, batched decodes bit-identical
to the staged tiles, and the picture's bytes. It exits 1 past a bound.

zig build tf-h3-image-decoder builds it (shaders compile at load);
compile-h3-image-decoder-host compiles it without the Metal compiler and
joins the macOS nightly host checks. picture_writer.zig roots MOSS-Image's
PNG writer and core's resampler in one module for tools beside the engine.
…es the canvas and the seed's starting rows

tf-h3-image-prompt takes an optional size, seed and smallest area: it
writes the canvas, the requested size and the starting rows (the seed's
first torch CPU randn over the latent, patchified) beside the prompt's
rows, a whole text-to-image case. tf-h3-image's free run exits 0 with
nothing to gate. The recipe runs prompt, transformer and decoder in turn.
…nt across pictures

tf-h3-image-server loads the three tools' weights once and serves one
text-to-image request per stdin line. A request whose canvas, row count,
reference count and tags match the last one's keeps the bound transformer
and only replaces the prompt's text rows (Model.retext); another layout
releases it and binds anew over the same mapped weights. The weights sit
in one residency set across the three stages' queues, so macOS does not
re-wire them on every request, and the idle keepalive keeps them wired
between pictures while holding its ticks off during a request. A set that
cannot be held or a ticker that cannot start stops startup, so the server
never serves requests unwarmed.

Model.load splits into open (the checkpoint mapped and read ahead) and bind
(kernels and buffers for a case), and release leaves the checkpoint open; a
failed bind frees every Metal object it made. The three tools load their
weights once and run a picture as functions (Encoder, Folder, Vae), so the
server and the one-shot tools share the same steps.

The image tools' modules read safetensors and checkpoint fixtures through
core, following main's core module split.

metal_targets.zig was 613 lines once the H3-Image tools were registered,
over the 600-line limit. FastH3's transformer and the H3-Image tools now
register from h3_metal.zig, leaving metal_targets.zig at 589.
One process for every picture warm: the request line, binding reuse and
retext, the weights held in one residency set, and the synthetic gates.
Follow main 4d244a0
(h3: use the current reader and share Metal tool registration).
Keep its shared clip/picture tool constructors and register the incoming
encoder, prompt, decoder and resident server beside them.
…ream-main

# Conflicts:
#	build.zig
#	docs/recipes/minimax-h3-image-metal.md
#	zig/build/h3_image_decoder.zig
#	zig/build/h3_image_prompt.zig
#	zig/build/h3_image_server.zig
#	zig/build/metal_targets.zig
#	zig/kernels/metal/h3/h3_prompt.metal
#	zig/kernels/metal/h3/image_decoder.metal
#	zig/kernels/metal/h3/image_decoder.zig
#	zig/src/families/h3/h3.zig
#	zig/src/families/h3/image.zig
#	zig/src/families/h3/image_decoder.zig
#	zig/src/families/h3/image_decoder_metal.zig
#	zig/src/families/h3/image_decoder_reference.zig
#	zig/src/families/h3/picture_prompt.zig
#	zig/src/families/h3/picture_prompt_test.zig
#	zig/src/families/h3/prompt.zig
#	zig/src/families/h3/prompt_reference.zig
#	zig/src/families/h3/prompt_weights.zig
#	zig/src/picture_writer.zig
#	zig/tests/h3_image.zig
#	zig/tests/h3_image_decoder.zig
#	zig/tests/h3_image_decoder_selftest.zig
#	zig/tests/h3_image_prompt.zig
#	zig/tests/h3_image_prompt_check.zig
#	zig/tests/h3_image_server.zig
…beside draft and routed steps

The ashhart#190 merge took the branch's tf-h3-image-server whole, dropping upstream's
keepalive ticker (weights re-wired after idle) and its refusal to start when the
weights cannot be held resident. Both return, with their tests, beside the
branch's --draft-steps, --routed-steps and profile options.
…n-190-follow-up-keep-u

Merge upstream main (ashhart#190 follow-up): keep upstream's H3 server idle ticker and fail-closed startup beside my draft/routed options
@plotarmordev
plotarmordev merged commit 7a9bcc5 into main Nov 22, 2026
@plotarmordev
plotarmordev deleted the feat/190-merge-upstream-main branch November 22, 2026 20:48
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.