Repository navigation
Description
Describe the bug
_convert_non_diffusers_flux2_lora_to_diffusers maps the original (BFL) key final_layer.adaLN_modulation.1 to norm_out.linear unchanged. The two layers order their output differently:
- The original final layer splits its modulation into
shift, scale. AdaLayerNormContinuoussplits it intoscale, shift.
The checkpoint converter accounts for this: convert_flux2_transformer_checkpoint_to_diffusers swaps the halves ("Handle separately since we need to swap mod params"). The FLUX.1 LoRA converters use swap_scale_shift for the same key. The FLUX.2 LoRA converter does not swap. So when a LoRA in the original layout adapts the final layer's modulation, the update meant for the shift lands on norm_out's scale, and the scale's on the shift.
The fix is to swap the halves of lora_B, whose rows are the layer's outputs, and leave lora_A as it is. I'd be glad to open a PR with that and a test in TestFlux2TransformerLoRA.
_convert_non_diffusers_flux2_lokr_to_diffusers maps the same key the same way. I have not checked LoKr adapters.
Reproduction
import torch
from diffusers.loaders.lora_pipeline import Flux2LoraLoaderMixin
dim = 64 # any hidden size; norm_out.linear maps dim -> 2 * dim
lora_A, lora_B = torch.randn(2, dim), torch.randn(2 * dim, 2)
state_dict = {
"diffusion_model.final_layer.adaLN_modulation.1.lora_A.weight": lora_A,
"diffusion_model.final_layer.adaLN_modulation.1.lora_B.weight": lora_B,
}
converted = Flux2LoraLoaderMixin.lora_state_dict(state_dict)
delta = converted["transformer.norm_out.linear.lora_B.weight"] @ converted["transformer.norm_out.linear.lora_A.weight"]
# The original final layer splits its modulation into (shift, scale), diffusers' norm_out into (scale, shift)
shift, scale = (lora_B @ lora_A).chunk(2, dim=0)
print(torch.allclose(delta, torch.cat([scale, shift]))) # expected TrueOn main (843f174) this prints False. With lora_B swapped in the converter it prints True.
Context
I found this while adding LoRA support to h3metal, an inference engine for Apple silicon. Its tests compare its results with diffusers'.
The test setup was a small random Flux2Transformer2DModel with a random adapter in the original layout that includes this layer, loaded through load_lora_weights. Its first-step output was 15% (relative L2) away from the same adapter merged into the float32 weights. With the swap it was 0.0.
I worked with an AI agent (Claude Code). The snippet above was run as shown.
Logs
No error is raised: the adapter loads, and its final-layer update is applied to the wrong halves.System Info
- diffusers
main(843f174), torch 2.15.0, Python 3.12, macOS 27.2 (arm64). - The bug is in the state-dict conversion and does not depend on the platform.
Activity
sayakpaul commentedon Nov 13, 2026
Thanks for reporting! Would you be willing to open a PR for this?
Swap shift and scale in Flux2 LoRAs of final_layer.adaLN_modulation.1 (…