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
2 times, most recently
from
August 22, 2026 00:07
9b1c0e9 to
34d1b0f
Compare
amepas
marked this pull request as ready for review
August 22, 2026 00:07
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
Collaborator
|
Could you also add SSIM metric against baseline for the following?
|
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
eltsai
reviewed
Aug 24, 2026
amepas
force-pushed
the
onboarding-imageedit-flux2klein
branch
from
August 25, 2026 23:37
ff44680 to
84dc112
Compare
…X (4B & 9B) with E2E parity and smoke tests - Add multi-image editing pipeline (FlaxFlux2KleinPipeline) supporting arbitrary reference image conditioning - Port VAE encoder and decoder to Flax NNX (AutoencoderKLFlux2NNX) - Implement efficient image preprocessing, tiling, aspect-ratio-aware padding, and packing utilities - Support fast sharded safetensors loading and TP sharding for Klein 4B & 9B - Use standard HF_HOME resolution without machine-specific hardcoded paths - Ensure clean compatibility across Transformers 4.x and 5.x via lazy module loading and dynamic FlaxPreTrainedModel lookup - Add end-to-end multi-image editing parity test and preprocessing unit test suite
amepas
force-pushed
the
onboarding-imageedit-flux2klein
branch
from
August 26, 2026 06:40
9136788 to
7eeb545
Compare
eltsai
approved these changes
Aug 26, 2026
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:
Below numbers generated on v6-4.
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:

Other notes
Code was tested under transformers versions 4.X and 5.X.
Future Work
KV Cache not supported in this PR.