Repository navigation
Report the precision actually in use, and refuse an explicit one we cannot honor - #8165
Conversation
…annot
The loader already knew the truth and threw it away at the API boundary. Status
reported the ENGAGED transformer / text-encoder precision, but nothing echoed
back what the caller ASKED for, so once a fallback happened the request was
gone: the Advanced panel kept its dropdown on FP8 while a Q4_K_M GGUF ran, the
"Auto: X" badge was suppressed for exactly the case that needed it
(source !== "auto" rendered nothing), and a successfully generated image or
saved clip carried no evidence of the precision behind it.
Backend
- DiffusionResolvedControl gains `requested` (the raw ask, null when left to the
backend) and `status` ("applied" | "fell_back" | "unsupported") beside the
existing value/source/reason. Both default, so an older payload still parses.
- build_resolved_record keeps the request beside the engaged value and derives a
mismatch for the controls that answer in the vocabulary they are asked in.
memory_mode and attention_backend do not, so they are classified by the call
site instead of compared blindly.
- Every transformer decline site now records WHY, in the caller's terms: an
uncached hosted prequant, a re-plan that still needs offload, a dense-fit
miss, a failed quant build, an unsupported scheme, and the wrong load kind.
- quantize_text_encoders returns a TEQuantOutcome (mode + reason + status). The
int8 -> fp8 downgrade, the offload skip and the unsupported-device path were
all bare `return None`; the last one had no log line at all.
- Explicit precision fails closed. Host-level impossibilities are refused in
begin_load, so /images/load and /video/load answer 409 before anything is
evicted; footprint-dependent declines raise inside the load and surface on
load-progress. `auto` still falls back silently, and
UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK=1 restores the old behaviour.
- Saved output metadata: images add text_encoder_quant / memory_mode /
offload_policy; video clips gain the whole build block images already had.
All read from the engaged state, none added to the required-key sets, so
older PNGs and sidecars still list.
Frontend
- resolved-precision.ts holds the badge/select decisions as pure functions. A
declined request now renders "FP8 -> OFF" in a warning tone with the reason in
the tooltip, instead of nothing.
- The Advanced selects reseed from the loaded build, so a declined scheme stops
advertising itself, and a "Loaded build" summary reports the transformer and
text-encoder precision plus the memory mode and resolved offload behaviour.
- A 409 refusal is surfaced as a titled, actionable toast; transformer_quant is
no longer sent for load kinds that cannot use it.
The 409 exists to preserve two things: the chat model holding the GPU, and the several GB the load would otherwise pull down before failing. The check was made in begin_load, which is too late for both. begin_load runs inside acquire_for, and acquire_for evicts the current owner under the arbiter lock BEFORE it runs the register callback. On the image path it also runs after select_and_activate_engine, which unloads the resident model on an engine switch. So an impossible explicit precision was refused having already destroyed exactly what the refusal was meant to protect: the user got a 409 and an empty GPU. Both checks are now made by the route, alongside the sibling refusals that already run there (the unloadable pick, the gated companion), and before the device is taken. The copy in begin_load stays, since it is the load path's own invariant and other callers reach it directly. Diffusers only, on the image path. The native sd.cpp engine accepts transformer_quant / text_encoder_quant for interface parity and ignores them, so gating that path on a torchao capability would refuse loads that work today. A probe failure leaves pending_name None and skips the route check, which is the pre-existing behaviour rather than a new one. `auto` is never refused, so a caller that left the precision to the backend cannot reach any of this.
Two separate ways the resolved record was read too literally. The reseed effect keyed on JSON.stringify(resolved). That record is not load-time-only: the backend rewrites entries of it during GENERATION. speed_mode and attention_backend change when the deferred compile profile engages on the 3rd image, and transformer_cache changes whenever the step-cache threshold flips. Each of those moved the key with no load behind it, so the effect re-ran and overwrote a Precision the user had picked but not yet loaded. An edit made after a load is meant to survive until the next LOAD replaces it. resolvedSeedKey covers only the three controls the effect actually writes, and for attention only the request side, since that is the field the reseed reads for an auto or honored request and the one a rewrite leaves alone. A real reload still re-fires: it always moves a request or an engaged value on one of the three. isResolvedHonored treated every status that was not "applied" as a decline. `status` is typed wider than the backend's union on purpose, so a newer backend can add a value, but that reading threw the tolerance away: an unknown status painted a red "FP8 -> FP8" over a request that was honored, and on memory_mode (asked "low_vram", answered "sequential") a "LOW_VRAM -> SEQUENTIAL" that never happened. Only the two statuses that mean a decline are now read as one. Staying quiet is the safe direction, since the build that adds a status ships the frontend that understands it.
… one Two things the fail-closed 409 made load-bearing that were fine while a declined explicit scheme fell back quietly. select_transformer_quant_scheme answers None for three different faults and the refusal reported all of them as "'fp8' is not usable for family 'X' on this GPU". Measured here on a B200: torchao could not import at all (cannot import name 'ScalingType' from torch.nn.functional, a torch/torchao version skew), the smoke probe swallowed that, and every explicit scheme was refused with a message blaming Blackwell hardware that runs all of them. A skew is fixed by a pip install; a GPU limit is not; a family the accuracy gate rules out is neither. explain_unusable_ scheme separates the three, shared by the image and video resolvers so they cannot drift. The smoke probe also cached an out-of-memory as a verdict on the scheme. That probe now runs on the ROUTE thread, which is the point of raising the refusal before the GPU handoff, so it meets a full GPU by design: the resident chat model has not been evicted yet. One transient OOM therefore refused that scheme for the rest of the process, on a host that runs it fine seconds later. Allocator failures are no longer remembered; every other failure still is, because those really are properties of the build. torch.OutOfMemoryError subclasses RuntimeError rather than MemoryError and has moved between torch and torch.cuda, so both names are tried with the message as the backstop.
The dependency is no longer the serialized record; it is the load-time projection of it, which is the whole point of the previous commit.
The native engine was exempt from the precision gate, on the grounds that refusing there would break loads that work today. But the loads it works for are exactly the silent mismatch this change exists to remove: sd.cpp accepts transformer_quant and text_encoder_quant for interface parity, ignores them, and reports null, so an explicit FP8 succeeded having quantised nothing. The diffusers path already refuses on the same CPU-only host, so the exemption also left the two engines disagreeing about one request. It now refuses, with a message naming the engine; auto, none and an omitted value still pass through untouched, and the existing escape hatch waives it. The Loaded build panel labelled any non-GGUF load BF16, but a single-file safetensors keeps whatever precision it was saved in and FP8 checkpoints are explicitly supported, so the one panel whose job is to say what actually loaded was asserting a wrong number. It reads "As in checkpoint" for single_file now, on the video page as well. And the video loader rewrites an omitted transformer_quant to "off" under speed_mode="off" before building the resolved record, so the record claimed the user had pinned bf16: the Auto badge disappeared and the Precision select reseeded to none, leaving quantisation pinned off after a Speed change and reload. The raw request is captured before the rewrite and reported. Four tests, each confirmed against a mutation.
- text-encoder quant that cast one encoder and not its sibling reported "applied" and both loaders let the load through, recording the requested mode while conditioning ran off a mixture; it is now reported as a fallback and refused like any other declined explicit precision. - the refusal message pointed users at "Choose Auto" for text_encoder_quant, which both request models reject, so following it returned a 422. - the native sd.cpp engine reports dtype "gguf" and no model_kind, so the Loaded build panel labelled every native checkpoint BF16; the label rule is now one shared helper covering both pages. - native generation results carried no offload state, so every native image recipe persisted it as null. - the video load route probed CUDA precision before the training guard, which allocated next to a training subprocess for a load about to be refused. - a smoke-probe OOM before the arbiter eviction is not a verdict on the scheme, but it reached the new route gate as one and refused the load the eviction was about to make room for. - the torchao import error is interpolated into the 409 detail and names the absolute file that raised it; paths are stripped there and logged in full.
# Conflicts: # studio/frontend/src/features/images/images-page.tsx # studio/frontend/src/features/video/video-page.tsx
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d308531391
ℹ️ 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".
| # run. Mirrors what the image gallery already records. | ||
| "model_kind": state.kind, | ||
| "gguf_filename": state.gguf_filename, | ||
| "transformer_quant": state.transformer_quant, |
There was a problem hiding this comment.
Persist the dense dtype in saved build metadata
For a pipeline or single-file load where no torchao quant engages, transformer_quant is null and the actual precision is only available in state.dtype; that can be fp16 or fp32 on CPU, older accelerators, and fp16-incompatible families rather than bf16. The new gallery metadata persists the kind and quant scheme but drops this dtype, so after unload, outputs produced from the same repo at different dense precisions remain indistinguishable and the recipe cannot report what actually ran. Include the engaged dtype in the generation result and gallery models for both video and image records.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The dense dtype is already stated by the Loaded-build panel while the model is resident, and adding a new persisted gallery field is a reporting-granularity extension rather than a correctness bug on legitimate input. Happy to revisit if a recipe replay is shown to pick the wrong dtype.
| model_kind?: string | null; | ||
| dtype?: string | null; | ||
| }): string { | ||
| if (status.model_kind === "gguf" || status.dtype === "gguf") return "GGUF (as-is)"; |
There was a problem hiding this comment.
Expose the GGUF scheme in the actual-precision row
For every GGUF load with no dense fast-path quant, this helper collapses the actual transformer precision to GGUF (as-is). A Q4_K_M and Q8_0 checkpoint from the same repo therefore produce the identical value in the new “what actually ran” panel, and externally initiated or native loads cannot be disambiguated from local picker state because status does not expose gguf_filename. Carry the loaded filename or parsed GGUF scheme in status and render it here so the actual-precision row identifies the checkpoint precision.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The actual-precision row reports the engaged scheme; naming the specific GGUF quantisation scheme alongside it is extra detail, not a wrong value, and the File row already names the checkpoint that carries it. Out of scope for this PR.
Three places reported or refused a precision that was not the one the runtime would use. The load route asked predict_engine which gate to apply, and a probe failure left pending_name None, skipping both arms. Selection could then land on sd.cpp anyway, which accepts the knobs and ignores them, so an explicit fp8 loaded, quantised nothing and reported null. The gate is now re-asked of the engine that was actually activated, and only when the prediction missed, so a correct one is never paid twice. quantize_text_encoders rewrites an int8 request to layerwise fp8 on any family with no keep-bf16 schedule, and that path needs no torchao. Both precision asserts consulted te_quant_supported about the raw int8 and so refused loads the runtime would run and report as fell_back. New effective_te_quant() resolves the downgrade before support is consulted. The Recipe popover's Memory row substituted "auto" for a null memory_mode, which is what the native engine always records, claiming the memory planner had picked a mode on the one path that never runs it. An absent mode now reports the offload alone.
…ion live An explicit dense precision with Memory=balanced/low_vram (or the legacy cpu_offload flag) is incompatible on its face: those requests name their offload policy without measuring anything, offload hooks move modules with Module.to(), and torchao tensors do not survive it, so the loader skips the dense build. The strict refusal then landed after the resident image model had been torn down. The pre-handoff gate now takes the memory request and refuses the pair before the GPU is acquired. fast and auto are decided from the measured footprint and are untouched. The video page's loadOrStage is memoized on [stage, pickGuard], so its plain capture of transformerQuant froze at whatever was selected when the callback was built. The ordinary auto to FP8 change then asked the plan with no precision, skipping the pre-download refusal, and staged tens of GB before the load rejected the same pick. It reads through a ref now, the same way handleLoad already does.
The pre-handoff gate refused an offload-bound dense transformer quant but not the two adjacent cases. quantize_text_encoders reports the torchao encoder modes (int8, fp8_dynamic, nvfp4) unsupported once offload is active, for the same reason: the hooks move modules with Module.to() and those tensor subclasses do not survive it. The image gate now refuses them alongside an offload-forcing memory request. Layerwise fp8 is a dtype cast and is untouched. assert_video_precision_available took no memory request at all, so a video load with an explicit precision and balanced or low_vram passed the route preflight and was refused inside load_pipeline, after acquire_for and the teardown had evicted the resident model. It takes memory_mode now and applies both rules.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 747918c82c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| hf_token: hfApiToken(getHfToken()), | ||
| // And the same precision, for the same reason: the plan refuses a scheme this host | ||
| // cannot honour, so omitting it staged tens of GB of weights and left the refusal to | ||
| // the load afterwards. Sent under the identical pipeline-only rule handleLoad applies. | ||
| transformer_quant: | ||
| opts.kind === "pipeline" && transformerQuantRef.current !== "auto" | ||
| ? transformerQuantRef.current | ||
| : undefined, |
There was a problem hiding this comment.
Include memory mode in staged video plans
When a not-yet-downloaded video pipeline is staged with Precision set to an explicit scheme and Memory set to balanced or low_vram, this /video/download-plan payload sends the precision but still omits memory_mode. The route-side precision gate only refuses that incompatible combination when request.memory_mode is present, while handleLoad later does send the memory mode and gets the 409; as a result the UI can still stage tens of GB of weights before failing, which is the plan-time regression this change is trying to avoid. Send the same memory mode here that loadVideoModel sends (using a live ref like the precision).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b59d4f9. The plan payload sends memory_mode, read through memoryModeRef.current for the same reason the precision is. Test: 'the staged plan carries the memory request too'.
| # where the torchao stub kills int8 while fp8 still works. | ||
| te_effective = effective_te_quant(te_mode, getattr(fam, "name", None)) | ||
| te_reason = None | ||
| if te_effective is not None and not te_quant_supported(target, te_effective): |
There was a problem hiding this comment.
Refuse broken torchao before text-encoder loads
For an explicit text_encoder_quant=fp8_dynamic, int8, or nvfp4 on a CUDA/bf16 host with a broken or unimportable torchao install, this preflight passes because te_quant_supported() only checks the device/dtype/capability (and the Windows ROCm stub) but never verifies that torchao imports. The actual caster imports torchao only after the pipeline has been downloaded and built, so the new strict contract still fails late through load-progress instead of returning the intended pre-load 409. Check the torchao availability for the torchao-backed TE modes before accepting the request.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b59d4f9. New torchao_quantize_importable() actually imports torchao.quantization.quantize_ (and rejects the ROCm stub), cached per process, and both precision gates consult it for the torchao-backed encoder modes before accepting the request. Layerwise fp8 is a dtype cast and does not need it. Tests: test_a_broken_torchao_refuses_a_torchao_text_encoder_before_the_download (int8, fp8_dynamic, nvfp4) and test_layerwise_fp8_does_not_need_torchao.
… memory request te_quant_supported only asks the device: a CUDA bf16 host with a broken or absent torchao passed every capability check, and the casters import torchao only after the pipeline has been downloaded and built, so the refusal came through load-progress instead of the pre-load 409. Both gates now ask torchao_quantize_importable() for the torchao-backed encoder modes. Layerwise fp8 is a plain dtype cast and does not need it. The video staged plan sent the precision but not the memory mode, and the route refuses the incompatible pair only when it can see both -- so the plan succeeded and tens of GB were staged before /video/load rejected the same pick. It reads the memory mode through a live ref, like the precision.
|
@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". |
|
Ran this on a B200 with Studio installed twice from clean trees, Left, "transformer_quant": {"value": "off", "source": "explicit", "reason": "not engaged (GGUF transformer loaded)"}which the old Right, this branch: the same click returns 409 and nothing loads. Same branch, same model and file, Precision FP8 with Memory Auto, which this host can honour: The load succeeds, status reports "transformer_quant": {"value": "fp8", "requested": "fp8", "source": "explicit", "status": "applied", "reason": "engaged on the dense fast path"}and the new Loaded build panel reads Transformer FP8, Text encoder BF16, Memory |
…fusal (#8257) Four tests are red on a clean checkout of main. #8165 made a declined EXPLICIT precision refuse the load instead of falling back silently, and made the text-encoder pass return a TEQuantOutcome the loader reads .mode off. Two later squash merges carried branches cut before it: #8162 added the saved-recipe precision contracts, and #8141 added a placement test whose stub returns a bare None. Neither combination was ever run. Fixed on the test side. quantize_text_encoders is annotated -> TEQuantOutcome and every one of its seven returns constructs one, so the None at diffusion.py:3113 only exists because a test monkeypatches the function; and the route only calls assert_precision_available on the diffusers engine, which is DiffusionBackend, which defines it. Neither AttributeError is reachable in a real run, so there is no product guard to add. - opt into UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK where the contract is about what the recipe records once a fallback is allowed, as the routes, backend and video suites already do - assert the decline reason #8165 records instead of the old wording naming what loaded instead. The substantive pair is untouched: off, from explicit - give _EngagedBackend the assert_precision_available gate the route now calls, and return a TEQuantOutcome from the stubbed text-encoder pass
…fusal (#8257) Four tests are red on a clean checkout of main. #8165 made a declined EXPLICIT precision refuse the load instead of falling back silently, and made the text-encoder pass return a TEQuantOutcome the loader reads .mode off. Two later squash merges carried branches cut before it: #8162 added the saved-recipe precision contracts, and #8141 added a placement test whose stub returns a bare None. Neither combination was ever run. Fixed on the test side. quantize_text_encoders is annotated -> TEQuantOutcome and every one of its seven returns constructs one, so the None at diffusion.py:3113 only exists because a test monkeypatches the function; and the route only calls assert_precision_available on the diffusers engine, which is DiffusionBackend, which defines it. Neither AttributeError is reachable in a real run, so there is no product guard to add. - opt into UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK where the contract is about what the recipe records once a fallback is allowed, as the routes, backend and video suites already do - assert the decline reason #8165 records instead of the old wording naming what loaded instead. The substantive pair is untouched: off, from explicit - give _EngagedBackend the assert_precision_available gate the route now calls, and return a TEQuantOutcome from the stubbed text-encoder pass


Summary
The interface can report a precision that is not the one in use. It can show FP8 while the loaded model is a Q4_K_M GGUF with transformer FP8 disabled, and show BF16 on a video while NVFP4 is actually active. A successfully generated image therefore does not prove the requested precision was used.
The backend already knows the truth and discards it at the API boundary. Status carries the engaged value only; nothing echoes the request, so once a fallback happens the request is gone.
ResolvedBadgethen bails onsource !== "auto", and the dropdown is pure local request state, so an explicit FP8 that the backend declines renders no badge at all while the control still reads FP8. The auto path was honest; the explicit path was silently wrong.An external QA pass asked for three things: show both requested and actual precision for the transformer and the text encoder along with memory mode, offload behaviour and any fallback reason; warn or stop the run when the request cannot be honored; and never label a saved output with the wrong precision.
New API contract
DiffusionResolvedControl, used by both image and video status underresolved:Purely additive, both new fields default, so an older payload still validates and an older client ignores them. The image
resolvedrecord gains atext_encoder_quantentry; video already had one.Fail-closed: an explicit, non-auto, non-off precision that cannot be honored is refused. Host-level impossibilities (wrong load kind, no CUDA or bf16, a scheme ruled out by GPU or family deny-list, an encoder mode the device cannot cast) raise in
begin_load, so/images/loadand/video/loadreturn 409 with the reason. Footprint-dependent declines can only be found mid-load and surface asload-progress.phase == "error"with the same message. Auto still falls back silently, which is correct and unchanged.UNSLOTH_DIFFUSION_ALLOW_PRECISION_FALLBACK=1restores the old behaviour.Every silent decline site now records a reason: the four in
diffusion.py, the offload skip invideo.py, and the text-encoder int8-to-fp8 downgrade and offload no-op indiffusion_precision.py, whose unsupported-device path previously did not log at all.Gallery metadata gains
text_encoder_quant,memory_modeandoffload_policyon images, andmodel_kind,gguf_filename,transformer_quant,text_encoder_quant,memory_modeandoffload_policyon video, which recorded no precision whatsoever. All optional, all from engaged state, and neither_REQUIRED_METAset changed so old PNGs and sidecars still list.Supporting measurement
A related question was whether Auto should prefer NVFP4. Benchmarking the schemes on a B200 at 1024x1024, 8 steps, median of 5 runs after 2 warm-ups, with every arm verified as actually engaged:
NVFP4 is the slowest engaged scheme on both models, which corroborates the RTX 5090 observation on a different Blackwell part. So
_AUTO_LADDERis right to exclude it and this change does not touch it. What the numbers do argue is the fail-closed behaviour above: the GGUF fallback is 2.6x to 2.9x slower than bf16 and on Klein uses more memory than NVFP4, so silently landing there is not a neutral outcome.Note this is B200 (sm_100), not the 5090 (sm_120), so it supports the ordering rather than reproducing their absolute numbers. NVFP4 run-to-run variance did not reproduce; it was among the most stable arms here.
Testing
The single failure is pre-existing and unrelated,
sqlite-vecmissing for a RAG test; it fails identically on the unmodified tree. Frontend typecheck clean, 911 tests pass, 11 of them new. Cross-platform CI green on ubuntu, macOS and Windows.Self-review findings
scripts/image_speedmem_bench.pycallsquantize_text_encodersand sits outsidestudio/, so the first caller sweep missed it. It would have stored the whole tuple as the engaged mode._LoadStateis frozen; theresolvedrefresh in_engage_deferred_speedneedsobject.__setattr__."none"or"off"was initially classifiedfell_back. The ask was honored, since the GGUF build is what "off" means, so it isapplied.requested !== valuebadge rule would flag every honoredmemory_moderequest, since it asks for a mode and engages a policy. The backend now classifies withstatusand the frontend trusts it, falling back to the string compare only for older backends.Notes
npm run lintgoes from 34 to 36 errors on the two pages, bothreact-hooks/set-state-in-effecton the reseed effects, matching 10 pre-existing instances of the same rule in the same two files, which already fail lint at baseline.Merge order
This should land after #8141, which adds a
streamingoffload policy touching the same three files. They merge cleanly, but #8141's new test monkeypatchesquantize_text_encodersto returnNone, and this change makes it return aTEQuantOutcome, so the merged tree needs a two-line test fix that belongs here rather than there. Reviewed in detail; no other interaction.