Skip to content

Studio: FLUX.3 Image Klein (distilled and base), with INT8 / FP8 / GGUF support - #13933

Merged
danielhanchen merged 49 commits into
mainfrom
studio-flux3-klein
Oct 18, 2026
Merged

danielhanchen merged 49 commits into
mainfrom
studio-flux3-klein

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Problem

FLUX.3 Image Klein (black-forest-labs/flux-3-image-klein and -base) cannot be loaded in Studio. Diffusers ships it only as Modular Diffusers blocks (Flux3DistilledAutoBlocks, Flux3AutoBlocks), the repos carry modular_model_index.json instead of model_index.json, and the support is not in any Diffusers release yet (huggingface/diffusers#15046).

Change

  • New core/inference/diffusion_flux3.py: loads the transformer, the Qwen3-VL-4B text encoder and processor, and the FLUX.2 VAE per subfolder, and puts a DiffusionPipeline face over the modular blocks. Placement, model and group offload, the step callback (progress, cancel), the decode phase hook and the scheduler swap all work through the same component objects the blocks run.
  • Two families: flux.3-klein (distilled, 16 steps, CFG 1, Euler) and flux.3-klein-base (50 steps, CFG 3.5, negative prompt). Defaults follow ComfyUI's current FLUX.3 templates (workflow templates 0.11.87): the base text to image and edit templates run 50 steps at CFG 3.5 (euler / simple), raised from the launch templates' 25, which is also the BFL reference setting (diffusers' FLUX.3 defaults: 50 steps, guidance 3.5); both distilled templates run 16 steps at CFG 1. On hand-heavy prompts (6 prompts, short and long, 2 seeds, same reference noise) 50 steps fixed a malformed handshake the 25-step render had and otherwise left the image nearly unchanged. Both take up to 10 images through the existing reference workflow. The -pup prompt upsampler repo is not matched as an image model.
  • Reference images are scaled to 1 megapixel (Lanczos, aspect kept) before encoding, as ComfyUI's ReferenceMultiLatent ["resize", 1] does in the FLUX.3 templates. Diffusers alone only downsizes above 16 megapixels.
  • A seeded request starts from the BFL reference noise layout, so a Studio seed renders what the BFL reference CLI renders for that seed. The VAE stays in bf16, as ComfyUI runs the FLUX.2 VAE on NVIDIA (the BFL reference decodes in fp32).
  • Download plan: the modular index is the manifest and only transformer/, text_encoder/ and vae/ are fetched, for full pipelines and as the companions of a GGUF or single file (which take only transformer/config.json from transformer/); the root BFL single file, ae.safetensors, variants/ and the prompt upsampler repo are not. The plan also reports a pick of the other variant before anything is staged.
  • BFL added the optional prompt upsampler (prompt_upsampler / prompt_upsampler_processor, from the separate ~19 GB black-forest-labs/flux-3-image-klein-pup repo) to both official manifests on 2026-10-16. Image loads ignore it: validation and the locality check require only the components FLUX.3 loads (text encoder and its processor, transformer, VAE). Checked on the current revision through the real load path for a bf16 pipeline, a GGUF with staged companions and the INT8 prequant: renders are pixel-identical to before and the pup repo is never downloaded.
  • Memory plan: bf16 size table entries, and the load-dtype sizing now prices only <component>/<file> weights. The cached variants/fp8r and variants/nvfp4 packages were inflating the plan from 19.8 GB to 31.7 GB.
  • Version gate: minimum 0.42.0, marked unreleased. Diffusers main and the FLUX.3 branch both report 0.41.0.dev0, which reads the same as the 0.41.0 release without FLUX.3, so the picker checks for the FLUX.3 module file in the installed package instead (no import).
  • Quantisation: a new FamilyProfile.quant_exclude_tokens leaves named layers dense for every transformer-quant scheme (int8, fp8, mxfp8, nvfp4). It is empty by default, so other families are unchanged. FLUX.3 keeps the per-token modulations, timestep embedders, norm_out, the text-stream per-mode blocks and the 20480-wide text projection in bf16, which leaves 228 of 273 Linears quantised. Without it, mxfp8 and nvfp4 crash at the first step: the modulation inputs are a stride-0 expand, and those kernels need contiguous inputs. int8 and fp8 also lose more quality without it.
  • nvfp4 is denied for FLUX.3: every keep-set measured 0.09 to 0.12 LPIPS, and so did BFL's own nvfp4 package.
  • MX and NVFP4 Linears in every family now get a contiguous activation through a forward pre-hook, installed by the shared post-quantisation hook. torchao's activation quantisers assert contiguity, and a stride-0 broadcast such as temb.expand(B, S, D) otherwise crashes at the first step; for contiguous inputs the hook does nothing. This is a cross-family change. FLUX.2 klein 4B with mxfp8 (106 MX Linears, compiled with CUDA graphs, the only way Studio runs a quantised denoiser), checked in one process: 2 prompts at 1024x1024 rendered without the hook, then again with it, give torch.equal decoded images, and so does the denoiser output on a captured step. Two renders without the hook are also torch.equal in that process. Across separate processes the same renders differ by up to 2 of 255 with or without the hook (before vs after this commit, and between two runs of the same commit), so that comparison cannot show a difference either way. The hook returns the arguments unchanged for any contiguous input. The scheme smoke probe is unchanged from main, so no family's auto choice moves.
  • Regional compile and CUDA graphs are on for FLUX.3. With compile available, auto resolves to int8 on sm80 and newer, as it does for the other families.
  • Single file and GGUF denoisers assemble around the base repo's components, and the block graph follows the loaded denoiser. A GGUF FLUX.3 reports uint8 as transformer.dtype, because its only float tensors are the fp32-kept QK norms. The denoise block casts the latents to that dtype, so the loader pins the compute dtype with an empty buffer. A checkpoint or pipeline of the other variant (distilled vs base) is refused with the family to use, before the loaded model is unloaded. BFL's own variants/fp8r and variants/nvfp4 packages are refused too: the nvfp4 one has the same tensor sizes as a ComfyUI NVFP4 file with a different scale layout, so it would decode silently wrong.
  • Memory: measured activation rows for the distilled checkpoint. Each reference is charged at 0.11 of the flat 8192 MiB per megapixel (about 900 MiB per 1 MP reference, the int8 / fp8 figure; bf16 measures about 700). Before this, FLUX.3 references were not charged at all. The placement planner uses those rows too (denoise 1081, decode 2924 MiB at bf16 instead of the flat 8192 headroom), so a 32 GiB card keeps a bf16 FLUX.3 resident instead of streaming the text encoder: measured peaks 21.2 GiB text to image and 21.9 GiB with 4 references, 5.7 s vs 7.0 s per 1024x1024 text to image. 20 and 24 GiB still pick group offload. The base checkpoint keeps the flat estimate (no measured rows).
  • Auto-switch: a FLUX.3 cache snapshot downloaded around the hosted INT8/FP8 file (no dense transformer shards) counts as downloaded when that file is cached, and the switch loads it by repo id from the cache.
  • LoRAs: the pipeline face uses the pinned build's Flux3LoraLoaderMixin (transformer only). Checked on real weights with a random rank-4 adapter on 215 attention and feed-forward Linears: bf16 eager, the adapter changes the render, weight 0 and removing it give the base render bit for bit; int8 with the adapter baked in at load changes the render too.
  • Hosted artifacts: flux.3-klein lists unsloth/flux-3-image-klein-FP8 for int8 and fp8 (files flux-3-image-klein-INT8.safetensors / -FP8.safetensors), the same layout as flux.2-klein. flux.3-klein-base lists unsloth/flux-3-image-klein-base-FP8 the same way: its INT8 file is BFL's own ComfyUI int8_convrot denoiser from black-forest-labs/flux-3-image-klein-comfy, mirrored byte for byte and read through the ComfyUI quant loader, and its FP8 file is ours. Checked on real weights through the API load (50 steps, CFG 3.5, 2 prompts): the seeded INT8 renders match BFL's single file loaded directly (LPIPS 0.0001 and 0.004), the seeded FP8 renders match our FP8 file loaded by path (LPIPS 0.0001 and 0.0000). Without access to the repo the load logs prequant_repo_unavailable and quantises on the fly.
  • Ungated base files: black-forest-labs/flux-3-image-klein and -base are gated, so a GGUF or FP8 pick (which carries only the denoiser) fetched its text encoder and VAE through the gate. The upstream Diffusers folders Studio loads (modular_model_index.json, text_encoder/, transformer/, vae/) are now copied byte for byte (21 files each, sha256 checked against the pinned upstream revision) into unsloth/flux-3-image-klein-FP8 and unsloth/flux-3-image-klein-base-FP8 beside the pre-quantized files, and both are in the gated mirror table, so no separate mirror repo is needed. Companion listings and the manifest check read those repos too, so no request reaches the gated upstream. The picker and status still show the BFL id.
  • Hosted text encoders: both FP8 repos also carry the Qwen3-VL-4B text encoder, the same bytes in each (the distilled and base text_encoder/ shards are identical), as flux-3-image-klein[-base]-text_encoder-INT8-ConvRot.safetensors (5.25 GB, int8 ConvRot weight-only, built by scripts/build_te_int8_convrot_checkpoint.py) and ...-text_encoder-FP8.safetensors (5.61 GB on disk, 4.83 GB resident: layerwise fp8, bit-identical to the runtime cast), the same pattern as Qwen-Image-2.1. An int8 request that cannot load the int8 file falls back to the fp8 file, then to the dense encoder with the runtime fp8 cast, as on Qwen-Image-2.1. Unset requests get the int8 ConvRot encoder (te_quant_auto = "int8"), as BFL's ComfyUI templates load qwen3vl_4b_int8_convrot (4 of 5 workflows in black-forest-labs/flux-3-image-klein-comfy); none still pins the bf16 encoder. Checked through Studio's load path: an unset request loads the int8 file on both families and renders pixel-identical to the explicit int8 render. Real weights, bf16 DiT, 19 cases against the bf16 encoder on one B200 (A/A repeat bit-identical): int8 LPIPS-alex 0.017 mean / 0.098 max, SSIM 0.974 at 16 steps; 0.023 / 0.121, SSIM 0.973 for the base at 25 steps, CFG 3.5. fp8 scores 0.038 / 0.220 and 0.035 / 0.132. The encoder goes from 8.27 to 4.89 GiB resident and from 18.4 to 1.8 s to load (warm page cache). Peak memory drops from 21.2 to 17.8 GiB. INT8 DiT with the int8 encoder: 0.033 / 0.134 (distilled) and 0.034 / 0.142 (base), 13.9 GiB peak. BFL's qwen3vl_4b_int8_convrot has the same int8 projections byte for byte but also quantises embed_tokens, which Studio's loader cannot read. Repacked with that table dequantised, it scored 0.018 / 0.150 and 0.027 / 0.113, a tie within per-image spread, so the hosted file is our own build. Planner estimate for the encoder: 8487 MiB for bf16, 5517 MiB for fp8 or int8. Studio's own load of the mirrored files (int8 distilled and base, fp8 distilled) renders bit for bit what the harness renders.
  • A GGUF pick with a transformer quant builds through _assemble_pipe, which called from_pretrained on the modular pipeline class and returned a pipeline with no transformer. It now assembles FLUX.3 through the same per-component loader.
  • Base checkpoint, checked on real weights (19 cases, 50 steps, CFG 3.5): Studio vs the BFL reference code LPIPS 0.038 mean, the diffusers harness 0.037 against the same reference; 25 steps, text to image, single and multi-reference edits and negative prompts render; every distilled / base mismatch is refused before loading and in the loader. Fixes this needed: a base single file on distilled companions takes flow_map from the family instead of the companion config (it crashed on meta tensors); BFL's own ComfyUI int8_convrot and nvfp4 files (black-forest-labs/flux-3-image-klein-comfy) now go to the ComfyUI quant loader instead of being refused as variants/ packages, with the fused q/k/v split for FLUX.3; and the family, not the file name, picks the base vs distilled recipe (BFL's base ComfyUI files have no "base" in their names, so they were seeded 16 steps / CFG 1).
  • Diffusers pin: diffusers-main.txt is re-enabled at Diffusers main d42ebf9c (archive digest included), which carries the FLUX.3 merge (Flux3 image huggingface/diffusers#15046) and the prompt upsampler block ( FLUX.3 prompt upsampler block huggingface/diffusers#15058), the same route Qwen-Image-2.1 used before 0.41.0. Studio never loads the upsampler, so flux3_blocks() drops that step from both FLUX.3 block graphs; a render at d42ebf9c matches the merge commit pixel for pixel. A host that cannot fetch the pin keeps 0.41.0 and only FLUX.3 is refused. The pin tests check release mode on a commented-out copy, so they pass with the pin on or off.
  • Diffusers main now requires Python 3.11 (ci: move to python 3.11. huggingface/diffusers#15030), so the installer and the startup repair skip the pinned build below 3.11 instead of cloning something that cannot install. Python 3.10 keeps 0.41.0 and gets a FLUX.3 refusal that names the Python requirement; 3.9 keeps 0.36.0 as before.

Results

Real weights, distilled, 16 steps, B200 shared lease. The 11 cases are the BFL example prompts and seeds (8 text to image at 832x1248 to 1248x832, 3 edits with 1 or 2 references), scored with LPIPS (alex) and SSIM.

Comparison LPIPS mean LPIPS max SSIM mean Identical images
Studio vs Diffusers ModularPipeline given the same noise and references 0.0073 0.080 (edit_figurine) 0.986 10 of 11 bitwise
Studio vs the BFL reference implementation 0.0115 0.083 (edit_figurine) 0.979 0
Diffusers vs the BFL reference (same inputs, for scale) 0.0046 0.026 0.991 0

Text to image cases against the BFL reference: LPIPS 0.0008 to 0.0018, except riso_lido at 0.026 (the most chaotic prompt, which also moves between two runs of the reference on different hosts). The one edit that differs is edit_figurine: its 896x1120 input is just under 1 megapixel, so the ComfyUI sizing scales it up to 912x1136 where the reference keeps it as is. Same composition, different detail (LPIPS 0.08).

Tiny random models, distilled and base, text to image and edit, resident, model offload and group offload: bitwise identical to the Diffusers pipeline given the same inputs.

Speed features, the same 11 cases, against Studio bf16 eager:

Arm Quantised Linears LPIPS mean LPIPS max SSIM mean
bf16, regional compile + CUDA graphs 0 0.004 0.027 0.992
auto (resolves to int8, compiled) 228 0.024 0.056 0.958
fp8, compiled 228 0.039 0.215 (riso_lido) 0.946
mxfp8, compiled 228 0.042 0.185 (riso_lido) 0.939

Every case except riso_lido is at or below 0.048 for all three schemes. For scale, compiled vs eager bf16 measured 0.0035 in the separate quantisation survey.

Dependency check for the pinned build (uv pip compile, the installer's requirement line):

Python Stack Result
3.11, 3.12, 3.13 Studio pins: transformers 5.5.0, huggingface-hub >=1.32,<2 resolves; huggingface-hub 1.33.0, transformers 5.5.0 and tokenizers 0.22.2 unchanged
3.10 same no solution (the build needs Python 3.11), so the installer skips it and keeps 0.41.0
3.11 transformers 4.57.6 no solution (it needs huggingface-hub <1.0); the released 0.41.0 conflicts the same way, and Studio pins 4.57.6 only on Python 3.9, where it installs Diffusers 0.36.0

A dry run of the installer's install against an existing Python 3.12 stack swaps only the diffusers package.

Edits at 1024x1024, 16 steps, with 1 and 4 references (B200, 160 GB free):

Load Placement Peak allocated, t2i / 1 ref / 4 refs
bf16 resident, no offload 21.2 / 21.2 / 21.9 GiB
auto (int8) resident, no offload 16.8 / 15.9 / 18.0 GiB
auto (int8), capped at 16 GB group offload, int8 denoiser and encoders streamed 3.2 / 3.6 / 5.7 GiB

The 16 GB cap is simulated: the allocator fraction and mem_get_info are both capped at 16 GiB. All three loads render all three requests.

GGUF and pre-quantised files, real weights, loaded through Studio's load API (begin_load) from local copies of the hosted files. The same 11 cases, 16 steps, against Studio bf16 eager:

Artifact Quantised Linears LPIPS mean LPIPS max SSIM mean Builder's gate (19 cases)
GGUF Q8_0 273 (GGUF) 0.010 0.035 (edit_figurine) 0.983 0.006
GGUF UD-Q4_K_XL 273 (GGUF) 0.038 0.139 (riso_lido) 0.947 0.038
INT8 safetensors (seeded) 228 0.024 0.056 (riso_lido) 0.958 0.035
FP8 safetensors (seeded) 228 0.039 0.215 (riso_lido) 0.946 0.036

A 3-case spot check (fox, man_dog, edit_coffee) also ran Q4_K_M: LPIPS 0.033 mean against 0.021 for UD-Q4_K_XL.

  • All 273 Linears of the GGUF denoisers stay GGUF weights; the 1-D QK norms are dequantized like other GGUF families. The real GGUF files hit the uint8 compute dtype problem described above, and render with the pin.
  • The INT8 and FP8 files quantise exactly the 228 Linears that on-the-fly quantisation picks under the keep-list, and the seeded renders are pixel identical to the on-the-fly int8 and fp8 renders.
  • A GGUF pick that asks for int8 seeds the INT8 file and renders pixel identical to the pipeline pick. Before the _assemble_pipe change the same load came back with no transformer.
  • CUDA graph capture fails on the K-quant GGUFs (a host-to-device copy inside the dequant). The load logs the reason as a warning and runs eager; every render completed and no error reaches the request.

Tiny Q8_0 GGUFs with BFL tensor names load for both variants and render text to image and edit. Pairing the base GGUF with the distilled family is refused.

Timing at 1024x1024, resident bf16, no compile: 1.3 to 2.5 s per text to image, 2.8 to 3.9 s per edit.

Tests

  • studio/backend/tests/test_diffusion_flux3.py: 84 CPU tests covering the download plan scope and variant verdict, the prompt upsampler entries in the current official manifests, the modular manifest in the gated-base probe, shard restore and staging, the pre-eviction variant check (single files and pipelines), the local folder validation, the FLUX.3 LoRA loader, per-image generation chunks, per-image negative prompts, a local modular base for GGUF loads, the refusal of separate encoder / VAE files, the hosted artifact rows and filenames, the operator mirror, the quantized GGUF pick assembly, the nvfp4 deny, the contiguous-input guard, the per-scheme keep-list (and that other families are unchanged), the variant and BFL-package refusals, the GGUF compute dtype pin, memory rows, detection, the -pup exclusion, modular index detection, defaults, size table, the unreleased gate and module-file probe, the modular download plan, plan sizing, reference sizing, the reference noise layout, and the pipeline face (prompt and generator splitting, step callback, interrupt).
  • Frontend model-catalog.check.ts: passes with the new GGUF row.
  • Family data freeze and autoopt parity fixtures updated for the two new families (new rows only).
  • Diffusion, image, inventory, quantisation and Diffusers-pin suites (10,470 passed): no new failing test IDs against the base commit.
  • Whole backend suite after the hosted-artifact commit: 74,977 passed, and the failing test IDs (all present before it, environment related) are the same set as on the previous commit.
  • tests/sh/test_clean_machine_notools_pinned_git.sh: 44 passed.

Not covered

  • A dense bf16 cold load (transformer_quant=none). Cold anonymous loads (fresh cache, no token) of a GGUF UD-Q4_K_XL pick, a base FP8 pick and a bf16 pipeline pick (which auto-selects int8) each requested only unsloth/flux-3-image-klein[-base]-FP8 / -GGUF and rendered at 1024x1024; the GGUF pick downloads 9.53 GB with the int8 encoder.

  • fp8r and nvfp4 variant files: they use Diffusers' new BFL quantizer format, which no Studio prequant path loads yet.

  • Upstream: Diffusers reports uint8 as the dtype of a GGUF FLUX.3 transformer, and a plain ModularPipeline fails the same way. Studio pins the compute dtype; the upstream fix is still to be filed.

  • A script that exits while Studio's deferred background compile is still running dies at interpreter shutdown (exit 245 or 250). This reproduced on a bf16 FLUX.3 run after all renders had finished, and the same way on FLUX.2 klein 4B (bf16, 3 renders, exit 245), so it is not in the FLUX.3 code. Calling unload() first exits cleanly. The background compile is shared by every family and is not changed here. I did not check whether a Studio server shut down mid-compile hits the same thing.

  • Follow-up: a smoke probe that also feeds a stride-0 activation, so a scheme missing the contiguous guard fails the probe instead of the first render. Left out of this PR.

  • MLX, Windows and AMD paths for FLUX.3 were not run. The native sd.cpp route is Studio: FLUX.3 Image Klein on the native sd.cpp engine #14144, stacked on this PR.

  • Hosted repos (public, ungated): unsloth/flux-3-image-klein-FP8, unsloth/flux-3-image-klein-base-FP8, unsloth/flux-3-image-klein-GGUF and unsloth/flux-3-image-klein-base-GGUF. The two GGUF repos are picker rows (shown under their repo names); model-catalog.check.ts --network checks every declared file against the Hub. If a FP8 repo cannot be reached, an int8 or auto load logs prequant_repo_unavailable and quantises on the fly (checked on real weights, same output as the file).

  • GGUF CUDA graphs on K-quants (falls back to eager).

  • nvfp4 quality (excluded from auto) and step caching.

  • Python 3.10 hosts cannot run FLUX.3 until a Diffusers release carries it (the refusal says so).

  • Timings: the runs above were on shared GPUs, so they are accuracy checks, not benchmarks.

  • A real 16 GB card (the cap was simulated in-process).

  • Measured memory rows for the base checkpoint (it uses the flat estimate).

  • Trained FLUX.3 LoRAs (and their key formats); only a random adapter was tried.

  • Separate text encoder / VAE files beside a FLUX.3 GGUF or single file: refused with a clear message for now (the supplied-component loader reads a model_index.json, which FLUX.3 does not ship).

  • Prompt upsampler integration: Studio: FLUX.3 prompt upsampling (Enhance prompt) through a llama.cpp sidecar #14137, stacked on this PR.

  • ComfyUI seeds do not reproduce (ComfyUI draws its own noise layout); BFL seeds do.

  • The single reference path differs from the BFL reference by design (1 megapixel resize instead of pad to 4 megapixels), following ComfyUI.

  • Text encoder length cap: 8192 tokens (Diffusers) against 4096 in the BFL reference; only prompts past 4096 tokens differ.

Another GPU generation

On a Colab RTX PRO 6000 Blackwell (sm120, torch 2.14.1+cu130), Studio's own DiffusionBackend from this branch loaded unsloth/flux-3-image-klein-FP8 with every setting left at its default and rendered 1024x1024 images. It picked an int8 transformer (int8 GEMM engaged), the hosted int8 ConvRot text encoder, compile with CUDA graphs and no offload, and the load took 84 s. The merge base does not detect the repo as FLUX.3 at all.

UI

Images model picker searched for "FLUX", before (merge base 7382805) and after (42e4b8a). After this PR, flux-3-image-klein-GGUF (Slow) (5.5B) and flux-3-image-klein-base-GGUF (Slow) are curated rows in the FLUX group, right after FLUX.2-klein-9B. Before, both only show up as bare, unsized Hub search hits further down.

Images model picker before and after: the two FLUX.3 GGUF rows

Diffusers ships FLUX.3 only as Modular Diffusers blocks and the repos carry
modular_model_index.json instead of model_index.json. diffusion_flux3 builds
the components per subfolder and puts a DiffusionPipeline face over the
modular blocks, so placement, offload, the step callback, cancel and the
scheduler swap work the same as for every other family.

- flux.3-klein (16 steps, no CFG) and flux.3-klein-base (50 steps, CFG 3.5)
  families with up to 10 reference images through the reference workflow
- download plan reads only transformer/, text_encoder/, vae/ and the
  modular index (never the root BFL single file or variants/)
- the memory plan prices only component-depth weight files
- class gate: 0.42.0 minimum (unreleased); listing probes the module file
  since main and the PR branch report 0.41.0.dev0
- prompt upsampler repo (-pup) is not matched as an image model
- defaults, labels, bf16 size table, fixtures
FLUX.3 Image Klein support is open upstream as huggingface/diffusers#15046
(branch flux3-image in huggingface/diffusers, current main plus additive
FLUX.3 files). Re-enable diffusers-main.txt at that branch head with its
archive digest, the same route Qwen-Image-2.1 used before 0.41.0. A host
that cannot fetch it keeps the 0.41.0 release and only FLUX.3 is refused.

The pin tests now exercise release mode on a commented-out copy instead of
the shipped file, so they hold in either state.
… BFL seeds

- each reference image is scaled to 1 megapixel (Lanczos, aspect kept),
  as ComfyUI's ReferenceMultiLatent ["resize", 1] in the FLUX.3 templates
  does; diffusers alone only downsizes above 16 megapixels
- a seeded, sized request starts from the BFL reference's noise layout, so
  a Studio seed renders what the BFL CLI renders for it
- base defaults to ComfyUI's CFG template (25 steps, CFG 3.5); distilled
  stays at 16 steps (edit template and BFL; the t2i template's er_sde is
  not a sampler this backend runs)
…ed memory

- FamilyProfile.quant_exclude_tokens: name tokens left dense for every
  transformer-quant scheme (default empty, other families unchanged).
  FLUX.3 keeps modulations, timestep embedders, norm_out, the text-stream
  per-mode blocks and the text projection in bf16. Without it mxfp8 and
  nvfp4 crash at the first step (stride-0 modulation inputs) and int8 /
  fp8 lose the most quality.
- regional compile and CUDA graphs on for FLUX.3 (measured: no graph
  breaks, no recompiles across sizes).
- single file and GGUF denoisers assemble around the base's modular
  companions; the block graph follows the loaded denoiser. A GGUF FLUX.3
  reports uint8 as transformer.dtype (only fp32-kept QK norms are float),
  which the denoise block casts the latents to, so the compute dtype is
  pinned with an empty buffer.
- the other variant's checkpoint and BFL's own fp8r / nvfp4 packages are
  refused up front (the nvfp4 one would decode silently wrong through the
  ComfyUI NVFP4 loader).
- measured activation rows for the distilled checkpoint, and references
  charged at their measured ~0.7 GiB per megapixel instead of nothing.
…s nvfp4

torchao's MX and NVFP4 activation quantisers assert a contiguous input,
so a stride-0 broadcast (an adaLN fed temb.expand(B, S, D)) crashes at the
first denoise step. The shared post-quantisation hook now registers a
pre-hook on MX / NVFP4 Linears that makes the activation contiguous (a
no-op for contiguous inputs), and the scheme smoke probe also runs a
stride-0 broadcast, so a missing guard fails the probe instead of the
render. Measured on B200: without the guard the probe fails mxfp8 and
nvfp4, with it all four schemes pass.

FLUX.3 Klein denies nvfp4 (every keep-set measured 0.09-0.12 LPIPS), and
references are charged at 0.11 of the flat per-megapixel estimate (about
900 MiB per 1 MP reference with an int8 / fp8 denoiser).
Diffusers main moved to requires-python >= 3.11 (huggingface/diffusers#15030),
so the FLUX.3 build cannot install on Python 3.10. Raise the installer's and
the startup repair's main-build floor to 3.11 so 3.10 keeps the 0.41.0
release without a clone that can never succeed, and give a 3.10 user a
FLUX.3 refusal that names the Python requirement instead of a reinstall.
… assembles the modular pipeline

flux.3-klein lists unsloth/flux-3-image-klein-FP8 for int8 and fp8, mirroring
flux.2-klein. A GGUF pick with a transformer quant builds through _assemble_pipe,
which called from_pretrained on a modular pipeline class and returned a pipe with
no transformer; it now assembles FLUX.3 through load_flux3_pipeline.
…eme smoke probe as it was

The picker offers unsloth/flux-3-image-klein-GGUF next to the FLUX.2 klein
rows. The smoke probe goes back to its zero-row input only; the stride-0
broadcast probe is left for a separate change. The contiguous-input guard
on MX / NVFP4 Linears stays, since mxfp8 FLUX.3 needs it to render.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-18T15:04:09.665500Z 119a983 Manual request
🔒 Security Review ⚠️ Failed 2026-10-15T20:15:41.714421Z 5358313 PR opened
ℹ️ 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cdb8654487

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

Comment on lines +311 to +312
if negative_prompt is not None and not self.is_distilled:
kwargs["negative_prompt"] = negative_prompt

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Pair each split prompt with its negative prompt

When FLUX.3 Base receives a mixed-prompt batch with a negative prompt, DiffusionBackend.generate broadcasts the negative into a list matching the batch, while this wrapper splits the positive prompts into separate scalar calls but forwards the entire negative list to every call. The modular CFG encoder therefore receives one positive prompt and multiple negatives, causing a batch-size mismatch or conditioning each output with the wrong batch; select the corresponding negative for each split call.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 816b535. When the call is split, the wrapper now passes negative_prompt[i] to call i. A single-entry list applies to every call, and any other length raises a ValueError naming the count. generate now also sends FLUX.3 one image per call, so it no longer builds a negative list for it. Test: test_split_calls_pair_each_prompt_with_its_own_negative.

Comment on lines +3741 to +3743
# FLUX.3 is a Modular Diffusers layout: its manifest is modular_model_index.json.
index_name = FLUX3_INDEX if is_flux3_family(fam) else "model_index.json"
if not local_pipeline_components_are_complete(local_root, index_name):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept modular indexes for local FLUX.3 companion bases

This modular-index exception applies only when the selected model itself is a pipeline. A GGUF or single-file FLUX.3 load using a local base_repo reaches the earlier _assert_local_base_is_pipeline call with its default allow_modular=False, so a valid local copy containing modular_model_index.json but no model_index.json is rejected before loading. Pass the FLUX.3 modular allowance to the companion-base validation as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 816b535. The companion base check now accepts modular_model_index.json for FLUX.3, so a local base with only the modular index validates for GGUF and single-file loads. Test: test_a_local_modular_base_is_accepted_for_a_gguf_denoiser.

Comment on lines +24 to +27
{ match: "flux-3-image-klein-base", steps: 25, guidance: 3.5 },
{ match: "flux3-klein-base", steps: 25, guidance: 3.5 },
{ match: "flux-3-image-klein", steps: 16, guidance: 1 },
{ match: "flux3-klein", steps: 16, guidance: 1 },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cover the registered flux3-image aliases in UI defaults

The backend registers and assigns recipes to flux3-image-klein and flux3-image-klein-base, but neither spelling matches these frontend entries: separator folding does not turn flux3-image-* into either flux-3-image-* or flux3-klein-*. Selecting a finetune with one of those supported aliases therefore seeds the Create form with the generic 9-step, guidance-0 recipe instead of 16/1 or 25/3.5; add the missing aliases so the frontend and backend resolve the same supported names.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 816b535. Added flux3-image-klein-base (25 steps, CFG 3.5) and flux3-image-klein (16 steps, CFG 1) to the UI defaults, so every alias the backend registers resolves the same way. Covered in image-generation-defaults.test.ts.

…lar local base, aliases

- generate runs each FLUX.3 image as its own chunk, so every image gets its
  own encode / denoise / decode phase and text-encoder release; renders are
  pixel identical.
- The pipeline face pairs a per-image negative prompt list with each split
  call instead of passing the whole list to every call.
- A GGUF / single-file FLUX.3 load accepts a local base with only
  modular_model_index.json.
- text_encoder_files / vae_file are refused for FLUX.3 up front; the
  supplied-component loader needs a model_index.json and was not used.
- The UI defaults cover the flux3-image-klein aliases the backend registers.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 816b5357a2

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

Comment on lines +172 to +175
from diffusers import DiffusionPipeline
_PIPELINE_CLASS = type(
"Flux3KleinPipeline", (_Flux3KleinPipelineMixin, DiffusionPipeline), {}
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Add LoRA handling to the FLUX.3 pipeline face

When a FLUX.3 request uses a LoRA—either on a bf16/eager load or while baking an int8/fp8 transformer—the shared LoRA gate accepts it and later calls pipe.load_lora_weights() and pipe.set_adapters(), but this generated class inherits only DiffusionPipeline, not a LoRA loader mixin, and the new mixin defines none of those methods. Consequently every otherwise-supported FLUX.3 LoRA request fails with a missing-method error; inherit an appropriate loader implementation or explicitly reject LoRAs for these families before loading.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ca6fe7e. The pinned diffusers build ships Flux3LoraLoaderMixin, so the FLUX.3 pipeline class now inherits it when it is available, and load_lora_weights, set_adapters and unload_lora_weights work on the same transformer the modular blocks run. On real weights a rank-4 adapter changes the render, weight 0 and removing it give the base render bit for bit, and baking it into an int8 load works too. Test: test_the_face_carries_the_flux3_lora_loader.

Comment on lines +364 to +368
canonicalId: "black-forest-labs/flux-3-image-klein",
displayName: "FLUX.3 Image Klein",
description: "Text-to-image and image editing",
scope: "image",
artifacts: [gguf("unsloth/flux-3-image-klein-GGUF")],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Hide the unpublished FLUX.3 GGUF artifact

The commit explicitly records unsloth/flux-3-image-klein-GGUF as not published yet, but this row makes that repository the model's only curated artifact. Any user selecting the new FLUX.3 entry therefore reaches the Hub with a nonexistent repository and the load fails before generation; keep the row out of the picker until the repository is published, or point it at an artifact that already exists.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in ca6fe7e. The FLUX.3 GGUF picker row is removed until unsloth/flux-3-image-klein-GGUF is uploaded, and model-catalog.check.ts asserts it is not offered. The hosted FP8 prequant registration stays: while that repo is missing, int8 and auto loads log prequant_repo_unavailable and quantise on the fly (checked on real weights), so no load fails.

… row until it is published

The FLUX.3 pipeline face now inherits Flux3LoraLoaderMixin (transformer-only)
when the installed Diffusers has it, so Studio's load_lora_weights /
set_adapters / unload_lora_weights calls work, eager and baked into an int8
build. The unsloth/flux-3-image-klein-GGUF picker row is removed until the
repo is uploaded.

[skip ci]
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… the folders FLUX.3 loads

- The route preflight and begin_load read the pick's tensor names (the file
  on disk, a GGUF header range read, or the safetensors header) and refuse a
  distilled / base mismatch or a BFL quantized package before the resident
  pipeline is unloaded. The loader's own check stays as the backstop.
- Local FLUX.3 validation checks <root>/text_encoder, /transformer and /vae,
  the folders load_flux3_pipeline reads, instead of a modular spec's source
  repo, so a manifest pointing elsewhere is refused before loading.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5f71ab9f88

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

Comment on lines +27 to +30
{ match: "flux3-klein-base", steps: 25, guidance: 3.5 },
{ match: "flux-3-image-klein", steps: 16, guidance: 1 },
{ match: "flux3-image-klein", steps: 16, guidance: 1 },
{ match: "flux3-klein", steps: 16, guidance: 1 },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Add canonical FLUX.3 family keys to generation defaults

The follow-up adds the registered aliases, but both defaults tables still omit the canonical override values flux.3-klein and flux.3-klein-base. For an opaque/local model whose name has no recognizable alias, defaultsKeyFor deliberately falls back to the explicit canonical family, and separator folding produces flux-3-klein[-base], which does not match any of these flux3-* rows; the Create form therefore seeds 9 steps/guidance 0 instead of 16/1 or 25/3.5. The backend _GENERATION_DEFAULTS has the same omission, so its resident recipe cannot correct the UI.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3ab0f43. flux.3-klein (16 steps, guidance 1) and flux.3-klein-base (25, 3.5) are now in both the UI and backend defaults tables. For an opaque path, the backend's resident recipe now falls back to the FLUX.3 family name, so an opaque path loaded with either family gets its recipe in both places.

danielhanchen and others added 3 commits October 15, 2026 17:04
…pipelines, canonical keys, modular status

- A FLUX.3 GGUF / single file assembles from the staged companion dir when
  the prefetch resolved one, like every other assembly.
- A full FLUX.3 pipeline whose manifest names the other variant is refused
  before eviction (local folder, cached or fetched manifest), with a loader
  backstop on the resolved block graph for every FLUX.3 assembly.
- flux.3-klein / flux.3-klein-base get their recipes in both defaults tables,
  and the resident recipe falls back to the FLUX.3 family for an opaque path.
- The image status lists FLUX.3 in modular_families, so the family override
  admits an opaque modular folder.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 3ab0f4311a

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

Copy link
Copy Markdown
Member Author

seam-guard fails on this branch only: families without a VAE config in vae_tile_configs.json: ['flux.3-klein-base', 'flux.3-klein'] (and the follow-on KeyErrors). The two new families need their vae/config.json (base repo, pinned revision) added to vae_tile_configs.json so the seam guard can check the tile geometry. The pip scan-packages :: hf-stack red on the same run is from a base before #13949 and clears on a rebase.

…w list

Since 2026-10-16 the official FLUX.3 Klein manifests (distilled 2a70d1707a,
base 6d332ea733) list prompt_upsampler / prompt_upsampler_processor from the
separate ~19 GB flux-3-image-klein-pup repo. FLUX.3 image loads never read
them, but local validation required them as folders of the repo, so a local
or cached copy of the current revision was refused, and the media locality
check wanted the pup repo cached.

FLUX3_COMPONENT_FOLDERS now names exactly the components the loader reads
(text_encoder, tokenizer, transformer, vae); fixed-folder validation checks
those and skips any other manifest entry, and the locality check judges a
FLUX.3 manifest the same way. The download plan already fetches only the
three component folders, and the loader builds the modular pipeline from
its own components without reading the manifest's sources.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9af13ada12

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

Comment on lines +1626 to +1629
("flux.3-klein-base", 25, 3.5),
("flux-3-image-klein-base", 25, 3.5),
("flux3-image-klein-base", 25, 3.5),
("flux3-klein-base", 25, 3.5),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Set the FLUX.3 base default to 50 steps

When a user selects flux.3-klein-base, these aliases seed only 25 inference steps, but the official FLUX.3 launch documentation specifies 50 steps for the undistilled base checkpoint (Hugging Face FLUX.3 documentation). This halves the intended denoising schedule and can materially degrade default generations; update these backend aliases and the matching rows in studio/frontend/src/features/images/image-generation-defaults.ts to 50.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping 25. Studio follows the ComfyUI templates for defaults, and the official base templates in black-forest-labs/flux-3-image-klein-comfy (workflows/image_flux3_klein_t2i.json and workflows/image_flux3_klein_image_edit.json) are set to 25 steps at CFG 3.5, euler / simple. The t2i template passes cfg 3.5, steps 25 into its sampler subgraph and carries a note to try 50 steps for better quality. The steps slider is still there for anyone who wants 50.

Comment on lines 2059 to 2061
if fixed_component_folders is not None and name not in fixed_component_folders:
continue
declared = True

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require every fixed FLUX.3 component folder

When a local FLUX.3 manifest omits one of the fixed entries, such as vae or text_encoder, this loop checks only the mapped entries that remain and returns true as soon as any one valid component sets declared. load_flux3_pipeline nevertheless opens all three fixed folders unconditionally, so an incomplete or hand-edited local pipeline passes preflight, evicts the resident model, and then fails during loading. Validate every required fixed folder independently of whether its manifest key is present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 16d6a46. Fixed-folder validation now checks every folder load_flux3_pipeline opens (text_encoder with its processor, transformer, vae, with the transformer skipped for a GGUF or single file), whether or not the manifest lists it, so a manifest that drops an entry cannot let a missing folder through. Covered by test_every_fixed_folder_is_required_even_when_the_manifest_omits_it.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 18, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 119a9830dc

ℹ️ 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 5019141 into main Oct 18, 2026
@danielhanchen
danielhanchen deleted the studio-flux3-klein branch October 18, 2026 16:31
danielhanchen added a commit that referenced this pull request Oct 18, 2026
Follows #13933 (FLUX.3 Image Klein, merged). Adds the native sd.cpp
route for FLUX.3 Klein and Klein Base, so a host with no usable GPU runs
our FLUX.3 GGUFs through sd-cli / sd-server instead of diffusers. It
also means FLUX.3 GGUFs load there without the unreleased diffusers
classes.

Three commits:

1. **FLUX.3 Klein and Klein Base on the native sd.cpp engine.** Asset
mapping and arch gate.
2. **Pin the sd.cpp prebuilt to `master-968-8cd731e-ubdb47d1`.** The
mirror's release built from the upstream master-968 sync, the first
upstream release with FLUX.3 Image Klein, published with every CPU,
Apple, Vulkan and CUDA asset.
3. **Reference edits and a checkpoint check.**
`DiffusionFamily.sd_cpp_reference` marks the FLUX.3 families, so the
native engine accepts their `reference` workflow (sd.cpp conditions
FLUX.3 on references through the VAE) and status lists it. After the
assets are fetched, `_run_load` runs
`assert_flux3_checkpoint_matches_family` on the denoiser, so a Klein
GGUF picked under Klein Base (or the reverse) is refused before sd-cli
starts.

### What sd-cli is handed

| | flux.3-klein | flux.3-klein-base |
|---|---|---|
| Denoiser | `unsloth/flux-3-image-klein-GGUF` (the pick) |
`unsloth/flux-3-image-klein-base-GGUF` (the pick) |
| VAE | `unsloth/flux-3-image-klein-FP8`
`vae/diffusion_pytorch_model.safetensors` |
`unsloth/flux-3-image-klein-base-FP8`
`vae/diffusion_pytorch_model.safetensors` |
| Text encoder (`--llm`) | `unsloth/Qwen3-VL-4B-Instruct-GGUF`
`Qwen3-VL-4B-Instruct-Q8_0.gguf` | same |
| Sampler | euler, no flow shift, no `--vae-format` | same |
| Arch marker | `Flux.3 Image Klein` | same |

- **Denoisers.** sd.cpp reads our GGUFs as published. They carry BFL
tensor names, and sd.cpp detects FLUX.3 from `emb_in.image` +
`txt_mode_blocks`. No metadata fix is needed.
- **VAE.** Both VAE files are the FLUX.2 VAE, byte-identical to
`unsloth/FLUX.2-VAE` (sha256 `d64f3a68...`). Each comes from its
family's own FP8 repo. That repo is in `prequant_repos`, so it stays
loadable and does not become a companion-only repo.
- **No vision projector.** sd.cpp feeds FLUX.3 references through the
VAE (`image_cond` stream), not through the VLM. A reference edit with no
mmproj renders correctly.
- **Flow shift.** sd.cpp's scheduler already applies FLUX.3's 6.93
shift. Passing one would override it.
- **Arch marker.** `Flux.3 Image Klein` is the model version name. It is
present in every sd-cli and sd-server that can run FLUX.3 and absent
from the current pin. A host keeping an older build gets diffusers
instead of a load that fails at the first step.
- **Companion repo.** `unsloth/Qwen3-VL-4B-Instruct-GGUF` joins the
companion-only set. Like the Qwen3-VL-8B encoder of Qwen-Image-2.1, it
only drops out of the non-GGUF cached listing.

### Why Q8_0 for the encoder

The setup: sd.cpp (synced build), CUDA, 4 prompts at 1024 with the same
seeds. Distilled ran 16 steps at CFG 1, base 25 steps at CFG 3.5. The
reference is our BF16 GGUF denoiser with the BF16 Qwen3-VL-4B GGUF.

Studio's diffusers renders cannot be the reference: sd.cpp draws its own
noise, so pixels never line up across engines. The diffusers
`transformer/` folder in the FP8 repo cannot be the reference either: it
uses diffusers names, which sd.cpp does not map for FLUX.3.

LPIPS-alex, mean / max over 4 prompts:

| DiT | TE | Klein | Klein Base |
|---|---|---|---|
| Q8_0 | Q8_0 | 0.031 / 0.115 | 0.008 / 0.010 |
| Q8_0 | Q4_K_M | 0.080 / 0.187 | 0.082 / 0.148 |
| UD-Q4_K_XL | Q8_0 | 0.068 / 0.180 | 0.110 / 0.172 |
| UD-Q4_K_XL | Q4_K_M | 0.090 / 0.213 | 0.109 / 0.209 |

Q8_0 is never worse than Q4_K_M. It costs 1.8 GB more (4.28 GB against
2.50 GB), and the TE quant is the largest error source in this pair.
Every render is coherent; the larger distances come from pose and layout
shifts, which are typical for a distilled model.

Speed at 1024 on one B200: distilled about 9 to 11 s/img, base 16 to 19
s/img. On CPU (32 threads, prebuilt-style build, host shared with other
jobs): distilled UD-Q4_K_XL + Q4_K_M encoder 345 s, Q8_0 + Q8_0 517 s;
base UD-Q4_K_XL + Q4_K_M encoder 1388 s. CPU output matches CUDA for the
same files (LPIPS 0.0008 to 0.006).

### End to end

Studio's own `SdCppDiffusionBackend` loaded
`unsloth/flux-3-image-klein-GGUF` UD-Q4_K_XL on a CPU-only process. It
used `SD_CLI_PATH` / `SD_SERVER_PATH` pointing at the synced CPU build,
and the assets came from this mapping. It reported `engine=sd_cpp`,
`native_mode=server`, `family=flux.3-klein`, then rendered a 512x512,
4-step image (coherent) in 72 s including load.

### Tests

`tests/test_sd_cpp_flux3.py` has 12 CPU tests covering asset mapping,
planned assets, companion classification, the arch gate, the no-GPU
router with and without a capable build, the reference workflow gate and
the checkpoint check. The first 9 fail without commit 1, the last 3
without commit 3.

The pin commit updates the pin assertions and raises the
upstream-fallback floor to master-968.

With both commits, the families, family-data freeze, FLUX.3, engine
router, sd.cpp backend/args/install/Vulkan routing, Qwen-Image-2.1
native edit and TE prequant test files pass: 766 passed, 3 skipped.

After merging the current #13933 head, the sd.cpp and FLUX.3 test files
pass again: 524 passed, 3 skipped.

Full backend suite, every test file, against the parent commit at the
time (`ac89bb0d44`): 74,633 passed on this branch against 74,623 on the
parent. Both sides have 195 failed and 27 errors, and the failing test
IDs are identical, so all of them are pre-existing and none involve
sd.cpp or FLUX.3. Most are chat-generation supervisor and llama
admission tests.

### Before merging

- The prebuilt pin is `master-968-8cd731e-ubdb47d1`. The installer
resolves it for CPU, CUDA 13 and Vulkan on Linux x64, and the CPU build
installs and runs.
- The published release carries the same 13 assets as the previous pin
`master-951-f89d9b1-uafac7a7` (macOS arm64 and x86_64, Linux x86_64 CPU
/ CUDA 12 / CUDA 13 / Vulkan, Linux aarch64, Windows CPU / CUDA 12 /
CUDA 13 / Vulkan, plus the manifest and sha256 files). Only the
patch-set id in the names changes.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 18, 2026
… sidecar (#14137)

Follows #13933 (FLUX.3 Image Klein, merged).

## Why

FLUX.3 Image Klein is trained on long, explicit captions. Sent a short
prompt as typed, it often draws broken bodies on unusual poses
(backflips, handstands, tangled arms) and generic scenes. BFL ships a
prompt upsampler for exactly this
(`black-forest-labs/flux-3-image-klein-pup`, a Qwen3.5-9B fine-tune,
Apache-2.0), and its model card says FLUX.3 "is not meant to run without
a prompt upsampler in front of it". ComfyUI's official FLUX.3 templates
run it by default. Studio currently drops that step and encodes the
prompt as typed.

Same 16 prompts, same seeds and reference noise, 32 images per arm:

| Arm | Broken bodies |
|---|---|
| distilled, prompt as typed | 3 (backflip on both seeds, one handstand)
|
| distilled, upsampled caption | 0 |
| base (50 steps), prompt as typed | 4 (headless handstand, tangled
arms, two odd violin grips) |
| base (50 steps), upsampled caption | 1 (odd violin angle) |

As typed, "a gymnast doing a backflip" mostly renders a back-bend or
walkover; upsampled, it renders a tucked backflip. Ordinary scenes
(groups, walking, dinner) were already fine and stay fine.

## What this adds

**Backend** (`core/inference/flux3_prompt_upsampler.py`)
- The upsampler runs as a llama.cpp `llama-server` sidecar, modelled on
the dictation (mtmd STT) sidecar: started on demand on an ephemeral
loopback port, five minute keep-alive, unloaded early when VRAM is
tight, and stopped at every training start, llama.cpp update, image
unload and GPU handover to chat or video. Stop during a cold start
cancels the server start. On a multi-account host it never starts beside
another account's run. CUDA, ROCm, Metal and CPU all work through the
same binary Studio already installs.
- Weights come only from `unsloth/flux-3-image-klein-pup-GGUF` (Q4_K_M
plus `mmproj-F16.gguf` for edits, 6.5 GB).
`UNSLOTH_FLUX3_UPSAMPLER_GGUF` / `_MMPROJ` point at local files instead.
- Prompts and sampling follow the ComfyUI FLUX.3 templates: BFL's `t2i`
/ `i2i` system prompts verbatim (sha256 pinned in a test, identical to
diffusers' `SYSTEM_PROMPTS`), greedy decoding, thinking off, 3584 max
tokens, presence penalty 1.5 for text-to-image and 0 for edits, repeat
penalty 1.05 for distilled and 1.0 for base. Edits send the reference
images (prepared as diffusers' `prepare_reference`) and the edit
scaffold.
- When the server supports `penalize_prompt` (unslothai/llama.cpp#283),
the penalties cover only generated tokens over the whole caption, which
is what ComfyUI and BFL's reference do. Against an exact-semantics
reference on 8 prompts this moves word similarity from 0.49 to 0.69 (the
cross-runtime floor is about 0.7 to 0.8). Older servers keep their
default window.
- `DiffusionGenerateRequest.enhance_prompt` (default: on for FLUX.3
Klein, ignored elsewhere). Records keep `prompt` as typed and add
`enhanced_prompt` (the caption encoded) and `prompt_enhancement`
(`applied` / `off` / `unavailable` / `failed`). Generation never fails
because of the upsampler: a missing download, missing binary or server
error falls back to the prompt as typed, and a multi-GB download is
never started implicitly.
- Routes: `GET /api/inference/images/prompt-upsampler/status`, `POST
.../download`, `POST .../cancel`, `POST .../preview`. `/images/status`
gains `supports_prompt_upsampler` and `prompt_upsampler_default`;
generate-progress reports an `enhance` phase.
- Captions are cached per (prompt, variant, references), so a batch
upsamples each distinct prompt once and a repeat costs nothing.
- Fix in the shared sidecar download progress: huggingface_hub 1.18+
writes `<etag>.<8 hex>.incomplete`, which the byte counter missed, so
the bar sat at 0% until the end. This also fixes the dictation model
download bar.

**Frontend** (Images page)
- "Enhance prompt" toggle under the prompt for FLUX.3 families only, on
by default, remembered per family.
- Download notice with size, progress and cancel when the upsampler is
missing.
- Preview: shows the caption with Copy and "Use as prompt" (puts the
caption in the prompt and turns the toggle off, so it can be edited).
- The Recipe popover shows the enhanced prompt and offers "Restore with
the enhanced prompt", which reproduces the image exactly.

## Evidence

End to end on a fresh install from this branch (B200,
`unsloth/flux-3-image-klein-FP8`):

| Check | Result |
|---|---|
| status before download | `downloaded: false`; generate falls back,
`prompt_enhancement: "unavailable"` |
| download through the route | 6,547,275,232 bytes in 44 s into the HF
cache |
| preview | 231-word caption, 12.2 s cold (includes llama-server start),
4.8 s for a new prompt warm |
| generate | 1.0 to 1.5 s warm without enhancement, about 8 s with a new
caption, 1.2 s with a cached one |
| restore (caption as prompt, enhance off, same seed) | max abs pixel
difference 0 |
| edit (reference workflow, "make it night time") | caption describes
the actual source image |
| VRAM | about 23 GB combined peak (DiT 13 to 16 GB, sidecar 6.2 GB
text-only, 7.5 GB with the vision projector) |
| non-FLUX.3 family (Z-Image Turbo) | no toggle; `enhance_prompt: true`
passes through untouched |

GGUF fidelity (llama.cpp `b11696-mix-7baeb9a`): the BF16 GGUF matches
transformers' chat template token for token and only diverges at
near-tie tokens (probability gaps 0.0015 to 0.041). Captions from Q4_K_M
and Q8_0 rendered the hard poses with no anatomy difference from the
BF16 captions.

Tests: `tests/test_flux3_prompt_upsampler.py` 73 passed; with the
training VRAM, multi-model serving, managed engine, STT, GPU selection,
GPU arbiter and diffusion route suites 777 passed. Frontend
`tests/image-*.test.ts` 144 passed, `tsc` clean.

## Not covered

- Clicking Download in the UI (the download was driven through the
route), cancel mid-download, the base variant end to end, edits with
several reference images, and the unload-when-tight path (the card never
ran tight).
- macOS, Windows and AMD were not run; the sidecar uses the same
llama-server binary and launch helpers as dictation.
- Exact ComfyUI caption parity needs the `penalize_prompt` pin in the
llama.cpp prebuilt; until then captions are valid but not word-for-word
ComfyUI's.

## UI

Images composer with `unsloth/flux-3-image-klein-FP8` loaded, before
(`studio-flux3-klein`, this PR's base) and after, with Preview clicked.
After this PR there is an Enhance prompt switch (on by default for
FLUX.3) and Preview opens the caption the upsampler wrote (237 words
here) with Copy and Use as prompt. `GET
/api/inference/images/prompt-upsampler/status` returns 404 before and
200 after.

![Images composer before and after: Enhance prompt switch and the
enhanced
caption](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14137/pr14137_composer_q-df214a7289c6.png)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
danielhanchen added a commit that referenced this pull request Oct 20, 2026
…kend fetches (#14316)

## Problem

The scheduled `Model catalog network check` failed on main (run
39381974211, fb372c1):

```
black-forest-labs/flux-3-image-klein-base: the Hub reports gated="auto" but the catalog entry has no `gated: true`, so an anonymous download 401s
black-forest-labs/flux-3-image-klein: the Hub reports gated="auto" but the catalog entry has no `gated: true`, so an anonymous download 401s
```

Both repos are gated on the Hub, but users never download them. The
FLUX.3 Klein bf16 rows deliberately keep the BFL ids (#13933, #14184),
and the backend fetches those ids from the open
`unsloth/flux-3-image-klein-FP8` and
`unsloth/flux-3-image-klein-base-FP8` repos, which carry the upstream
diffusers folders byte-identical (`_GATED_MIRROR_PAIRS` in
`diffusion_families.py`). This is the first scheduled run of the check
since the rows were added: the last one completed on 2026-10-01, and the
2026-10-19 run was cancelled.

Adding `gated: true` would be wrong. The router skips a gated,
not-downloaded artifact on a bare group click, so the working bf16 row
would stop being offered. The catalog is right and the check was judging
the wrong repo.

## Fix

- `ModelArtifact.fetchedFrom`: the open repo the backend downloads a
vendor id from. Set on the two FLUX.3 Klein bf16 rows.
- The network check judges gating and declared files on `fetchedFrom`
when it is set, otherwise on the repo id as before.
- `tests/model-catalog-fetched-from.test.ts` (frontend unit tests, every
PR) reads `_GATED_MIRROR_PAIRS` and `_VIDEO_GATED_MIRROR_PAIRS` from
`diffusion_families.py` and requires every `fetchedFrom` to be one of
those pairs, with no `gated: true` on the row. A catalog claim of a
mirror the backend does not use therefore fails on the PR, not at
download time.

No UI change: the field is read only by the check and the test.

## Testing

- `npm run catalog:check:network` against the live Hub: passes (`every
declared repo, file and gated flag agrees with the Hub`). On main it
fails with the two errors above.
- Pointing the base row's `fetchedFrom` at the wrong mirror makes both
new tests fail.
- `npm run catalog:check` and the full frontend suite (12886 tests, 0
failed) pass. `npm run build` passes, and the startup bundle stays
within budget (0.1 KB raw to spare).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant