feat(flux2): add FLUX.2 klein model support#8768
Conversation
- Add new invocation nodes for FLUX 2: - flux2_denoise: Denoising invocation for FLUX 2 - flux2_klein_model_loader: Model loader for Klein architecture - flux2_klein_text_encoder: Text encoder for Qwen3-based encoding - flux2_vae_decode: VAE decoder for FLUX 2 - Add backend support: - New flux2 module with denoise and sampling utilities - Extended model manager configs for FLUX 2 models - Updated model loaders for Klein architecture - Update frontend: - Extended graph builder for FLUX 2 support - Added FLUX 2 model types and configurations - Updated readiness checks and UI components
FLUX.2 VAE uses Batch Normalization in the patchified latent space (128 channels). The decode must: 1. Patchify latents from (B, 32, H, W) to (B, 128, H/2, W/2) 2. Apply BN denormalization using running_mean/running_var 3. Unpatchify back to (B, 32, H, W) for VAE decode Also fixed image normalization from [-1, 1] to [0, 255]. This fixes washed-out colors in generated FLUX.2 Klein images.
…nkuchensack/InvokeAI into feature/flux2-klein-support
…ompatibility - Add FLUX.2 transformer loader with BFL-to-diffusers weight conversion - Fix AdaLayerNorm scale-shift swap for final_layer.adaLN_modulation weights - Add VAE batch normalization handling for FLUX.2 latent normalization - Add Qwen3 text encoder loader with ComfyUI FP8 quantization support - Add frontend components for FLUX.2 Klein model selection - Update configs and schema for FLUX.2 model types
- Add isFlux2Klein9BMainModelConfig and isNonCommercialMainModelConfig functions - Update MainModelPicker and InitialStateMainModelPicker to show license icon - Update license tooltip text to include FLUX.2 Klein 9B
|
I tested with two models: the diffusers model at Initial observations:
|
|
Here's a trivial fix for the error |
Backend: - Add klein_4b/klein_9b variants for FLUX.2 Klein models - Add qwen3_4b/qwen3_8b variants for Qwen3 encoder models - Validate encoder variant matches Klein model (4B↔4B, 9B↔8B) - Auto-detect Qwen3 variant from hidden_size during probing Frontend: - Show variant field for all model types in ModelView - Filter Qwen3 encoder dropdown to only show compatible variants - Update variant type definitions (zFlux2VariantType, zQwen3VariantType) - Remove unused exports (isFluxDevMainModelConfig, isFlux2Klein9BMainModelConfig)
Distinguish between FLUX.2 Klein 9B (distilled) and Klein 9B Base (undistilled) models by checking guidance_embeds in diffusers config or guidance_in keys in safetensors. Klein 9B Base requires more steps but offers higher quality.
Backend changes: - Update text encoder layers from [9,18,27] to (10,20,30) matching diffusers - Use apply_chat_template with system message instead of manual formatting - Change position IDs from ones to zeros to match diffusers implementation - Add get_schedule_flux2() with empirical mu computation for proper schedule shifting - Add txt_embed_scale parameter for Qwen3 embedding magnitude control - Add shift_schedule toggle for base (28+ steps) vs distilled (4 steps) models - Zero out guidance_embedder weights for Klein models without guidance_embeds UI changes: - Clear Klein VAE and Qwen3 encoder when switching away from flux2 base - Clear Qwen3 encoder when switching between different Klein model variants - Add toast notification informing user to select compatible encoder
|
The recent commit is causing the previously-installed ZImage Qwen3 encoders to fail validation with warnings like this one: |
|
@Pfannkuchensack Fantastic work! I am doing testing now. Hope to be able to approve and merge Friday. |
|
@Pfannkuchensack With this PR I'm getting config validation errors on previously-installed Z-Image Turbo models. I can reinstall the models and they work. Is this expected? |
I dont have a z-image installed in my test instance, so i cant check that. Do you have message from the console ? |
So far the only issue I've encountered with your PR is that the VAE and text encoders (in the "Advanced" section) are not being recalled when you recall generation parameters. Inpainting is working, but I find that I can't significantly modify the raster layer unless I set the denoising level to a high level of 0.95 or greater. Is this expected for this model? I'm continuing to test various features. |
The scheduler, VAE model, and Qwen3 encoder model were not being recalled correctly for FLUX.2 Klein images. This adds dedicated metadata handlers for the Klein-specific parameters.
- Apply exponential denoising scaling (exponent 0.2) to FLUX.2 Klein, matching FLUX.1 behavior for more intuitive inpainting strength - Add isFlux1VAEModelConfig type guard to filter FLUX 1.0 VAEs only - Restrict Z-Image VAE selection to FLUX 1.0 VAEs, excluding FLUX.2 Klein 32-channel VAEs which are incompatible
|
The inpainting should be better now. |
|
@Pfannkuchensack I think this is nearly ready to go. The only things missing for release are:
A couple of questions for the release notes:
|
- Add FLUX.2 Klein hardware requirements to quick start guide - Create flux2_klein_bundle with GGUF Q4 model, VAE, and Qwen3 encoder - Add "What's New" entry announcing FLUX.2 Klein support
FLUX.2 Klein has native multi-reference image editing without requiring a separate model (unlike FLUX.1 which needs a Kontext model). Backend changes: - Add Flux2RefImageExtension for encoding reference images with FLUX.2 VAE - Apply BN normalization to reference image latents for correct scaling - Use T-coordinate offset scale=10 like diffusers (T=10, 20, 30...) - Concatenate reference latents with generated image during denoising - Extract only generated portion in step callback for correct preview Frontend changes: - Add flux2_reference_image config type without model field - Hide model selector for FLUX.2 reference images (built-in support) - Add type guards to handle configs without model property - Update validators to skip model validation for FLUX.2 - Add 'flux2' to SUPPORTS_REF_IMAGES_BASE_MODELS
|
Added the image edit functionality. I did not test it yet but i saw that you can use openpose images as ref images and changes poses with klein Prompt format may be importantAccording to diffusers documentation, you should reference images in your prompt:
FLUX.2 Klein only
No model selector
VRAM usage
|
Resize large reference images to match BFL FLUX.2 sampling.py limits: - Single reference: max 2024² pixels (~4.1M) - Multiple references: max 1024² pixels (~1M) Uses same scaling approach as BFL's cap_pixels() function.
…nkuchensack/InvokeAI into feature/flux2-klein-support
|
Great! I'll do final review tonight and hopefully can merge after that. I'll take a look at VRAM consumption as edit images are added and add some guidance to the release notes. |
lstein
left a comment
There was a problem hiding this comment.
I have tested all features, reviewed documentation, and everything checks out. Amazing work!
Can you check the model manager to see what the problematic model has been autodetected as? It looks like it thinks that this is a flux.1 model, not flux.2. |
I don't think so. I just installed a safetensors model file via Scan Folder tab with default settings -- Ok I just updated to 6.11rc and downloaded klein 9bfp8 model from Starter pack, now it initializes correct.
But it still doesn't work. My qwen_3_8b_fp8mixed (https://huggingface.co/Comfy-Org/vae-text-encorder-for-flux-klein-9b/tree/main/split_files/text_encoders) defines as checkpoint and an error occurs during generation. As you can see Qwen3 4B text encoder from starter pack doesn't even shown in Advanced tab
This error occurs if I change my qwen_3_8b_fp8mixed model format to Qwen3 Encoder
|
|
By default a heavy 8B 16GB encoder is starts downloading when I select klein 9bfp8 from Starter pack. And I can even see it in an Advanced tab, but it's impossible for my 4070 12Gb / 64Gb |
|
I've try to use new flux2 model on my laptop with NVIDIA GeForce RTX 5060 Laptop GPU, 8 Gb VRAM, but have no success. OOM occured. I've downloaded FLUX.2 Klein 4B (FP8) model, Invoke AI have installed FLUX.2 Klein Qwen3 4B Encoder Loading checkpoint shards: 100%|█████████████████████████████████████████| 2/2 [00:00<00:00, 66.62it/s] I'm using v6.11.0.rc1 version of the programm. Does it possible to use this model in my situation? As stated in the release documentation, this config should work: FLUX.2 Klein 4B - 1024×1024 |
|
I just tryied 'FLUX.2 Klein 4B GGUF Q4_K_M quantized', that labeled 'runs on 6-8GB VRAM' with same result |
|
Do you have enabled low vram mode https://invoke-ai.github.io/InvokeAI/features/low-vram/ ? |
|
Hmm, I actually changed these parameters, but apparently a program update reset this file. I re-added the parameters and it helped, thank you very much! |





Summary
Add initial support for FLUX 2 klein models architecture.
New Invocation Nodes
Backend Support
flux2module with denoise and sampling utilitiesFrontend Updates
Related Issues / Discussions
QA Instructions
Merge Plan
Standard merge after review.
Checklist
What's Newcopy (if doing a release after this PR)