已合并
bugfix: Bind embed_token and lm_head weights during DCP weight loading when tie_word_embeddings is True #3039
bugfix: Bind embed_token and lm_head weights during DCP weight loading when tie_word_embeddings is True #3039
已合并
LKONE创建于 8月25日
LKONE
LKONE成员
8月25日

What this PR does / why we need it?

在对Qwen3.5-4B模型在hf权重和dcp权重两种加载场景下的精度进行对比时发现存在差异,定位发现Qwen3.5-4B的embed_tokens和lm_head层的权重是绑定的,在hf权重加载场景,两者能够共享同一份权重,但是在dcp场景下,两者虽然在权重转换过程中实现了权重的一致,但是在后续训练过程中并未保持一致,两者会独立进行更新,导致训练梯度存在差异,因此做以下改动:

(1)模型初始化完成后,对embed_tokens和lm_head层的weight进行绑定;

(3)删除原有Qwen3.5 readme权重转换过程中对4B以下模型的权重绑定要求,将其从权重转换过程中移至模型初始化过程中实现。

Does this PR introduce any user-facing change?

无

How was this patch tested?

(1)对于tie_word_embeddings=true的模型,原有hf权重和dcp权重加载时精度存在差异,本PR调整后精度完全对齐;

(2)对于tie_word_embeddings=false的模型,本PR调整后不会对精度产生任何影响。

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 LKONE 的贡献)
LKONELKONE成员
8月25日 创建了 pull request,commit 0c2c780d
atomgit-bot
atomgit-bot
8月25日 评论:

变更摘要

本 PR 是一个针对 tie_word_embeddings 为 True 时权重绑定逻辑的 bugfix:将 _retie_embeddings(model) 的调用位置从 DCP 权重加载后的后处理流程(hf_load_utils.py 中的 post_process_after_load)移动到 trainer.py 中 Trainer 构建模型之后执行,用于重新绑定 embed_tokens 与 lm_head 的权重;同时在 Qwen3TTSConfig 的初始化中强制将 tie_word_embeddings 置为 False,规避 transformers 4.57.3 在未显式提供该字段时默认设为 True 所导致的 _retie_embeddings 失败问题。

主要改动

  • 移除加载后处理中的重绑定调用:在 mindspeed_mm/fsdp/checkpoint/hf_load_utils.py 的 post_process_after_load 中删除 _retie_embeddings(model) 调用,使权重加载阶段不再执行嵌入权重重绑定。
  • 在 Trainer 中执行重绑定:在 mindspeed_mm/fsdp/train/trainer.py 中新增 _retie_embeddings 的导入,并在 Trainer 完成模型构建(含 LoraWeightManager 设置)后调用 _retie_embeddings(model),在 tie_word_embeddings 为 True 时重新绑定 embed_tokens 与 lm_head 权重。
  • 修正 Qwen3TTSConfig 默认配置:在 mindspeed_mm/fsdp/models/qwen3tts/core/models/configuration_qwen3_tts.py 的 Qwen3TTSConfig.__init__ 中强制设置 kwargs["tie_word_embeddings"] = False 后再转发给父类配置,防止 transformers 4.57.3 的默认行为导致后续 _retie_embeddings 失败。
likedislike
不准确?
atomgit-bot
atomgit-bot
8月25日 评论:

代码审查

✅ 未发现问题

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

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.


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 ✅ 王海涛, gaojie_, WendongPang (3/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

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

likedislike
LKONELKONE成员
8月25日 关联了issue:[Bug]: DCP 加载路径缺少 _retie_embeddings,导致 tie_word_embeddings=True 的模型 loss 异常
LKONE
LKONE成员
8月25日 评论:

compile

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

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
8月25日 添加了label:ci-pipeline-running
ascend-robotascend-robot成员
8月25日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
8月25日 评论:

✅ 文档门禁通过!

检查项 检查结果 详情
markdownlint ✅ 已通过 查看详情
link-validity-check ✅ 已通过 查看详情
resource-existence-check ✅ 已通过 查看详情
tag-closed-check ✅ 已通过 查看详情
likedislike
ascend-robotascend-robot成员
8月25日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
8月25日 添加了label:docs-ci-pipeline-success
LKONELKONE成员
8月25日 修改了pull request 的描述
ascend-robot
ascend-robot成员
8月25日 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
8月25日 删除了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
8月25日 添加了label:docs-ci-pipeline-running
ascend-robot
ascend-robot成员
8月25日 评论:

✅ 文档门禁通过!

检查项 检查结果 详情
markdownlint ✅ 已通过 查看详情
link-validity-check ✅ 已通过 查看详情
resource-existence-check ✅ 已通过 查看详情
tag-closed-check ✅ 已通过 查看详情
likedislike
ascend-robotascend-robot成员
8月25日 删除了label:docs-ci-pipeline-running
ascend-robotascend-robot成员
8月25日 添加了label:docs-ci-pipeline-success
ascend-robotascend-robot成员
8月25日 删除了label:ci-pipeline-running
ascend-robotascend-robot成员
8月25日 添加了label:ci-pipeline-passed
ascend-robot
ascend-robot成员
8月25日 评论:
流水线 PR-pipeline_MindSpeed-MM#4544 [ commitID:19c86669 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build ✅ >>>
恶意代码检查 Antipoison ✅ >>>
编码安全与规范检查 Only_doc_commit ✅ >>>
codeCheck_pre-commit ✅ >>>
pre-commit ✅ >>>
Compatibility_Interface ✅ >>>
开源片段检查 SCA ✅ >>>
开发者测试 UT 🛑 >>>
ST 🛑 >>>
UT-pool ✅ >>>
ST_pool ✅ >>>
流水线 PR-pipeline_MindSpeed-MM ✅ >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, htwang, hhhzhuyizhi, cxiaolong, bigdog1206, ghoshaw, yaoyaoxu]评论有效
  • compile : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
且奏长歌
且奏长歌成员
8月25日 评论:

/lgtm

likedislike
gaojie
gaojie成员
8月25日 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
8月25日 添加了label:lgtm
htwang成员
8月25日 评论:

同意合入

likedislike
htwang成员
8月25日 评论:

/approve

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