Flux Control and HunyuanVideo LoRA converters swap the scale/shift halves of `lora_A` in `final_layer`

未关闭
#15,305 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@MaiAditya 已经在做这个了。

开始于 2026年11月16日。

  • #15307 来自 @MaiAditya —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python, pytorch

调研方向

Read loaders/lora_conversion_utils.py and the existing test_lora_bfl_final_layer_modulation test. The issue identifies both affected converters and proposes one test per converter, checking that only lora_B is swapped; run those tests to confirm the converted delta matches the expected scale/shift order. A pull request is already open for this issue.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

final_layer.adaLN_modulation.1 in the original checkpoints orders its output (shift, scale), and diffusers' norm_out.linear orders it (scale, shift), so the converters swap the two halves. For a LoRA only lora_B should be swapped: its rows are the layer's outputs. lora_A is (rank, in), so swapping its halves reorders the rank dimension and the converted delta is wrong.

Two converters in loaders/lora_conversion_utils.py swap both:

  • _convert_bfl_flux_control_lora_to_diffusers: swap_scale_shift is applied for every lora_key, including lora_A (weight and bias).
  • _convert_hunyuan_video_lora_to_diffusers: remap_norm_scale_shift_ swaps every final_layer.adaLN_modulation.1 key, lora_A included.

The kohya Flux converter already swaps only lora_B. This is the same class of bug #15276 fixed for Flux2.

Reproduction
import torch
from diffusers.loaders.lora_conversion_utils import _convert_bfl_flux_control_lora_to_diffusers

RANK, INNER = 4, 3072
torch.manual_seed(0)

class FillingDict(dict):
    # dummy tensors for the keys the converter pops that this repro doesn't care about
    def pop(self, key, *default):
        if key in self:
            return super().pop(key)
        if default:
            return default[0]
        return torch.zeros(21504, RANK) if ".lora_B." in key else torch.zeros(RANK, 8)

lora_A = torch.randn(RANK, INNER)
lora_B = torch.randn(2 * INNER, RANK)  # rows: (shift, scale)
sd = FillingDict({
    "final_layer.adaLN_modulation.1.lora_A.weight": lora_A.clone(),
    "final_layer.adaLN_modulation.1.lora_B.weight": lora_B.clone(),
    "double_blocks.0.img_attn.norm.query_norm.scale": torch.ones(1),
})
out = _convert_bfl_flux_control_lora_to_diffusers(sd)
A = out["transformer.norm_out.linear.lora_A.weight"]
B = out["transformer.norm_out.linear.lora_B.weight"]
shift, scale = (lora_B @ lora_A).chunk(2, dim=0)
expected = torch.cat([scale, shift])
print(torch.allclose(B @ A, expected, atol=1e-4), (B @ A - expected).abs().max().item())
print(torch.allclose(B @ lora_A, expected, atol=1e-4))  # lora_A left as is
Logs
False 39.052650451660156
True

The HunyuanVideo converter gives the same result (max error 17.05 in the equivalent check).

System Info

diffusers main @ 43e3002, torch 2.15.0, Python 3.12, macOS (CPU).

Who can help?

@sayakpaul

I have a fix with tests for both converters (swap only lora_B; one test per converter in the style of test_lora_bfl_final_layer_modulation, both fail on main) and can open a PR if you'd like. It may change the expected slices of the slow Flux Control LoRA integration tests, which I can't regenerate without a GPU.

主要语言
Python
星标
34.9k
派生
7.5k
平均合并
3 天 16 小时
30 天内合并 PR
65

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。