Repository navigation
Studio diffusion: faster returning-user load for cached int8 FLUX.3 (one Hub call, persisted CUTLASS tile probe) - #18837
Conversation
- Read an unchanged, already validated Hub snapshot from the cache with one Hub call instead of one revalidation per file (FLUX.3 loader). - Persist the prebuilt CUTLASS tile probe verdict per card, driver, toolchain, library bytes and code.
Codex Review Summary: ✅ CompletedThis 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: 6858657e21
ℹ️ 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 not any(_probe_tile(index, fam, t, pairs) for t in failed): | ||
| _store_tiles(index, fam, ok) |
There was a problem hiding this comment.
Avoid persisting an all-failed probe under temporary GPU pressure
If GPU memory pressure causes every tile probe to fail, immediately retrying the probes can encounter the same pressure and persist an empty ok list. _probe_tile converts allocation and CUDA exceptions into False, so these failures do not establish that the kernels are incompatible. Subsequent healthy launches accept that empty verdict without probing again, disabling CUTLASS acceleration indefinitely for the same fingerprint. Avoid persisting an all-failed result, as the existing quant-probe cache does, or distinguish resource failures from definitive correctness failures before storing them.
Useful? React with 👍 / 👎.
The warm-load record compared file names, so a dangling link still matched and the load read cache-only; transformers (4.57.6 and 5.17) then loads the processor without its chat template and raises nothing. Count only links that resolve, so a partially deleted cache revalidates and fetches the file again.
A tile probe that ran out of memory on a full card, or after a sticky launch error, failed both times and was stored, so the tile stayed off in every later process on that card and driver. Persist only when the allocator's OOM count did not move and the context still syncs. [skip ci]
|
@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". |
…ding, not bitwise (#18840) ## Summary `(Python 3.13, diffusion)` fails intermittently across unrelated PRs (#18837, and the `studio-klein-ref-kv` branch): ``` tests/test_diffusion_vae_upsample_fold.py::test_strip_fold_matches_the_whole_map[5] tests/test_diffusion_vae_upsample_fold.py::test_strip_fold_matches_the_whole_map[13] E assert False E + where False = torch.equal(whole, strips) ``` The test, added by #18792, runs the folded transposed conv once over the whole map and once strip by strip with the one-row halo, then asserts the two are bitwise equal. The fold is correct (the same test passes here, and its second assert still checks both against the unfused nearest 2x + conv chain to 1e-6). Bitwise equality is just not something the CPU conv backend promises: a strip-sized input can be blocked differently from the whole map, so the taps are summed in another order. Which kernel gets picked depends on the runner's CPU, which is why it only fails on some runs and only for the multi-strip heights (5 and 13; 1 and 2 are a single strip). ## Fix Compare `whole` and `strips` to `1e-10` instead of bitwise. The data is fp64, so reordering costs about `1e-16`, while a seam or halo bug is off by O(1). ## Testing - `studio/backend/tests/test_diffusion_vae_upsample_fold.py`: 11 passed. - Sabotage: dropping the halo row in `_fold_upsample` (`lo = a` instead of `max(0, a - 1)`) still fails `test_strip_fold_matches_the_whole_map[5]` and `[13]`.
…ache reads, OOM tile probe, ConvRot-only hosted int8 video (#18982) ## Summary Four fixes found while re-checking recent Studio image and video load changes, one commit each, plus one test-compat fix. 1. **klein 9B KV identity (follow-up to #18831).** `_resolve_base_repo` swaps the KV base (`black-forest-labs/FLUX.2-klein-9b-kv`) for the stock 9B it borrows its text encoder, VAE and scheduler from. The queued load then wrote that 9B back into `base_repo` before `load_pipeline` picked the pipeline class, and a base taken from the model card never reached it at all. A KV GGUF or single file with a generic name (no "KV" in the repo or file name) ran through the stock `Flux2KleinPipeline`, advertised inpaint / outpaint, and passed the guard that keeps the base's dense transformer from replacing the KV DiT. `_resolve_base_repo` now records the base the caller or the card named (`_checkpoint_base_of`), the queued load passes it to `load_pipeline` as `_checkpoint_base`, and the pipeline class, that guard, the dense prefetch widening and the load state read it. Companion fetches still use the stock 9B. 2. **FLUX.3 cache-only reads pin the validated commit (follow-up to #18837).** `current_snapshot` returns the commit it validated, but the loader only kept a bool. Every cache-only read then resolved `refs/main` again. If another download moved that ref in between, the load read files from a snapshot nobody had validated. The commit is now passed as `revision` to every cache-only read (index, processor, text encoder, transformer, VAE, stored-dtype probes). A read that falls back to the Hub is unpinned, as before. 3. **CUTLASS tile probe and the async allocator (follow-up to #18837).** A failure persists only when it repeats and `num_ooms` did not move. Under `PYTORCH_CUDA_ALLOC_CONF=backend:cudaMallocAsync` that count stays 0, because the async allocator fills none of the native allocator's stats (`CUDAMallocAsyncAllocator.cpp`, `getDeviceStats`). A probe on a full card therefore persisted an empty tile list, and every later process on that card skipped the CUTLASS int8 tiles. `_probe_tile` now counts its own out-of-memory failures, and a probe that hit one does not persist. Editing the module also invalidates the verdicts already stored. 4. **Torchao-free hosted int8 commit takes only the ConvRot file (follow-up to #18958).** With no usable torchao (the Windows ROCm stub), the check that drops the dense LTX-2.5 DiT shards accepted any hosted `.safetensors` name. The native read only accepts the ConvRot file. So with `UNSLOTH_DIFFUSION_INT8_CONVROT=0` (which resolves the unrotated `LTX-2.5-INT8.safetensors`), or with a listing that has no ConvRot file, the load staged 25 GB and the reader then refused it. Now only the `-ConvRot.safetensors` file counts. With ConvRot off, the ROCm hosted int8 route (plan, price, commit) does not apply, so the load uses the dense shards and runtime build as before. This matches the ConvRot gate the image route already has. 5. **Tests.** The FLUX.3 warm-load fixture patched `diffusers.Flux3Transformer2DModel.from_pretrained`, so its four loader tests failed with `AttributeError` on a diffusers that meets the declared floor (>= 0.39) but predates the FLUX.3 classes. A missing class now gets a stand-in. ## Tests New tests fail on the merge base and pass on this branch (base arm = the merge base with the new test files copied in): | file | new tests | base | head | |---|---|---|---| | `test_diffusion_flux2_klein_kv.py` | card-only and explicit KV identity, queued load hands `load_pipeline` the KV identity, `load_pipeline` wiring | 4 failed | pass | | `test_diffusion_hub_snapshot.py` | cache-only reads pin the validated commit, Hub fallback stays unpinned, real `hf_hub_download` cache read after `refs/main` moves | 2 failed (4 more fail on the old fixture with diffusers 0.40) | pass | | `test_diffusion_int8_cutlass_probe_persist.py` | an OOM the allocator stats never count is not persisted | 1 failed (persisted `ok: []`) | pass | | `test_video_hosted_int8_fit.py` | unrotated file never committed without torchao, ConvRot file beside it still committed, ConvRot off takes the hosted route off | 3 failed | pass | Related suites (klein KV, FLUX.3 loader / storage / manual cast, hub snapshot, CUTLASS, gated base, compat preflight, video hosted int8 / native hosted / families, refactor guard): 1676 passed. The 8 failures are the same 8 test IDs on the merge base: 5 MiniMax H3 download-plan tests and 2 FLUX.3 retired-copy tests from a `huggingface_hub` without `get_cached_repo_tree` / diffusers 0.40, and 1 causal-mask patch test. ## Not covered - No GPU run. The async-allocator OOM path is shown by injecting `OutOfMemoryError` with `num_ooms` fixed at 0, which is what the upstream allocator source reports. It was not run on a real card with `backend:cudaMallocAsync`. - No Windows ROCm run of the ConvRot gate. The check is CPU-only, using the existing torchao-stub fixture. - The native sd.cpp engine takes its base from the request alone, so a card-only KV identity does not reach its reference-edit refusal. That is not changed here.
Summary
This makes a returning user's load faster for FLUX.3 klein with cached int8 weights. That is the case where a launch reuses the Studio home and the local int8 cache from an earlier one. On a Colab L4 with klein base int8, a fully warm launch loads 2.4 to 6.7 s sooner (depending on the Hub round trip) and starts its first image 0.7 s sooner. Every image is bit-identical to main. The second launch's 10 s GEMM re-race at the real row count is a separate change and is not part of this PR.
I profiled the warm load first: a wall-clock stack sampler ran during the load and the first render of launches 1 to 3. The real costs turned out to be different from the earlier estimate:
model_info)import unslothfor the zoo patch helpersBefore the first image, the prebuilt CUTLASS tile probe takes 1.3 to 1.5 s on every launch. On launch 2 only, a 10 s GEMM race also runs at 4224 rows; that is handled elsewhere.
Changes
diffusion_hub_snapshot.py, FLUX.3 loader). A load that may download asks the Hub about every file it opens, about 25 requests. After a load has revalidated every file and the Hub confirms the commit, it writes a record. The record holds the repo, commit, components, library versions (transformers, diffusers, huggingface_hub, tokenizers), a hash of the loader code and the snapshot's file list, including.no_existentries. A later load with the same record makes onemodel_infocall. Ifmainstill names that commit, it reads every component withlocal_files_only=True, so it opens exactly the files the revalidating load opened. Anything else revalidates per file as before: a moved ref, new versions or code, a file added or removed, offline, unreachable, or a local directory. A component that fails the cache-only read is read online and the record is dropped.UNSLOTH_DIFFUSION_HUB_SNAPSHOT=0turns it off.diffusion_int8_cutlass.probed_tiles). The bit-exact probe verdict is stored throughdiffusion_probe_cache.Namespace. The key covers the card UUID, driver, torch / CUDA / Triton / torchao, theUNSLOTH_DIFFUSION_*env, the source ofdiffusion_int8_cutlass.pyanddiffusion_int8_gemm.py, and the loaded library's bytes. A missing, stale or malformed verdict re-probes. A failing tile is only stored when it fails twice in a row, so one transient error cannot drop a tile for good.UNSLOTH_DIFFUSION_PROBE_CACHE=0turns it off.Results
Colab L4, klein base int8, 1024x1024. Base is the merge base and head is this branch, on the same VM. Each arm runs launches 1 to N against its own home, one fresh process per launch. The weight files (Hub snapshot and the home's int8 cache) are read once right before every launch to control the page cache.
20 steps, two timed renders per launch. Launch 2 still re-races GEMM tiles in both arms (about 10 s, not changed here). Launches 3 and 4 show the fully warm state:
Not changed
import unsloth(4.8 s) runs because the zoo patch helpers need it. Moving it to a background thread or skipping it could change which patches the text encoder sees, so it stays as is.Tests
test_diffusion_hub_snapshot.py(record / match / miss on a moved ref, other versions or code, a file added or gone, offline, the switch, loader routing and fallback),test_diffusion_int8_cutlass_probe_persist.py(stored verdict skips the probe; stale or malformed re-probes; a flapping failure is not stored; driver and library changes miss).Not covered