Adding Image Editing to Flux2.Klein Models - #461
Open
amepas wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for the FLUX.2-Klein model in MaxDiffusion, adding the top-level NNXFlux2KleinTransformer2DModel and NNXAutoencoderKLFlux2 VAE models, along with image editing capabilities, concurrent AOT compilation, and end-to-end parity tests. The review feedback highlights several critical runtime issues that must be addressed, including missing imports (snapshot_download, Image, and time) and the use of non-existent Flax NNX API functions (nnx.to_flat_state and nnx.from_flat_state), which should be replaced with .flat() and nnx.State.from_flat() respectively.
amepas
force-pushed
the
onboarding-imageedit-flux2klein
branch
from
August 21, 2026 23:59
753f68b to
9b1c0e9
Compare
…X (4B & 9B) with E2E parity and smoke tests
amepas
force-pushed
the
onboarding-imageedit-flux2klein
branch
from
August 22, 2026 00:07
9b1c0e9 to
34d1b0f
Compare
amepas
marked this pull request as ready for review
August 22, 2026 00:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Adds Image Editing Support to the Flux2.Klein 4B and 9B models. Supports both single-image and multi-reference image editing (conditioning image generation on up to 4 reference images alongside textual prompts).
Additions
use_base_exp2=Trueto eliminate mathematical precision loss when running the custom 2D Ring Ulysses attention kernel (ulysses_ring_custom_fixed_m).Usage
Code is configured to re-use all possible pipeline components and existing entry points. Calling image editing only requires a flag pointing to the image file locations.
Runtime:
Editing single image of size 1024 by 1024 with the Flux2.Klein 9B using the Optimal TPU-v7 T2I settings from PR #458.
TP=4)24.28 ms26.47 ms8.60 ms7.35 ms640.19 ms1204.24 ms31.11 ms34.02 ms107.76 ms113.21 ms707.75 ms1276.39 ms815.51 ms1389.50 msCorrectness:
E2E Parity Test against Diffusers pytorch baseline shows SSIM of 0.80 (both running bfloat16). Test included!
Visual Verification
Example 1:
Prompt: "add a bunch of animals swimming in the water in front of the castle and get rid of all birds"
Original:

Edited:

Example 2:
Prompt: "change the painting so she is facing forward instead of looking over her shoulder"
Original:

Edited:

Future Work
KV Cache not supported in this PR.