mindspore-ai / mindspore-ai/hyper-parallel

[Feature] HyperParallel integration follow-up: CP/TP/EP/activation/HSDP

Open
#710 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

Reminder
  • I have read the above rules and searched the existing issues.
Description

【动机】

#10289 已经把 MindSpore HyperParallel 作为 FSDP2 后端接入 LlamaFactory。在此基础上补齐五项能力,让长序列、大 MoE、显存紧张以及多副本 DP 场景也能复用同一后端:

  • Context Parallel (CP):沿序列维切分长上下文。
  • Tensor Parallel (TP):对线性层做 colwise / rowwise 权重切分。
  • Expert Parallel (EP):把 MoE 专家层分布到多卡。
  • Activation Swap / Recompute:把激活换出到 CPU 或重算以省显存。
  • HSDP(fsdp_size:在 1D FSDP 之外支持 2D (dp_size, fsdp_size) mesh —— 每 fsdp_size 个 rank 组成一个 shard 组,组与组之间做 DP 复制,避免 shape[0] % world_size != 0 的参数 fallback 到 replicate 路径导致 OOM。

HyperParallel 侧已实现并提供集成接口,本 issue 只负责 LlamaFactory 侧的接入与开关暴露。

【架构目标】

  • 默认行为不变:未开启 use_hyper_parallel 时不触发任何 HP 代码;新增字段全部默认 off / None
  • LlamaFactory 侧只暴露 use_hyper_parallel + hyper_parallel_args(JSON 路径或 dict),并行 / 显存策略字段全部经 JSON 注入到 HyperParallelArguments
  • 本期接入 pt + sft 两个 stage。

【建议的方案】

启动方式与 #10289 一致,yaml 中开启 HP 后端:

use_hyper_parallel: true
hyper_parallel_args: examples/hyper_parallel/example.json

example.json 描述并行 / 显存策略:

{
  "cp_size": 2,

  "tp_size": 2,

  "ep_size": 4,
  "ep_style": "ep",
  "expert_module_cls": "Qwen3VLMoeTextSparseMoeBlock",

  "activation_mode": "swap",
  "activation_swap_inputs": true,

  "fsdp_size": 4
}

LlamaFactory 侧改动:

  1. tuner.py._training_functionuse_hyper_parallel 分支条件由 stage == "sft" 扩到 stage in {"pt", "sft"}
  2. train/hyper_parallel/trainer.py:新增 HyperParallelTrainer,继承 CustomSeq2SeqTrainer,复用 LF 既有的 loss / metric / save_predictions。
  3. train/hyper_parallel/workflow.py:新增 run_pt,与已有 run_sft 共享 HP arguments 解析与 HyperParallelTrainer 构造。

组件关系:

flowchart TD
    ARGS[FinetuningArguments<br/>use_hyper_parallel + hyper_parallel_args]
    TUNER[_training_function]
    WORKFLOW[run_pt / run_sft]
    TRAINER[HyperParallelTrainer<br/>extends CustomSeq2SeqTrainer]

    subgraph HP [HyperParallel integration]
        FSDP[FSDP2 / HSDP]
        CP[Context Parallel]
        TP[Tensor Parallel]
        EP[Expert Parallel]
        ACT[Activation Swap / Recompute]
    end

    ARGS --> TUNER -->|use_hyper_parallel=True<br/>stage ∈ pt, sft| WORKFLOW --> TRAINER
    TRAINER --> FSDP
    TRAINER --> CP
    TRAINER --> TP
    TRAINER --> EP
    TRAINER --> ACT

【约束】

  • 模型 / 算子支持范围以已验证清单为准,其余按需补充 adapter。

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

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 with tuner.py._training_function and the existing HyperParallel integration from #10289, then read train/hyper_parallel/trainer.py and train/hyper_parallel/workflow.py. Add the proposed pt and sft integration while preserving defaults when use_hyper_parallel is disabled. Done means the JSON-configured CP, TP, EP, activation, and HSDP options are exposed through HyperParallelTrainer for both stages.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.