Skip to content

fix(flux2): filter non-transformer keys from bundled checkpoints#9060

Open
lstein wants to merge 3 commits intomainfrom
fix/flux2-bundled-checkpoint-loading
Open

fix(flux2): filter non-transformer keys from bundled checkpoints#9060
lstein wants to merge 3 commits intomainfrom
fix/flux2-bundled-checkpoint-loading

Conversation

@lstein
Copy link
Copy Markdown
Collaborator

@lstein lstein commented Apr 17, 2026

Summary

This PR handles the case of FLUX.2 all-in-one checkpoints that have bundled text encoders and or VAEs. It uses the same logic as the Z-Image loader:

  • Fixes RuntimeError: Error(s) in loading state_dict for Flux2Transformer2DModel when loading bundled Flux.2 .safetensors checkpoints that include text encoder (text_encoders.*) and VAE (vae.*) keys alongside the transformer weights.
  • Filters out non-transformer keys before BFL-to-diffusers conversion and load_state_dict, matching the approach already used by the Z-Image loader.
  • Applied to both the regular checkpoint loader (Flux2CheckpointModel) and the GGUF loader (Flux2GGUFCheckpointModel).

Testing

  • Confirm that there is are no regressions when loading FLUX.2 diffusers and GGUF models.
  • Confirm that the key filter unit test tests/backend/model_manager/load/model_loaders/test_flux2_checkpoint_bundled_keys.py succeeds.
  • (optional) Confirm that generation works with an actual FLUX.2 bundled .safetensors models (no examples given here; the only ones I've seen in the wild are 3d party tuned NSFW models on civitai.red)

Merge Plan

Simple merge

Some Flux.2 .safetensors files are combined checkpoints that bundle
text encoder and VAE weights alongside the transformer. These extra
keys (text_encoders.*, vae.*) were passing through to load_state_dict
and causing RuntimeError due to unexpected keys. Filter them out
before conversion, matching the approach used by the Z-Image loader.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added python PRs that change python files backend PRs that change backend files labels Apr 17, 2026
Verify that text_encoders.* and vae.* keys are properly filtered
from bundled FLUX.2 checkpoints, and that non-bundled checkpoints
are unaffected.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added the python-tests PRs that change python tests label Apr 17, 2026
@lstein lstein marked this pull request as ready for review April 17, 2026 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend PRs that change backend files python PRs that change python files python-tests PRs that change python tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants