mindspore-ai / mindspore-ai/hyper-parallel
[Feature] HyperParallel integration follow-up: CP/TP/EP/activation/HSDP
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 侧改动:
tuner.py._training_function:use_hyper_parallel分支条件由stage == "sft"扩到stage in {"pt", "sft"}。train/hyper_parallel/trainer.py:新增HyperParallelTrainer,继承CustomSeq2SeqTrainer,复用 LF 既有的 loss / metric / save_predictions。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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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