Skip to content

Unsloth Studio: give the memory planner the companion split on a pipeline image load - #11548

Merged
danielhanchen merged 3 commits into
unslothai:mainfrom
LeoBorcherding:fix-diffusion-pipeline-companion-split
Sep 22, 2026
Merged

danielhanchen merged 3 commits into
unslothai:mainfrom
LeoBorcherding:fix-diffusion-pipeline-companion-split

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Collaborator

Fixes #11547.

A pipeline image load hands plan_diffusion_memory None for companion_dense_mib and text_encoder_dense_mib (diffusion.py:6289 on main). _sum_required propagates that None into group_floor and group_floor_streamed_te, and both group-tier checks are ... is not None and ..., so group offload is unreachable on a pipeline load regardless of the card. Every such load that does not fit resident goes straight to whole-module offload, which pages every component per step and switches VAE tiling on with it.

On a 40 GB A100 loading Qwen/Qwen-Image-2.1 the group floor is 28,264 MiB against roughly 36,400 MiB of budget. It fits, on the faster tier, and the planner never looks.

Change

The pipeline branch derives the split from _companion_cache_bytes / _text_encoder_cache_bytes, the same walk the GGUF and single-file branch already uses. That keeps the companion terms on the same trees as model_dense_mib, which this branch also reads from the cache, instead of introducing a second source of truth.

Two edge cases:

  • A narrow base (ideogram-4 ships raw fp8) already has model_dense_mib raised to the bf16 table total. The companions upcast with it, so their share comes from that same table rather than leaving an on-disk figure next to a bf16 total.
  • The companion and model terms come from different merges over the cache roots, so a repo only one of them can see would otherwise report companions larger than the model. Clamped.

The final reason string is split so an unknown companion size says so, instead of claiming the companions exceeded the budget: that sends anyone reading the log looking for a card that is too small. plan.estimates is added to the diffusion.loaded line, since today it reports the verdict with none of the numbers behind it.

Verification: draft, nothing here is a hardware result yet

This is up as a draft specifically so it can be tested on the Colab A100 where the report came from. No row below is a claim about a real load.

what result
tests/test_diffusion_memory.py 98 passed, 1 skipped, at 4123f33eba
tests/test_diffusion_backend.py 13 failed, 486 passed, 2 skipped, not yet attributed against stock main
Qwen-Image-2.1 on a 40 GB A100, before/after not run
ideogram-4 narrow-base path not run, and there is no card here that could

The 13 backend failures are the open question. They may well be pre-existing, several are in download-plan and staging tests that look unrelated to the planner, but I have not run the same file on 070f292617 without this patch to prove it, so treat the number as unattributed rather than unrelated.

The machine this was written on has an AMD card, so there is no A100 here for a before/after. What exists is the log line from the reporting session showing offload=model tiling=True with reasons=companions exceed budget, plus the arithmetic in #11547 from the checked-in family table.

What settles it: load Qwen/Qwen-Image-2.1 in the Images page before and after this branch on a 40 GB card and compare diffusion.loaded. Before says offload=model tiling=True, after should say offload=group tiling=False, and generation should be faster. Tests to follow once that run exists.

…ge load

A pipeline load handed plan_diffusion_memory None for companion_dense_mib
and text_encoder_dense_mib. _sum_required propagates that None into
group_floor and group_floor_streamed_te, and both group-tier checks are
'... is not None and ...', so group offload was unreachable on a pipeline
load regardless of the card. Every such load that did not fit resident went
straight to whole-module offload, which pages every component per step and
switches VAE tiling on.

Derive the split from the same cache walk the GGUF/single-file branch
already uses, so it comes from the same trees as model_dense_mib. A narrow
base takes its companion share from the bf16 table that already raised
model_dense_mib, and the companion term is clamped to the model total.

Also split the final reason string so an unknown companion size says so
instead of claiming the companions exceeded the budget, and log
plan.estimates with diffusion.loaded so the verdict can be checked.

Refs unslothai#11547
@LeoBorcherding LeoBorcherding changed the title Studio: give the memory planner the companion split on a pipeline image load Unsloth Studio: give the memory planner the companion split on a pipeline image load Sep 22, 2026
@danielhanchen danielhanchen self-assigned this Sep 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Verified this, attributed the test numbers you flagged, and pushed three commits to the branch.

The planner bug is real, and reproduces exactly

