Repository navigation
Studio FLUX.3 manual cast: keep LoRA adapters at the fp32 compute dtype and out of the bf16 fold - #17201
Merged
Conversation
…pe and out of the bf16 fold #17173 stores the FLUX.3 weights as bf16 on fp16-only cards and upcasts each Linear per call. PEFT places every injected adapter at its base layer's weight dtype, so a LoRA loaded onto those layers ran its A / B GEMMs in bf16 and rounded fp32 adapter files through bf16. The LoRA fold also rounded the merged update into the bf16 storage, dropping updates the former fp32 storage kept. Adapters on a manual-cast base now go to its compute dtype, and the fold declines manual-cast layers. UNSLOTH_STUDIO_MANUAL_CAST_LORA=0 restores the previous placement and fold.
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. More of your lovely PRs please. 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 9, 2026
…uff-unsloth wheel (#17211) ## Summary The Backend CI step that installs the pinned `ruff-unsloth` wheel retries 3 times with 5 s and 10 s gaps. Between 05:19 and 05:40 UTC today, GitHub served intermittent 504s for the release asset, and every attempt of an unlucky job landed inside one burst. That turned `Repo tests (CPU, fsdp2 / gloo-cp / gloo-pp / gloo-tp / rest / studio-install)` red on #17188, #17191, #17197, #17201 and #17202, while sibling jobs in the same runs installed the wheel fine a minute later. This raises the loop to 6 attempts with exponential backoff (10, 20, 40, 80, 160 s, about 5 minutes total). A healthy download still never sleeps, and a lasting outage still fails the job with the same `::error::` line, so the fixed-point formatter guard keeps failing loudly in CI when the wheel is truly unavailable. ## Changes - `.github/workflows/studio-backend-ci.yml`: 6 attempts, `sleep $((10 << (attempt - 1)))`. - `tests/test_ruff_unsloth_install_retries.py`: runs the step's own `run:` script under bash with `pip` and `sleep` faked on `PATH`, and checks that - 5 failed downloads in a row still install, after at least 300 s of backoff, - a download that never recovers still fails the job, in under 10 minutes, - a healthy download does not wait at all. ## Testing - `pytest tests/test_ruff_unsloth_install_retries.py`: 3 passed. - Against the old step from `main`, the burst test fails with `ruff-unsloth install failed after 3 attempts`. - The other tests that read `studio-backend-ci.yml` pass.
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.
What happened
#17173 loads FLUX.3 on fp16-only cards (T4 and other pre-Ampere GPUs) with bf16 weight storage and float32 compute per layer: each plain
Linearbecomes a manual-cast twin that upcasts its weight per call. That covers the base GEMMs, but not LoRA:_move_adapter_to_device_of_base_layer). On a manual-cast layer that is the stored bf16, solora_A/lora_Bwere bf16, PEFT cast the activation down to bf16, and both adapter GEMMs ran in bf16 on exactly the cards that have no native bf16. fp32 adapter files were also rounded through bf16 on load.diffusion_lora_fuse) computes the update in fp32 and rounds the merged weight back to the weight dtype. With bf16 storage, small updates that the former fp32 storage kept are rounded away (a weight of 1.0 plus an update of 1/1024 stayed 1.0), and the layer is then marked merged so the adapter no longer runs separately.What this changes
low_cpu_mem_usagepath. Every other layer keeps PEFT's own placement.UNSLOTH_STUDIO_MANUAL_CAST_LORA=0restores the previous adapter placement and fold.Base storage is unchanged: the bf16 weights stay bf16, so the host and VRAM savings from #17173 hold. The adapters add only their own fp32 bytes.
Evidence
CPU, tiny 3-layer model (bf16 storage + manual cast, PEFT 0.19.1 injection, the same path diffusers
load_lora_adaptertakes),tests/test_diffusion_manual_cast_lora.py:On main, 3 of the 6 new tests fail (
test_adapter_keeps_fp32_values_and_gemms[False],[True],test_fuse_declines_manual_cast_layers); on this branch all 6 pass. The kill switch test and a plain bf16 model (no manual cast) keep the previous behavior on both.Tesla T4 (sm 7.5, torch 2.14.1, diffusers 0.42.1, PEFT 0.19.1), random tiny-config FLUX.3 transformer (hidden 1536, 2 + 4 blocks, 1024 image + 128 text tokens), rank 32 LoRA on every block Linear, loaded with
load_lora_adapter. Same card and process for every arm, 3 x 10 forwards each:The T4 renders finite output on main as well, and the timing difference sits inside the main-vs-main repeat spread, so this is a precision fix rather than a speed fix: with the change, LoRA output on manual cast is bit-equal to the fp32-stored model, and adapter memory is the only extra cost (0.88 to 0.91 GB peak here, against 1.58 GB for fp32 storage).
torch.compile(fullgraph=True)over a manual-cast model with an fp32 adapter: 0 graph breaks, 1 graph, no recompiles (same as main).Existing tests
test_diffusion_flux3_manual_cast.py,test_diffusion_lora_fuse.py,test_diffusion_lora_files.py,test_diffusion_lora.py,test_diffusion_lora_incremental_remerge.py,test_diffusion_lora_quant_merge.py: same results as main (the fourmossloader failures intest_diffusion_lora_files.py/test_diffusion_lora.pyfail on main too).