Repository navigation
Studio: Qwen-Image-Edit streamed-tier activation seed keeps more of the DiT resident on tight cards - #15645
Merged
Conversation
Place the streamed group-offload tier of Qwen-Image-Edit-2511 from a streamed-tier measured peak (3824 MiB, 4608 reserved) that excludes the prefetch window, instead of the resident seed that already pads for it. At a 12 / 16 GiB budget this keeps 7 / 14 of 61 transformer groups resident (was 2 / 9). The prompt encode on that path streams every resident group back out, so the wider residency never stacks on top of the encoder. The VAE kernel prebuild child is priced against the streamed runtime the first render still allocates, and is skipped when it would not fit. UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_STREAMED=0 restores the previous placement.
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. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 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
Qwen-Image-Edit-2511 on a tight VRAM budget runs the streamed group-offload tier. Before this change, that tier was placed from the whole-render measured peak (6046 MiB, 7168 MiB reserved), and that peak already pads for the block prefetch window. The streamed room then subtracts the window a second time, so too few transformer groups stayed resident.
This PR adds a streamed-tier seed,
_MEASURED_STREAMED_IMAGE_PEAK_MIB["qwen-image-edit"] = 3824(4608 MiB reserved). It was measured with every DiT group streamed, with the window excluded, and it is read only where the window is subtracted on its own. The request guard prices requests on the same scale, through a 13th entry in the reserve tuple.Two follow-ups make the wider residency safe:
encode_resident_transformer_mib = 0, the state the 12 GiB plan already uses). The flat encode room no longer stacks on top of the wider residency. Without this, a 16 GiB load overran during the warm-up encode: the allocator hit OOM, then retried.torch.OutOfMemoryErrorat 16 GiB.The kill switch is
UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_STREAMED=0. It restores the previous placement, the encode room and the prebuild gate.UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_QWEN_EDIT=0still drops the measured seed entirely.Results
RTX PRO 6000, budget capped at 12 / 16 GiB. Base is the merge base (71dd6d2). Arms alternate in ABBA order, 3 repeats per arm, a fresh Studio home per cell, and 3 timed renders after a warm-up. Times are the median s/image over 3 new prompts.
OutOfMemoryErrorlines in any process. The prebuild child exited 0 in every base arm and was skipped in every head arm.Tests
studio/backend/tests/test_diffusion_qwen_edit_streamed_seed.py(CPU only, sizes taken from the 12 / 16 GiB load logs):test_diffusion_vae_prebuild.pystill passes.