Repository navigation
Studio diffusion: shipped activation seed for Qwen-Image-Edit placement - #15542
Merged
Merged
Conversation
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.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On a fresh Studio home, Qwen-Image-Edit-2511 under a VRAM budget streamed every int8 DiT offload group, because
qwen-image-edithad 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: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.UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_QWEN_EDIT=0drops 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.
4826 MiB of the 32496 MiB transformer ... stay resident (measured peak 7168 MiB); peak VRAM 9.5 GiB, inside the budget.Tests
tests/test_diffusion_measured_placement.py:Limits