Skip to content

Studio FLUX.3 on fp16-only GPUs: an explicit INT8 / FP8 quant reads the bf16 checkpoint as stored instead of widening the transformer to float32 - #17228

Merged
danielhanchen merged 2 commits into
mainfrom
studio-turing-native-quant-bf16-storage
Nov 9, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
studio-turing-native-quant-bf16-storage

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

#17173 keeps FLUX.3's bf16 weights as stored on fp16-only GPUs (T4) and upcasts per layer, but an explicit transformer quant still loads the transformer widened to float32 first ("a transformer quant rebuilds the dense Linears it reads"). For the fp16-only card's native build (INT8 from #17167, FP8 from #17218) that widened copy is not needed: the native linear reads weight.float() anyway, and widening bf16 to float32 is exact, so the codes are the same either way. The widened load costs host RAM on the 31 GB Kaggle T4 VM, where a Studio INT8 load already sits at 23 GiB PSS.

This PR loads the transformer at bf16 with the manual cast when the requested scheme takes the fp16-only card's native route, and lets that build read manual-cast Linears:

  • load_flux3_pipeline(..., transformer_storage=...) is also true for a native scheme on an fp16_card_int8_host that is not the shared ROCm / MPS native route (native_quant_scheme(...) is None) and not the native offload build.
  • make_filter_fn(require_dtype=...) counts a manual-cast Linear by its compute dtype (linear_compute_dtype: _unsloth_compute_dtype, else the weight dtype), so the float32 filter of the fp16-card path still selects them.
  • The native linear takes its compute dtype from that attribute too, and holds a manual-cast source's bf16 bias at the compute dtype (F.linear needs one dtype).
  • Everything the quant skips (the M=1 modulation projections, small layers) stays a bf16 manual-cast Linear instead of a float32 copy.

bf16 GPUs, explicit-quant loads elsewhere, ROCm / MPS native routes and the native offload build are unchanged. Kill switch: UNSLOTH_DIFFUSION_FP16_CARD_QUANT_STORAGE=0 restores the widened load.

Results (Kaggle T4, 31 GB host, FLUX.3 klein, 1024x1024, 16 steps, fresh process per arm, one process on the VM, same seeds)

Both arms carry #17217 (INT8 renders), #17218 (FP8 on Turing) and the other T4 FLUX.3 PRs of this round; head adds this PR. Order head-less, head, head, head-less.

format arm s / image (2 runs) load s process tree PSS min MemAvailable peak VRAM LPIPS
INT8 widened (today) 52.8 / 52.9 145.7 / 143.6 23.1 / 23.0 GiB 8.0 / 8.0 GiB 11.34 GiB -
INT8 head (stored bf16) 53.1 / 53.2 136.0 / 133.7 20.9 / 21.2 GiB 12.9 / 12.9 GiB 11.20 GiB 0.000 vs widened (pixel-identical), both runs
FP8 widened (today) 185.2 121.9 22.0 GiB 8.3 GiB 11.05 GiB -
FP8 head (stored bf16) 185.8 113.9 21.1 GiB 12.7 GiB 11.19 GiB 0.000 vs widened (pixel-identical)

Same images and the same speed; 0.9 to 2.2 GiB less process PSS, 4.4 to 4.9 GiB more host memory left free at the low point of the load, and an 8 to 10 s shorter load.

Tests

studio/backend/tests/test_diffusion_fp16_card_quant_storage.py (tiny diffusers Flux3Transformer2DModel, Turing capability monkeypatched):

  • INT8 (and FP8 where Studio: run FP8 on T4 and other Turing GPUs as weight-only fp8 instead of refusing it #17218 is present) built from the manual-cast bf16 transformer gives the same native layers as the widened float32 load: same layer set, compute dtype float32, torch.equal codes, scales and biases; the rest stay bf16 manual-cast Linears; the forward output is torch.equal to the widened model's.
  • The filter counts a manual-cast Linear by its compute dtype; a plain bf16 Linear is still rejected by the float32 filter.
  • The loader gate is the fp16-card native route only; the kill switch and its name.

The INT8 case fails on main (no layer passes the float32 filter). The fp16-card INT8, FLUX.3 manual cast, native quant, fused native quant and FLUX.3 suites pass unchanged (407 passed, diffusers 0.42.1).

Not covered

…f16 checkpoint as stored (manual cast) instead of widening the transformer to float32
@danielhanchen danielhanchen self-assigned this Nov 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T09:06:35.278336Z 4a917dc 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 4a917dc902

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

@danielhanchen
danielhanchen merged commit 184cdb8 into main Nov 9, 2026
@danielhanchen
danielhanchen deleted the studio-turing-native-quant-bf16-storage branch November 9, 2026 11:55
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