Skip to content

train 1121221029: #3718 (CI only) - #4445

Closed
ashhart wants to merge 13 commits into
mainfrom
lead/train-1121221029
Closed

ashhart wants to merge 13 commits into
mainfrom
lead/train-1121221029

Conversation

@ashhart

@ashhart ashhart commented Nov 21, 2026

Copy link
Copy Markdown
Owner

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

ashhart and others added 13 commits November 21, 2026 22:10
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.
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.

2 participants