mindspore-ai / mindspore-ai/hyper-parallel
RFC: HyperParallel Linear Attention Context Parallel 架构
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 53
- Forks
- 63
- Avg merge
- 23h 45m
- Merged PRs (30d)
- 63
Description
Hyper-Parallel 支持 Gated DeltaNet Context Parallel
1. 基本信息
| 项目 | 内容 |
|---|---|
| 作者 | xu-xianliang |
| 相关模块 | model / distributed / custom_ops / trainer |
| 小算子 CP PR | Hyper-Parallel PR 1035 |
| 融合后端 PR | Hyper-Parallel PR 1114 |
| 相关 issue / SR / AR | 待补充 |
| 适用后端 | PyTorch |
| 目标硬件 | Ascend NPU |
本 RFC 将 Gated DeltaNet(GDN)Context Parallel 的数学语义、通信算法和
本地 GDN 计算后端分层描述:
- eager/小算子后端是可移植的语义基线。
- Triton-Ascend 融合后端是显式开启的性能能力。
- Ulysses、State-P2P 和 Summary-AllGather 是 CP 算法,不是 GDN backend。
2. 背景
Qwen3.5 dense decoder 以 3:1 的比例混合 Gated DeltaNet Linear Attention 与 Full
Attention。Hyper-Parallel 原有 Full Attention CP 可以通过 Ulysses 在 sequence shard 和
head shard 之间转换 Q/K/V,但不能直接处理 GDN 的两类跨 rank 因果依赖:
- causal depthwise Conv1D 需要当前 rank 左侧的少量 token halo。
- GDN recurrent state 的当前 rank 初始值依赖前一 rank 的 final state。
如果每个 rank 只使用零初始状态独立计算本地序列,Conv1D 边界和 GDN 状态都
会错误。这会使 Qwen3.5 混合模型无法在 FSDP+CP 下保持单卡数学语义。
2.1 GDN 计算特征
GDN 不显式构造 [S,S] attention score,而是维护状态矩阵:
H_t: [B, H, K, V]
忽略 chunkwise 并行化细节后,可以将单 token 计算概念化为:
residual_t = beta_t * (v_t - k_t @ H_(t-1))
H_t = exp(g_t) * H_(t-1) + outer(k_t, residual_t)
o_t = q_t @ H_t
实际 GDN 将 token 按 chunk_size=64 分块,通过 gate cumsum、chunk KKT、
下三角求解、WY 表示、state scan 和 output kernel 完成前反向。无论如何
分块,rank r 的首状态都必须等于 rank r-1 的末状态。
2.2 从完整状态扫描到仿射 summary
当本 rank 的 Q/K/V/g/beta 固定后,整段局部序列对输入状态的作用可写成:
H_out = M @ H_in + S
其中:
S [B,H,K,V]是H_in=0时本地序列产生的 final state。M [B,H,K,K]描述本地序列对任意输入状态的线性变换。
对两个按序执行的区间:
H_mid = M0 @ H_in + S0
H_out = M1 @ H_mid + S1
其组合为:
M = M1 @ M0
S = M1 @ S0 + S1
该 compose 满足结合律但不满足交换律。State-P2P 使用本地 (M,S) 尽早产生
H_out;Summary-AllGather 则收集各 rank (M,S) 后按 rank 顺序计算 prefix。
本 RFC 要解决的问题:为 Hyper-Parallel 补齐 Gated DeltaNet Context Parallel,
并提供显式可选的 Triton-Ascend 融合 GDN 后端。
成功标准:Qwen3.5 Full/Linear Attention 混合模型可在 PyTorch/Ascend NPU
上完成 FSDP+CP4/CP8 多步训练;输出、梯度、loss 和 grad norm 与单卡
基线对齐;融合 P2P 在目标长序列下性能不低于 Ulysses。
3. 目标和非目标
3.1 目标
- 支持 Qwen3.5 Full Attention 和 GDN 混合层使用同一一维 CP mesh。
- Full Attention 继续复用已有
ContextParallel,GDN 使用
LinearAttentionContextParallel。 - 支持
ulysses/p2p/all_gather三种 GDN CP mode。 - 使用 eager 后端建立无 Triton 依赖的功能和精度基线。
- Ulysses 和 P2P 支持显式 Triton-Ascend GDN backend。
- State-P2P 正向只沿 sequence rank 传递 final state,反向只传递 state gradient。
- 通过仿射 summary 将 P2P 串行链从完整 GDN state scan 缩短为
M@H+S
和小状态通信。 - 正确处理 causal Conv1D halo、DTensor/local tensor 边界和 FSDP 参数分片。
- 不支持的 mode/backend/device/dtype/shape 组合必须直接报错,不静默回退。
- 在 CP4/CP8 下完成单算子、完整 GDN 层、混合整网和 activation checkpoint
验证。
3.2 非目标
- 本期不支持 MindSpore GDN CP。
- 本期不支持 Linear Attention TP+CP 组合;开启 Linear Attention CP 时要求
tp=1。 - 本期不验收 PP/EP 与 GDN CP 的组合。
- 本期不支持 inference state cache、decode 和增量生成。
- 本期不支持 packed/varlen GDN CP。
- 不提供
backend=auto,避免环境或 shape 不满足时静默转为 eager。 - 不提供
all_gather + triton;AllGather 仅保留 eager 对比路径。 - 不将 fused Conv1D、head/V chunk、Ulysses×P2P、All-Scan 和 prepare-summary 融合
纳入当前稳定接口。 - 不引入 MindSpeed-MM 等框架级运行时依赖。
4. 相关实现参考
融合 kernel 以源码形式随 Hyper-Parallel wheel 发布,保留原始版权声明并包含
hyper_parallel/platform/torch/custom_ops/gdn/LICENSE。
5. 对外接口
5.1 接口定义
CP 样式入口:
LinearAttentionContextParallel(
mode="p2p", # "ulysses" | "p2p" | "all_gather"
backend="triton", # "eager" | "triton"
).apply(linear_attention_module, cp_mesh)
Qwen3.5 模型并行化入口:
parallelize_qwen3_5_cp(
model,
cp_mesh,
ulysses_degree=None,
linear_attention_cp_mode="p2p",
linear_attention_gdn_backend="triton",
)
Trainer YAML 配置:
train:
accelerator:
cp: 4
tp: 1
ulysses_degree: null
linear_attention_cp_mode: p2p
linear_attention_gdn_backend: triton
| 入参 / 配置项 | 类型 | 默认值 | 是否必填 | 含义 | 合法范围 | 错误处理 |
|---|---|---|---|---|---|---|
cp |
int |
1 |
否 | Context Parallel degree | >=1 |
mesh 中没有 cp 维时报错 |
ulysses_degree |
Optional[int] |
None |
否 | Full Attention Ulysses degree | 当前仅支持 None 或 cp_size |
非 pure Ulysses 报 NotImplementedError |
linear_attention_cp_mode |
str |
"ulysses" |
否 | GDN CP 通信算法 | ulysses/p2p/all_gather |
未知 mode 报错 |
linear_attention_gdn_backend |
str |
"eager" |
否 | 本地 GDN 计算后端 | eager/triton |
未知 backend 报错 |
5.2 mode/backend 支持矩阵
| CP mode | eager | Triton-Ascend |
|---|---|---|
| Ulysses | 支持,默认基线 | 支持,完整 local GDN fwd/bwd |
| State-P2P | 支持,PyTorch summary | 支持,融合 GDN + state-summary |
| Summary-AllGather | 支持,对比模式 | 不支持,直接报错 |
不提供 auto。用户显式选择 triton 后,若设备、dtype、shape 或
Triton-Ascend 版本不符合契约,立即报错,不会在运行时静默转成 eager。
5.3 使用示例
稳定功能基线:
train:
accelerator:
cp: 4
tp: 1
linear_attention_cp_mode: ulysses
linear_attention_gdn_backend: eager
长序列融合 P2P:
train:
accelerator:
cp: 8
tp: 1
linear_attention_cp_mode: p2p
linear_attention_gdn_backend: triton
5.4 接口设计说明
mode 只选择分布式算法,backend 只选择本地 GDN 计算实现。二者正交,
可以在不改变 CP 语义的情况下对比 eager/Triton,也可以在同一 Triton backend
上对比 Ulysses/P2P。默认 ulysses+eager 保证新增 Triton 依赖不改变已有行为。
6. 方案设计
6.1 总体分层
Qwen3.5 model / parallelize
|
v
LinearAttentionContextParallel(mode, backend)
|
+-- Ulysses communication/layout
+-- State-P2P communication/autograd
+-- Summary-AllGather communication/prefix
|
v
GDN backend contract
|
+-- eager PyTorch reference
+-- Triton-Ascend fused backend
|
v
platform.torch.custom_ops.gdn
模型层保持 projection、gate、norm 和 out projection 的 Qwen3.5 语义;CP 层管理布局、
halo、collective/P2P 和 distributed autograd;backend 层管理 GDN 前反向;Triton
层不感知 CP mesh 和 rank。
6.2 公共输入和 Conv1D halo
Linear Attention CP 边界输入为 local sequence shard:
hidden_states: [B, S/P, hidden]
若输入为 DTensor,wrapper 在 CP 边界取得 local tensor。各 rank 先执行本地
QKV/Z/A/B projection。
P2P/AllGather 保留 sequence shard,因此 causal Conv1D 需要左侧 halo:
halo_width = (kernel_size - 1) * dilation
实现使用 differentiable all-to-all-v 传递有效 payload:每个 rank 仅向下一 rank
发送尾部 [B,halo_width,conv_dim],每个非 rank0 只接收前一 rank halo。这不是
全量 all-gather,反向由平台可微 collective 处理。Conv 本体保持 eager depthwise Conv1D。
6.3 Ulysses GDN CP
local sequence shard
-> local projection
-> differentiable A2A: sequence shard -> head shard
-> full sequence + reduced heads
-> local causal Conv1D
-> local GDN (eager or Triton)
-> inverse differentiable A2A: head shard -> sequence shard
-> gated norm + out projection
Ulysses 使每个 rank 持有完整 sequence 和部分 heads,所以 Conv 和 recurrent state 都不
跨 rank。其优点是可直接复用完整 local GDN;代价是前反向的大张量 all-to-all,
以及 CP 增大后每 rank GDN heads 减少、单 head 扫描序列变长。
6.4 State-P2P GDN CP
P2P 模式保持每个 rank 拥有全部 GDN heads 和连续 local sequence,只传递 FP32
state:
state: [B, H, K, V]
以 Qwen3.5 GDN core B=1,H=32,K=V=128 为例,单份 state 约为 2 MiB,与
sequence length 无关。
6.4.1 eager 仿射 summary
eager P2P 使用 PyTorch 小算子先计算 local prepared tensors 和 (S,M):
all ranks: prepare -> local summary (S, M)
rank chain:
recv H_in -> H_out = M @ H_in + S -> isend H_out
local output:
prepared + H_in -> token states -> token output
它是 Triton P2P 的语义基线,也可以在没有 Triton-Ascend 的环境下验证 CP。
6.4.2 Triton 正向流程
forward_prepare
-> Q/K norm, gate cumsum, chunk A, W, U
forward_state_summary
-> S, M
forward_summary_apply
-> H_out = M @ H_in + S
forward_apply_state
-> per-chunk states h, v_new
forward_output
-> local token output
各 rank 并行执行不依赖 H_in 的 prepare/summary。rank>0 在 summary 前预先 post
irecv;收到 H_in 后只在串行链上执行 FP32 M@H+S,随后立即 isend
H_out。本 rank 生成 token states/output 时,下一 rank 已可以处理其状态。
time ---> | |
------------------------------------------------------------------------------------------------
Rank0 | PS0 |A0|send H1| O0 |
Rank1 | PS1 |wait H1 |recv|A1|send H2| O1 |
Rank2 | PS2 | wait H2 |recv|A2|send H3| O2 |
Rank3 | PS3 | wait H3 |recv|A3| O3 |
PS: parallel prepare + state summary
A : state-summary apply, H_out=M@H_in+S
O : local state scan + token output
isend 不是不需要 wait。实现只是将 wait 推迟到本地 output 之后,在 send buffer
被释放前必须等待 work 完成。
6.4.3 Triton 反向流程
反向沿 rank 反序传递 state gradient:
backward_prepare(saved, dO)
-> W, h, v_new, dv and local backward context
backward_state_gradient_summary
-> dS_local, M
backward_summary_apply
-> dH_in = M^T @ dH_out + dS_local
backward_state + backward_finish
-> dQ, dK, dV, dg, dbeta
state-gradient summary 只是用来尽早生成并发送 dH_in,不是 GDN 的全部反向。
Q/K/V/g/beta 的梯度由 backward_state 和 backward_finish 继续计算。GDN
本身没有额外的可训练 weight;projection、Conv、norm 和 out projection 参数由外层
PyTorch autograd/FSDP 计算梯度。
6.5 Summary-AllGather
all ranks: prepare -> local (S, M)
-> pack S/M
-> differentiable all_gather
-> rank r 按序合并 rank 0..r-1 summary
-> 得到本 rank H_in
-> local state scan + output
AllGather 取消了 rank-to-rank state receive 链,但每 rank 都需保存所有 summary,并重复
prefix merge。当前只保留 eager 实现用于精度及算法对比,不作为融合后端交付路径。
6.6 GDN backend 组织
hyper_parallel/models/modules/linear_attention.py
-> eager implementation
-> explicit backend dispatch + capability check
hyper_parallel/platform/torch/custom_ops/gdn/
-> chunk_gated_delta_rule.py # Hyper autograd/operator contract
-> state_summary.py # P2P summary/apply/gradient-summary
-> triton/*.py # chunkwise Triton-Ascend kernels
-> LICENSE
Triton 导入是 lazy 的:普通 Hyper-Parallel CPU/MindSpore import 不会导入 GDN Triton
kernel。只有用户显式选择 backend=triton 且进入 GDN 路径时才执行版本、
NPU、dtype 和 shape 检查。
6.7 代码改动点
| 模块 | 改动内容 | 是否影响已有行为 |
|---|---|---|
core/context_parallel/linear_attention_context_parallel.py |
Ulysses/P2P/AllGather wrapper、Conv halo、state-summary 通信与 autograd | 否,只有显式开启 GDN CP 时生效 |
models/modules/linear_attention.py |
eager GDN oracle、Triton capability 和 dispatch | 默认 eager,不改变已有行为 |
models/qwen3_5/parallelize.py |
按 layer type 分别挂载 Full/Linear Attention CP | cp=1 时不进入新路径 |
platform/torch/custom_ops/gdn |
GDN Triton-Ascend 前反向和 P2P summary kernel | 新增可选能力 |
trainer/config.py |
新增 CP mode 和 GDN backend 配置 | 默认值保持 eager/Ulysses |
setup.py |
wheel 打包 GDN LICENSE | 否 |
checkpoint |
无公共接口改动 | 不涉及 |
optimizer |
无改动 | 不涉及 |
6.8 方案取舍
| 方案 | 优点 | 缺点 | 是否选择 | 原因 |
|---|---|---|---|---|
| Ulysses | 直接复用完整 local GDN,没有 rank state 链 | 大张量 A2A;CP 增大后 head 并行度降低 | 是,默认 | 语义简单、稳定基线 |
| 原始完整 GDN P2P | 只通信小状态 | 完整 local GDN 位于 rank 串行链 | 否 | CP 增大时等待累积 |
| Affine-summary P2P | 串行链只留 M@H+S 和 state send;保持全 heads |
额外计算 summary,依赖定制前反向 | 是,性能路径 | 目前长序列/大 CP 下的最优稳定 P2P |
| Summary-AllGather | 无链式 state recv | 收集全部 summary、重复 prefix merge | 是,eager 对比 | 用于数学和通信方案对比 |
backend=auto |
用户配置简单 | 容易因环境/shape 静默改变性能语义 | 否 | 必须 fail-fast |
| Fused Conv1D | 可进一步减少 Conv 时间和 activation | 导入顺序、shape 和算子审查风险 | 否,后续 | 不与 GDN summary 同时扩大提交面 |
| Head/V wavefront、All-Scan | 大 CP 下可继续降低状态链 | 小 kernel 效率和通信原语复杂 | 否,研究项 | 需要独立 RFC 和 CP16/32 证据 |
7. 组件依赖
| 依赖组件 | 强依赖 / 弱依赖 | 当前状态 | 未 ready 时本期能力 |
|---|---|---|---|
PyTorch DeviceMesh |
强依赖 | 已有 | 无 GDN CP |
| HCCL collective/P2P | 强依赖 | 已有 | 无分布式能力 |
| differentiable all-to-all | Ulysses/Conv halo 强依赖 | 平台层已有 | Ulysses 和 halo 路径不可用 |
Triton-Ascend >=3.2.1,<3.3 |
融合 backend 强依赖 | 已验证 | eager 三种 CP mode 仍可用 |
| Ascend NPU | 融合 backend 强依赖 | 已验证 | 只可运行 eager/非 NPU 可执行项 |
| FSDP | 目标组合强依赖 | CP4/CP8 已验证 | 仍可做 module CP,无法验收整网目标 |
| activation checkpoint | 弱依赖 | CP4/CP8 full 已验证 | 不影响 checkpoint-off 能力 |
| MindSpore | 本期不涉及 | 未实现 | PyTorch 能力不受影响 |
完整融合能力需要:PyTorch + Ascend NPU + HCCL + DeviceMesh +
triton-ascend 3.2.x。
最小可交付能力是:eager Ulysses/P2P/AllGather GDN CP,无 Triton 运行时依赖。
8. 约束与兼容性
| 类型 | 内容 |
|---|---|
| 已有行为 | cp=1、非 Qwen3.5 模型、未选择 Triton 时不增加融合依赖 |
| 后端范围 | GDN CP 当前只支持 PyTorch;Triton 只支持 Ascend NPU |
| Triton 版本 | triton-ascend >= 3.2.1, < 3.3,Python triton module 为 3.2 系列并包含 Ascend backend |
| Triton dtype | Q/K/V/beta 为 BF16,gate g 为 FP32 |
| Triton shape | head_k_dim=head_v_dim=128,chunk_size=64 |
| P2P Triton sequence | 每 rank local sequence 必须被 64 整除 |
| Ulysses | 相关 head/projection 维必须满足 CP 整除契约;Full Attention 仅支持 pure Ulysses |
| Conv | stride=1、depthwise groups=conv_dim、local sequence 不小于 halo width |
| P2P 顺序 | 所有 rank 必须使用对称 tag/order;async send buffer 在 wait() 前不能释放 |
| AllGather | all_gather+triton 直接报错,不回退 eager |
| 组合约束 | Linear Attention TP+CP、packed/varlen、decode/cache、PP/EP 不在当前验收范围 |
| 短序列 | P2P summary 存在固定成本,不保证短序列一定快于 Ulysses |
9. 验证设计与结果
9.1 测试环境与统一口径
主要验证环境:
Hardware: Ascend 910B3
CANN: 9.1.0-beta.3
PyTorch: 2.10.0
torch-npu: 2.10.0
triton-ascend: 3.2.1
Compute dtype: BF16
GDN gate/state: FP32
性能使用 warmup=5, repeat=20。计时边界前后执行 CP barrier 和 device synchronize,
并对各 rank elapsed 取 MAX,报告 median/min/p90。显存报告所有 rank 中的
peak allocated 最大值。首次 Triton compile/autotune 不计入稳态时间。
9.2 用例分层
| 用例级别 | 覆盖内容 | 通过标准 |
|---|---|---|
| CPU UT | mode/backend 参数、unsupported combination、QKV slice、summary pack/merge 及 autograd | 全部通过,不导入 Triton kernel |
| NPU 算子 | eager/Triton,8K/16K/32K,随机 H0/dO/dHT,全部输入梯度 | rel-L2 <1e-2,全部 finite |
| CP 完整层 | CP4/CP8,Ulysses/P2P/AllGather,padding/partial chunk | output/input-grad/parameter-grad/grad norm 对齐,无 hang |
| 整网 Level1 | 3 Linear + 1 Full,FSDP+CP4/CP8,非零学习率 | 100/200 step loss 和 grad norm 无持续漂移 |
| checkpoint | full activation checkpoint,CP4/CP8 | 重放时 P2P 顺序稳定,精度不变 |
| 性能/显存 | CP4/CP8 长序列,rank-max | 报告稳态时间、tokens/s 和 peak allocated |
9.3 单卡 GDN 融合算子
GDN core 实际输入为 B=1,H=32,K=V=128。下表只表示 GDN core,不包含
projection、Conv、norm、out projection 或 CP 通信。
| Sequence | 最差 output rel-L2 | final-state rel-L2 | dH0 rel-L2 | 最差 input-grad rel-L2 |
|---|---|---|---|---|
| 8K | 4.3701e-3 | 3.3544e-3 | 1.5870e-3 | 5.6839e-3 |
| 16K | 4.3707e-3 | 3.3464e-3 | 1.5942e-3 | 5.8559e-3 |
| 32K | 4.3712e-3 | 3.3549e-3 | 1.5840e-3 | 5.6893e-3 |
序列增长后误差没有系统性放大,全部张量 finite。
| Sequence | Triton Forward speedup | Triton Backward speedup | Triton Fwd+Bwd speedup | Incremental peak reduction |
|---|---|---|---|---|
| 8K | 7.98x | 13.56x | 12.65x | 3.83x |
| 16K | 7.90x | 26.40x | 22.37x | 3.84x |
| 32K | 10.09x | 50.23x | 40.08x | 3.84x |
| 64K | 10.71x | 95.31x | 74.17x | 3.84x |
eager backward 保存并遍历大量逐 chunk autograd 节点,所以融合 backward 收益随
local chunk 数增长。64K 仅补测性能和显存,未纳入上述长序列精度矩阵。
9.4 CP4/CP8 完整 Linear Attention 层
完整层配置为 hidden=2048,QK/V heads=16/32,K=V=128,BF16,包含 projection、
Conv halo、Q/K norm、GDN、RMSNormGated 和 out projection。
CP4/32K 精度:
| Mode | Output rel-L2 | Input-grad rel-L2 | Parameter-grad rel-L2 | Grad-norm rel |
|---|---|---|---|---|
| Ulysses Triton | 4.4771e-3 | 5.8584e-3 | 5.0756e-3 | 3.7054e-5 |
| P2P Triton | 4.4771e-3 | 5.8587e-3 | 5.0757e-3 | 3.7163e-5 |
| AllGather eager | 1.3481e-4 | 3.5978e-4 | 2.3472e-3 | 1.0898e-6 |
B=2,global sequence=8192,valid_length=7777 的 padding/partial-chunk 用例中,三种 mode
的 padding output 均为 exact zero,且输出和梯度通过验收。
性能与显存:
| Topology | Global/local seq | Ulysses Fwd+Bwd | P2P Fwd+Bwd | P2P time reduction | Peak allocated difference |
|---|---|---|---|---|---|
| CP4 | 32K/8K | 76.884 ms | 65.807 ms | 14.4% | P2P +12.0 MiB |
| CP4 | 64K/16K | 160.283 ms | 132.973 ms | 17.0% | P2P +12.0 MiB |
| CP4 | 128K/32K | 311.687 ms | 281.569 ms | 9.7% | P2P +12.0 MiB |
| CP8 | 64K/8K | 98.427 ms | 67.336 ms | 31.6% | P2P -52.1 MiB |
| CP8 | 128K/16K | 279.313 ms | 151.257 ms | 45.8% | P2P -116.2 MiB |
P2P 保持每 rank 32 个 GDN heads。Ulysses CP4/CP8 则将 repeated heads 降为每 rank
8/4 个,同时使单 head sequence 和 chunk 数增长。因此 CP 增大时 Ulysses 的 state
scan kernel 效率下降,P2P 相对收益扩大。
9.5 FSDP+CP 整网精度
整网为 4 层 Qwen3.5,层型为 3 Linear + 1 Full,使用 BF16、AdamW 和非零
学习率。每一步使用不同真实 token 序列。CP4/CP8 都同时开启 FSDP 参数分片。
| Topology | Mode | Steps | Max loss abs/rel | Max grad-norm abs/rel |
|---|---|---|---|---|
| CP4 + FSDP4 | Ulysses | 100 | 2.6097e-3 / 3.6715e-4 | 1.7036e-2 / 3.7480e-3 |
| CP4 + FSDP4 | P2P | 100 | 2.6107e-3 / 3.6729e-4 | 1.8070e-2 / 3.9756e-3 |
| CP8 + FSDP8 | Ulysses | 200 | 2.6898e-3 / 3.7746e-4 | 1.7224e-2 / 3.7883e-3 |
| CP8 + FSDP8 | P2P | 200 | 2.6526e-3 / 3.7223e-4 | 1.7531e-2 / 3.8563e-3 |
所有轨迹无 NaN/Inf、无 P2P 顺序错配、无误差持续扩大。Ulysses/P2P 的数值
误差量级接近,没有观察到 P2P state chain 特有的漂移。AllGather eager 额外完成
10 步功能回归。
9.6 整网性能和显存
固定 local sequence=16K:
| Topology | Layers | Ulysses Fwd+Bwd | P2P Fwd+Bwd | P2P time reduction | Throughput increase | Peak allocated reduction |
|---|---|---|---|---|---|---|
| CP4/FSDP4, global 64K | 4 | 854.047 ms | 778.644 ms | 8.83% | 9.68% | 372.0 MiB / 2.33% |
| CP4/FSDP4, global 64K | 8 | 1686.321 ms | 1529.381 ms | 9.31% | 10.26% | 744.1 MiB / 2.46% |
| CP8/FSDP8, global 128K | 4 | 1151.401 ms | 967.863 ms | 15.94% | 18.96% | 372.0 MiB / 2.38% |
| CP8/FSDP8, global 128K | 8 | 2276.529 ms | 1915.960 ms | 15.84% | 18.82% | 744.0 MiB / 2.47% |
完整层收益进入整网后被 MLP、Full Attention、embedding、lm_head、loss 和 FSDP
公共开销按 Amdahl 定律稀释。CP4/64K 四层整网仍保留约 9% 收益;CP8
下 Ulysses 的小-head state scan 与布局通信代价更明显,整网收益扩大到约 15.9%。
9.7 Activation checkpoint 交互
full activation checkpoint 会使 GDN custom autograd forward 在正常 forward 执行一次,并在
backward-time layer recompute 再执行一次;custom backward 仍只执行一次。
| Topology | Checkpoint | Ulysses Fwd+Bwd | P2P Fwd+Bwd | P2P reduction | Ulysses/P2P peak |
|---|---|---|---|---|---|
| CP4/FSDP4, 64K/16K | off | 854.047 ms | 778.644 ms | 8.83% | 15986.9 / 15614.9 MiB |
| CP4/FSDP4, 64K/16K | full | 1082.048 ms | 990.121 ms | 8.50% | 5602.3 / 5478.3 MiB |
| CP8/FSDP8, 128K/16K | off | 1151.401 ms | 967.863 ms | 15.94% | 15645.2 / 15273.2 MiB |
| CP8/FSDP8, 128K/16K | full | 1481.585 ms | 1248.249 ms | 15.75% | 5490.1 / 5366.1 MiB |
四组多步轨迹都完整结束,无死锁和数值异常。额外的 deterministic CP4/P2P
checkpoint-off/full 配对实验中,loss、grad norm 和 optimizer trajectory 逐打印位完全一致。
9.8 Level0 profile 和稳定性
CP4/64K Level0 trace 中,P2P 单次 HcclSend device self duration 约为
0.12--0.14 ms,中间 rank 约 9.8 ms communication 被计算覆盖。状态张量链路传输
带宽不是当前主要瓶颈;后续优化应面向 summary/gradient-summary 构造和
backward_finish。
每种分布式 mode 连续执行至少 20 次前反向,未观察到 P2P 消息顺序错配、
async buffer 生命周期错误、死锁、NaN/Inf 或显存持续增长。
10. 实现计划
| 阶段 / PR | 内容 | 依赖 | 验证 | 状态 |
|---|---|---|---|---|
| PR 1035 | eager Ulysses/P2P/AllGather、Conv halo A2AV、Qwen3.5 混合层接入 | 已有 Hyper CP/FSDP | CPU UT + NPU 完整层 + 多步精度 | 已完成并合入 |
| PR 1114 | Triton local GDN、P2P state-summary 正反向、backend fail-fast、wheel/LICENSE | PR 1035,triton-ascend 3.2.x | 单算子、CP4/CP8、100/200 步、profile、checkpoint | 已完成实现和验证 |
| Follow-up 1 | 将 forward summary 融入 W/U prepare,减少 HBM 回写/重读 | 稳定 P2P Triton | output/state/全梯度 + CP4/CP8 A/B | 规划中 |
| Follow-up 2 | 将 gradient-summary 融入 backward prepare,优化长 local sequence backward | Follow-up 1 可独立 | dH0/dHT/全梯度 + Level0 | 规划中 |
| Follow-up 3 | segmented summary / parallel prefix scan | 新 kernel | CP8/CP16 扩展、peak memory | 研究项 |
| Follow-up 4 | Fused Conv1D、AllGather Triton、Ulysses×P2P、All-Scan | 独立算子和通信设计 | 独立 RFC/PR | 不阻塞当前交付 |
当前稳定提交边界只包含:
mode = ulysses | p2p | all_gather
backend = eager | triton
ulysses + triton: 完整 local fused GDN
p2p + triton: fused GDN + fused state-summary
all_gather: eager only
conv: eager only
实验性 head/V chunk、persistent producer、fused Conv、All-Scan 和 backend=auto 不进入当前
公共 API。任何后续 kernel 替换都必须保留当前稳定路径作为 A/B 基线,并重新验证
output、final state、dH0/dHT、全部输入梯度、CP4/CP8 rank-max 性能和
peak allocated。
schema_version: 1
source: gitcode
gitcode_repo: mindspore/hyper-parallel
gitcode_issue: 212
source_url: https://gitcode.com/mindspore/hyper-parallel/issues/212
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 by reading the existing context-parallel entry points in core/context_parallel/linear_attention_context_parallel.py and models/qwen3_5/parallelize.py, then compare the eager GDN path in models/modules/linear_attention.py with platform/torch/custom_ops/gdn/. Validate the three CP modes and backend capability checks using the stated CP4/CP8 single-operator, full-layer, mixed-model, and activation-checkpoint coverage. Done means the documented PyTorch/Ascend Qwen3.5 FSDP+CP scenarios match the single-card outputs, gradients, loss, and grad norm.
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
- 30/100