Repository navigation
fix(flux): load diffusers FLUX LoRAs with text-encoder layers - #10046
Merged
Pfannkuchensack merged 1 commit intoOct 28, 2026
Merged
Conversation
Pfannkuchensack
approved these changes
Oct 27, 2026
Pfannkuchensack
left a comment
Member
There was a problem hiding this comment.
Thanks, this fixes #10024. Checked:
- Repro from #10024. A diffusers FLUX.1 LoRA with
transformer.andtext_encoder.layers now loads instead of tripping the closing assert. - Patching real module trees. I converted a state dict with CLIP (
text_encoder.text_model.encoder.layers.0.{self_attn.q_proj,mlp.fc1}) and T5 (text_encoder_2.encoder.block.0.layer.{0.SelfAttention.q,1.DenseReluDense.wi_0}) layers and applied it withLayerPatcherand the CLIP / T5 prefixes to a CLIP-L-shapedCLIPTextModeland a T5-XXL-shapedT5EncoderModel(one block each, transformers 5.10). Exactly those four weights change, each byB @ A * alpha / rank(relative error ~5e-8), and they are restored on exit. The text-encoder layers get the samealphaas the transformer layers because they go through the sameget_lora_layer_values. - Tests. The new test passes and fails with
main's converter.tests/backend/patches: 279 passed, 2 skipped.
Two small things, neither blocking:
1 task done
Contributor
Author
|
Thanks for the thorough check! Added #10045 had already landed, so I rebased on main (9427b32) and kept both tests at the end of |
Route text_encoder.* keys to the CLIP prefix and text_encoder_2.* keys to the T5 prefix instead of leaving them unconverted, which tripped the closing assert and rejected the whole LoRA (transformer layers included).
chiliec
force-pushed
the
fix/flux-diffusers-lora-text-encoder
branch
from
October 28, 2026 11:42
684bc34 to
9427b32
Compare
6 of 7 tasks
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.
What
Closes #10024
FLUX.1 diffusers-format LoRAs that also train the text encoders fail to load (#10024):
Diffusers keeps the CLIP layers under
text_encoder.and (for e.g. OneTrainer) T5 layers undertext_encoder_2., next to thetransformer.layers.lora_layers_from_flux_diffusers_grouped_state_dictonly converted the transformer keys, so any text-encoder key was left over and tripped the closingassert len(grouped_state_dict) == 0. The whole LoRA was rejected, transformer layers included.Fix
Before stripping the
transformer.prefix, split the text-encoder layers out and route them to the existing internal prefixes:text_encoder.*→FLUX_LORA_CLIP_PREFIX,text_encoder_2.*→FLUX_LORA_T5_PREFIX. This mirrors what the kohya (lora_te1_/lora_te2_) and OneTrainer paths already do, and produces the same internal key shapes (text_model.encoder.layers.*for CLIP,encoder.block.*for T5). Only the transformer layers continue through the diffusers conversion, so the closing assert still guards against genuinely unhandled transformer keys.Tests
Added
test_lora_model_from_flux_diffusers_state_dict_with_text_encoder_layersto the existing diffusers conversion test, asserting that a state dict withtransformer.*,text_encoder.*, andtext_encoder_2.*keys loads and yields layers under all three prefixes.Validation
Ran the conversion test module (full file: 3 existing load tests, detector true/false tests, the extra-keys error test, and the new text-encoder test):
RED→GREEN confirmed: the new test raises
AssertionErroron the unpatched source and passes after the fix.ruff checkis clean on both files.Verified locally on Linux/CPU (torch 2.14.1+cpu). I could not run the project's full pytest suite on this machine — the repo's
conftest.pyimports the whole app, which pulls in packages with no Linux wheels here (patchmatch); the conversion tests were run directly against the installed package in app-import order.Need help on this PR? Tag
@codesmith-botwith what you need.