Repository navigation
Conversation
xuxl1008
force-pushed
the
research/kda-ascendc-cp-reference
branch
from
October 24, 2026 08:32
def35f1 to
29382dc
Compare
xuxl1008
force-pushed
the
research/kda-ascendc-cp-reference
branch
from
October 29, 2026 17:28
29382dc to
15a659d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
目的和分支范围
这是用户 fork 内的研究参考 PR,保留 KDA AscendC 状态 CP、分 head 调度和后续内存优化的必要实现,实验结论在本描述中整理。不向
mindspore-ai/hyper-parallel:master提交,不请求作为生产功能直接合入。xuxl1008:reference/kda-ascendc-base-53788bdd。xuxl1008:research/kda-ascendc-cp-reference。53788bdd5e3c9d05a6a3401ad3a9e47364a624fe;FLA-NPU 基线47d7c97ce439228e0ead6fab4dad8b0440b663a8,另需本 PR 归档的 native 补丁。包含哪些代码
ascendclocal/Ulysses adapter,不更改已有 eager/triton 默认路径。trim、trim_norm、trim_norm_bwd2、trim_norm_bwd4,不是只保存 baseline。本次从168个文件精简到23个,移出123份结果JSON、长篇历史记录、索引/manifest及18个重复或诊断脚本。原始实验目录和本地备份分支保留;统一入口覆盖整层精度、checkpoint、性能与显存。普通 clone/install/import 不会执行实验或编译 AscendC;显式运行仍需按 README 安装匹配的 patched FLA-NPU 和 Triton-Ascend。
重要边界:公开 Hyper
backend="ascendc"仍只开放 stateless local/Ulysses;State-CP 使用experiments/kda_ascendc/scripts/stateful_layer.py的实验执行器。它是 AscendC core + Hyper Triton summary/merge + HCCL,不是纯 AscendC CP。分 head P2P 版本
四类实现均已在本 PR 中,本次补齐对照说明和 CP4/8 复验,不另外复制源码或新增 UT。后缀
2/4指 head 块数,H96 对应 H48/H24;不是 CP 大小,也不是只把最后一次矩阵乘法切块。p2p_whole2/4scripts/stateful_heads.py::head_corep2p_sf2/4scripts/stateful_heads.py::HeadStateCPp2p_dual2/4scripts/stateful_heads.py::HeadStateCP/StatePacketsp2p_summary2/4scripts/stateful_summary_heads.py::SummaryHeadCP以上路径都发送 FP32 state,不发送
(S,M);反向镜像传递 state gradient。Projection、ShortConv、Q/K L2Norm 不按块执行,output norm/projection 在 core 后执行。State-first 并不是“等待所有 rank 的所有包完成”:它在本 rank 提交各包状态 consumer,建立 finish 所需的流依赖,最后 drain 仍待完成的发送。双流不保证资源不竞争,四类仍保留 O(CP) rank 链。它们不是当前 AscendC 的 RD/Tree 或 device-side All-Scan。
--modes用于独立进程的性能比较;--compare-modes用于同权重/输入的数值比较。安装、所有模式的完整命令及 forward/backward 顺序见experiments/kda_ascendc/README.md。不把任意块数、跨层并发、TND 或多层训练宣称为已验收。dHT 修复和 CP 流程
原 Dhu 未消费终态梯度。补丁为 A2 K-first 路径初始化真实非零 dHT carry,贯通 FP32 h0/dHT/dh0 的 host/tiling/kernel/Python-C++ 接口,并修复 FP32 空序列 scratch 写出后的复用同步。不修改 UB 容量或 Cube GEMM。
P2P 传 state;AllGather 传 affine summary,用融合 prefix/suffix merge,不是 Python 矩阵循环。S/M/G 不额外重复反传一次;局部完整 backward 消费真实 h0/dHT。
前期实验整理
早期失败、污染样本作废、复测和大 CP 条件推演的原始记录保留在本地,不随本 PR 分发;本描述只整理已核对的结果,未使用被污染的性能补表。
历史性能和显存
环境:910B3、CANN 9.1.0-beta.3、torch/torch-npu 2.10.0、Triton-Ascend 3.2.2。
统一完整层配置:B1/H96/D128/hidden4096/chunk64、local8192、BF16 token、FP32 state。
覆盖 projection、ShortConv、core、output gate/norm/projection;不含 optimizer、参数梯度归约、FSDP、多层。
显存为所有 rank 的最大 peak allocated,不是 npu-smi 总占用。
CP8 基线两轮
2026-10-22,CP8/global65536,两个新进程轮次,每轮 warmup5/repeat20;以下为40个 rank-max 样本的中位数。
内存优化消融
这是后续另一批同轮对照,每配置20次,不与上述两轮基线合并统计。下表均为
Fwd+Bwd ms / peak allocated MiB。CP8 core state-first h4:baseline为
199.581 ms / 7947.2 MiB,加trim_norm为182.810 ms / 7306.7 MiB。trim不再保存 backward 无读者的 prepared.u/Qg,H96/local8K 实省约384 MiB,时间基本不变。trim_norm另融合输出 sigmoid gated RMSNorm,保留 FP32计算、epsilon及全部梯度;不是SiLU。trim_norm_bwd2/4仅切 backward-finalize,保留完整 prepare/S/M/G/FwdH/Dhu;省工作区但有复制、额外调用及cat代价。trim_norm更快,bwd4进一步省显存;core sf4更省但更慢。没有一种变体同时在所有指标最优,也没有将其设为生产默认。精度与本轮复验
历史 Dhu 最大 rel-L2 约0.00294,Local KDA约0.00895,CP core对CPU最大约0.01643,CP8整层参数最大约0.01839。整层预先固定门槛为各项finite且rel-L2<0.03,不是所有梯度都小于1%。
2026-10-24,在新参考工作树和独立editable环境中重新执行:
21 passed;既有KDA eager UT9 passed,未新增正式UT。8.95442e-3。8.93816e-3。1.83892e-2。3.44629e-4。30 passed,以及统一入口的 CP4 H8/hidden64/local64/global256、seed101、P2P/AG整层+checkpoint+全部五种内存变体检查。整层对CPU最大rel-L28.93816e-3;trim与baseline完全一致,其他内存变体对baseline最大rel-L27.30300e-4。这是另一次小shape复验,不与上面的CP8精度数值混为同一配置。2026-10-30 分 head 入口复验
同上固定环境、patched native 产物;B1/H8/D128/hidden64/local64、seed23,开启 non-reentrant checkpoint。CP4/global256 与 CP8/global512 都完成八个分 head 组合及 AllGather/Ulysses 对照,output、hidden gradient 和全部14项参数梯度 finite,无超时。
后面三行是跨模式对照,不是每个模式独立对 CPU 的误差;不与长序列性能混用。本次只补数值和入口验证,没有重新采集长序列性能。本轮提交仅更新现有 README,仍为23个文件、单个commit,无新增测试或结果文件。
最小复现入口
experiments/kda_ascendc/README.mdexperiments/kda_ascendc/patches/experiments/kda_ascendc/scripts/run_stateful_benchmarks.pyexperiments/kda_ascendc/scripts/check_stateful_kda.pyexperiments/kda_ascendc/scripts/check_dht_matrix.py运行结果写入被git忽略的
experiments/kda_ascendc/runs/,不进入提交。实验数字与边界在本PR描述中分表保留。其他可整理的历史实验,不混入本 PR
2026-10-30 已核对 fork 的现有分支与 PR,以下内容已经有独立位置,不重复搬进本 PR:
feat/kda-cached-rd-cp。其 CP8 验证是同一 S/M/G 上的边界协议,不是完整 KDA;“head 分工到不同 rank”也不是本 PR 的“同 rank head-block P2P”。另一个来源是旧 Triton 研究分支
kimi_k3_large_cp_new_arch@9b5c253b的experiments/kda_cp/。下面的“通过”指其原固定基线上的历史验证,不是当前 master 或本 AscendC 分支的验收。旧代码还依赖已变化的hyper_parallel.platform和platform/torch/custom_ops/kda接口,直接复制到本分支会有 import/API 问题。runners/virtual_scan.py;本次 CPU FP64 2~256 ranks 重跑通过,最大绝对误差3.886e-16扣除已有 PR 后,下一份建议优先整理 V-block + dual-drain/dual-immediate 调度对照,再整理 组内 AG + 组间 P2P 分层。每份保留必要源码、一个统一入口和简短说明。旧 async Tree 仅见 prefix 原型,不并入“完整链路已通过”的声明。Compressed two-level AllGather、M-tree once + S-block tree、设备端 put/signal All-Scan 在本参考路径没有完整可交付链路,不作为已完成的优化推送。TND 和最新 RD 的能力以各自分支及验证记录为准,不因旧研究快照而判定它们全局尚未实现。
未完成范围
TND/varlen整层、RD/Tree与任意subgroup的AscendC接线、多层/FSDP/100步训练、真实CP16/32/256、A3/A5和V-first仍未验收。FP32 dHT要求显式h0 descriptor;当前固定长度、按序WORLD的边界不能直接外推。单边通信、进一步native workspace复用和梯度cat优化仍是后续方向。
这是参考实现,不新增依赖强制安装,不伪装成上游FLA-NPU已有完整CP,也不触发主仓生产门禁。