Repository navigation
Conversation
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.
…at once and at a canvas's ratio
…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.
The native HIP server wraps the qwen3_5 dense target with the lane core's Drafted over the HIP DFlash2 drafter: taps are set from the drafter's config before streams are sized, the drafter's weights and per-stream state count in the memory plan, and window costs go to the drafter. - refuse --drafter under --tp > 1, at other --drafter-bits, and for HIP families without a DFlash2 drafter; benchmark --drafter on rocm - an absorb refuses kept rows past its features; features serve only rows the ring holds for the drafter's window - docs: the 27B recipe and community benchmarks A test pins that --no-drafts with --drafter loads no drafter and is not refused.
tf-qwen35-test check takes --drafter <dir>: the lanes session opens the HIP DFlash2 drafter as the native server does and wraps the target with Drafted, so drafted == serial, solo == together and graph == eager run for Qwen3.8-27B instead of skipping. The taps invariant restores the taps it found instead of switching them off. The lanes session likewise restores the taps it found when it ends or its drafter fails to open.
A stream resumed from a kept prompt state taps no rows below the resume point, so its ring holds zeros there while features() counted them as written. features() now refuses them with RowsNotHeld, as Nemotron and Gemma4 do. Drafted already absorbs from s.cached, so no served path asks for those rows.
…a fresh one The resumed invariant compares a resumed drafted run with a serial one. This adds the drafted run of the same prompts with every kept prompt evicted first: it must resume nothing and give the resumed run's tokens, and the check prints each run's drafts kept, drafted and rounds, so a resume's effect on acceptance is visible.
main now serves some BF16 qwen3_5 checkpoints (image towers the engine reads, and joint-head decisions), but the engine times no BF16 windows, so the DFlash2 drafter would run its rounds unpriced. A BF16 checkpoint with --drafter is refused by name before any load, as the drafter's stated limit says; quantized checkpoints and serves without --drafter are unchanged. A host test pins the refusal on a BF16 chat config and its absence on the same config quantized, or without --drafter.
… (six blank lines fewer) Main's 2027e7a ("flashnext hip: one refusal test for --drafter and --mtp-drafts, so hip.zig stays within 600 lines") left hip.zig at 599 lines, and the DFlash2 drafter's group check put it at 606. Six blank lines between adjacent tests at the end of the file go; no code changes.
…calls, after main's 1a10b0b Main's 1a10b0b ("hip flashnext: opt-in --mtp-drafts up to 7 on a lone stream (#3053)") gave checkGroup a comptime family parameter. The merged --drafter test's four calls pass qwen35.native, as main's own refusal tests do; at --tp 1 that family drafts at most 3, so the test's --mtp-drafts case keeps its message.
…n's 1a10b0b (one blank line fewer) Main's 1a10b0b ("hip flashnext: opt-in --mtp-drafts up to 7 on a lone stream (#3053)") added the mtp_drafts_hip_test.zig import, and with the DFlash2 drafter hip.zig came to 601 lines. The blank line between the group-flags test and the --drafter refusal test goes; no code changes.
A frame now runs min(block, deepest depth + 1) rows a stream, so a hold costs what the lane core's step_ms x drafts price assumes, and step_ms is measured as the marginal cost of a draft past a one-draft hold. The core's existing depth rule then drafts shallower in shared rounds. Tests pin that truncated frames keep acceptance within 0.05 of the full block at depths 1 and 3, that a frame refuses blocks outside 2 to the config's before it takes any scratch, and that the measured draft step falls back to the full block's cost a draft when noise makes it non-finite or below a 0.01 ms floor.
The recipe's plain and drafted decode figures on gfx1151 came from the proposal branch's base. They are now the medians of this branch's served runs on main f0a54bd (bench_concurrent, 256 tokens, 3 reps, two fresh servers an arm), with two streams added; four chat streams decode below plain, and the recipe says so.
7 of 8 tasks
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: #3718 #3918 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.