Skip to content

train 1120231322: #3438 #3718 (CI only) - #4268

Closed
ashhart wants to merge 27 commits into
mainfrom
lead/train-1120231322
Closed

ashhart wants to merge 27 commits into
mainfrom
lead/train-1120231322

Conversation

@ashhart

@ashhart ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

CI for a landing train: #3438 #3718 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.

jayleaton and others added 27 commits November 20, 2026 23:13
…usage

A request may name "deadline_s" (seconds, more than 0, at most 1000000), for
chat and legacy completions. At that time the server cancels the engine
itself, still commits the tokens the engine gives before its finished event,
and labels the reply finish_reason "deadline". The final response keeps
usage and token_ids/token_sha256. A token the engine gives after the
deadline cancel may be EOS, hit a stop string or reach max_tokens; the
reply still ends "deadline". A deadline that passes after the reply already
ended (a stop string's own cancel) is not counted. Without the field
nothing changes.

A cancel from POST /v1/requests/{id}/cancel that came first keeps the
reply "cancelled": the deadline then sends no second cancel and never
relabels it. docs/api.md lists the field.

test-request-deadline-host: through chat.run and through openai.run (chat
and completions, whole and streamed): a forced deadline ends the reply with
finish deadline, the late token, usage and ids; no field and a deadline the
reply never meets give the same reply, token sha and stream choices; 0, -1,
"300", true and 1e7 are refused before the engine. A cancel ask before the
deadline, with an engine that ends late, still ends "cancelled".
…adline passes while it drains

A slow client could still be writing out tokens the engine had already
finished with (stop or length) when deadline_s passed; the server then sent
a cancel to the finished request and labelled the whole reply "deadline".
Before marking a deadline, the read loop now checks the mailbox's finished
flag under the mailbox's own mutex: an engine that ended first keeps its
finish reason and gets no cancel.

test-request-deadline-host: the engine ends inside submit, before the
50 ms deadline, and the first stream write takes 100 ms: the reply ends
"stop" with abcde and no cancel is sent (chat.run); over HTTP, for chat and
completions, whole and streamed, a reply the engine ended before the
deadline and the server first reads after it keeps "stop".
…mage

A case without audio's input projection is read as a picture's: it may
carry no audio tensor and no audio rows, and the forward dispatches no
audio projection. A clip's case is read and run as before.
MiniMax-H3-Image's distilled checkpoint replaces the output layer with a
head per sampling step. A picture's case may hold them as video_out
[steps, width, hidden] and [steps, width]; step i reads head i, and a run
with another step count is refused. A clip's case keeps its one head.
…3-image)

picture.zig holds the picture's rules on the host: the canvas a size is
drawn on, the distilled schedule from pdd_config.json through float32
timesteps, plain Euler, each row's centred 3D position and the rotary
table from rope.inv_freq, the latent's 2 x 2 packing, the dense tile
map, and the model folder's checks. tf-h3-image builds the transformer's
case from a picture case and runs the six steps, each first on the
reference's own input and gated, then from the noise.
…in core/picture

picture_vae.zig: the released VAE config, the tile split (256 pixels,
overlaps of at least 64 spread 16 at a time), the float32 band blend and
placement, the latent statistics, ImageNet pixels with truncating bytes,
and the fp16-kept posterior sample. resample.zig gains Pillow's LANCZOS
filter, sinc(x) sinc(x / 3) within 3.
…, grids, encoder layers, clean and anchor rows
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.
The macOS dev-tools job failed to compile tf-h3-image-encoder: "file exists in modules 'picture_codec' and 'core'".
The tool's encoder imports core, whose root has imported picture/picture.zig since eb43e2b, and the tool also
built a picture_codec module rooted at that file. The tool now imports that same core and reads core.picture: the
picture half of #2779's "the edit encoder, its reference rules and its tool read safetensors and pictures through
core", which this stack's older copy of the encoder commit lacks.
@ashhart

ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner Author

Conflicts with main (main moved after stacking); restacking.

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

3 participants