Repository navigation
Studio diffusion: download a partially cached snapshot before sizing it for small hosts - #16080
Conversation
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: 7a79737002
ℹ️ 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 any(not (sub / shard).is_file() for shard in shards): | ||
| return False |
There was a problem hiding this comment.
Check only the weight layout selected for loading
When a cached snapshot contains complete .fp16.safetensors twins but also a default shard index whose shards are absent, this loop marks the snapshot incomplete even though local_fp16_variant() selects the complete fp16 layout. This newly triggers _small_host_fetch(), which calls pipeline_cls.download() without variant="fp16": the caller only adds that argument after _small_host_decision() returns. Consequently, an otherwise fully cached fp16 load now downloads the unused default weights, potentially consuming tens of gigabytes of disk and bandwidth or failing on insufficient disk space. Make the completeness check and early download respect the selected variant rather than requiring every cached index's shards.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4d4186f. snapshot_weights_complete now takes the variant the load will use and checks only that layout's files and shard indexes. _small_host_decision gets the local_fp16_variant() pick, and the early fetch passes the same variant="fp16". A cached load with complete fp16 twins no longer counts as incomplete because of an orphan default index, and nothing downloads the unused default weights. Added a test for complete fp16 twins plus an orphan default index: the snapshot is complete and nothing is fetched.
There was a problem hiding this comment.
Fixed in f73deec: the completeness check now only looks at the selected variant's files and index, and the early download passes the same variant. Covered by test_complete_fp16_twins_with_an_orphan_default_index_skip_the_download.
A cached fp16 load with complete .fp16 twins and an orphan default shard index was judged incomplete, so the early fetch downloaded the unused default weights. snapshot_weights_complete now takes the variant the load reads, and the early fetch passes it too.
|
@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". |
…uments The fp16 variant was chosen before the hosted VAE, extra text encoders and native-quant transformer were added, so a component without an fp16 twin could trigger a default-weights download the load never reads.
[skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
[skip ci]
… installed (unslothai#16126) ## What was wrong `test_twins_completed_by_a_supplied_component_skip_the_early_download` (added in unslothai#16080) fails in Backend CI's `(Python 3.13, a-f)` shard on main and on every PR: that shard installs transformers but not diffusers, so `_class_pins_fp32("diffusers", "SD3Transformer2DModel")` cannot import the class and conservatively reports an fp32 pin, `plan_fp16_twins` returns None, and `local_fp16_variant` answers None instead of `"fp16"`. The fp32 pin is not what the test checks (it checks that a supplied component completes the twins and skips the early download), so the test now stubs `_class_pins_fp32` to False, the way a diffusers class without `_keep_in_fp32_modules` answers. ## Testing - Shard environment (transformers 5.17.0, no diffusers): main `1 failed, 34 passed, 1 skipped` (this test); this branch `35 passed, 1 skipped`. - With diffusers 0.42.1 and transformers 5.22.1: 36 passed on both. - Negative control with the stub in place: the same snapshot answers `fp16` with the VAE supplied and `None` without it, so the test still fails if the supplied-component handling regresses. - Main's own Backend CI `(Python 3.13, a-f)` failed on this test (job 124087281866), as did `perf/r10-gemma3-decode` (124086773561) and unslothai#16021 (124087032249).
Problem
On a small host, Studio's diffusion loader downloads the full snapshot before deciding whether to spill components to disk, so the decision sizes the real weights. That download-first step only runs when the snapshot is missing or holds no stored components. A partially cached snapshot (an interrupted download) skips it: the decision sizes only the files present, spilling stays off, and the load then pulls the missing components into a dense load that can exceed host RAM.
Reproduced with header-only safetensors at Klein-9B sizes on a 12977 / 11161 MiB host: with one DiT shard missing, main makes no spill decision (
assert [] == [1]).Change
diffusion_small_host.snapshot_weights_complete(snapshot, skip): False when amodel_index.jsoncomponent folder is missing, a model folder (one withconfig.json) has no weights, or a shard listed in a*.index.jsonis absent. Components the caller supplies are skipped; a snapshot withoutmodel_index.jsonmakes no claim._small_host_decisionalso downloads first when the cached snapshot is incomplete, so the sizing sees every component.local_fp16_variant(), only the.fp16.files and indexes are checked and the fetch passesvariant="fp16", so an orphan default index never triggers a download of unused default weights. The variant is picked from the final load arguments (after the hosted VAE, extra text encoders and native-quant transformer are added), the same way the load picks it.Tests
studio/backend/tests/test_diffusion_small_host.py: 4 new cases (missing DiT shard, weightless model folder, missing component folder, complete fp16 twins with an orphan default index). main: 3 failed, 31 passed on the first three. This branch: 36 passed; withtests/test_diffusion_fp16_variant.py, 67 passed.Not covered