fix(flux2): Fix FLUX.2 Klein image generation quality#8838
fix(flux2): Fix FLUX.2 Klein image generation quality#8838lstein merged 7 commits intoinvoke-ai:mainfrom
Conversation
This commit addresses severe quality degradation and artifacts when generating images larger than 1024x1024 with FLUX.2 Klein models. Root causes fixed: 1. Dynamic max_image_seq_len in scheduler (flux2_denoise.py) - Previously hardcoded to 4096 (1024x1024 only) - Now dynamically calculated based on actual resolution - Allows proper schedule shifting at all resolutions 2. Smoothed mu calculation discontinuity (sampling_utils.py) - Eliminated 40-50% mu value drop at seq_len 4300 threshold - Implemented smooth cosine interpolation (4096-4500 transition zone) - Gradual blend between low-res and high-res formulas Impact: - FLUX.2 Klein 9B: Major quality improvement at high resolutions - FLUX.2 Klein 4B: Improved quality at high resolutions - Baseline 1024x1024: Unchanged (no regression) - All generation modes: T2I and Kontext (reference images) Fixes: Community-reported quality degradation issue See: Discord discussions in #garbage-bin and #devchat Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
I can confirm that the PR does not degrade image quality or performance, but I'm having a difficult time reproducing the image quality degradation on the I am going to ask other developers on Discord to do some testing. |
|
Just updating the comment thread to match conclusions on Discord. This PR does not fix the underlying issue. At higher step counts, larger image sizes, and/or shorter prompts, both flux.2 klein models produce marked image artifacts. The effect is easily seen at 1024x1024 by generating without a prompt, which produces images with prominent diagonal elements. |
Fixes grid/diamond artifacts and color loss at resolutions > 1024x1024.
Root causes identified and fixed:
- BN normalization was incorrectly applied to random noise input
(diffusers only normalizes image latents from VAE.encode)
- BN denormalization must be applied to output before VAE decode
- mu parameter was resolution-dependent causing over-shifted schedules
at high resolutions (now fixed to 2.02, matching ComfyUI)
Changes:
- Remove BN normalization on noise input (not needed for N(0,1) noise)
- Preserve BN denormalization on denoised output (required for VAE)
- Fix mu to constant 2.02 for all resolutions (matches ComfyUI)
Tested at 2048x2048 with FLUX.2 Klein 4B
…hub.com/Pfannkuchensack/InvokeAI into fix/flux2-klein-high-resolution-quality
JPPhoto
left a comment
There was a problem hiding this comment.
Results are worlds better than they were, great job!
* fix(flux2): Fix image quality degradation at resolutions > 1024x1024
This commit addresses severe quality degradation and artifacts when
generating images larger than 1024x1024 with FLUX.2 Klein models.
Root causes fixed:
1. Dynamic max_image_seq_len in scheduler (flux2_denoise.py)
- Previously hardcoded to 4096 (1024x1024 only)
- Now dynamically calculated based on actual resolution
- Allows proper schedule shifting at all resolutions
2. Smoothed mu calculation discontinuity (sampling_utils.py)
- Eliminated 40-50% mu value drop at seq_len 4300 threshold
- Implemented smooth cosine interpolation (4096-4500 transition zone)
- Gradual blend between low-res and high-res formulas
Impact:
- FLUX.2 Klein 9B: Major quality improvement at high resolutions
- FLUX.2 Klein 4B: Improved quality at high resolutions
- Baseline 1024x1024: Unchanged (no regression)
- All generation modes: T2I and Kontext (reference images)
Fixes: Community-reported quality degradation issue
See: Discord discussions in #garbage-bin and #devchat
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix(flux2): Fix high-resolution quality degradation for FLUX.2 Klein
Fixes grid/diamond artifacts and color loss at resolutions > 1024x1024.
Root causes identified and fixed:
- BN normalization was incorrectly applied to random noise input
(diffusers only normalizes image latents from VAE.encode)
- BN denormalization must be applied to output before VAE decode
- mu parameter was resolution-dependent causing over-shifted schedules
at high resolutions (now fixed to 2.02, matching ComfyUI)
Changes:
- Remove BN normalization on noise input (not needed for N(0,1) noise)
- Preserve BN denormalization on denoised output (required for VAE)
- Fix mu to constant 2.02 for all resolutions (matches ComfyUI)
Tested at 2048x2048 with FLUX.2 Klein 4B
* Chore Ruff
---------
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-authored-by: Jonathan <34005131+JPPhoto@users.noreply.github.com>
Summary
This commit addresses severe quality degradation and artifacts when generating images with FLUX.2 Klein models.
Root causes fixed:
BN Normalization on noise input (flux2_denoise.py)
Missing BN Denormalization on output (flux2_denoise.py)
Dynamic mu calculation causing over-shifted schedules (sampling_utils.py)
Impact:
Related Issues / Discussions
#8832
Community-reported quality degradation issues on Discord:
QA Instructions
Test Setup
Use FLUX.2 Klein models (both 4B and 9B variants) with the following configurations:
Critical Test Cases (Priority)
1. Baseline - Standard Resolution:
2. High Resolution Test:
3. Color Reproduction:
4. Both Generation Modes:
What to Look For
Improvements:
Technical Verification:
Merge Plan
No special merge considerations needed.
This is a targeted bug fix with:
Safe to merge after QA verification.
Checklist
What's Newcopy (if doing a release after this PR) - Recommended: "Fixed FLUX.2 Klein image quality issues (color loss, artifacts)"