Pull Request has been successfully merged by CANN-robot.
(Thank you for Can Learn Bot's contribution.)变更摘要
本 PR 将 DeepSeek V4 与 V4.1 的 SFT 数据处理从单体文件拆分为分层模块:把“会话监督策略”“图像/媒体解析”“Grain 数据图装配”“兼容导出”分离到各自的 sft 子包中,原模块(deepseek_v4/chat_processor.py、deepseek_v4_1/vision/language_dataset.py)收缩为兼容转发层,并同步更新配置注册表与单元测试的导入路径与类名。整体属于数据管道结构化重构,同时新增了对 .jsonl 数据集源的支持。
主要改动
- V4 监督逻辑拆层:新增
deepseek_v4/sft/policy.py,把messages_from_sample、validate_messages、encode_sample从DeepSeekV4ChatProcessor.__call__抽出,encode_sample以(input_ids, label_ids)元组返回并自带IGNORE_INDEX = -100,不再依赖TextSequence/torchtitan.components.loss.IGNORE_INDEX。 - V4 Grain 装配独立:新增
deepseek_v4/sft/data.py,其中保留DeepSeekV4ChatProcessor并新增is_valid_sample与sft_dataloader_config(...);config_registry.py中deepseek_v4_flash_sft改为调用该函数,移除注册表内的FirstFitPackingConfig、SingleDatasetConfig等内联装配代码。 .jsonl数据源分支:V4 的sft_dataloader_config在路径后缀为.jsonl时使用IndexedJsonlSource.Config,否则回退到HuggingFaceRandomAccessSource.Config;V4.1 的vision/sft/data.py同样为.jsonl引入IndexedJsonlSource.Config分支。- V4.1 视觉 SFT 四分法:
vision/language_dataset.py中的代码被拆到vision/sft/policy.py(normalize_messages、normalize_context)、vision/sft/media.py(load_image)、vision/sft/processor.py(DeepSeekV41VisionLanguageProcessor,保留_message_parts = staticmethod(normalize_messages)别名)与vision/sft/data.py;_GrainSFTProcessor更名为DeepSeekV41SFTProcessor,_SFTCollator更名为VisionLanguageCollator,sft_dataloader_config签名与行为保持不变。 - 调用方与测试适配:
deepseek_v4_1/config_registry.py的延迟导入改为from .vision.sft.data import sft_dataloader_config,tests/unit_tests/models/deepseek_v4_1/test_vision_language_sft.py同步改用新模块路径并断言VisionLanguageCollator.Config与DeepSeekV41SFTProcessor.Config。


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
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/torchtitan-npu | ✅ zhaowei1936, xuyujun (2/2) | ✅ zhaowei1936 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
botcanlearn, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/lgtm


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


描述
DeepSeek V4.1 在 TorchTitan 0.4.0 上复用 CPT 配方,通过
--override接入图文 SFT。数据层调用模型目录中的官方encoding/encoding.py,支持纯文本对话及同一条消息内多图与文字交错,使用 assistant 目标 token 计算 SFT loss。类型
Checklist:
如何测试
从 DOCCI 训练集选取 4 条图文样本。输入为图片和指令
Describe the image in detail.,参考答案为人工标注的图片描述。在开发阶段用这组样本进行 64 步图文 SFT。微调前和重载微调权重后,在同一组样本上计算回答 token 的交叉熵。
精度和性能验证结果
当前提交验证
用 8 份 DeepSeek 官方发布 encoding.py 文件完成 4,000 组对照。Prompt 和 token ID 与官方输出逐项相同,assistant 监督和 EOS 检查通过。在 CPU 上比较屏蔽标签的交叉熵与逐有效位置计算,最大绝对误差为
4.44e-16,低于1e-12。