mindspore-ai / mindspore-ai/hyper-parallel

补齐 DeepSeek、Qwen 及 LlamaFactory 网络训练所需分布式算子

Open
#220 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
53
Forks
63
Avg merge
23h 45m
Merged PRs (30d)
63

Description

1. 基本信息

项目 内容
作者 rongyue
相关模块 core/shard
相关 issue / PR 暂无
适用后端 PT

2. 背景

Hyper-Parallel 当前已经完成部分分布式算子的迁移,并统一接入新的三阶段分布式算子流程:

preprocess
    ↓
infer_layout
    ↓
get_expand_impl
    ↓
local operator execution
    ↓
wrap_output

目前已有算子能够支持部分基础网络训练场景,但在 DeepSeek、Qwen 以及 LlamaFactory 网络训练过程中,仍存在部分算子未注册或未实现完整分布式语义的问题。

缺失算子可能导致:

  • DTensor 无法正常 dispatch;
  • Layout 无法正确推导;
  • 输出 DTensor 的 tensor_map 与实际 shape 不匹配;
  • local execution 与 global semantic 不一致;
  • backward 或 optimizer step 阶段失败;
  • 模型训练流程无法闭环。

本 RFC 要解决的问题:

补齐 DeepSeek、Qwen 和 LlamaFactory 网络训练过程中依赖的缺失分布式算子,使目标模型能够完成完整训练流程。

完成后的成功标准:

  • 目标模型训练过程中不存在阻塞性 Missing operator;
  • 新增算子均遵循统一分布式算子流程;
  • forward、loss、backward、optimizer step 均可正常执行;
  • 分布式结果与单卡 reference 对齐。

3. 目标和非目标

3.1 目标

  1. 支持 DeepSeekV32、Qwen 系列以及 LlamaFactory(Qwen) 训练过程中缺失算子。
  2. 统一新增算子的 Layout 推导和分布式执行流程。
  3. 支持模型训练闭环:
forward
    ↓
loss
    ↓
backward
    ↓
optimizer step
  1. 明确不同算子的 Layout、Partial 和分片约束。
  2. 建立模型级算子覆盖和回归验证能力。

3.2 非目标

  1. 本期不保证所有算子支持任意维度切分。

原因:

部分算子在某些 shard 方式下需要额外通信,第一阶段优先支持语义明确的场景。

  1. 本期不针对单个模型增加特殊逻辑。

原因:

算子实现需要基于通用 Layout 语义,而不是模型名称或固定 shape。

  1. 本期不涉及训练框架 API 改造。

原因:

当前问题主要集中在 distributed operator 支持。


4. 相关实现参考

来源 做法 限制 对本 RFC 的影响
Hyper-Parallel 已有 distributed ops 通过 Layout inference + local execution 实现分布式算子 部分算子覆盖不足 复用已有基础能力
DTensor 分布式语义 根据 placement 推导 global tensor 语义 需要算子明确 Layout 规则 作为设计基础
DeepSeek/Qwen/LlamaFactory 实际训练调用 根据 trace 结果补齐缺失算子 依赖真实模型场景 确定开发优先级

5. 缺失算子范围

本 RFC 按模型驱动推进。

优先级:

DeepSeekV32
    ↓
Qwen 系列模型
    ↓
LlamaFactory(Qwen)

5.1 DeepSeekV32

缺失算子:

cpu
cross_entropy
gather
histc
index_add_
new_zeros
npu_rms_norm
npu_rotary_mul
tolist
type_as
vstack

优先完成 DeepSeekV32 训练关键路径。


5.2 Qwen 系列

Qwen-3.5-0.8B
conv1d
cross_entropy
softplus
to
tril
Qwen3_5_35B_A3B_Base
conv1d
cross_entropy
greater
one_hot
softplus
to
tril
where
Qwen3_VL_30B_A3B_Instruct
bool
cross_entropy
greater
index_add_
one_hot
scatter_
tolist
where

5.3 LlamaFactory(Qwen)

缺失算子:

cross_entropy
clamp_
grouped_mm_fallback
histc
type_as
conv1d
softplus
tril
to
one_hot
greater
where
scatter_
index_add_

6. 方案设计

6.1 总体流程

新增算子统一遵循:

