Repository navigation
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
Conversation
…f16 checkpoint as stored (manual cast) instead of widening the transformer to float32
Member
Author
|
@codex review |
Codex Review Summary: ✅ CompletedThis 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. |
|
Codex Review: Didn't find any major issues. You're on a roll. 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". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 anfp16_card_int8_hostthat 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.F.linearneeds one dtype).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=0restores 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.
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 diffusersFlux3Transformer2DModel, Turing capability monkeypatched):torch.equalcodes, scales and biases; the rest stay bf16 manual-cast Linears; the forward output istorch.equalto the widened model's.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