Open
[fix] Align v0.4.0 performance with v0.3.0 #1424
[fix] Align v0.4.0 performance with v0.3.0 #1424
Open
1Fire4Add on 6 days ago
1Fire4
1Fire4Collaborators
6 days ago

描述

恢复 DeepSeek V4.1 的 ViT 激活重算,在 FSDP 包装前为 32 个视觉 block 注册重算。分块 loss 将输出头的 BF16 梯度累积到独立 FP32 缓冲区,末块沿用 FSDP ReduceScatter,减少重复 Cast 和 Transpose。

新增 DeepSeek V4.1 的 A5 八卡 block-FP8 性能配方,使用轮转路由和 40 层 fullgraph 编译。该配方将 Engram 门控投影纳入 FP8,并在 A5 Inductor 编译 Engram 层时限制融合,避免反向传播生成超大工作区。

类型

Checklist:

如何测试

  • TORCH_DEVICE_BACKEND_AUTOLOAD=0 python -m pytest -q tests/unit_tests/models/common/test_chunked_loss.py tests/unit_tests/models/deepseek_v4_1/test_model_split.py::test_multimodal_parallelize_wraps_each_vision_block_before_fsdp,3 项通过。

  • 全量 pre-commit 通过,包含 Pyrefly。

  • 单元测试 python -m pytest -q tests/unit_tests,1462 项通过,42 项跳过,1 项符合预期失败。

  • A5 八卡复现命令(路径已脱敏)

    HF_ASSETS_PATH="$TOKENIZER_DIR" \
    MODULE=torchtitan_npu_recipes.tests.models.deepseek_v4_1 \
    CONFIG=deepseek_v4_1_flash_8p_cpt_4k_a5_balanced_compile \
      bash scripts/run_train.sh
    

精度和性能验证结果

  • A3 精度。2K BF16 eager 下,loss 和 grad_norm 各 50/50 步比特一致。

50 步 loss 与 grad_norm 精度对比

  • A3 性能。A3 8 卡 4K BF16 eager,MoE 强制均衡、FSDP compute-stream 分配关闭。第 3–5 步对比,耗时和吞吐取中位数,显存取峰值。
版本 秒/步 tokens/s/卡 峰值预留显存
master 2c6eb407 74.536 440 51.66 GiB
v0.4.0,含本 PR 两项修复 74.758 438 52.31 GiB
v0.4.0 相对 master +0.30% −2 +0.65 GiB

A5 性能。8 卡 block-FP8,序列长度 4096,每卡每个 microbatch 8192 tokens,梯度累积 4 次,全局每步 262144 tokens。两版各运行 10 步,耗时和吞吐取第 2–10 步中位数,显存取日志峰值。基线为 v0.3.0,CPU 绑核、loss 实现、运行栈和编译调试设置沿用各自版本。

版本 秒/步 tokens/s/卡 峰值预留显存
v0.3.0 17.678 1854 69.24 GiB
v0.4.0,含本 PR 16.969 1931 72.98 GiB
v0.4.0 相对 v0.3.0 -4.01% +4.15% +3.74 GiB

其他信息

沿用现有 checkpoint 参数和格式,无新增依赖。性能验证使用本地 4K 基准配方,路径已脱敏。

likedislike
Merge blocked
1Fire41Fire4Collaborators
6 days ago Created pull request, commit 5491da2c
CANN-robot
CANN-robotCollaborators
6 days ago Comments:

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.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
repo-cann/torchtitan-npu ❌ (0/2)(You can also ask: zzyyjj012, zhaowei1936, 钟林, xuyujun, wanghui0) ❌ (0/1)(You can also ask: wanghui0, lrwei0709, 钟林, zhanghz1, panchao-gitcode)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robotCollaborators
6 days ago Added label: cann-cla/yes
CANN-robotCANN-robotCollaborators
6 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
CANN-robotCANN-robotCollaborators
6 days ago Set hwcaifubi,lrwei0709,zhaowei1936,zhong_lin,zhanghz1,depeng1994,shengnan666,XDaoHong,xuyujun,zhuofanshen,wanghui0,panchao-gitcode,zzyyjj012 as approver
55 messages are collapsed here。 See more
CANN-robot
CANN-robotCollaborators
2 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
2 days ago Removed label: ci-pipeline-failed
CANN-robotCANN-robotCollaborators
2 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
2 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
2 days ago Added label: ci-pipeline-passed