已合并
[Pynative] fix tp bug in embedding. #8169
[Pynative] fix tp bug in embedding. #8169
已合并
niujunhao创建于 3月27日
niujunhao成员
3月27日

https://gitcode.com/mindspore/mindformers/issues/2213

修改描述 (Description)

修复内容

修复在 hyper-parallel 模式下 vocab embedding 的 Tensor Parallel (TP) 报错问题。

变更说明

文件: mindformers/pynative/base_models/common/embeddings/vocab_embedding.py

主要修改:

  1. 将 mint.nn.functional.embedding 替换为 mint.gather
    原使用 mint.nn.functional.embedding 会导致 hyper-parallel 模式下报错,现改用 mint.gather 实现相同功能。

  2. 新增 mint.tile 操作
    用于扩展输入维度以适配 gather 操作的需求。

  3. 重构 forward 逻辑

    • 使用 tile 将 input_ 从 (batch_size, seq_len) 扩展为 (batch_size, seq_len, embedding_dim)
    • 使用 gather 从 weight 中按指定维度收集 embedding
    • 最终 reshape 为 (-1, seq_len, embedding_dim) 保持输出形状一致

影响范围

  • 仅影响 VocabEmbedding 类的 forward 实现
  • 修复了 hyper-parallel TP 模式下的兼容性问题
  • 功能行为保持不变,仅更换了底层实现方式

修改类型 (Type of Change)

测试结果 (Test Results)

修改之前,embedding结果错误:
image.png

修改之后,开启tp后结果正确:
image.png

检查清单 (Checklist)

likedislike
Pull Request已成功合入, 合并人@MindSpore-Bot
(感谢 niujunhao 的贡献)
Nniujunhao成员
3月27日 创建了 pull request,commit 89349d55
Nniujunhao成员
3月27日 关联了issue:无法生成策略文件
MindSpore-BotMindSpore-Bot成员
3月27日 添加了label:mindspore-cla/yes
niujunhao成员
3月27日 评论:

/retest

likedislike
MindSpore-BotMindSpore-Bot成员
3月27日 添加了label:ci-pipeline-running
此处折叠了71条消息 查看更多
renyujin成员
3月28日 评论:

/lgtm
/approve

likedislike
MindSpore-Bot
MindSpore-Bot成员
3月28日 评论:

Review Code Feedback

  • The label lgtm-renyujin was added to this pull request. It means that renyujin reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
MindSpore-Bot
MindSpore-Bot成员
3月28日 评论:

Review Code Feedback

  • The label approved was added to this pull request. It means that renyujin reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
MindSpore-BotMindSpore-Bot成员
3月28日 添加了label:approvedlgtm-renyujin
MindSpore-BotMindSpore-Bot成员
3月28日 合入了pull request,合并节点 SHA:18a833dfe741081ac381be4c796bb58640357224