Skip to content

Studio: keep Qwen-Image's bf16 text encoder automatically when the card has room - #16678

Merged
danielhanchen merged 4 commits into
mainfrom
studio-qwen-te-bf16-auto
Nov 4, 2026
Merged

danielhanchen merged 4 commits into
mainfrom
studio-qwen-te-bf16-auto

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Qwen-Image's automatic text encoder is the int8 ConvRot file. Over 16 prompts it is most of the gap between Studio's default and a bf16 reference (LPIPS 0.0865 mean, 0.401 worst prompt); the denoiser path alone sits near the bf16 floor. On a card where the denoiser stays resident with room to spare, those 6 GiB of VRAM are otherwise idle.

This keeps the bf16 text encoder automatically for an unset Qwen-Image request when the whole load, with the bf16 encoder, stays resident on one card with a margin. Otherwise the int8 encoder is used as today.

Change

  • diffusion_precision.py: te_bf16_auto_wanted (unset or auto request, a qwen-image full-pipeline load, family auto pick int8) and te_bf16_auto_fits (nothing offloaded or streamed, one discrete card, required memory + max(512 MiB, 10%) within the safe budget).
  • diffusion.py: _run_load decides before the download plan (the int8 path skips the dense encoder shards). The load is priced with the bf16 encoder on the denoiser the plan would pick, crediting this process's own reservation as free. When it engages, the load status says why.
  • Explicit choices (none, off, int8, fp8) always win. Offline loads, user-supplied encoder components and GGUF / single-file loads are excluded. Kill switch UNSLOTH_DIFFUSION_TE_BF16_AUTO=0.
  • tests/test_diffusion_te_bf16_auto.py: 31 tests (decision tables plus the real planners: a bf16 denoiser engages on 96 / 80 GiB and declines on 64 / 24; the int8 denoiser engages on 96 / 64 and declines on 56 / 24).

Evidence

G4 (RTX PRO 6000), Qwen-Image, 16 prompts, LPIPS against Studio's own bf16 reference:

arm text encoder LPIPS mean / max s/img own VRAM load (cached)
main default int8 (auto) 0.0865 / 0.4014 6.960 / 6.956 43.86 GiB 22.1 s
this PR default bf16 (auto) 0.0588 / 0.0977 6.949 / 6.947 49.98 GiB 22.7 / 21.8 s
main, explicit none bf16 0.0588 / 0.0977 6.965 49.98 GiB 21.8 s
this PR, kill switch int8 identical to main 6.965 43.86 GiB 21.8 s
  • This PR's default output is identical to main with an explicit none (same image hashes); repeats of every arm are identical. Host RAM is unchanged.
  • Where it must not engage, it does not: G4 with a 56 GiB budget (the bf16 load would offload) and L4 (the load streams) both keep int8, with output identical to main.

Tests

  • test_diffusion_te_bf16_auto.py: 31 passed here; all 31 error on main (the helpers do not exist there).
  • The related existing suites pass (about 1,500 tests).
  • AMD gfx1151 (Linux, ROCm), base and head in the same job: 421 -> 452 passed, no regressions.

Not covered

  • A fresh user downloads the 16.6 GB dense encoder instead of the 8.8 GB int8 file; first-download time was not measured.
  • 80 GiB cards are covered by unit tests only. Other families were not changed: FLUX.2-klein and Z-Image already default to bf16 encoders, FLUX.2-dev needs its own A/B first.

@danielhanchen danielhanchen self-assigned this Nov 4, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T17:35:43.221972Z 0bbba69 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: 386c85583d

ℹ️ 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 5513 to +5515
te_quant_planned, _ = resolve_te_quant_request(
kwargs.get("text_encoder_quant"), getattr(fam, "te_quant_auto", None)
"none" if te_bf16_auto else kwargs.get("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.

P2 Badge Apply the bf16 auto decision to the public download plan

For a default Qwen-Image load on a card where this upgrade engages, download_plan() still resolves the unset request to int8 and excludes the dense encoder shards. The Images page calls /images/download-plan and stages its returned files before loading, so a fresh download fetches the unused int8 encoder, then _run_load unexpectedly downloads the dense encoder as well. This also makes Download only omit the encoder that the subsequent online load needs. Share this decision with download_plan() so its file list and byte estimates describe the actual load.

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.

Fixed in 0bbba69: download_plan now makes the same bf16 auto decision as the load (same room check, same supplied-component and probe guards), so the plan stages the encoder the load will open (test_download_plan_stages_the_encoder_the_load_will_open).

…s the load

The Images page stages /images/download-plan before it loads; with the plan
still resolving the unset request to int8, a fresh download fetched the unused
int8 encoder and the load then pulled the dense one.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 0bbba69e26

ℹ️ 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".

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