operator call
      |
      v
preprocess
      |
      v
infer_layout
      |
      v
get_expand_impl
      |
      v
local operator execution
      |
      v
wrap output DTensor

6.2 核心设计原则

Layout 推导

新增算子需要明确:

  • 输入 Layout 合法范围;
  • 输出 Layout;
  • tensor_map 与 Tensor rank 一致性;
  • shape 变化后的维度映射;
  • 广播维处理方式。

Partial 处理

新增算子需要明确 Partial 支持范围。

以下类型通常需要额外限制:

  • 非线性计算;
  • 比较操作;
  • index 操作;
  • inplace 更新;
  • Python scalar conversion。

不支持场景需要:

  • 显式报错;
  • 或执行 redistribution。

Local 与 Global 语义一致性

不能仅因为 local Tensor 可以执行,就认为满足分布式语义。

需要考虑:

  • shard 维度;
  • 全局结果一致性;
  • 是否需要 collective communication;
  • 是否存在跨 rank 数据依赖。

原地算子

需要保证:

  • Layout 不变化;
  • DeviceMesh 不变化;
  • Placements 不变化;
  • autograd 正确。

Fused 算子

对于语义一致的 fused 和 non-fused 算子:

rms_norm / npu_rms_norm
rotary_mul / npu_rotary_mul
adamw / fused_adamw

尽量复用同一套 Layout 规则。


7. 组件依赖

依赖组件 强依赖/弱依赖 当前状态 未 ready 时本期能力
DTensor 强依赖 已支持 无法完成输出封装
DeviceMesh 强依赖 已支持 无法完成 Layout 推导
Distributed Operator Framework 强依赖 已支持 无法接入新算子
Shard Ops Test Framework 强依赖 已支持 无法完成 ST
FSDP 弱依赖 已支持 不影响算子开发
TP/DP 弱依赖 已支持 影响部分测试范围

完整能力需要:

  • 分布式算子支持;
  • 模型训练验证;
  • backward 流程验证。

本期最小交付:

  • 支持目标模型关键路径算子;
  • 完成 forward/loss/backward 验证。

8. 约束与兼容性

类型 内容
不支持项 不支持所有算子的任意 shard 组合
Layout 约束 必须保证输入输出 Layout 合法
Partial 约束 不支持的 Partial 场景需要提前报错
PT/MS 差异 不同 backend 算子接口可能不同,需要保持 Layout 语义一致
已有行为影响 新增算子不改变已有算子行为

9. 验证设计

9.1 用例分层

用例级别 覆盖内容 通过标准
UT Layout 推导、参数校验、异常场景 输出 Layout 正确
Level0 单算子分布式执行 与单卡结果一致
Level1 模型训练组合验证 完成训练闭环

9.2 模型验证

模型 验证内容 通过标准
DeepSeekV32 forward/loss/backward/optimizer 无 Missing operator
Qwen 系列 多规模模型验证 输出和梯度一致
LlamaFactory(Qwen) 完整训练流程 可以继续训练

9.3 性能验证

本 RFC 不以性能优化为目标。

主要关注:

  • 算子正确性;
  • 训练流程完整性;
  • 分布式结果一致性。

10. 实现计划

PR 内容 依赖 验证
PR1 DeepSeekV32 缺失算子支持 UT +ST
PR2 Qwen 系列缺失算子支持 PR1 UT +ST
PR3 LlamaFactory 训练闭环支持 PR2 UT+ST

11. 总结

本 RFC 以真实模型训练需求为驱动,按照:

DeepSeekV32
    ↓
Qwen
    ↓
LlamaFactory

的优先级补齐 Hyper-Parallel 缺失分布式算子。

通过统一 Layout 推导、Partial 处理和分布式执行流程,使 Hyper-Parallel 支持目标模型完整训练闭环。

schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 293
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/293

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in core/shard by tracing existing distributed operators through preprocess, infer_layout, get_expand_impl, local execution, and wrap_output. Use the DeepSeekV32 operator list as the first scope, then add unit and distributed tests covering layout inference, parameter validation, and unsupported cases. Done means the target training path completes forward, loss, backward, and optimizer steps with no missing operators and results aligned with the single-card reference.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
distributed-systems, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.