Skip to content

Studio: split DiffusionGemma across GPUs when one GPU cannot hold it - #13291

Merged
danielhanchen merged 6 commits into
mainfrom
diffusiongemma-multi-gpu-split
Oct 12, 2026
Merged

danielhanchen merged 6 commits into
mainfrom
diffusiongemma-multi-gpu-split

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #6319. Addresses the inference half of #6347.

Problem

Studio serves DiffusionGemma GGUFs through a dedicated runner (the unsloth_zoo diffusion shim driving llama-diffusion-gemma-visual-server). Studio always handed that runner exactly one device token: the lowest picked GPU, or the first visible GPU when nothing was picked. A GGUF larger than that card therefore never loaded on a multi-GPU box. On 2x RTX 3090 (24 GB each), Q8_0 (26.9 GB) and BF16 (50.5 GB) put every layer on CUDA0 and stall at the graph reservation; on Windows the overflow spills into shared system memory and looks like a hang. Checking a second GPU in the picker did nothing, because the backend collapsed the pick to its lowest id.

Runner support

The visual server builds its model with llama_model_default_params(), so llama.cpp's default layer split already spans every device in its CUDA_VISIBLE_DEVICES, and the zoo engine sets that mask from the --gpu token. But with more than one GPU the server turns its single-device prompt-KV store off, and that path asked for logits on every [prompt|canvas] row while the server caps outputs at the canvas, so current builds abort on the first request (GGML_ASSERT(n_outputs_max <= cparams.n_outputs_max), reproduced on 2x T4 with the shipped prebuilt b11541-mix-2500203). The runner fix lands separately in the DiffusionGemma llama.cpp pin; fixed builds answer --capabilities with multi_gpu_split. Studio only splits when the installed visual server carries that marker, so with today's prebuilt nothing changes.

Change

  • _diffusion_fit_gpus decides the device set. It only acts with a visual server that supports the split, and only when the GGUF does not fit the single device the runner would use today (same _select_gpus budget as llama-server). The pool is the explicit pick, else every visible GPU; the smallest fitting subset is used, and a pool that cannot hold it either still gets all of it rather than one card. An unpinned fit happens only with no inherited CUDA_VISIBLE_DEVICES and ids from nvidia-smi / NVML, the same gate as the llama-server auto fit.
  • Unchanged: a GGUF that fits one card, a single explicit GPU, a manual GPU-layer split (--ngl), DG_GPU, non-numeric tokens (UUID / MIG), CPU-only, and Vulkan builds.
  • The launch records the devices it used (gpu_ids, requested_gpu_ids), CUDA_DEVICE_ORDER=PCI_BUS_ID is set for the split as it already is for a pick, and matches_gpu_ids / the frontend resident match accept either the lowest id or the split set so an identical Apply does not reload.
  • The chat-load-during-training guard calls the same fit decision and budgets the GPUs it returns, so it sizes the devices the runner will actually use; a manual split keeps the single-device budget.

