FlowMatchSFTLoss: BF16 timestep rounding silently zeros Wan training loss

未關閉
#1,829 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

  • #1830 來自 @number-eleven11 —— 已關閉,未合併
  • #1831 來自 @number-eleven11 —— 已關閉,未合併

評估

難度
3/5
預估耗時
1-2 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python, pytorch

研究方向

Start with diffsynth/diffusion/flow_match.py and the FlowMatchSFTLoss code that casts scheduler.timesteps[timestep_id] before calling add_noise and training_weight. Reproduce the CPU example in the issue, then trace how both scheduler methods look up the timestep. Done when the sampled ID 1 retains its nonzero weight under BF16 model compute and a regression test covers the case.

由索引模型根據 Issue 內容生成。

描述

Summary

In Wan FlowMatch SFT with a BF16 pipeline, a sampled timestep with a nonzero training weight can silently become a zero-loss step. The sampled FP32 timestep is converted to BF16 before FlowMatchScheduler.training_weight() looks it up again by value. Near 1000, several distinct schedule entries round to 1000 and resolve to index 0, whose training weight is zero.

This is related to #1499's BF16 timestep rounding, but that fix changed DDIMScheduler's out-of-range indexing. This report concerns FlowMatchScheduler's silent zero weight in Wan training.

Minimal reproduction (CPU; no model weights needed)

import torch
from diffsynth.diffusion.flow_match import FlowMatchScheduler

scheduler = FlowMatchScheduler("Wan")
scheduler.set_timesteps(1000, training=True)

sampled_id = torch.tensor([1])
fp32_timestep = scheduler.timesteps[sampled_id]
bf16_timestep = fp32_timestep.to(torch.bfloat16)
sampled_weight = scheduler.linear_timesteps_weights[sampled_id]
effective_weight = scheduler.training_weight(bf16_timestep)

print("sampled_id:", sampled_id.item())
print("fp32_timestep:", fp32_timestep.item())
print("bf16_timestep:", bf16_timestep.item())
print("sampled_weight:", sampled_weight.item())
print("effective_weight:", effective_weight.item())
assert sampled_weight.item() > 0
assert effective_weight.item() == 0

Observed: sampled_id=1, FP32 timestep 999.7998046875, BF16 timestep 1000.0, sampled weight 0.0012814513, effective weight 0.0. With the Wan schedule and BF16 conversion, sampled IDs 0..9 all resolve to weight index 0.

Training observation

In an 8-GPU Wan2.2-I2V-A14B high-noise SFT run (min_timestep_boundary=0, max_timestep_boundary=0.358, BF16, seed 3407), rank 0 recorded loss 0.0 at steps 86 and 89. A diagnostic rerun with only logging added to FlowMatchSFTLoss reproduced both steps:

Step Sampled ID Unweighted MSE Effective weight Final loss
86 1 0.01783781499 0.0 0.0
89 1 0.02866772749 0.0 0.0

The nonzero MSE rules out a perfect prediction. The loss code currently casts scheduler.timesteps[timestep_id] to pipe.torch_dtype before calling add_noise and training_weight; both scheduler methods locate the nearest entry from the rounded value. set_training_weight() subtracts the minimum weight, making index 0 exactly zero for this 1000-step Wan schedule.

Expected behavior / possible fix

Keep the original sampled schedule entry or index for scheduler calculations, including add_noise and training-weight lookup. Cast the timestep for model compute separately if required. A regression test could check that sampled ID 1 retains its nonzero weight under BF16 model compute; currently it silently maps to ID 0.

主要語言
Python
星號
13.5k
分支
1.3k
平均合併
1 天 13 小時
30 天內合併 PR
46

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelscope/DiffSynth-Studio 的其他 Issue

查看 modelscope/DiffSynth-Studio 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。