Repository navigation
Studio: load FLUX.1 and Qwen-Image on fp16-only GPUs with small host RAM - #12480
Conversation
A bf16 repo loaded at fp16 materialises every converted weight in host RAM (FLUX.1-schnell 35 GB, Qwen-Image 56 GB), which OOM-kills a 31 GB host inside from_pretrained. When the dense converted load does not fit the available host RAM, load the large components at their stored dtype (memory-mapped), stream the text encoders with layerwise casting, and store an offloaded denoiser as int8 per-channel weights. Qwen-Image is marked fp16-incompatible (NaN latents).
… for dense denoisers On a 15 GB T4 (fp16, speed off, no transformer quant) the flat 8192 MiB activation reserve streamed FLUX.2-klein-4B's 7.4 GB DiT block by block every step. Extend the measured-activation placement to dense denoisers on the eager tier with a table of measured fp16 peaks above the resident weights at 1024x1024 (klein 2455 MiB, FLUX.1-schnell 2448, Qwen-Image 4248), bounded by the loaded DiT size so a larger model of the same family keeps the flat estimate. The refinement only adds resident groups to the flat plan's hooks, so oversized requests still release them. Kill switch: UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE=0 (the existing UNSLOTH_DIFFUSION_MEASURED_ACTIVATION / UNSLOTH_DIFFUSION_PARTIAL_RESIDENT also apply).
… stay memory-mapped Layerwise-cast the streamed encoders' embeddings too, convert kept-fp32 layers up front, scale the dense eager activation table by the compute dtype (Qwen-Image promoted to fp32 measured 8480 MiB above its weights vs 4248 at fp16), and test the decision table, conversions and route plan. The Z-Image fp16 tests now use FLUX.1 as the fp16-compatible control.
Keep fp32 buffers (RoPE inv_freq) as the dense load does, apply the route to the GGUF companion load, int8 only denoisers, report the route in status and refuse generation-time LoRA on an int8 denoiser with a clear message, keep the dense load for LoRA loads without refusing, and gate the dense eager activation table to fp16 or fp32-promoted denoisers (bf16 cards keep the flat plan).
Codex Review SummaryThis 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 SummaryThis 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. |
|
The test does |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
…kip weight variants
|
Codex Review: Didn't find any major issues. Chef's kiss. 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". |
Problem
On a fp16-only card with a modest host (a Kaggle T4: 2x T4, 31 GB RAM), FLUX.1-schnell and Qwen-Image never load. The process is killed for host RAM before the first step.
pipeline.from_pretrained(torch_dtype=float16), before the memory planner runs. Each bf16 weight converted to fp16 becomes a private in-RAM copy instead of staying memory-mapped. Measured by sampling RSS every 20 ms on each load step:Change
New
diffusion_small_host.py, a load route for this case.wo) keep their dense-load dtype.wo), and a UNet or large VAE at its converted size; weight variants such asmodel.fp16.safetensorsare not counted. LoRA on an int8 transformer is also refused with a message.UNSLOTH_DIFFUSION_SMALL_HOST=0turns the route off;=1forces it.UNSLOTH_DIFFUSION_HOST_RAM_CHECK=0skips the pre-load refusal.UNSLOTH_DIFFUSION_MEASURED_ACTIVATION_DENSE=0restores the flat reserve.Results
Kaggle T4x2 (31 GB host RAM), base and head on the same VM, same seeds. A warm render is a new prompt after the first.
Accuracy
LPIPS, 1024x1024:
Tests
test_diffusion_small_host.py(12 tests: the decision table for small hosts, large hosts and bf16 cards; the kill switch and force; the pre-load refusal; LoRA keeping the dense load, or being refused on the int8 route; header-only size reads; int8 storage against the dense layer; streamed encoders; the route plan; status). It errors at import on main.test_diffusion_small_host_planner.pyandtest_diffusion_measured_placement_dense.py, plus the updated Z-Image family test intest_diffusion_backend.py. Seven of these fail on main:test_zimage_is_fp16_incompatible.test_diffusion_backend.py,test_diffusion_memory.pyandtest_video_backend.py: 1316 passed. The full diffusion suite: 5933 passed, 0 failed.Follow-up checks
Each row ran base and head on the same machine.
Not covered
fuse_qkvat speed max is skipped with a warning on the int8 transformer.test_zimage_is_fp16_incompatible); whichever lands second takes both sides.