Repository navigation
Studio images: MiniMax-H3-Image sequential lockstep batching, opt-in batched forward - #19880
Merged
Merged
Conversation
H3-Image never ran a batched forward: lockstep ran each image as its own batch-1 call through every block, sharing only the streamed upload. With UNSLOTH_H3_IMAGE_BATCHED=1, rows that share a packed layout (canvas, text token count and tags, reference grids, steps) run every block as ONE call over all rows; other layouts still share the forward as separate block calls. Each row keeps its own noise, reference noise, refined text and scheduler, and per-row references come in through row_images. The fp32 patch projection and the output head run per row, so a batched row is bit-identical to its solo render. The row-mod kernel runs over the flattened rows with the index repeated per image; batch 1 calls the original forward. A block call takes at most UNSLOTH_H3_IMAGE_BATCH_TOKENS (4608) packed rows. It is off by default: a batch of 4 is 1.11x the incumbent at 1024 on an RTX PRO 6000 (resident and streamed) but 1.00x on an A100-80 at 1024 and 0.88x at 2048, so the family keeps lockstep until a measured race picks it. row_layout_key is the coalescer's match key. On the sequential tier (one big component on the card at a time) every image of a request brought the DiT onto the card and back on its own. The images now denoise together there: the DiT comes in once for the group and each image runs each block as its own batch-1 call (lockstep), so its pixels are its own render's; the group's room is priced with the DiT's size deducted while it waits on the host. RTX PRO 6000 forced sequential, batch of 4: 11.35 s against 29.48 s, every image bit-identical to its own render. UNSLOTH_H3_IMAGE_LOCKSTEP=0 keeps one render after another.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Summary
MiniMax-H3-Image has never run a batched forward. Its lockstep mode runs each image as its own batch-1 call through every block, and only the streamed weight upload is shared. This PR adds a real batched forward behind
UNSLOTH_H3_IMAGE_BATCHED=1. It is off by default, because it wins only on some device and size combinations.row_images.UNSLOTH_H3_IMAGE_BATCH_TOKENS(4608) packed rows. At 2048 px one image already fills that budget, so each image runs in its own call there.It also lets the sequential tier denoise a request's images together. On that tier (one big component on the card at a time), every image used to bring the DiT onto the card and back on its own. Now the DiT comes in once for the group, and each image runs each block as its own batch-1 call (lockstep), so its pixels are those of its own render. This is on by default.
UNSLOTH_H3_IMAGE_LOCKSTEP=0keeps one render after another.row_layout_key(pipe, prompt, ...)indiffusion_minimax_h3_image_batch.pyis the match key for a cross-request batcher. It uses only the tokenizer.Based on main; it needs nothing from the image batching infrastructure (#19837). The sequential lockstep is on by default; the batched forward stays behind its env flag.
Results
int8, Colab RTX PRO 6000 (G4) for the final build, and A100-80 for an earlier build. Bit-identical means equal latent and PNG hashes.
Batch of 4, median of 3 runs (spread under 0.5%):
Sequential tier, forced with
UNSLOTH_H3_IMAGE_PLACEMENT=sequentialon an RTX PRO 6000 (Auto: int8, model offload), 1024 px, 6 steps:Changes
diffusion_minimax_h3_image_batch.py(new):row_layout_key.diffusion_minimax_h3_image.py: therow_imagesargument, batching on resident DiTs, the per-row head, and lockstep on the sequential tier (_sequential_refusal, with the room priced without the waiting DiT).diffusion_minimax_h3_image_speed.py: installs the row-mod wrapper.Tests
tests/test_h3_image_batched_forward.py(new, 13 tests): neighbour invariance, per-row references, call counts and the row-mod wrapper. All 13 fail on base; there, a batch of 4 makes 48 calls of 1 row instead of 12 of 4.tests/test_diffusion_h3_image_lockstep.pyis pinned to the lockstep path. It adds a sequential-tier test: the DiT enters once for 3 images, not 3 times, and the latents are bit-identical to separate renders.tests/test_diffusion_minimax_h3_image_parity.pyalso reads batched rows.Not covered