Skip to content

Studio diffusion: shipped activation seed for Qwen-Image-Edit placement - #15542

Merged
danielhanchen merged 2 commits into
mainfrom
studio-vsc3-img-qedit-seed
Oct 27, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-vsc3-img-qedit-seed

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

On a fresh Studio home, Qwen-Image-Edit-2511 under a VRAM budget streamed every int8 DiT offload group, because qwen-image-edit had no entry in the shipped activation seed table. With no learned peak and no seed, the placement has no headroom figure and keeps nothing resident:

diffusion.memory: QwenImageTransformer2DModel streams 60 offload groups with event-fenced prefetch (2 ahead, 1620 MiB window)

Changes

  • diffusion_memory.py: _MEASURED_IMAGE_PEAK_MIB["qwen-image-edit"] = 6046. This is the whole-render peak Studio itself records for this model (1024x1024 output, one 1024x1024 source, 40 steps, true CFG 3, untiled decode, step CUDA graphs), the same figure a returning home learns. With the usual 1.15 margin and 256 MiB rounding it places from 7168 MiB.
  • Kill switch: UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_QWEN_EDIT=0 drops the seed for this family only (back to learned-peak-only placement). A learned peak still overrides the seed as before.

Results

Qwen-Image-Edit-2511, Studio auto (int8 DiT, int8 encoder), 1024x1024, one source image, 40 steps, true CFG 3. RTX PRO 6000 Blackwell, one VM, the budget held by a VRAM ballast, a fresh Studio home per arm, a warm-up plus 3 new instructions per process.

budget main r1 / r2 this PR r1 / r2 change
16 GiB 49.224 / 49.215 s 45.403 / 45.255 s -7.9%
12 GiB 49.235 / 49.438 s 48.303 / 48.379 s -2.0%
  • A/A spread: main 0.02% (16 GiB) and 0.4% (12 GiB); this PR 0.3% and 0.2%.
  • 16 GiB: 4826 MiB of the 32496 MiB transformer ... stay resident (measured peak 7168 MiB); peak VRAM 9.5 GiB, inside the budget.
  • 12 GiB: 1080 MiB stays resident (9 of 61 groups); peak 5.7 GiB.
  • Resident (no budget) placement does not change: the seed only sizes the partial-residency headroom.
  • The seed changes which groups stream, not the math: every render hashes identical to main's at the same budget.

Tests

  • tests/test_diffusion_measured_placement.py:
    • the seed value (7168 MiB after margin);
    • a fresh home with the Qwen-Image-Edit loaded sizes keeps part of the DiT resident at 16 and 12 GiB budgets;
    • the kill switch.
  • Main: the new tests fail (seed missing, nothing resident). This branch: 427 passed (main: 423 passed, the 4 new ones failing).

Limits

  • The seed was measured at 1024x1024 with one source image. Larger outputs or more source images peak higher; the learned peak replaces the seed after the first render, as for the other seeded families.
  • Measured on sm_120 only.

A fresh Studio home had no learned peak for qwen-image-edit, so under a VRAM budget the int8 DiT
streamed every offload group. Seed the whole-render peak measured on the edit path (6046 MiB) so
the first load keeps part of the denoiser resident. Kill switch
UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_QWEN_EDIT=0.
@danielhanchen danielhanchen self-assigned this Oct 27, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T11:51:38.835659Z 3c20c4a 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: 3c20c4afbe

ℹ️ 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 cbe4498 into main Oct 27, 2026
@danielhanchen
danielhanchen deleted the studio-vsc3-img-qedit-seed branch October 27, 2026 12:58
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 29, 2026
… of the int8 DiT resident under a VRAM budget (unslothai#15985)

## 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 unslothai#15542 / unslothai#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 unslothai#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.
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