Repository navigation
Studio: FLUX.3 Image Klein on the native sd.cpp engine - #14144
Conversation
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.
…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]
… 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]
… 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]
…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.
[skip ci]
…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]
… manifest; require every loaded folder - The gated-base access probe (route preflight, load prefetch, download plan) looks for modular_model_index.json on a FLUX.3 base, so a cached gated repo with no usable token is recognised instead of refused. - Restoring the released transformer shards after a failed prequant seed fetches the modular manifest, and the prefetch recognises it as the staged snapshot marker, so the dense fallback restores and loads. - Fixed-folder validation checks every folder load_flux3_pipeline opens (text_encoder with its processor, transformer, vae; the transformer is skipped for a GGUF / single file), whether or not the manifest lists it, and nothing else. [skip ci]
…scoped and staged by the modular manifest - download_plan carries the FLUX.3 verdict (a single file / GGUF of the other variant or a BFL quantized package from its header, a pipeline of the other variant from its manifest) in incompatible_reason, so the Images page refuses at selection instead of staging the files the load then refuses. - A FLUX.3 GGUF / single file stages only the folders the assembler opens (text_encoder, vae, transformer/config.json; the transformer shards only on the dense quant path) plus modular_model_index.json. Before, the official repo's variants/fp8r and variants/nvfp4 packages were staged and the manifest was not, so the staged snapshot was never recognised. [skip ci]
- Single file / GGUF on the other variant's companions: the transformer config came from the companion repo, so a base file on the distilled repo (the base repo is gated, the TE and VAE are shared) built the flow-map target-time embedder and died on meta tensors. The family, already matched to the checkpoint by the variant check, now sets flow_map. - The variant check refused BFL's official ComfyUI int8_convrot / nvfp4 files (black-forest-labs/flux-3-image-klein-comfy) as BFL variants/ packages. A file that declares ComfyUI quantization (.comfy_quant tensors or the _quantization_metadata header) now goes to the ComfyUI loader; the undeclared variants/ packages stay refused, local and Hub headers alike. - The ComfyUI loader splits FLUX.3's fused <block>.qkv.weight into the q/k/v projections the diffusers converter expects (rows only, so int8 scales and ConvRot stay exact).
BFL's ComfyUI base files are flux3_image_klein_{bf16,int8_convrot,nvfp4}
.safetensors: no "base" in the name, so the name tables matched the
distilled key and seeded 16 steps / CFG 1 for the undistilled base (25 / 3.5),
in the status defaults, the auto step-cache plan and the Images form. The
variant check has already matched the checkpoint to the family, so for
FLUX.3 the family goes first; other families keep names first.
[skip ci]
…hot switch, base prequant repo - Local FLUX.3 validation checks an excluded transformer config-only instead of skipping it: the loader still builds the denoiser from <base>/transformer. - The distilled FLUX.3 family uses its measured activation rows: every reference is resized to 1 MP and the request guard charges those pixels on top. - Media auto-switch plans and loads a seeded FLUX.3 cache snapshot (no dense transformer shards) by its repo id, so the cached pre-quantized seed counts. - flux.3-klein-base lists unsloth/flux-3-image-klein-base-FP8 for int8 and fp8. The INT8 file is BFL's ComfyUI int8_convrot denoiser, read through the ComfyUI quant loader; the FP8 file is Studio's own. [skip ci]
…ense-cache probe scoped to transformer/ [skip ci]
…t; FLUX.3 GGUF picker rows [skip ci]
…bf9c Diffusers main changed three sources the Qwen-Image patches fingerprint, so at the pinned commit every one of them fell back to stock: - QwenImage21Transformer2DModel.build_token_metadata builds the block ids from a Python list instead of a tensor-repeats repeat_interleave. The ids are the same int64 values, so the fast step accepts that digest next to the 0.41.0 one. - _qwenimage21_prepare_qkv splits heads by attn.inner_dim // attn.heads (tensor parallel). That is the same split whenever every head is local, so the real RoPE wrapper accepts it, and the ConvRot fused QKV now splits the same way. - transformer_qwenimage dropped ROPE_PER_DEVICE and its attention processor calls the module global apply_rotary_emb_qwen directly. The Qwen-Image real RoPE now swaps that global when there is no table, gated on both the RoPE and the processor digests, and restores it on uninstall. Any other source still keeps the stock path.
- _estimate_download_bytes probed the mirror choice for a pipeline load with model_index.json, which FLUX.3 does not ship, so a cached upstream FLUX.3 snapshot never satisfied the probe and the plan staged the same pipeline again under the unsloth mirror. It now probes the family's base_manifest, as the access checks do. - resolve_local_single_file treated only model_index.json as a pipeline marker, so a local FLUX.3 modular directory with one root .safetensors was rewritten into a single-file load before the modular validation ran. It now returns None when either index exists. [skip ci]
…ests without diffusers Add vae/config.json for flux.3-klein and flux.3-klein-base to vae_tile_configs.json, read from unsloth/flux-3-image-klein-FP8 and unsloth/flux-3-image-klein-base-FP8 at pinned revisions, so test_vae_tile_fixture_coverage and the seam guard cover both families. Backend CI has no diffusers: the prompt upsampler block test now stubs the diffusers module it only reads a class from, and the fp8 prequant fixture skips when diffusers.hooks (layerwise casting) is missing.
…3 Image Klein) The mirror's release built from the upstream master-968 sync, the first upstream release with FLUX.3 Image Klein. Hosts the mirror does not build fall back to upstream master-968.
…rrent templates and the BFL reference
…shot loaded by repo id
…sed before eviction [skip ci]
…loth into studio-flux3-sdcpp # Conflicts: # studio/backend/core/inference/diffusion_compat.py # studio/backend/tests/test_diffusion_flux3.py # studio/backend/tests/test_diffusion_flux3_te_prequant.py # studio/backend/tests/test_diffusion_te_int8_convrot.py
… with its manifest's family The locality check plans the snapshot by its repo id, like the load, but passed no family, so an opaquely named repo could not pick the FLUX.3 seeds and read the omitted dense shards as missing. One helper now gives both the check and the load the family modular_model_index.json declares. [skip ci]
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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ebfb09d090
ℹ️ 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".
| sd_cpp_vae = ("unsloth/flux-3-image-klein-FP8", "vae/diffusion_pytorch_model.safetensors"), | ||
| sd_cpp_text_encoders = _FLUX3_SD_CPP_TEXT_ENCODERS, | ||
| # sd.cpp's documented invocation (docs/flux3.md). No flow shift: its scheduler already applies FLUX.3's 6.93. | ||
| sd_cpp_sampling_method = "euler", | ||
| sd_cpp_arch_marker = _FLUX3_SD_CPP_ARCH_MARKER, |
There was a problem hiding this comment.
Permit FLUX.3 references on the native path
When either FLUX.3 family is routed to sd.cpp and a request supplies an init/reference image, generate() calls _native_edit_ready(), which returns false for every family that is neither edit nor unified_edit with an edit marker and vision projector. These entries are only reference=True and deliberately provide no projector, so status advertises only txt2img and every reference request raises “Image editing is not available,” even though upstream explicitly lists both FLUX.3 variants as supporting the VAE-based flux2 reference preset in its image-edit documentation. The native readiness gate needs to recognize this projector-free reference mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4c0222f: FLUX.3 entries set sd_cpp_reference, and _native_reference_ready admits the reference workflow for them without a projector or edit marker (the arch gate already admitted the build). Status advertises txt2img and reference; instruction edits are still refused.
| sd_cpp_vae = ("unsloth/flux-3-image-klein-base-FP8", "vae/diffusion_pytorch_model.safetensors"), | ||
| sd_cpp_text_encoders = _FLUX3_SD_CPP_TEXT_ENCODERS, | ||
| sd_cpp_sampling_method = "euler", | ||
| sd_cpp_arch_marker = _FLUX3_SD_CPP_ARCH_MARKER, |
There was a problem hiding this comment.
Validate the FLUX.3 GGUF variant on the native path
For a renamed/local GGUF that requires family_override, these declarations make the model native-loadable, but SdCppDiffusionBackend.begin_load() never calls assert_flux3_checkpoint_matches_family; that check currently exists only in the diffusers loader. A base GGUF can therefore be recorded as distilled, or vice versa, and the route will silently apply the wrong defaults (16 steps/CFG 1/no negative prompt versus 50 steps/CFG 3.5) instead of issuing the variant-mismatch error already used by the torch path. Inspect the downloaded GGUF tensor names and reject the mismatch before committing native state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4c0222f: _run_load calls assert_flux3_checkpoint_matches_family on the downloaded GGUF right after the assets resolve, before any native state is built, so a mismatched variant gets the same refusal as the torch path.
… and refuses the other variant's GGUF - sd.cpp feeds FLUX.3 references through the VAE, so the native engine advertises and runs the reference workflow for both variants (not instruction edits). - The native load runs the same variant check as the diffusers loader on the downloaded GGUF, so a renamed base file is not loaded as distilled (or the reverse). [skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
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". |
…UF support (#13933) ## 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 (huggingface/diffusers#15046) and the 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 (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 #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: #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.  --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…lux3-sdcpp [skip ci]
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:
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.DiffusionFamily.sd_cpp_referencemarks the FLUX.3 families, so the native engine accepts theirreferenceworkflow (sd.cpp conditions FLUX.3 on references through the VAE) and status lists it. After the assets are fetched,_run_loadrunsassert_flux3_checkpoint_matches_familyon the denoiser, so a Klein GGUF picked under Klein Base (or the reverse) is refused before sd-cli starts.What sd-cli is handed
unsloth/flux-3-image-klein-GGUF(the pick)unsloth/flux-3-image-klein-base-GGUF(the pick)unsloth/flux-3-image-klein-FP8vae/diffusion_pytorch_model.safetensorsunsloth/flux-3-image-klein-base-FP8vae/diffusion_pytorch_model.safetensors--llm)unsloth/Qwen3-VL-4B-Instruct-GGUFQwen3-VL-4B-Instruct-Q8_0.gguf--vae-formatFlux.3 Image Kleinemb_in.image+txt_mode_blocks. No metadata fix is needed.unsloth/FLUX.2-VAE(sha256d64f3a68...). Each comes from its family's own FP8 repo. That repo is inprequant_repos, so it stays loadable and does not become a companion-only repo.image_condstream), not through the VLM. A reference edit with no mmproj renders correctly.Flux.3 Image Kleinis 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.unsloth/Qwen3-VL-4B-Instruct-GGUFjoins 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:
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
SdCppDiffusionBackendloadedunsloth/flux-3-image-klein-GGUFUD-Q4_K_XL on a CPU-only process. It usedSD_CLI_PATH/SD_SERVER_PATHpointing at the synced CPU build, and the assets came from this mapping. It reportedengine=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.pyhas 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
master-968-8cd731e-ubdb47d1. The installer resolves it for CPU, CUDA 13 and Vulkan on Linux x64, and the CPU build installs and runs.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.