Interaction with the Auto layer fit (#13312)

Main now gives a GGUF too big for one GPU a GPU / CPU layer split in Auto mode. After merging main, the two fits compose like this:

  • The single-device layer fit runs first. When it says the device is too small, the multi-GPU fit trusts that verdict (its stricter context reserve included) instead of re-checking with the weights-only budget, so a GGUF that only fits one card once the context reserve is ignored still spreads over a second card rather than putting layers on the CPU.
  • A GPU subset that holds the GGUF wins: no --ngl, the runner keeps its own context auto-size.
  • When no subset holds it (BF16 on 2x 24 GB), the multi-GPU fit returns nothing and the single-device GPU / CPU fit applies as on main, instead of handing every GPU a load that cannot fit them.

End to end (real runner, two physical B200s, memory reading spoofed to two 12 GB cards)

LlamaCppBackend.load_model with gpu_ids=(0, 5), tensor_parallel=True, DiffusionGemma Q4_K_M (16.8 GB), the visual server built from the pinned DiffusionGemma commit (c9b81be, answers multi_gpu_split), then one chat request:

main (2762603) this PR
runner --gpu 0 0,5
layers on GPU offloaded 15/31 layers to GPU offloaded 31/31 layers to GPU
model buffers CUDA0 7836 MiB, CPU_Mapped 8765 MiB CUDA0 7146 MiB, CUDA1 8867 MiB, CPU_Mapped 578 MiB
runner memory per GPU GPU 0 10546 MiB, GPU 5 nothing GPU 0 11548 MiB, GPU 5 10530 MiB
reply to "What is 2+2?" 4 in 14.2 s 4 in 2.4 s

Studio end to end (two isolated Studio installs)

Merge base 2762603 and this PR (fd38991) each installed with install.sh --local into their own home, the same split-capable visual server, both picked GPUs reported as 12 GiB cards to the fit, DiffusionGemma Q4_K_M loaded with GPUs [0, 2] picked, then "What is 2+2?" sent from the chat:

merge base this PR
/api/inference/status gpu_ids [0] [0, 2]
runner --gpu 0, offloaded 15/31 layers to GPU, CPU_Mapped 8765 MiB, plus "does not fit GPU 0 ... rest on CPU" --gpu 0,2, every layer on the two GPUs (10.3 GB / 11.3 GB held)
chat reply 4 after 41.7 s 4 after 10.4 s

No screenshot pair: the run-settings GPU list shows both GPUs switched on in both builds after this load, so it does not tell the two apart; the difference is in where the model runs.

Tests

  • New: fit decisions (fits one card, Q8_0 and BF16 on 2x24 GB, explicit pool bounds, single pick never widened, Vulkan, UUID / DG_GPU overrides, move to one card that fits), the real _start_diffusion_server argv / env / recorded ids for split, auto split, fits-one-card and manual split, the dedup round trip, the guard pool budget, and the frontend resident match.
  • test_differential.py vs merge base: 5 FIXED (3 new behavioural, 2 updated source asserts), 9 NEW_API, 23 UNCHANGED, 0 head failures.
  • Every backend suite touching diffusion GPU selection or the training guard (38 files): identical failure sets on base and head (91 pre-existing cross-file failures on both), head +15 passing.

@danielhanchen danielhanchen self-assigned this Oct 11, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-10-12T12:38:18.368434Z fd38991 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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 11, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 63507baaf4

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 783a190789

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

# Conflicts:
#	studio/backend/core/inference/llama_cpp.py
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9992b16ea

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

Comment on lines 19692 to +19695
if manual_ngl is None:
fit_ngl = self._diffusion_fit_ngl(model_path, gpu, maxtok, pinned = bool(gpu_ids))
try:
fit_gpus = self._diffusion_fit_gpus(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Respect the inherited NGL placement override

When an operator sets the runner's NGL environment override, _diffusion_fit_ngl intentionally returns None to leave that manual split in charge, but execution still reaches this multi-GPU fit. If the GGUF exceeds one card, the child is now widened over several GPUs while retaining the inherited layer count, whereas first-class manual --ngl requests are explicitly kept on one device. Skip _diffusion_fit_gpus when NGL is present so the environment form preserves the same single-device semantics and does not unexpectedly consume additional GPUs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NGL sets how many layers go to the GPU, not which GPUs: those layers spread over the picked GPUs by llama.cpp's default split, which loads and serves correctly. Using GPUs the user picked is not a correctness bug, so leaving this as is.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 12, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd38991335

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

Comment on lines +19561 to +19565
need = model_size_bytes + overhead
if cls._select_gpus(need, first, total_by_idx = total_by_idx)[0]:
return None
picked, _ = cls._select_gpus(
need, gpus, total_by_idx = total_by_idx, per_device_overhead_bytes = overhead

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the context reserve in the multi-GPU fit

When a GGUF fits by weight but not after _diffusion_auto_ngl's attention/context reserve (for example, roughly 19–21 GiB on the tested 24 GiB cards), this check declares the first GPU sufficient because it budgets only the file plus 512 MiB. _start_diffusion_server consequently retains fit_ngl and offloads layers to CPU even though another selected GPU is available; near the aggregate limit, the same under-budgeting can clear fit_ngl for a multi-GPU load without reserving enough memory for its context. Pass through the layer fit's single-device verdict and include its context reserve when selecting the multi-GPU subset.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The layer fit's one-card verdict has no context reserve in it: _diffusion_auto_ngl returns None as soon as file_mib <= usable - 512 MiB, and the attention reserve only sizes the layer count after that test fails. This check is that same test, and test_diffusion_fit_gpus_agrees_with_the_layer_fit_on_one_card sweeps 18 to 26 GiB on 24 GiB cards and asserts the two agree at every 0.1 GiB step, so a 19 to 21 GiB GGUF never gets CPU layers here.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: fd38991335

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

Copy link
Copy Markdown
Member Author

pre-commit.ci run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Studio] DiffusionGemma GGUF does not appear to use Tensor Parallelism on dual GPUs

1 participant