已合并
feat: add model container #2921
feat: add model container #2921
已合并
chenpeizhe创建于 8月4日
chenpeizhe成员
8月4日

What this PR does / why we need it?

Support model container for Wan2.2 Training.
https://gitcode.com/Ascend/MindSpeed-MM/issues/576

Does this PR introduce any user-facing change?

New Wan2.2 modeling for FSDP2 training. Support AE/Text Encoder/DiT training.

How was this patch tested?

UT/ST will be presented in other PR.

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 chenpeizhe 的贡献)
Cchenpeizhe成员
8月4日 创建了 pull request,commit 56389e16
atomgit-bot
atomgit-bot
8月4日 评论:

变更摘要

此 PR 引入了一个多模型容器架构 ModelContainer,用于在 FSDP2 训练场景中统一管理多个子模型(如 VAE、文本编码器、预测器等),并通过可插拔的 pipeline 机制编排子模型间的数据流。同时,围绕 Wan2.2 视频生成模型提供了完整的配套实现:flow-matching 扩散调度器 WanFlowMatchScheduler、T2V/I2V 训练 pipeline WanT2VPipeline、Diffusers 权重键名映射转换表,以及具体的 Wan2_2ModelContainer 容器子类,支持冻结子模型的检查点策略和向后兼容的旧格式权重加载。

主要改动

  • 新增 ModelContainer 基类:提供多子模型注册、按前缀分发的 state_dict/load_state_dict、检查点子模型过滤(checkpoint_submodels)以及旧格式扁平键兼容(legacy_flat_key_target),同时内置 FSDP2 的 fully_shard、set_is_last_backward、set_requires_all_reduce 委托方法。
  • 新增 WanFlowMatchScheduler 扩散调度器:实现 flow-matching 的训练损失计算(training_losses)、采样去噪循环(sample)、前向加噪(q_sample)以及基于 timestep 的训练权重策略。
  • 新增 FlowMatchT2VPipeline 与 WanT2VPipeline:定义四阶段训练数据流——条件编码(VAE 编码、文本编码、图像条件准备)、前向扩散加噪、预测器前向、损失计算;WanT2VPipeline 在此基础上扩展了 T2V/I2V 双任务支持。
  • 新增 Wan2_2ModelContainer:继承 ModelContainer,绑定 WanT2VPipeline 作为 pipeline,仅将 predictor 子模型纳入训练检查点,并重写 train() 方法使冻结子模型保持在 eval 模式。
  • 新增 Diffusers 权重转换映射:定义 DIFFUSERS_CONVERT_MAPPING 精确键名映射和 DIFFUSERS_STR_REPLACE_MAPPING 子串替换规则,通过 Wan22DiffusersTransformPipeline 注册到全局转换管道,用于将 Diffusers 格式权重迁移到原生 WanModel 格式。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月4日 评论:

代码审查

I have 8 findings. Let me now write the closing summary.


审查总结

各文件审查结果

文件 结果
mindspeed_mm/fsdp/models/model_container.py 1 个问题(P2: legacy_flat_key_target 不在 _model_names 中时 KeyError)
mindspeed_mm/fsdp/models/wan2_2/diffusers_ckpt_trans.py 1 个问题(P0: DiffusersKeyMapTransformPipeline 导入失败)
mindspeed_mm/fsdp/models/wan2_2/diffusion.py 4 个问题(P1: len() 在 0-d tensor 崩溃; P2: None 减法 / IndexError; P3: sigma_start 循环定义)
mindspeed_mm/fsdp/models/wan2_2/pipeline_wan2_2.py 2 个问题(P0: GenerativePipelineBase 模块缺失; P2: ae None 未检查)
mindspeed_mm/fsdp/models/wan2_2/wan2_2_model_container.py 无独立问题(已审查,train() 不调用 super().train() 为有意设计)

按优先级统计

  • P0: 2 个(均为导入依赖缺失,模块无法加载)
  • P1: 1 个(len() 在 0-d tensor 上 TypeError,batch_size=1 时崩溃)
  • P2: 4 个(None 安全、边界索引、KeyError、None 调用)
  • P3: 1 个(循环定义/可疑代码)

整体风险评估

高风险。 2 个 P0 导入错误意味着本 PR 作为独立变更无法运行 — diffusers_ckpt_trans.py 和 pipeline_wan2_2.py 依赖的基类/模块 (DiffusersKeyMapTransformPipeline、GenerativePipelineBase、GenerativePipelineOutput) 在当前仓库中不存在。如果这些依赖属于同一 PR 中其他尚未展示的 commit,则 P0 降级;否则必须补全。此外 diffusion.py 中的 len() 在 0-d tensor 上的崩溃是确定性的运行时错误,batch_size=1 训练场景会直接触发。建议在上线前修复所有 P0–P2 问题。

类型 数量
🔴 阻塞 4
🟡 建议 5

⛔ 需要修改

likedislike
不准确?
ascend-robotascend-robot成员
8月4日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
8月4日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/MindSpeed-MM ✅ 王海涛, MoCuishle-M (2/2) ✅ 王海涛 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

chenpeizhe, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
此处折叠了60条消息 查看更多
htwang成员
8月7日 评论:

/approve

likedislike
ascend-robotascend-robot成员
8月7日 添加了label:approved
ascend-robotascend-robot成员
8月7日 合入了pull request
ascend-robot
ascend-robot成员
8月7日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike
ascend-robot
ascend-robot成员
8月7日 评论:

Pull Request 已合并或已关闭。

If you want to solve this problem, you can click here to do it in the FAQs.

likedislike