Skip to content

Studio diffusion: CFG-parallel for a group-offloaded denoiser - #16681

Merged
danielhanchen merged 13 commits into
mainfrom
mg3-cfg-parallel-streamed-primary
Nov 5, 2026
Merged

danielhanchen merged 13 commits into
mainfrom
mg3-cfg-parallel-streamed-primary

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

A group-offloaded DiT whose first group sits in host memory was refused for CFG-parallel (denoiser is not on a CUDA card): the check read the device of the first weight.

Change

  • The execution device falls back to the offload groups' onload card, and a bare cuda is resolved to the current card.

Evidence

  • Wan2.2-TI2V-5B, CFG 5, Kaggle 2x T4: one card 211.10 s per clip, Automatic 144.49 s (1.46x), LPIPS 0.0025 against one card; the kill switch is bitwise.

Stack

This is one of four stacked PRs that make every decision to use a second GPU automatic, merged in order:

  1. U-Net CFG-parallel (SDXL)
  2. Automatic arms CFG-parallel on an idle card of the same model
  3. CFG-parallel for a group-offloaded denoiser
  4. Automatic partner card, FLUX batch split, LoRA scale mirror, CFG batching fallback

Results for the whole stack, Kaggle 2x T4, same VM per row, base A/A first:

model one card s Automatic s speedup output vs one card
SDXL 1024, CFG 7 23.13 13.18 1.75x LPIPS 0.003, >= 39.97 dB (kill switch bitwise)
SDXL, compiled 20.12-20.16 11.06-11.29 1.79x LPIPS 0.0040 (one-card A/A 0.0043)
SDXL, batch 2 55.83 27.97 2.00x LPIPS 0.0042
Qwen-Image-2.1, CFG 4 256-280 164-165 1.63x bitwise
Wan2.2-TI2V-5B, CFG 5, per clip 211.10 144.49 1.46x LPIPS 0.0025 (kill switch bitwise)
FLUX.2-klein-4B, batch 2 22.61 12.74-13.40 1.69-1.77x LPIPS 0.0007
  • 0 graph breaks and 0 recompiles or CUDA-graph captures on every follow-up render. The first compiled image is 25-30 s slower on two cards, paid once per load while the second card compiles its copy.
  • AMD gfx1151 (Linux, one real GPU plus a faked second device) and Windows 11 CPU: no regressions (same failures on base and head). No change touches a Triton / CUDA kernel.
  • Not covered: no run on more than 2 cards (the 3-8 card rule is unit-tested only); NVLink pairs; a Windows GPU run.

A U-Net pipeline sends both guidance branches through one call at batch 2B, so
CFG-parallel declined it ('no DiT denoiser') and the second card stayed idle.
UnetCfgParallelRouter cuts that call in half along the batch, runs the second
half on the replica card through run_pair, and concatenates. Odd batches,
unknown tensor inputs and replica failures stay on the source card.
UNSLOTH_DIFFUSION_CFG_PARALLEL_UNET=0 turns it off.
The primary half goes through _primary_noting (waits on a cold replica, marks its
signature warm); a module compiled whole after the router was installed, or a call
under torch.compile, runs whole on the source; PAG-style processors that chunk the
batch themselves keep the U-Net off the router.
…same model

With no gpu_ids (the UI's Automatic) CFG-parallel always declined, so a guided
render on a two-card box left the second card idle unless the user picked both
cards. Automatic now arms it when a secondary is the same card model and idle at
load (at most 1 GiB in use); a busy or different card is never borrowed.
UNSLOTH_DIFFUSION_CFG_PARALLEL_AUTO=0 restores the old behaviour.
Record compile arguments under Automatic too (a compiled denoiser's replica needs
them), and re-check at replica build time that the card Automatic borrowed is
still idle.
…eights sit in host memory

cfg_parallel_decline read the denoiser's first parameter device, so a group-offloaded
DiT whose first group lives in host memory between calls (Wan2.2-TI2V-5B on a 15 GiB
card) was refused as 'not on a CUDA card' while one whose first group stayed resident
(Qwen-Image-2.1) armed. The execution device now falls back to the offload groups'
onload card: the primary branch keeps streaming, the replica runs resident on the
second card.
An automatic load on the current card onloads its offload groups to bare 'cuda'
(no index), so the CFG-parallel replica search found no card model to compare
and declined every secondary as 'a different model'.
@danielhanchen danielhanchen self-assigned this Nov 4, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-04T16:40:59.647715Z c0f4c31 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. Nice work!

Reviewed commit: c0f4c31717

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

Base automatically changed from mg3-auto-cfg-parallel to main November 5, 2026 03:26
@danielhanchen
danielhanchen merged commit 4ddd527 into main Nov 5, 2026
@danielhanchen
danielhanchen deleted the mg3-cfg-parallel-streamed-primary branch November 5, 2026 03:27
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