Repository navigation
Studio diffusion: place bf16 and GGUF / int8 packed denoisers from their learned peak - #13860
Conversation
…tall downloads _peak_model_identity fingerprinted the vendor repo id (e.g. black-forest-labs/FLUX.2-klein-4B), but Studio fetches a mirrored base from its byte-identical unsloth/ mirror, so on a fresh install the vendor id has no cached revision, the key became unknown and learned peaks were never recorded nor read. Fall back to mirror_repo() for the denoiser repo and the companion base, and name the repo the revision came from.
…eir learned peak refine_plan_from_loaded_weights returned before the learned-peak lookup for a dense denoiser whose compute dtype is bf16 or whose weights are GGUF / int8 packed, because the dense eager table was measured on fp16 / fp32 unpacked weights only. Those loads still recorded a peak at every render, but no later load read it, so every bf16 card and every GGUF image load kept the flat 8 GiB/MP estimate and streamed the whole denoiser. Such a load now places from the peak this machine recorded for its exact build alone (no static seed); with nothing recorded the flat plan stands. The fp16 table still seeds fp16 / fp32 loads and a learned value only raises it. The request guard reads the same flag from the reserve so a learned-only load never sizes requests from the fp16 table. Every kill switch is unchanged.
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. |
… cfg:off key A family that can run classifier-free guidance skipped recording every render that did not run it, so Z-Image-Turbo at its default guidance 0 never learned a peak. Such a render now records under its load label plus cfg:off. A load reads that key only when the label has no CFG peak, and marks the reserve: the request guard then sizes any request that runs CFG (or whose guidance mode is unknown) from the flat estimate, since the doubled denoiser batch was never measured. A CFG render records the unlabelled key, which wins on the next load. UNSLOTH_DIFFUSION_LEARNED_PEAKS_CFG_OFF=0 restores the previous behaviour.
…ithub.com/unslothai/unsloth into studio-generalize-learned-peaks [skip ci]
…unslothai/unsloth into studio-generalize-learned-peaks [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? 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". |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
Stacked on #13847 (learned peaks keyed on the unsloth mirror). Without it a fresh install keys every build as
unknown, so nothing here engages. Merge #13847 first. Both branches now carry current main (c08dfbbe64), merged cleanly.Problem
#13724 records a learned activation peak at every completed image render, and
refine_plan_from_loaded_weightsreads it on the next load to keep more of the model resident. For a dense denoiser that function still returns before the learned lookup on main when:_denoiser_compute_bytesis None), or_pipe_denoisers_hold_packed).The early return exists because the static dense eager table was measured on fp16 / fp32 unpacked weights only. That is a reason to skip the table, not the learned peak, which is a real measurement of the exact build (model revision, quant label, VAE savers, attention backend, graphs, GPU name). These loads recorded a peak on every render that no later load ever read: every dense load on a bf16 card (Ampere and newer) and every GGUF image load kept the flat 8 GiB/MP estimate and streamed the whole denoiser.
Change
measured_image_runtime_mib(..., static_seed=True): withstatic_seed=False, every static table is skipped and the answer comes from the learned peak alone (None when nothing was recorded).refine_plan_from_loaded_weights: a bf16 or packed dense denoiser setsstatic_seed=Falseinstead of returning. With no learned peak the lookup answers None and the flat plan stands, which is today's behaviour. Dense loads keep the conservative branch: the whole-DiT and wide-window pins stay torchao-only._unsloth_measured_reserve[8]), so a learned-only load never sizes requests from the fp16 table. Older 8-field reserves read as before. A layer split still drops the reserve (Studio: split one diffusion denoiser across GPUs by block ranges #14412), unchanged.<label>|cfg:off. A load reads that key only when no CFG peak exists, and marks the reserve. The request guard then sizes any request that runs CFG, or whose guidance mode is unknown, from the flat estimate, because the doubled denoiser batch was never measured. Kill switch:UNSLOTH_DIFFUSION_LEARNED_PEAKS_CFG_OFF=0.UNSLOTH_DIFFUSION_LEARNED_PEAKS=0,UNSLOTH_DIFFUSION_MEASURED_ACTIVATION=0,UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE=0,UNSLOTH_DIFFUSION_PARTIAL_RESIDENT=0).Results
Colab A100 40 GB, allocator capped, fresh VM (models downloaded from the
unsloth/mirrors). Base is main + #13847, head is this branch, both at current main. Order base, head, head, base. Each arm loads twice in a fresh Studio home: load 1 has no learned peak and records one, load 2 reads it. Median s/step of 3 renders at 1024x1024, speed tier off.cfg:offpeakmodel:unsloth/FLUX.2-klein-4B@04e0a8a...), and the Z-Image peak is stored with a trailingcfg:offpart. Base records no Z-Image peak at guidance 0.Tests
test_diffusion_learned_peaks.py: the CFG test now asserts thecfg:offkey (it pinned the old skip), plus 2 new tests for the load fallback / guard and the wiring (the wiring check is whitespace-free so the formatter cannot break it).test_diffusion_measured_placement_dense.py: 5 new tests, all failing without this change:test_diffusion_learned_peaks.py,test_diffusion_measured_placement.py,test_diffusion_measured_placement_dense.py,test_diffusion_small_host_planner.py,test_offload_planner.py,test_diffusion_gguf_offload_route.py,test_diffusion_stream_residency.py,test_video_stream_residency.py,test_diffusion_offload_seed_balanced.py,test_group_offload_background_pin.py: 6 fixed, 2 new, 573 unchanged, 6 skipped (CUDA only), 0 new failures. 4 tests fail identically on main and are not touched here (test_background_pinner_pins_gguf_host_copiesand three video peak persistence tests).Not covered
graphs:onbut can render graph-free and record undergraphs:off, so that peak is not read back. Follow-up: re-refine after the graph decision.cfg:off-only peak are sized from the flat estimate (resident groups stream again for that request) until a CFG render records its own peak. Covered by CPU tests, not by a GPU run.