fix(model_manager): detect Flux 2 Klein LoRAs in Kohya format with transformer-only keys - #8938
Merged
lstein merged 4 commits intoMar 7, 2026
Conversation
…ansformer-only keys LoRAs trained with musubi-tuner (and potentially other trainers) that only target transformer blocks (double_blocks/single_blocks) without embedding layers (txt_in/vector_in/context_embedder) were incorrectly classified as Flux 1. Add fallback detection using attention projection hidden_size and MLP ratio from transformer block tensors
Pfannkuchensack
requested review from
JPPhoto,
blessedcoolant,
dunkeroni and
lstein
as code owners
March 2, 2026 21:08
lstein
requested changes
Mar 7, 2026
lstein
left a comment
Collaborator
There was a problem hiding this comment.
Would it be possible to add a test for this format in model_identification/stripped_models?
lstein
self-requested a review
March 7, 2026 01:37
lstein
approved these changes
Mar 7, 2026
lstein
left a comment
Collaborator
There was a problem hiding this comment.
Code looks good. No examples of this format easily available, so will go ahead and accept.
lstein
enabled auto-merge (squash)
March 7, 2026 01:43
Pfannkuchensack
deleted the
fix/flux2-kohya-transformer-only-lora-detection
branch
March 7, 2026 16:59
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
LoRAs trained with musubi-tuner (and potentially other trainers) that only target transformer blocks (
double_blocks/single_blocks) without embedding layers (txt_in/vector_in/context_embedder) were incorrectly classified as Flux 1.The existing Kohya-format detection in
_is_flux2_lora_state_dictand_get_flux2_lora_variantonly checked for embedding layer keys (lora_unet_txt_in.*,lora_unet_vector_in.*,lora_unet_context_embedder.*). LoRAs that exclusively target transformer blocks (e.g.lora_unet_double_blocks_0_img_attn_proj.*) fell through all checks and defaulted to Flux 1.This PR adds fallback detection for Kohya-format LoRAs using transformer block tensor dimensions:
_is_flux2_lora_state_dict: Checkimg_attn_projhidden_size (lora_down.weightshape[1]). If hidden_size ≠ 3072 → Flux 2. If hidden_size = 3072 (ambiguous between Flux 1 and Klein 4B), check MLP ratio viaimg_mlp_0ffn_dim — Klein 4B uses mlp_ratio=6 (ffn_dim=18432) vs Flux 1 mlp_ratio=4 (ffn_dim=12288)._get_flux2_lora_variant: Sameimg_attn_projhidden_size check to determine Klein 4B (3072) vs Klein 9B (4096).Both functions also handle LoKR variants of these keys.
QA Instructions
Tested with simulated state dicts matching the tensor shapes from a real musubi-tuner Flux 2 Klein 9B LoRA:
_is_flux2_lora_state_dict_get_flux2_lora_variantTrueKlein9BTrueKlein4BFalseChecklist
What's Newcopy (if doing a release after this PR)