Skip to content

Studio multi-GPU: split an even Lumina 2 batch across two cards (1.7-2.1x, fp-order only) - #16786

Merged
danielhanchen merged 2 commits into
mainfrom
studio-dit-batch-split
Nov 5, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-dit-batch-split

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

With two cards selected, an even batch rendered without guidance branches (a distilled model, or guidance 1) runs half the batch on each card at the same time (#16682, #16687). That batch split only covered FLUX.1 and FLUX.2, because the gate checks argument shapes: every per-sample input has to be a dim-0 tensor.

This adds Lumina2Transformer2DModel with its exact keyword set: hidden_states, timestep, encoder_hidden_states, encoder_attention_mask, return_dict. Any other input, including non-empty attention_kwargs, keeps the call whole on the source card, as before. The kill switch is unchanged: UNSLOTH_DIFFUSION_BATCH_SPLIT=0.

Lumina 2 pads each sample's caption to the batch's longest caption under its own mask. A half pads to its own longest caption, and the extra positions are masked out of every attention. The math is the same, and only floating-point order changes.

Audit of the other DiT classes

class per-sample inputs verdict
Lumina2Transformer2DModel all dim-0 tensors (latents, timestep, caption states, caption mask) added
QwenImageTransformer2DModel dim-0 tensors plus img_shapes, a Python list with one entry per prompt. With zero_cond_t (Edit 2511) it builds a per-sample index from that list, so a half would need the list cut too not added: needs list-aware splitting, and a 20B replica cannot be timed on any pair available here
HiDreamImageTransformer2DModel encoder_hidden_states_llama3 carries the batch on dim 1 (layers first) unsafe for a dim-0 split, not added
ZImageTransformer2DModel per-sample lists already has its own split (diffusion_zimage_cfg_split)
SD3Transformer2DModel, ChromaTransformer2DModel all dim-0 tensors, ids unbatched like FLUX split-safe on tiny models (below), but neither is a Studio family, so not added

Evidence

Tiny random diffusers models, Studio's real CfgParallelRouter across two cards (Kaggle 2x T4, cuda:0 + cuda:1). Each model runs a 4-step loop, compared with the same model called whole on cuda:0. Every case engaged: 3 of 4 steps split, and step 1 learns there is one call per step.

class fp32 batch 2 fp32 batch 4 fp16 batch 2 fp16 batch 4
Lumina2 (per-sample caption lengths differ) max abs 2.4e-7 bitwise bitwise bitwise
QwenImage (audit only) 2.4e-7 bitwise 2.0e-3 bitwise
SD3 (audit only) 2.4e-7 bitwise 9.8e-4 2.4e-4
Chroma (audit only) 2.4e-7 bitwise bitwise 4.9e-4

Real render, Alpha-VLLM/Lumina-Image-2.0, Kaggle T4x2 (both T4s in one kernel). Studio was installed with its own install.sh (torch 2.13.0+cu130, diffusers 0.42.1). Settings: cards 0,1 selected, 768x768, 12 steps, guidance 1.0, batch 2, three prompts per arm. Studio picked fp32 on T4, plan group. Every arm is a fresh process on the same head tree. Base is UNSLOTH_DIFFUSION_BATCH_SPLIT=0, which is the code path main takes for this class. Values are scheduler-step medians in s/step.

kernel arm prompt 1 prompt 2 prompt 3
1 split off r1 / r2 / r3 7.854 / 8.001 / 7.973 7.941 / 7.980 / 8.015 8.532 / 8.531 / 8.532
1 split on r1 / r2 / r3 4.614 / 4.630 / 4.660 4.408 / 4.405 / 4.427 4.051 / 4.056 / 4.083
2 split off r1 / r2 n/a 8.463 / 8.488 9.116 / 9.179
2 split on r1 / r2 5.078 / 5.092 4.820 / 4.937 4.321 / 4.334
3 split off 6.885 6.887 7.412
3 split on 3.970 3.968 3.768

(The kernel 2 notebook log lost the first prompt's line for the off arms.)

  • A/A spread inside a kernel: off 1.9% at most, on 2.4% at most. Speed-up per prompt is 1.72x to 2.11x on every kernel, far outside that spread.
  • Engagement: the second card holds the replica (peak 10.4 GiB on cuda:1 with the split on, 0 with it off). A guidance-1 render shows no guidance branches, and only the batch split builds that replica.
  • Output: each arm is deterministic (the same image hashes on every repeat and kernel). Split on against off, all six images: not bit-identical, max difference 1 (of 255) per channel, at most 0.01% of pixels differ, PSNR 91.5 to 96.8 dB. That is floating-point order, from batch-1 against batch-2 kernels.

Tests (tests/test_diffusion_auto_multigpu_policy.py + tests/test_video_stream_residency.py, CPU):

tree result failing IDs
base (main + this test file) 2 failed test_lumina2_batch_splits_with_per_sample_masks_and_matches_one_card, test_lumina2_attention_kwargs_and_kill_switch_stay_whole
head all passed (6 CUDA-only skips) none

Not covered

  • Lumina 2 with guidance runs two calls per step. CFG-parallel already pairs those, and that path is unchanged. Only guidance-1 or truncated-guidance steps take the new split.
  • Only T4 (fp32) was timed. bf16 cards and the reference runtime were not run.
  • Automatic placement: a class in this table also counts as able to serve every request type in the automatic layer-split vs streamed choice (_hidden_stream_reason). For Lumina 2 that choice was not measured, because on T4x2 the layer split declined on its own (it did not fit).

The batch split (an even batch without guidance branches runs half on each
card) was limited to FLUX.1 and FLUX.2. Lumina 2's denoiser takes only
dim-0 per-sample inputs (latents, timestep, caption states and caption
mask), so it is added with that exact keyword set; attention kwargs or any
other input keep the call whole on the source card.

A half pads its captions to its own longest one under the same mask, so
the masked positions drop out of attention and the result differs from the
whole-batch call only in floating-point order.

Kill switch unchanged: UNSLOTH_DIFFUSION_BATCH_SPLIT=0.
@danielhanchen danielhanchen self-assigned this Nov 5, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T13:00:51.385802Z 6681170 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 6681170032

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit 1e50add into main Nov 5, 2026
@danielhanchen
danielhanchen deleted the studio-dit-batch-split branch November 5, 2026 17:38
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.

1 participant