Skip to content

Studio diffusion: Qwen-Image text-to-image activation seeds keep part of the int8 DiT resident under a VRAM budget - #15985

Merged
danielhanchen merged 2 commits into
mainfrom
studio-qwenimage2512-budget
Oct 29, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-qwenimage2512-budget

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

When Qwen-Image-2512 text-to-image runs under a VRAM budget, Studio streamed every offload group of the int8 DiT. Nothing stayed resident. At 16 GiB the Studio process used 5.4 GiB of the budget, and each denoising step re-uploaded the whole 31.7 GiB transformer.

The cause is that the qwen-image family had no entry in the shipped activation seed tables. With no seed and no learned peak, which is the case on a fresh home, _refine_plan_from_loaded_weights has no headroom figure. It returns the flat all-streamed plan. Qwen-Image-Edit had the same problem, and #15542 / #15645 fixed it for that family only.

Change

  • diffusion_memory.py:
    • _MEASURED_IMAGE_PEAK_MIB["qwen-image"] = 6032. This is the whole-render peak Studio itself recorded for Qwen-Image-2512 on sm_120 (1024x1024, 20 steps, true CFG 4, int8 DiT and int8 encoder). A returning home learns the same figure.
    • _MEASURED_STREAMED_IMAGE_PEAK_MIB["qwen-image"] = 3824. This is the Edit streamed figure. The model uses the same DiT class and the same VAE, and text-to-image has half the image tokens (no source latents), so this figure bounds the text-to-image peak.
  • Kill switch: UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_QWEN_IMAGE=0 drops both seeds for this family only and restores the previous all-streamed placement. UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_STREAMED=0 still drops only the streamed figure.
  • Scope:
    • Only torchao int8 / fp8 denoisers on the default and max tiers read these seeds.
    • Dense bf16 (the eager table), GGUF, packed and fp8-stored denoisers keep their current placement, as does the off tier.
    • A learned peak still raises the seed as before.
  • The seed changes which groups stay on the card, not the math.

Measurements

The base is origin/main 2a7e3a553e, which already includes #15930. Setup:

  • Qwen-Image-2512, Studio auto (int8 DiT, int8 encoder), 1024x1024, 20 steps, true CFG 4, empty negative.
  • One RTX PRO 6000 Blackwell (sm_120) VM. The budget is held by a VRAM ballast plus a capped device total.
  • Base and head arms are interleaved, each a fresh process with a fresh Studio home.
  • Each arm runs a warm-up, then reports the median s/image over 3 new prompts.
budget base (r1 / r2 / r3) head (r1 / r2 / r5) change head, kill switch
16 GiB 12.913 / 12.889 / 12.927 s 11.466 / 11.381 / 11.339 s -11.7% 12.984 s (same as base)
12 GiB 12.891 s 11.991 s -7.0%
  • A/A spread: base 0.3% (3 repeats), head 1.1% (3 repeats). Both deltas are far outside the spread.
  • Placement:
    • 16 GiB: 7101 MiB resident (14 of 61 offload groups), against 0 on base.
    • 12 GiB: 3319 MiB resident (7 of 61).
    • Log line: measured-activation placement group -> group (7343 MiB of the 32496 MiB transformer ... stay resident (measured peak 7168 MiB).
  • Torch profiler, one 16 GiB render:
    • host-to-device traffic during denoise falls from 666.4 GiB to 520.8 GiB (33.3 to 24.8 GiB per step);
    • copy time not hidden behind compute falls from 5.75 s to 4.18 s;
    • kernel busy time is unchanged (6.985 vs 6.972 s).
  • Peak VRAM of the Studio process at 16 GiB rises from 5.4 to 12.4 GiB, inside the budget. At 12 GiB it rises from 5.4 to 8.7 GiB.
  • No out-of-memory line in any log. At both budgets the VAE prebuild child is skipped, as on Qwen-Image-Edit, because the streamed placement still allocates 6229 MiB.
  • Both guidance branches still share each streamed block's upload. Every render on base and head logs diffusion.cfg_pair: 19 guided step(s) ran both branches through each streamed block. With UNSLOTH_DIFFUSION_CFG_PAIR=0 the times are 24.481 s on base and 19.702 s on head.
  • Output: every PNG is md5-identical across all 13 Studio arms on this VM: base, head, kill switch, pair off, 12 and 16 GiB, and profiler runs.
  • No regression where the DiT already fits: on an A100 40 GB with no budget, the DiT stays resident and the placement does not change. Base 12.114 / 12.122 s, head 12.138 / 12.113 s, kill switch 12.140 s. All PNGs are md5-identical.

Tests

  • New tests/test_diffusion_qwen_image_seed.py (CPU only, sizes taken from the 16 / 12 GiB load logs):
    • the seed values and their pixel scaling;
    • partial residency at 16 and 12 GiB, never above free memory, with the encode streaming the resident groups back out;
    • both kill switches;
    • the off / eager tiers and a dense bf16 denoiser keep the flat plan.
  • 56 placement, offload, CFG and Qwen suites: head 1525 passed, base 1516 passed. The same 6 tests fail on both, all pre-existing in test_diffusion_qwenimage21_vision.py and test_diffusion_qwenimage_rope.py.

Not covered

  • Measured on sm_120 (16 / 12 GiB budgets) and sm_80 (resident) only. No consumer 16 GB card was used, and the budget was simulated.
  • The streamed figure is borrowed from Qwen-Image-Edit, not measured for text-to-image. The peaks measured here stay inside the budget at 16 and 12 GiB.
  • Requests larger than 1024x1024 were not run. The request guard re-streams groups for them, as for the other seeded families.
  • Qwen-Image (the original release) shares the family but was not run.

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

chatgpt-codex-connector Bot commented Oct 29, 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-29T14:58:33.921407Z 6122e8d 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. Swish!

Reviewed commit: 6122e8dfab

ℹ️ 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 added a commit to unslothai/unsloth-zoo that referenced this pull request Oct 29, 2026
…hared between v1 and v0 (#2253)

## Summary


`tests/test_gc_collect_early_stop_loops.py::test_release_passes_go_through_the_helper[vllm_utils.py-expected0]`
fails on main since #2221, and with it the unsloth `Core zoo` jobs on
every unsloth PR that installs zoo main (staging runs for
unslothai/unsloth#15985 and #15934):

```
E   assert [2, 3, 3, 3, 3] == [2, 2, 3, 3, 3, 3]
E     Right contains one more item: 3
```

The test lists every `collect_garbage(...)` call in `vllm_utils.py` with
its pass count. #2221 replaced the separate v1 and v0 graph-capture
wrappers with one `wrap()` used for both, so the two `passes = 2` call
sites became one. The product change is intended (both versions still
run the 2-pass collect around capture, through the shared wrapper); the
census was stale.

## What changed

`vllm_utils.py` expects `[2, 3, 3, 3, 3]`, and the comment names the
shared wrapper.

## Verification

- Base (main at `4cdccb4a`): 1 failed, 15 passed. Bisected: #2221's
parent passes, #2221 fails.
- Head: 16 passed.
- With the capture call changed back to `passes = 3`, the test fails
again, so the census still pins the pass count.
@danielhanchen
danielhanchen merged commit 2aedb67 into main Oct 29, 2026
39 checks passed
@danielhanchen
danielhanchen deleted the studio-qwenimage2512-budget branch October 29, 2026 17:52
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