Repository navigation
Studio: take the hosted pre-cast fp8 text encoder by default on Qwen-Image-2.1 - #11539
Conversation
…Image-2.1 Loading Qwen-Image-2.1 with the INT8 denoiser still cost about 26 GB, because INT8 only quantises the transformer. On this family the transformer is not the big component: the Qwen3-VL-8B text encoder is 16.33 GiB dense against 6.76 GiB for the INT8 transformer, and it was loading dense on every default request. unsloth/Qwen-Image-2.1-FP8 has hosted a pre-cast encoder all along (Qwen-Image-2.1-text_encoder-FP8.safetensors, 8.75 GiB) and the family already pointed at it through te_prequant_repos, but nothing could reach it: text_encoder_quant defaults to None, and the hosted artifact is only consulted once a request normalises to fp8. The file was unreachable by default. Give DiffusionFamily a te_quant_auto field and resolve the text-encoder request as a tri-state, the same shape the transformer control and MiniMax-H3 already use: unset or "auto" takes the family's scheme, "none"/"off" pins the released bf16 encoder, an explicit scheme pins itself. Only qwen-image-2.1 opts in here. The other families that host fp8 encoders keep today's behaviour, because those encoders are different models (T5, CLIP, Gemma) and fp8 tolerance does not transfer between them; each wants its own measurement first. Three details that are not incidental: - The refusal path reads the RAW request. An auto-selected scheme that fails to engage must fall back to dense quietly, since nobody asked for it; refusing would turn a working load into an error the caller cannot attribute. - The download plan and the size estimate resolve through the same tri-state, so a family whose unset request takes the hosted encoder does not stage the dense shards it is about to not open. - Status reports the raw request alongside the engaged scheme and annotates an automatic pick, so the badge cannot show a scheme the caller never typed as though they had pinned it. Measured on Qwen-Image-2.1, INT8 denoiser both arms, 16 prompts at 1024 with 40 steps and matched seeds: encoder bytes resident peak encoder load dense bf16 (before) 16.33 GiB 23.74 GiB 30.46 GiB 11.6 s hosted fp8 (after) 8.75 GiB 16.16 GiB 22.87 GiB 1.5 s Per-image render time is unchanged (median 8.93 s against 8.95 s). Against a bf16 transformer plus bf16 encoder reference on the same seeds, the INT8 denoiser alone is LPIPS 0.0439 / SSIM 0.9564, and with the fp8 encoder it is LPIPS 0.0794 / SSIM 0.9299. The encoder cast re-rolls the sample rather than reproducing it, so that is a real change and not a free swap, in exchange for 7.58 GiB.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 09e2056a24
ℹ️ 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".
| text_encoder_quant, text_encoder_quant_auto = resolve_te_quant_request( | ||
| text_encoder_quant, getattr(fam, "te_quant_auto", None) | ||
| ) |
There was a problem hiding this comment.
Expose a dense opt-out before enabling the FP8 default
For Qwen-Image-2.1, every omitted request now resolves to FP8, but the product's public surfaces cannot send the documented opt-out: DiffusionLoadRequest.text_encoder_quant in studio/backend/models/inference.py rejects both "none" and "off", while the Images UI in studio/frontend/src/features/images/images-page.tsx offers only Default—which omits this field—and quantized modes. Consequently users cannot restore the released bf16 encoder through the API or UI even though this default measurably changes output quality; add the dense spellings to the request schema and a corresponding UI option before treating omission as FP8.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct on both surfaces, and it contradicted a claim in my own description. DiffusionLoadRequest.text_encoder_quant was Literal["fp8", "fp8_dynamic", "int8", "nvfp4"], so none and off were 422s, and the Images advanced panel listed Default plus the four schemes and nothing else. While Default meant bf16 everywhere, omitting the field WAS the dense request; once an omitted request can resolve to a family scheme that spelling stops meaning dense, and on Qwen-Image-2.1 there was then no way back to the released encoder through either surface.
Fixed in 8fb6d3b: the request Literal gains auto/none/off, matching VideoLoadRequest which already carries them for the MiniMax-H3 tri-state; the picker gains a Dense (bf16) option; the hand-written TS request type in features/images/api.ts mirrored the old list and is widened too, so the option typechecks. The hint now says what Default does on 2.1.
The new test goes through DiffusionLoadRequest rather than normalize_te_quant, which is the gap that let this through: the normaliser already accepted these spellings, so my original test passed while the API boundary rejected them.
…s not it With an omitted text_encoder_quant meaning the family's scheme, omitting the field stopped being the way to ask for the released bf16 encoder, and neither public surface could send the replacement. DiffusionLoadRequest accepted only fp8/fp8_dynamic/int8/nvfp4, so 'none' and 'off' were 422s, and the Images advanced panel offered Default plus the quantised modes and nothing else. On Qwen-Image-2.1 that left no way back to the encoder the model shipped with. Widen the request Literal to auto/none/off alongside the schemes, matching VideoLoadRequest which already carries them for the MiniMax-H3 tri-state, add a Dense (bf16) option to the picker, and widen the hand-written TS request type that mirrored the old list. The hint now says what Default does on 2.1. The new test goes through DiffusionLoadRequest rather than normalize_te_quant: the normaliser already accepted these spellings, which is exactly why the gap reached the API boundary unnoticed.
|
@codex review |
|
@codex security review |
|
@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: 8fb6d3b66b
ℹ️ 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".
| ["auto", "Default"], | ||
| // The opt-out. Reachable only since a family default can pick a scheme on its own: with | ||
| // "Default" meaning bf16 everywhere, omitting the field WAS the dense request. | ||
| ["none", "Dense (bf16)"], |
There was a problem hiding this comment.
Keep the dense selection after loading
When a user selects Dense, the backend returns an honored explicit request of "none", but the loaded-build reseed mapper at lines 2377–2381 still translates none/off to "auto". The dropdown therefore snaps back to Default immediately after the dense load, and a subsequent Reapply or model switch omits text_encoder_quant, silently restoring Qwen-Image-2.1's FP8 default and changing output quality. Add none to that mapper's option vocabulary and reserve auto for genuinely automatic records.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and reproduced. The mapper folded the engaged off/none into the select's Default option, which was right while Default meant bf16 (a declined or dense load reseeding to Default described what ran) and is wrong now that Default means the family chooses. Fixed in a6daaf2 by mapping off to the none option, exactly as the transformer_quant mapper directly above it already does.
One detail worth recording, because the obvious version of this fix introduces the inverse bug: resolvedSelectValue collapses a null request to the literal string none (if (source === null) return toOption("none")), so a vocabulary mapping none to Dense could reseed an AUTOMATIC fp8 pick as Dense and pin it on the next load. It does not, because build_resolved_record sets source: "auto" whenever the request was unset and resolvedSelectValue early-returns toOption("auto") for that before the null path is reached. Both directions now have a test in tests/resolved-precision.test.ts: an unset request reseeds as Default even when fp8 engaged, and a pinned dense request reseeds as Dense, as does a declined scheme that ran dense.
The loaded-build reseed mapper folded the engaged 'off'/'none' into the select's Default option. That was right while Default meant bf16: a declined or dense load reseeding to Default described what ran. It is wrong now that Default means the family chooses, because the select snapped back to Default after a dense load and the next Reapply or model switch omitted text_encoder_quant, silently restoring Qwen-Image-2.1's fp8 encoder and changing output. Map 'off' to the select's none option instead, exactly as the transformer_quant mapper directly above already does. The naive version of this fix introduces the inverse bug, which is why both directions are tested. resolvedSelectValue collapses a null request to the literal string 'none', so a vocabulary that maps 'none' to Dense would reseed an AUTOMATIC fp8 pick as Dense and pin it on the next load. It does not, because build_resolved_record sets source='auto' whenever the request was unset and resolvedSelectValue early-returns Default for that before the null path is reached. The first new test asserts that end to end rather than trusting the early return to stay put; the second covers the reported case and a declined scheme, which must also read as what actually ran.
Chat UI Tests (extra) fails the declined leg of playwright_image_text_encoder.py on main: the select reads Dense (bf16) where the driver expects Default. unslothai#11539, whose own Chat UI legs were cancelled, made that change on purpose: once a family default can pick a scheme, Default no longer means dense, so an engaged "off" maps to the Dense option. The driver's own rule is that the select shows what ran, and a decline runs the dense encoder.
…Image-2.1 (unslothai#11539) * Studio: take the hosted pre-cast fp8 text encoder by default on Qwen-Image-2.1 Loading Qwen-Image-2.1 with the INT8 denoiser still cost about 26 GB, because INT8 only quantises the transformer. On this family the transformer is not the big component: the Qwen3-VL-8B text encoder is 16.33 GiB dense against 6.76 GiB for the INT8 transformer, and it was loading dense on every default request. unsloth/Qwen-Image-2.1-FP8 has hosted a pre-cast encoder all along (Qwen-Image-2.1-text_encoder-FP8.safetensors, 8.75 GiB) and the family already pointed at it through te_prequant_repos, but nothing could reach it: text_encoder_quant defaults to None, and the hosted artifact is only consulted once a request normalises to fp8. The file was unreachable by default. Give DiffusionFamily a te_quant_auto field and resolve the text-encoder request as a tri-state, the same shape the transformer control and MiniMax-H3 already use: unset or "auto" takes the family's scheme, "none"/"off" pins the released bf16 encoder, an explicit scheme pins itself. Only qwen-image-2.1 opts in here. The other families that host fp8 encoders keep today's behaviour, because those encoders are different models (T5, CLIP, Gemma) and fp8 tolerance does not transfer between them; each wants its own measurement first. Three details that are not incidental: - The refusal path reads the RAW request. An auto-selected scheme that fails to engage must fall back to dense quietly, since nobody asked for it; refusing would turn a working load into an error the caller cannot attribute. - The download plan and the size estimate resolve through the same tri-state, so a family whose unset request takes the hosted encoder does not stage the dense shards it is about to not open. - Status reports the raw request alongside the engaged scheme and annotates an automatic pick, so the badge cannot show a scheme the caller never typed as though they had pinned it. Measured on Qwen-Image-2.1, INT8 denoiser both arms, 16 prompts at 1024 with 40 steps and matched seeds: encoder bytes resident peak encoder load dense bf16 (before) 16.33 GiB 23.74 GiB 30.46 GiB 11.6 s hosted fp8 (after) 8.75 GiB 16.16 GiB 22.87 GiB 1.5 s Per-image render time is unchanged (median 8.93 s against 8.95 s). Against a bf16 transformer plus bf16 encoder reference on the same seeds, the INT8 denoiser alone is LPIPS 0.0439 / SSIM 0.9564, and with the fp8 encoder it is LPIPS 0.0794 / SSIM 0.9299. The encoder cast re-rolls the sample rather than reproducing it, so that is a real change and not a free swap, in exchange for 7.58 GiB. * Make the dense bf16 encoder requestable now that an omitted request is not it With an omitted text_encoder_quant meaning the family's scheme, omitting the field stopped being the way to ask for the released bf16 encoder, and neither public surface could send the replacement. DiffusionLoadRequest accepted only fp8/fp8_dynamic/int8/nvfp4, so 'none' and 'off' were 422s, and the Images advanced panel offered Default plus the quantised modes and nothing else. On Qwen-Image-2.1 that left no way back to the encoder the model shipped with. Widen the request Literal to auto/none/off alongside the schemes, matching VideoLoadRequest which already carries them for the MiniMax-H3 tri-state, add a Dense (bf16) option to the picker, and widen the hand-written TS request type that mirrored the old list. The hint now says what Default does on 2.1. The new test goes through DiffusionLoadRequest rather than normalize_te_quant: the normaliser already accepted these spellings, which is exactly why the gap reached the API boundary unnoticed. * Reseed a pinned dense encoder as Dense, not as Default The loaded-build reseed mapper folded the engaged 'off'/'none' into the select's Default option. That was right while Default meant bf16: a declined or dense load reseeding to Default described what ran. It is wrong now that Default means the family chooses, because the select snapped back to Default after a dense load and the next Reapply or model switch omitted text_encoder_quant, silently restoring Qwen-Image-2.1's fp8 encoder and changing output. Map 'off' to the select's none option instead, exactly as the transformer_quant mapper directly above already does. The naive version of this fix introduces the inverse bug, which is why both directions are tested. resolvedSelectValue collapses a null request to the literal string 'none', so a vocabulary that maps 'none' to Dense would reseed an AUTOMATIC fp8 pick as Dense and pin it on the next load. It does not, because build_resolved_record sets source='auto' whenever the request was unset and resolvedSelectValue early-returns Default for that before the null path is reached. The first new test asserts that end to end rather than trusting the early return to stay put; the second covers the reported case and a declined scheme, which must also read as what actually ran.
Chat UI Tests (extra) fails the declined leg of playwright_image_text_encoder.py on main: the select reads Dense (bf16) where the driver expects Default. unslothai#11539, whose own Chat UI legs were cancelled, made that change on purpose: once a family default can pick a scheme, Default no longer means dense, so an engaged "off" maps to the Dense option. The driver's own rule is that the select shows what ran, and a decline runs the dense encoder.
The problem
Loading Qwen-Image-2.1 with the INT8 denoiser still costs about 26 GB. INT8 only quantises the transformer, and on this family the transformer is not the big component:
The encoder is 2.4x the size of the quantised denoiser, and nothing was quantising it.
unsloth/Qwen-Image-2.1-FP8has hosted a pre-cast encoder all along,Qwen-Image-2.1-text_encoder-FP8.safetensorsat 8.75 GiB, and the family already points at it throughte_prequant_repos. Nothing could reach it:text_encoder_quantdefaults toNone, and the hosted artifact is only consulted once a request normalises tofp8. The resolver works fine when you ask it:So the file was published, wired and unreachable by default.
The change
DiffusionFamilygets ate_quant_autofield, and the text-encoder request becomes a tri-state with the same shape the transformer control and MiniMax-H3 already use:"auto"takes the family's scheme"none"/"off"pins the released bf16 encoderOnly
qwen-image-2.1opts in. The other families that host fp8 encoders keep today's behaviour: those encoders are different models (T5, CLIP, Gemma) and fp8 tolerance does not transfer between them, so each wants its own measurement before it joins.Three details that are not incidental:
Measured
Qwen-Image-2.1, INT8 denoiser on both arms, 16 prompts at 1024 with 40 steps and matched seeds, one B200:
7.58 GiB and 10 s off the load, with per-image render time unchanged: median 8.93 s before against 8.95 s after. The before arm reproduced an earlier independent run to the digit (30.458974838256836 GiB), so the pair is a clean differential.
Against a bf16 transformer plus bf16 encoder reference rendered on the same seeds:
The encoder cast re-rolls the sample rather than reproducing it. That is a real change and not a free swap: it roughly doubles a deviation that choosing INT8 already accepted, in exchange for 7.58 GiB. No NaN, no black frames, no failure at the model's own schedule. Anyone who wants the released encoder back sets
text_encoder_quanttononeoroff, which this keeps working and has a test.Tests
New in
test_diffusion_precision.py:""/"auto"are the only spellings that invite a family default, andnone/off/ an explicit scheme are notNew in
test_diffusion_te_prequant.py:te_quant_autoscheme is one we actually host a pre-cast encoder for, which catches a family opting in before its artifact is publishedunsloth/Qwen-Image-2.1-FP8and the exact safetensors filenametest_diffusion_precision.pyandtest_diffusion_te_prequant.pyare 80 passed. The wider backend selection (-k "diffusion or precision or prequant or memory or contract or image") is 6427 passed with 21 failures, and all 21 reproduce unchanged on the parent commit on this host:test_diffusion_arch_patches.py, the bitsandbytes optimiser state test andtest_native_audio.pyare failing for local CUDA and missing-module reasons that predate this branch.The option this adds
Two isolated Studio installs, BEFORE at the merge base
b7aca5553and AFTER at8fb6d3b66, same scene driven against both. The Images advanced panel's Text encoder precision select goes from five options to six:Dense (bf16)is inserted underDefault, and the four scheme rows are unchanged and in the same order, which is the control for the pair. Read from the same servers photographed,option_count5 to 6 andhas_dense_optionfalse to true.That option is the point of the change rather than a cosmetic addition: with an omitted request now resolving to the family's own scheme,
Defaultno longer means bf16, so the released encoder needed a spelling of its own on both the API and the picker.