Pull Request已成功合入, 合并人@ascend-robot
(感谢 chenpeizhe 的贡献)变更摘要
此 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 格式。


代码审查
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 |
⛔ 需要修改


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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


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.