Repository navigation
Studio FLUX.3: keep float16 on fp16-only GPUs behind a residual rescale (T4 INT8 -24% per image, GGUF Q8_0 -73%) - #17385
Merged
Merged
Conversation
…le instead of promoting to float32
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. |
[skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
danielhanchen
added a commit
that referenced
this pull request
Nov 10, 2026
…17421) ## Summary `pip scan-packages :: hf-stack` fails on main since unsloth-zoo 2026.11.4 reached PyPI (run 42852360538, on the #17385 merge commit): ``` Summary: 2 CRITICAL, 5 HIGH, 173 MEDIUM 7 of the 180 finding(s) above are at a site already reviewed in scripts/scan_packages_baseline.json. What differs from the reviewed entry: HIGH unsloth-zoo unsloth_zoo/compiler.py same matched code, file digest outside the pin HIGH unsloth-zoo unsloth_zoo/mlx/decision.py same matched code, file digest outside the pin HIGH unsloth-zoo unsloth_zoo/saving_utils.py 1 matched line(s) gone, none added HIGH unsloth-zoo unsloth_zoo/temporary_patches/moe_utils.py same matched code, file digest outside the pin CRITICAL unsloth-zoo unsloth_zoo/vision_utils.py (env + network) same matched code, file digest outside the pin CRITICAL unsloth-zoo unsloth_zoo/vision_utils.py (IMDS + network) same matched code, file digest outside the pin HIGH unsloth-zoo unsloth_zoo/vllm_utils.py same matched code, file digest outside the pin ``` This is the per-release re-review the digest pins are for, as in #16922 (2026.11.3), #16732 (2026.11.2) and #16624 (2026.11.1). ## Review I read the six files in the 2026.11.3 and 2026.11.4 wheels downloaded from PyPI. - Six of the seven new entries have the same `evidence_hash` as an already reviewed entry: the matched code is unchanged and only the file digest moved. - In `saving_utils.py` one of the two `__import__("transformers", fromlist = [model_class_name])` lines is gone and nothing was added. Its entry was unpinned before and stays unpinned. - None of the changed lines add `exec`, `eval`, `compile`, `marshal`, `zlib`, `__import__`, environment reads, HTTP or socket calls, or the metadata address. | File | What changed in 2026.11.4 | Verdict | |---|---|---| | `unsloth_zoo/compiler.py` | MHC projection rewrites become a tuple of `(old, new)` pairs instead of one source and replacement | benign | | `unsloth_zoo/mlx/decision.py` | decision loads install the MLX `model_file` guard, so a repository `config.json` cannot run code | benign, hardening | | `unsloth_zoo/saving_utils.py` | safetensors header reads reuse the mapped header, and previous export shards are snapshotted and kept; one duplicate `__import__` removed. The "metadata" here is safetensors header metadata, not IMDS | benign | | `unsloth_zoo/temporary_patches/moe_utils.py` | MoE backward pads the stored expert rows instead of the transposed view | benign | | `unsloth_zoo/vision_utils.py` | data URI parsing accepts any parameter that prefixes `base64`, as FFmpeg does | benign | | `unsloth_zoo/vllm_utils.py` | vLLM spawn and FlashInfer fallbacks pop `VLLM_USE_FLASHINFER_SAMPLER` / `VLLM_USE_V2_MODEL_RUNNER` and reword the standby hints | benign | ## Change `scripts/scan_packages_baseline.json` gains the seven entries for the 2026.11.4 files. Each one sits next to the entry it re-reviews. No entry is removed or widened, so 2026.11.3 installs still match their own pins. ## Testing - `scripts/scan_packages.py -r` on `unsloth-zoo==2026.11.4`: exits 1 against main's baseline (2 CRITICAL, 5 HIGH) and 0 with this one (24 suppressed, 13 MEDIUM). - The baseline tests (`git grep -l scan_packages_baseline -- tests`): 218 passed.
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
GPUs without bf16 (T4 and other pre-Ampere cards) ran FLUX.3 klein in float32, because plain float16 renders black. Dense, GGUF and the non-GEMM work around INT8 therefore ran on float32 SIMT kernels without tensor cores. This PR keeps FLUX.3 in float16 on those cards behind a new fp16 guard recipe.
On a T4, INT8 goes from 55 to 42 s per image (-24%) and GGUF Q8_0 from 188 to 50 s per image (-73%), with LPIPS 0.006 / 0.018 against the float32 render.
Root cause
Only the text-token residual stream overflows float16 (limit 65504). Activation maxima from a float32 run with forward hooks, real weights, 512px:
context_embedderoutput (first overflow: plain fp16 gives inf here, then NaN everywhere, black image)txt_mode_blocksff.linear_outoutput (block 25)to_out.0outputThe image stream, modulations, q/k/v and the dense text encoder in float16 all fit.
Fix
New recipe
rescale_residual(S = 1024) on the existinginstall_fp16_guardmechanism:context_embedderandx_embedders, the attention input and the SwiGLU output, and divides every LayerNorm and q/k-norm eps by S squared.diffusion.fp16_guard: recipe=rescale_residual blocks=43.UNSLOTH_STUDIO_FLUX3_FP16_GUARD=0(FLUX.3 only) orUNSLOTH_STUDIO_FP16_GUARD=0restores the float32 promotion.Before / after
Colab T4, 1024x1024, 16 steps, fresh process per arm, order base / head / head / base / base / head. Base is origin/main
00d10566e6.Tests
tests/test_diffusion_flux3_fp16_guard.py: 7 fail on main, all pass here (one real-class test skips without diffusers 0.42.1 and passes with it).test_diffusion_flux3.py::test_fp16_only_cards_promote_flux3_to_fp32now covers the kill-switch path.Not proven