Repository navigation
Diffusion: allow fp8 on Qwen-Image again, and split the training deny - #8018
Conversation
_FAMILY_SCHEME_DENY refused fp8 on qwen-image / qwen-image-edit because the
family rendered every frame black. That cause is gone. It was torchao's
_choose_scale_float8 having no eps clamp: qwen's text stream emits all-zero
token rows through a run-varying set of txt_mlp.net.2 linears, so the per-row
scale went to 0 and the qdata to NaN. _make_quant_config now floors it with
activation_value_lb = 1e-12, and the deny was left behind on its old
justification.
Re-measured on B200 with the floor, on BOTH paths the deny governs, since it
gates select_transformer_quant_scheme rather than one loader:
prequant checkpoint, full 28-pair gate:
28/28 PASS, SSIM 0.87-0.99, LPIPS 0.027-0.228, CLIP delta <= 0.019
on-the-fly quantize_, the gate's own simple_object prompt and seeds:
LPIPS 0.048 / 0.033 / 0.027 / 0.063 (gate checkpoint: 0.050 / 0.048 / 0.033 / 0.027)
against pre-floor plain fp8 at LPIPS 0.712, SSIM 0.016, mean luma 0. The bar
is 0.10. Keeping the deny cost speed: it pinned qwen to int8 at 1.10x bf16
when compiled fp8 measures 1.21x.
mxfp8 and nvfp4 stay denied. Those failures were activation outliers and the
4-bit noise floor, not the zero-row bug, and nothing here touches them.
The deny table has a second consumer: core/training/diffusion_train_common.py
filters the Train UI's precision list and hard-rejects a run through
_family_denied. All the evidence above is rendering evidence. It says a frozen
fp8 forward reconstructs the bf16 image, not that a LoRA converges when its
frozen linears are fp8, and nobody has run that. So training gets its own
_FAMILY_TRAIN_SCHEME_DENY and keeps refusing qwen fp8, via a
_family_train_denied helper that is a strict superset of the inference rule.
A test pins that direction, because training being more permissive than
inference is the one way this split could go wrong.
Lifting the qwen fp8 deny lets a pre-floor artifact load. Its serialized activation quantiser still carries hp_value_lb=None, so it reproduces the black frames the deny existed for, and neither existing guard catches it: _validate_checkpoint checks fp8_granularity but nothing about the floor, and the smoke probe exercises a NEWLY BUILT config rather than the loaded tensors. These artifacts are real, not hypothetical. Auditing every transformer_fp8.pt on this box, four carry hp_value_lb=1e-12 and one, built before the fix, carries None. Checked on the loaded TENSORS rather than metadata, deliberately. The floor is serialized per tensor as act_quant_kwargs.hp_value_lb, so it can be read directly; a pre-floor checkpoint predates any metadata field that could be stamped; and every metadata check around this one accepts an absent field for back-compat, which is exactly the wrong default here. Reading the tensors is fail-closed and needs no format bump. Verified against both artifacts on disk: the pre-floor one is rejected, the floored one accepted, and a rejection falls through to the dense re-quantise path that applies the floor. A dense tensor has no act_quant_kwargs, and an unwalkable state dict raises, so both are treated as "not evidence of a missing floor" and left to the scheme and granularity checks. Failing closed there would reject every int8 checkpoint too.
Lifting the qwen fp8 deny changed what auto picks, and that has a consequence beyond quality. auto now returns fp8 for qwen-image, but the family publishes only an int8 DiT checkpoint, so usable_prequant_source(fp8) is empty and the loader must size the ~40 GB dense fp8 build. On a host that rejects that transient the dense-fit check set dense_declined and the pick fell through to GGUF, losing the int8 prequant that auto reached before this change. A machine that used to load a fitting checkpoint would have started loading GGUF instead. select_transformer_quant_scheme returns only the winner, which is all the load needs until the winner has no published checkpoint AND cannot fit dense. So auto_scheme_candidates exposes the whole ladder, built from the same tiers, deny list and smoke probe as the selector's auto branch, and a test asserts the selector's answer is always the head of that list so the two cannot drift. _auto_prequant_retry_scheme then walks the rungs BELOW the winner for one with a usable prequant and pins transformer_quant to it. Strictly below: a higher rung was already rejected by the ladder, so offering it back would hand the loader a scheme auto itself would refuse. Only for auto, since an explicit scheme is honored or refused and never swapped, and not when a LoRA is baked, which takes the dense path regardless.
Two follow-ons to the retry, both consequences of putting it in one branch and not re-reading the policy it has to live under. Cached-only. For a GGUF pick with auto, a hosted prequant is used only when already cached: fetching one means downloading a SECOND multi-GB denoiser for a pick that already has its GGUF. _uncached_prequant_repo enforces that, but it runs select_transformer_quant_scheme, which only ever returns the WINNER, so it inspected fp8 alone. A retry handing back an uncached int8 repo went straight past it. The retry now applies the same rule: a repo source must be cached, a local override is the operator's own file and costs no bytes. Reachable from the offload path. The retry sat only in the else branch, the one taken when the GGUF plan does NOT offload. When it does, the branch above replans auto's winner alone; if that replan still offloads, quant_plan stays unset and the gate below skips the dense/prequant load entirely, so a cached lower rung that WOULD have fit was never looked at. The retry now also runs when that branch produces no resident plan, re-resolving the candidate and replanning at the lower scheme before anything falls back to GGUF. The existing test needed updating rather than replacing: it stubbed usable_prequant_source with a bare string, which no longer satisfies the source contract. It now covers cached repo (retry), uncached repo (no retry) and local override (retry regardless).
…mage-fp8-lift # Conflicts: # studio/backend/tests/test_diffusion_backend.py
The offload-path retry rebinds `candidate` and calls `_replan_candidate`, but that closure was defined inside `if candidate is not None:`. The retry is reached precisely when the first resolve returned None (the free-disk gate skips auto's winner while a lower cached prequant still passes), so the name was unbound exactly where it is needed and the load raised UnboundLocalError under the load lock instead of loading the cached rung. The closure reads `candidate` at call time, so hoisting it changes nothing for the callers that already worked. Regression test asserts both resolves run, and fails with UnboundLocalError when the definition is nested again.
…sloth into qwen-image-fp8-lift # Conflicts: # studio/backend/tests/test_diffusion_backend.py
Three review findings on the resident-plan branch. The retry sat under 'if dense_mib > 0', but dense_mib is zero exactly when the prefetch capacity gate declined the base transformer/ shards, which is the fresh Qwen cache this PR was written for: fp8 wins, only int8 is published, so the load ran fp8 with no prequant and no dense fallback and dropped straight back to GGUF. Zero staged shards is not missing information, it means the dense build cannot run, so the retry now covers that case too. The retry also pinned a rung on existence alone. An int8 checkpoint can outweigh the Q4 GGUF that planned resident, so a host that fits the GGUF need not fit the rung retried into; the load would move it onto CUDA after eviction under a GGUF-sized budget. It is now resolved and replanned like the offload branch, and taken only when that plan is resident. Pinning the retry also overwrote the user's 'auto' request, and build_resolved_record calls anything but None/''/'auto' explicit, so status badged a backend decision as the user's own choice. The request is frozen before any retry and that is what provenance reads. Tests: the retry fires with zero staged shards; a rung that does not plan resident is declined and the GGUF stands; an auto pick that retried is still badged auto while a real int8 request is not relabelled. The first two fail against the previous shape.
|
Codex Review: Didn't find any major issues. Swish! 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". |
…s scheme Two problems the fp8 lift exposed. 1. resolve_dense_quant_candidate ran its download-space gate unconditionally, even though its own comment says a cached re-download is a no-op. The auto retry only ever proposes a rung whose checkpoint is ALREADY cached, so on a low-disk or moved-cache install the gate discarded exactly the candidate the retry exists to find and the pick fell back to the GGUF. Skip the gate when the prequant source is cached; an uncached one still trips it. 2. resolve_prequant_source returns a path source for ANY override without looking at the file, so with fp8 no longer denied for qwen-image, `auto` now picks fp8 and an allowlisted local INT8 checkpoint reads as an available fp8 prequant. Planning then skips staging the dense transformer, the loader hits the same metadata.scheme check it runs at load time, refuses the file, and with no dense fallback the pick silently drops to GGUF. usable_prequant_source now requires the override to be baked for the scheme being resolved. Reading that is cheap despite the file size: mmap plus map_location="meta" maps the storages instead of reading them, so only the pickle structure is parsed (measured 1.18s on a 34 GB checkpoint), cached on (path, mtime, size) because the auto ladder asks once per candidate. An unreadable checkpoint counts as unknown, so planning budgets dense. Three tests, all verified load-bearing against the unfixed code.
The cached-prequant excuse added in f5ce05a called prequant_checkpoint_cached without a cache_dir. Unpinned, cached_checkpoint_path searches only huggingface_hub's import-time constant, so after Studio's cache folder changes the retry proves the checkpoint cached in the LIVE root and this still called it uncached and re-applied the space gate. That defeats the moved-cache retry the excuse exists for, which is the same case the excuse was added to rescue. Both other call sites already pin hub_cache_dir(); this one now does too, via active_hf_hub_cache directly since importing diffusion here would be circular. Test asserts the root reaching the probe, and fails when the argument is dropped.
…he scheme memo on nanoseconds Two follow-ons to the cached-prequant excuse. prequant_checkpoint_cached only answers for hosted repos: _cached_in_root returns None for any kind other than "repo", so a `path` source always reported "not cached" and the space gate re-applied to a file the operator already has on disk. On a low-disk host that dropped the local rung back to GGUF. A path override downloads nothing, so it is cached by construction. The local scheme memo keyed on int(st_mtime), which truncates to seconds. The int8 and fp8 bakes of one model are the same size, so an atomic swap inside one second left the key unchanged and every later probe in that process reported the old scheme, which is the failure the scheme check exists to stop, inverted. st_mtime_ns instead.
|
Codex Review: Didn't find any major issues. Swish! 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". |
One conflict, in test_diffusion_backend.py, and it is positional rather than semantic: this branch appended the auto-retry-to-a-lower-scheme cases at the end of the file and main appended the download-plan cache cases at the same point. Both blocks kept. studio/backend/tests/test_diffusion_backend.py 209 passed
|
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
# Conflicts: # studio/backend/core/inference/diffusion.py # studio/backend/core/inference/diffusion_transformer_quant.py # studio/backend/tests/test_diffusion_transformer_quant.py
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7794421b58
ℹ️ 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".
| # gate used to run anyway, which discarded exactly the candidate the auto retry exists to find: | ||
| # that retry only ever proposes a rung whose checkpoint is already cached, so on a low-disk or | ||
| # moved-cache install every retry fell back to the GGUF despite a resident-fit local artifact. | ||
| if estimate is not None and not (estimate.prequant and prequant_cached): |
There was a problem hiding this comment.
Revalidate hosted cache hits before bypassing the disk gate
When a hosted checkpoint is cached but has since been republished under the same filename, this bypasses the free-space check even though _resolve_checkpoint_path deliberately calls hf_hub_download to revalidate the pointer and fetch the new multi-GB blob. On a cache volume with less than the checkpoint size plus the intended 10 GiB reserve, the next load can therefore fill the disk; only local overrides or immutable/revalidated hosted artifacts can safely skip this gate.
Useful? React with 👍 / 👎.
Why the deny existed, and why it no longer applies
_FAMILY_SCHEME_DENYrefused fp8 onqwen-image/qwen-image-editbecause the family rendered every frame black. The root cause was never the family: torchao's_choose_scale_float8has no eps clamp, and qwen's text stream emits all-zero token rows through a set oftxt_mlp.net.2linears that changes run to run, so the per-row activation scale went to 0 and the qdata to NaN._make_quant_confignow floors it:The deny was left behind on its old justification. This removes it.
Measured on both paths, not one
The deny gates
select_transformer_quant_scheme, so it governs the prequant checkpoint loader and on-the-flyquantize_. Checkpoint evidence alone would not have been enough, so both were measured on a B200 with the floor in place.Full 28-pair prequant accuracy gate, rebuilt checkpoint:
On-the-fly
quantize_transformer(mode="fp8"), using the gate's ownsimple_objectprompt at its own seeds and resolutions so the two are directly comparable:The bar is 0.10. For contrast, pre-floor plain fp8 measured LPIPS 0.712 with SSIM 0.016 and mean luma 0.
Keeping the deny cost real speed: it pinned qwen to int8 at 1.10x bf16 where compiled fp8 measures 1.21x.
What stays denied
mxfp8andnvfp4keep their entries. Those failures were activation outliers and the 4-bit noise floor respectively, not the zero-row bug, and nothing here touches them. A test asserts that auto still skips both and lands on int8 when fp8 is unavailable.The part that needed splitting
The deny table has a second consumer I did not expect:
core/training/diffusion_train_common.pycalls_family_deniedboth to build the Train UI's precision list and to hard-reject a run. Two tests failed and caught it.All the evidence above is rendering evidence. It shows a frozen fp8 forward reconstructs the bf16 image; it does not show a LoRA converges when its frozen linears are fp8, and nobody has run that. So training keeps refusing qwen fp8 through a new
_FAMILY_TRAIN_SCHEME_DENY, reached via_family_train_denied, which is a strict superset of the inference rule rather than a parallel table. Delete the entry once a training run is measured.test_the_training_deny_is_a_superset_of_the_inference_denypins the direction across every family and scheme, because training being more permissive than inference is the one way this split could go wrong.Tests
tests/test_diffusion_*.py tests/test_video_*.py1435 passed.hub/tests/175 passed, separate invocation.ruff checkclean.