Repository navigation
Studio diffusion: key learned peaks on the unsloth mirror a fresh install downloads - #13847
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.
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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 741f0c55ad
ℹ️ 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".
| if revision or filename: | ||
| return repo, revision |
There was a problem hiding this comment.
Key peaks to the repository actually fetched
When an upstream cache contains only model_index.json (for example after an interrupted or previously gated pull) while the complete weights are available only from the mirror, the download planner still selects the mirror because it checks every base_files entry, but this early return selects the upstream revision merely because its index is cached. The resulting key therefore names a repository whose weights were not loaded, misses peaks previously recorded under the mirror key, and can associate measurements with the wrong build. Pass the load's already-resolved fetch_base into the identity calculation, or apply the same full-file cache predicate used by the planner.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e51511c. The key now follows the load's own mirror decision: load_pipeline passes its fetch_base into _peak_model_identity, and when that names a different repo than the upstream id, the revision is read from the repo the bytes actually came from. A cached upstream model_index.json no longer wins when the weights were pulled from the mirror, and when the load read the upstream bytes the mirror's revision is never used (no revision there means the key stays unknown). Callers without a fetch decision keep the earlier fallback. Test: test_peak_model_identity_keys_on_the_repo_the_load_fetched.
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ba97f6b598
ℹ️ 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".
| revision = checkpoint_fingerprint(repo, filename) | ||
| if revision or filename or fetched: | ||
| return repo, revision |
There was a problem hiding this comment.
Carry the video fetch repo into the peak key
For video loads whose upstream cache contains only model_index.json while _predownload_base selected the complete mirror, _calibration_revision still calls this helper without fetch_base; this revision branch therefore keys the persisted peak to the partial upstream snapshot even though the loaded weights came from the mirror. The image caller is fixed, but the video path drops _base_fetch_repo when constructing _VideoLoadState, so an old upstream peak can be reused for a different mirror build; retain the selected fetch repo in the video state and pass it here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ba92924. The video load state now keeps the base repo the load actually fetched (_VideoLoadState.fetch_base, set from the same fetch_base that load_pipeline and the H3 modular loader read from), and _calibration_revision passes it into _peak_model_identity. A video load that staged the complete mirror while the upstream cache holds only model_index.json is now keyed to the mirror's revision. Callers without a load decision (the native H3 runtime) still fall back to the mirror only when the upstream has no cached revision.
New test test_video_peak_key_names_the_repo_the_load_fetched: fails at ba97f6b (the key names Wan-AI/Wan2.2-TI2V-5B-Diffusers@u1), passes here. Related CPU tests base vs head: 1 fixed, 785 unchanged, no new failures.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
…eir learned peak (#13860) 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_weights` reads 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: - the compute dtype is bf16 (`_denoiser_compute_bytes` is None), or - the weights are GGUF or int8 packed (`_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)`: with `static_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 sets `static_seed=False` instead 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. - The reserve the request guard reads carries the flag (`_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 (#14412), unchanged. - A family that can run classifier-free guidance used to skip recording every render without it, so Z-Image-Turbo at its default guidance 0 never learned a peak. Such a render now records under `<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`. - Unchanged: fp16 / fp32 dense and torchao loads, "a learned value only raises a seed", non-CUDA and unified-memory devices (the refine is a no-op there), and every kill switch (`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. | Case | base load 1 / load 2 (arms 1, 4) | head load 1 / load 2 (arms 2, 3) | head placement on load 2 | Peak alloc base / head | Output | |---|---|---|---|---|---| | FLUX.2-klein-4B bf16, 10 GiB | 0.643 / 0.643, 0.641 / 0.641 | 0.643 / **0.491**, 0.641 / **0.489** | 1943 of 7393 MiB DiT resident (learned peak 2816 MiB reserved) | 2620 / 4397 MiB | bit-identical | | FLUX.2-klein-4B GGUF Q8_0, 8.75 GiB | 0.687 / 0.687, 0.689 / 0.688 | 0.686 / **0.311**, 0.689 / **0.310** | 663 of 4102 MiB DiT resident | 2620 / 3245 MiB | bit-identical | | Z-Image-Turbo GGUF Q8_0, guidance 0, 10 GiB | 0.621 / 0.623, 0.621 / 0.622 | 0.622 / **0.484**, 0.621 / **0.484** | 1946 of 6888 MiB DiT resident, from its `cfg:off` peak | 2611 / 4562 MiB | bit-identical | | FLUX.2-klein-4B GGUF Q8_0, 10 GiB | 0.239 to 0.241 throughout | 0.239 to 0.241 throughout | unchanged: the plan is whole-module offload, out of scope | 4842 / 4842 MiB | bit-identical | - Speedups on learned loads: klein bf16 1.31x, klein GGUF 2.21x, Z-Image GGUF 1.28x. Every load without a learned peak matches base within 0.5%, which is also the base-vs-base spread. - No OOM in any arm. The stored keys name the mirror (`model:unsloth/FLUX.2-klein-4B@04e0a8a...`), and the Z-Image peak is stored with a trailing `cfg:off` part. Base records no Z-Image peak at guidance 0. - A local B200 run (host heavily loaded, so timings are noisy) with an offline HF cache holding only the mirrors showed the same placements and bit-identical images: klein GGUF 0.80 to 1.01 s/step down to 0.13, while klein bf16 (0.148 vs 0.154) and Z-Image (0.16 to 0.19 vs 0.17) moved within that host's noise. On a card this fast the streamed bf16 copy hides behind compute, so the gain depends on the card's compute to PCIe ratio. ## Tests - `test_diffusion_learned_peaks.py`: the CFG test now asserts the `cfg:off` key (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: - bf16 and GGUF denoisers place from a recorded learned peak, and each kill switch restores the flat plan. - An fp16 load keeps its 3072 MiB table seed over a lower learned peak. - The request guard of a learned-only load scales the learned peak and ignores the fp16 table. - The load stores the flag in the reserve. - CPU, base (main + #13847) vs this branch, over `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_copies` and three video peak persistence tests). ## Not covered - Video: this PR changes no video path. - LoRA loads still skip learned peaks. Runtime adapters attach after placement, so this needs a measured per-adapter overhead term, not just a key. - On the default speed tier a streamed load is labelled `graphs:on` but can render graph-free and record under `graphs:off`, so that peak is not read back. Follow-up: re-refine after the graph decision. - CFG requests on a load placed from a `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. - No real 8 / 10 / 12 GB consumer card, no AMD card and no Windows run: a larger card with a capped allocator. macOS / MPS and CPU are untouched (the refine returns before any of this on non-CUDA and unified memory). --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Problem
#13724's learned activation peaks never engage on a default install.
_peak_model_identityreads it fromcheckpoint_fingerprint(repo_id), using the vendor repo id the family names, for exampleblack-forest-labs/FLUX.2-klein-4B.unsloth/mirror instead (unsloth/FLUX.2-klein-4B,prefer_ungated_mirror).unknown. No peak is ever recorded or read, and the planner keeps streaming the DiT exactly as before Studio diffusion: learned activation peaks, OOM retry in group offload setup, pinned GGUF host copies, tied-weight groups #13724.Still true on main today (
c08dfbbe64):_peak_model_identity(repo_id, gguf_filename, kind, base)reads only the vendor id.Change
fetch_base(the repo it actually read) into_peak_model_identity. The key names that repo and its revision: the mirror on a fresh install, the vendor repo when the vendor cache satisfied the load. This holds for the pipeline itself and for the companion base of a GGUF or single-file load.unsloth/mirror's revision when the vendor repo has no cached revision.unknown.Results
Fresh-install layout: an HF cache holding only the
unsloth/mirrors (vendor repos absent), offline, FLUX.2-klein-4B on the default speed tier at 1024x1024, 16 GiB allocator cap, two loads per process in a fresh Studio home.model:unknownmodel:unsloth/FLUX.2-klein-4B@04e0a8a...record -> False)3865 MiB of the 3865 MiB transformer and 3216 MiB of the 5940 MiB encoders stay resident (measured peak 3840 MiB)Speed, Colab A100 40 GB, same cell (default tier: torchao int8, compiled, CUDA graphs), 16 GiB cap, order base, head, head, base, each arm two loads, median s/step of 3 renders:
That is 1.09x on load 2 (0.601 to 0.552), with peak allocation 2314 MiB on main and 6416 MiB here (more of the model resident). Within a process the image is bit-identical between load 1 and load 2. Across processes the compiled int8 tier already gives different bytes on main itself (arm 1 vs arm 4), so that comparison is not a placement effect.
On a Colab A100 VM (a real fresh install that downloads from the mirror), the stored keys were
model:unsloth/FLUX.2-klein-4B@04e0a8a...andmodel:unsloth/Z-Image-Turbo-GGUF/z-image-turbo-Q8_0.gguf@6c80814...+unsloth/Z-Image-Turbo@dd53895..., neverunknown.Tests
test_peak_model_identity_reads_the_unsloth_mirror_on_a_fresh_installandtest_peak_model_identity_keys_on_the_repo_the_load_fetched(new) andtest_peak_model_identity_names_the_whole_build(call-site check, now whitespace-free so the formatter cannot break it): all 3 fail on main and pass here.test_diffusion_learned_peaks.py,test_diffusion_measured_placement.py,test_video_stream_residency.py,test_video_backend.pyon CPU, main vs this branch: 3 fixed, 782 unchanged, 0 new failures. 4 tests fail on both sides and are not touched here (test_background_pinner_pins_gguf_host_copiesand three video peak persistence tests).Not covered
checkpoint_fingerprintusestry_to_load_from_cacheand matches the snapshot on the POSIX form of the path, so a cache without symlinks resolves the same way. Not run on Windows.