Skip to content

Studio: take the hosted pre-cast fp8 text encoder by default on Qwen-Image-2.1 - #11539

Merged
danielhanchen merged 3 commits into
mainfrom
studio-te-auto-fp8
Sep 22, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-te-auto-fp8

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

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:

component precision loaded today size
transformer INT8, from the hosted checkpoint 6.76 GiB
text_encoder (Qwen3-VL-8B) bf16, untouched 16.33 GiB
vae bf16, untouched 1.26 GiB
resident total 24.35 GiB (26.1 GB)

The encoder is 2.4x the size of the quantised denoiser, and nothing was quantising it.

unsloth/Qwen-Image-2.1-FP8 has hosted a pre-cast encoder all along, Qwen-Image-2.1-text_encoder-FP8.safetensors at 8.75 GiB, and the family already points at it through te_prequant_repos. Nothing could reach it: text_encoder_quant defaults to None, and the hosted artifact is only consulted once a request normalises to fp8. The resolver works fine when you ask it:

resolve_te_prequant_source(fam, "text_encoder", "fp8")
-> TePrequantSource(kind='repo', location='unsloth/Qwen-Image-2.1-FP8',
                    filename='Qwen-Image-2.1-text_encoder-FP8.safetensors')

So the file was published, wired and unreachable by default.

The change

DiffusionFamily gets a te_quant_auto field, and the text-encoder request becomes a tri-state with 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. 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:

  • The refusal path reads the raw request. An auto-selected scheme that fails to engage falls back to dense quietly, because nobody asked for it. Refusing there would turn a load that works today into an error the caller cannot attribute to a choice they made.
  • 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 16.33 GiB of 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

Qwen-Image-2.1, INT8 denoiser on both arms, 16 prompts at 1024 with 40 steps and matched seeds, one B200:

encoder encoder bytes resident after assembly peak encoder load
dense bf16 (before) 16.33 GiB 23.74 GiB 30.46 GiB 11.6 s
hosted pre-cast fp8 (after) 8.75 GiB 16.16 GiB 22.87 GiB 1.5 s

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:

arm LPIPS vs bf16 reference SSIM vs bf16 reference
INT8 denoiser, dense bf16 encoder 0.0439 0.9564
INT8 denoiser, hosted fp8 encoder 0.0794 0.9299

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_quant to none or off, which this keeps working and has a test.

Tests

New in test_diffusion_precision.py:

  • unset / "" / "auto" are the only spellings that invite a family default, and none / off / an explicit scheme are not
  • an unset request takes the family scheme and is marked as not asked for
  • an opt-out still pins the released bf16 encoder
  • an explicit scheme still wins over the family default, and a bad one is still refused
  • a family that has not opted in keeps today's dense bf16 default
  • a typo in a family's own default is refused rather than passed through to every default load of that family

New in test_diffusion_te_prequant.py:

  • every family's te_quant_auto scheme is one we actually host a pre-cast encoder for, which catches a family opting in before its artifact is published
  • Qwen-Image-2.1 resolves to unsloth/Qwen-Image-2.1-FP8 and the exact safetensors filename

test_diffusion_precision.py and test_diffusion_te_prequant.py are 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 and test_native_audio.py are failing for local CUDA and missing-module reasons that predate this branch.

The option this adds

Text encoder precision options, before and after

Two isolated Studio installs, BEFORE at the merge base b7aca5553 and AFTER at 8fb6d3b66, same scene driven against both. The Images advanced panel's Text encoder precision select goes from five options to six: Dense (bf16) is inserted under Default, 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_count 5 to 6 and has_dense_option false 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, Default no longer means bf16, so the released encoder needed a spelling of its own on both the API and the picker.

…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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T14:37:16.684853Z 8fb6d3b Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +4107 to +4109
text_encoder_quant, text_encoder_quant_auto = resolve_te_quant_request(
text_encoder_quant, getattr(fam, "te_quant_auto", None)
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
…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.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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)"],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 22, 2026
@danielhanchen
danielhanchen merged commit 0fb5edc into main Sep 22, 2026
7 of 60 checks passed
@danielhanchen
danielhanchen deleted the studio-te-auto-fp8 branch September 22, 2026 14:47
pull Bot pushed a commit to RealShocky/unsloth that referenced this pull request Sep 22, 2026
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.
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…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.
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant