Merged
[fix] 修复 VLM 默认训练配置 #422
[fix] 修复 VLM 默认训练配置 #422
Merged
panchao-gitcodeAdd on Jul 10
panchao-gitcode
panchao-gitcodeCollaborators
Jul 10

描述

VLM 的图片 patch 会展开为视觉 token,并与图片边界、caption 和 EOS 一起占用语言模型序列长度。原默认配置使用 training.seq_len=256,当前 cc12m-test 图片编码后长度为 258~452,导致样本因超长被跳过,无法进入有效训练。

本次修改:

  • 将 vlm_debugmodel_npu 默认训练配置调整为 local_batch_size=8、seq_len=2048、steps=10。
  • 将图片配置调整为 max_patches_per_image=1024、max_images_per_batch=64;当前测试图片编码后长度为 767~1212,可被 seq_len=2048 容纳。
  • 将 docs/feature_guides/vlm.md 示例改为 8 卡真实通信运行,删除 fake_backend 及会覆盖正确默认值的命令行参数。

类型

Checklist:

如何测试

  1. 代码检查:
pre-commit run --files \
  docs/feature_guides/vlm.md \
  torchtitan_npu/models/vlm/config_registry.py \
  tests/unit_tests/models/test_multimodal_helpers.py

结果:全部通过。

  1. VLM 现有配置测试:
PYTHONPATH=/data/p00465316/npu_moe_re_routing/torchtitan:$PWD \
python3 -m pytest tests/unit_tests/models/test_multimodal_helpers.py -q -k vlm_config

结果:5 passed。

  1. 不覆盖训练参数,直接使用新默认配置执行 8 卡训练:
PYTHONPATH=/data/p00465316/npu_moe_re_routing/torchtitan:$PWD:${PYTHONPATH:-} \
NGPU=8 \
MODULE=torchtitan_npu.models.vlm \
CONFIG=vlm_debugmodel_npu \
bash scripts/run_train.sh

结果:成功完成默认 10 step;训练初始化确认 local batch size=8、global batch size=64、sequence length=2048,loss 从 8.18690 降至 0.47367,无 OOM、NaN 或 Inf。

  1. 使用仓内 premerge-accuracy-check 对改动前后进行数值验证:
  • 基线:9d4ad2a92e5b1a328dbe4aa9e186790adf64d957
  • 候选:a26f3dbb56e7963ee378ceecd61b506d27b4ebd5
  • 配置:8 卡 FSDP,双方加载同一个 DCP model-only checkpoint,seed=42,确定性模式,各训练 100 step
  • 结果:100 个共同 step 上,loss 和 grad_norm 的最大/平均绝对误差均为 0;无 NaN 或 Inf,结论为 PASS

VLM loss and grad norm comparison

其他信息

  • 本次不修改模型结构、计算逻辑或 checkpoint key,不影响 checkpoint 兼容性。
  • 100-step 日志生成后删除了一个仅锁定配置字面值的冗余测试并 amend 提交;c49d9ac..a26f3db 在 torchtitan_npu/ 和 docs/ 下无差异,训练运行时内容一致。
likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for panchao-gitcode's contribution.)
atomgit-bot
atomgit-botCollaborators
Jul 10 Comments:

变更摘要

此 PR 修复了 vlm_debugmodel_npu 默认训练配置中因 seq_len=256 过短导致 cc12m-test 数据集样本(编码后长度 258~452)被跳过、无法进入有效训练的问题。通过将序列长度提升至 2048 并同步调整图片相关参数,使编码后长度为 767~1212 的样本可被正常容纳;同时更新了文档示例以使用 8 卡真实通信运行。

主要改动

  • 训练配置参数调整: 将 vlm_debugmodel_npu() 中的 local_batch_size 从 1 改为 8、seq_len 从 256 改为 2048、steps 从 2 改为 10,确保序列长度足以容纳视觉 token 展开后的样本。
  • 图片数据加载器配置增强: 在 HuggingFaceMultiModalDataLoader.Config 中新增 max_patches_per_image=1024 和 max_images_per_batch=64 两个参数,匹配调整后的序列长度。
  • VLM 文档示例更新: 将 docs/feature_guides/vlm.md 示例改为 8 卡真实通信方式运行,移除 fake_backend 及会覆盖正确默认值的命令行参数。
likedislike
Incorrect?
atomgit-bot
atomgit-botCollaborators
Jul 10 Comments:

代码审查

✅ 未发现问题

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Jul 10 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Jul 10 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


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-cann/torchtitan-npu ✅ lrwei0709, xuyujun (2/2) ✅ lrwei0709 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
panchao-gitcode
panchao-gitcodeCollaborators
Jul 10 Comments:

compile

likedislike
CANN-robotCANN-robotCollaborators
Jul 10 Added label: ci-pipeline-running
CANN-robot
CANN-robotCollaborators
Jul 10 Comments:

流水线任务触发成功
任务链接 [40ec7c8411a14d4685e4f0bb7d82d85c][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
pre_comment ✅ SUCCESS >>>>>
lint ✅ SUCCESS
UT_Test ✅ SUCCESS >>>>>
PreSmoke_A900_npupool ✅ SUCCESS >>>>>
codecheck_codestyle ✅ SUCCESS >>>>>
precommit ⚠️ WARNING >>>>> >>>>>

[2026-07-10 21:18:12]    CI执行结束

likedislike
CANN-robotCANN-robotCollaborators
Jul 10 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Jul 10 Added label: ci-pipeline-passed
CANN-robot
CANN-robotCollaborators
Jul 10 Comments:
流水线 PR-pipeline_cann_torchtitan-npu#1645 [ commitID:a26f3dbb ] 已完成
likedislike
xuyujun
xuyujunCollaborators
Jul 11 Comments:

【MR评价】评价分数:3,
评价意见:基本功能修复
编码规范遵守度:无编码规范问题;
代码设计:不涉及代码设计;
DT质量:基本逻辑DT测试覆盖充足;

likedislike
xuyujun
xuyujunCollaborators
Jul 11 Comments:

/lgtm

likedislike
weijinyi
weijinyiCollaborators
Jul 11 Comments:

/approve

likedislike
CANN-robotCANN-robotCollaborators
Jul 11 Added label: lgtmapproved
CANN-robotCANN-robotCollaborators
Jul 11 Merged pull request