Skip to content

flux2-klein-base-4b训练出错 RuntimeError: FlashAttention only support fp16 and bf16 data type #1271

Closed

Description

@zhenbuxianggaimingzi
Image

Activity

  1. zhenbuxianggaimingzi commented on Feb 6, 2026

    @zhenbuxianggaimingzi
    Author

    看起来似乎是因为flux2_dit中使用的是torch.nn库中的Layernorm和RMSNorm,accelerate自动混合精度训练时会自动将类型向上转换为fp32,但并不会再自动转换回bf16,因此需要手动在所有的norm后手动添加类型转换,转回bf16。
    在我自己的代码里这样修改确实是可行的,修改后训练能正常进行了。

    历史issue中似乎也有过类似的问题 #628 #696,但都是wan相关的训练,新版本代码仓wan中使用的自定义RMSNorm会自动将类型转回bf16,另外zimage/qwen-image/flux1等其他dit代码中也都是使用的自定义RMSNorm,仅有flux2会出现类似问题......

  2. Artiprocher commented on Feb 10, 2026

    @Artiprocher
    Collaborator

    @zhenbuxianggaimingzi 这是个存在很久但我们一直没能复现的问题,近期我们发现这是由于 torch 版本过低导致的,这个问题已修复,但我们仍然建议升级到最新版的 torch:#1280

  3. added a commit that references this issue on Oct 13, 2026
    6425692
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