Differential at the planner, Qwen-Image-2.1 numbers, a simulated idle A100-SXM4-40GB (budget 36,104 MiB after the reserve). The only thing that varies is the companion split:

split handed to the planner offload vae_tiling reason
None, what main passes model True companions exceed budget
companions 18,024 / TE 16,689 group False tight fit; stream the transformer, companions resident

Then the same thing end to end against a real 31 GB Qwen-Image-2.1 snapshot on disk, through _plan_memory itself rather than a table:

arm model_dense companion_dense text_encoder_dense offload tiling
main 31,596 None None model True
this branch 31,596 18,024 16,689 group False

The base arm reproduces the offload=model tiling=True reasons=companions exceed budget line from the report, and the derived companion figures land on the family table (18.9 GB and 17.5 GB), so the walk is reading the real layout correctly rather than coincidentally clearing a threshold.

The 13 backend failures: not pre-existing, and not 13

They do not reproduce here. Same file, same commit, base against head:

  • base 070f292617: 1 failed, 500 passed
  • head 4123f33eba: 2 failed, 499 passed

The single pre-existing one is test_every_third_party_bf16_pipeline_the_catalog_offers_is_mirrored, red on both and unrelated.

The extra one is caused by this branch: test_plan_memory_sizes_a_pipeline_load_from_the_other_root_snapshot. It is not a bug in the change. That assertion documents the pre-split behaviour, and the split is exactly what the PR adds, so the 2,348 MiB group floor is now sized and fits where before it failed the is not None check. Group is the better answer there for the same reason it is on the A100. I updated the assertion to OFFLOAD_GROUP with a comment saying why, rather than leaving the arithmetic to be rediscovered.

tests/test_diffusion_backend.py and tests/test_diffusion_memory.py together are now 599 passed, 1 failed, that one failure being the pre-existing one above.

Pushed to the branch

  1. Updated the stale assertion, plus two planner tests: one pinning that an unknown split says so instead of "exceeds budget" (fails on base), one pinning the group tier with the split known (passes on base, and is labelled the control, since the planner was never the broken half).
  2. A separate fix, same family: a quantised Qwen-Image-2.1 now seeds a 512 canvas instead of 1024. Measured about 26 GB at 1024 against about 19 GB at 512. Quantising the denoiser shrinks the weights and leaves the activations alone, so on this family the canvas is what decides whether it fits. Read off the ENGAGED build, so a declined quant request keeps 1024, dense keeps 1024, and the GGUF route keeps 1024 since it streams the denoiser and does not turn on this. Six tests cover the matrix.

Still not answered

Neither of us has run this on real A100 silicon. Everything above is the planner's decision and the sizes it derives, which is where the bug lives, but the end-to-end claim that generation is faster and the streaking clears is still unmeasured. The streaking point in particular I would not carry into the description as anything more than a hypothesis.

@danielhanchen
danielhanchen marked this pull request as ready for review September 22, 2026 15:32
@danielhanchen
danielhanchen self-requested a review as a code owner September 22, 2026 15:32
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@danielhanchen
danielhanchen merged commit f2e6a44 into unslothai:main Sep 22, 2026
3 of 36 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…line image load (unslothai#11548)

* Studio: give the memory planner the companion split on a pipeline image load

A pipeline load handed plan_diffusion_memory None for companion_dense_mib
and text_encoder_dense_mib. _sum_required propagates that None into
group_floor and group_floor_streamed_te, and both group-tier checks are
'... is not None and ...', so group offload was unreachable on a pipeline
load regardless of the card. Every such load that did not fit resident went
straight to whole-module offload, which pages every component per step and
switches VAE tiling on.

Derive the split from the same cache walk the GGUF/single-file branch
already uses, so it comes from the same trees as model_dense_mib. A narrow
base takes its companion share from the bf16 table that already raised
model_dense_mib, and the companion term is clamped to the model total.

Also split the final reason string so an unknown companion size says so
instead of claiming the companions exceeded the budget, and log
plan.estimates with diffusion.loaded so the verdict can be checked.

Refs unslothai#11547

* Studio: update the pipeline-load planner test for the companion split, and pin the unknown-split reason

* Studio: default a quantised Qwen-Image-2.1 to a 512 canvas

---------

Co-authored-by: danielhanchen <[email protected]>
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.

[Bug] Unsloth Studio: a pipeline image load can never pick group offload, so Qwen-Image-2.1 falls to whole-module offload on a 40 GB A100

2 participants