Skip to content

Flux2 LoRA conversion maps final_layer.adaLN_modulation.1 to norm_out.linear without swapping shift and scale #15275

Closed

Description

@audenvenn

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.
  • AdaLayerNormContinuous splits it into scale, 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 True

On 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.

Who can help?

@sayakpaul

Activity

  1. sayakpaul commented on Nov 13, 2026

    @sayakpaul
    Member

    Thanks for reporting! Would you be willing to open a PR for this?

  2. added a commit that references this issue on Nov 13, 2026
    2c58e66
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions