Repository navigation
Conversation
…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.
…load's io, and H3's Metal tools in h3_metal.zig Main moved H3's safetensors import into the core module (h3_core in metal_targets.zig, core in h3_host.zig). This series came from before that move: tf-h3-image imported safetensors and checkpoint_fixture modules of their own. It now imports core and reads both from it, since a file may sit in one module of a build only and core holds both. Main's h3.Model.load also takes the process's io now, so tf-h3-image passes init.io as tf-h3-dit does. Main's metal_targets.zig is at the 600-line cap, so tf-h3-image's target, and main's tf-h3-dit beside it, move to h3_metal.zig with the H3 modules they share (and the kernel sources they take); metal_targets.zig calls it in one line (589 lines). The steps and their modules are otherwise unchanged.
… that draw several tensors
…, grids, encoder layers, clean and anchor rows
…oder and its selftest
…rs and pictures through core, as main does On main, H3's geometry.zig reads safetensors as core.safetensors. The encoder's module pulls geometry.zig in through picture_reference.zig, so it now imports core instead of a safetensors module of its own, and image_encoder.zig, picture_reference.zig and its test read st from core.safetensors. The tool reads PNGs through core.picture, since core already holds picture.zig and a file may sit in one module of a build only.
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.
… its fixture through core, as main does prompt.zig pulls in tensors.zig, which on main reads core.safetensors, so the tool's prompt module imports core. A file may sit in one module of a build only, and core already holds picture.zig, qwen_vl/rope.zig and checkpoint_fixture.zig, so picture_prompt.zig, its test and the tool read them through core, and the build's own picture, rope and fixture modules go. test-h3-image-prompt's root imports core in their place.
…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.
… main does image_decoder.zig pulls in geometry.zig, which on main reads core.safetensors, and image_decoder_test.zig runs in test-h3-geometry, whose module imports core alone, so the decoder's files read st from core.safetensors. The tool also writes PNGs with MOSS-Image's writer, whose test reads core/picture/png.zig by path, and a file may sit in one module of a build only. So the tool's core is h3_decoder_core.zig, one module holding safetensors, core's pictures and that writer, in place of picture_writer.zig; it resamples through core.picture.
…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.
…at once and at a canvas's ratio
lfm3_qk_segments runs lfm3_qk's body for each row of a shared round, reading the row's stream, cache length, capacity, keys and values from the attention table that lfm3_attn_segments already uses. A shared round now dispatches qk once per attention layer instead of once per stream. lfm3_qk keeps its bindings and arithmetic through the shared inline row function, so every row computes the same bytes at the same address. The contract registers the kernel and a planted control (every row reads stream 0's entry), with a probe whose replaced path is lfm3_qk stream by stream; the qk reference takes each row's position. An engine test compares queries, keys and values byte for byte against the per-stream dispatches.
…alls other streams' rounds LFM3's Metal backend gains prefill_step and cancel_prefill (#3021). Each call runs one chunk at exactly the whole pass's cuts (the chunk cap, the next planned start, the next kept mark); LFM3 declares no chunk invariance, so max_rows is ignored and the cuts never move. The whole pass and the steps share one chunk body, so replies are unchanged. A cancel keeps the state at the last chunk's end; a stream that leaves mid-pass is forgotten; image rows are prepared once, at the first call. The whole pass still yields at chunk starts as before. Host tests on recording fakes: stepped chunks equal the whole loop's, a resumed pass cuts as main does, a cancel keeps the last chunk's end, and another stream decodes between two chunks. The new step joins the macOS host CI list, and check-metal-prefill-rest-host compiles the new bodies.
Owner
Author
|
Held: main is red. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CI for a landing train: #2781 #3079 #3088 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.