Repository navigation
Conversation
Owner
Author
|
NPU 自洽验证结果(910B3 / CANN 9.2 / Transformers 5.13.1):单卡与 8 卡使用同一份 2 层、16 专家 BF16 checkpoint 和同一份 Megatron 数据,均完成 20/20 步,无缺失权重、NaN 或运行异常。
另有一个文档兼容问题:README 中裁剪 checkpoint 使用 |
Owner
Author
|
补充 500 步自洽验证:单卡 vs 4 卡(TP2 × CP2 × DP1、EP4 × EDP1,loss parallel)。使用同一份裁剪 checkpoint 和 Megatron 数据,均完成 500/500 步,无 NaN 或运行异常。
500 步内:
loss 满足 说明:本次验证的是 TP2 × CP2 × DP1 的 4 卡拓扑,不等同于此前 8 卡 DP2 配置的覆盖。 |
hf1s
force-pushed
the
feat/deepseek-v32-hf
branch
3 times, most recently
from
November 11, 2026 10:29
dd97cce to
a1b43a3
Compare
…t, add a parallel recipe - Register a materialization provider that rebuilds the non-persistent RoPE buffers (inv_freq, original_inv_freq) after HyperAutoModelForCausalLM loads weights; they were left uninitialized (zeros or NaN). - Import dsa_indexer and dsa_sparse_attention from the functional package in the DSA CP wrapper. Importing the submodules replaced the package attributes with modules, so cp_size=1 runs with a `when: cp` entry failed with "'module' object is not callable". - Add recipes/train_parallel_offline.yaml and run_parallel_offline.sh, which train an 8-layer crop on 8 NPUs with TP2 x CP2 x DP2, EP4 x EDP2 and loss parallelism. - Add the family README in English and Chinese.
hf1s
force-pushed
the
feat/deepseek-v32-hf
branch
from
November 12, 2026 02:48
a1b43a3 to
96ec3d9
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.
What type of PR is this?
/kind bug
What does this PR do / why do we need it:
修复 master 上训练 DeepSeek-V3.2(Transformers 原生
DeepseekV32ForCausalLM)的两个问题。改动只在hyper_parallel/models/deepseek_v32/adapter/,框架代码不变。from_pretrained之后 RoPE 的 buffer 没有初始化inv_freq/original_inv_freq是非持久 buffer,checkpoint 不保存。Transformers 自己的from_pretrained在加载后会对 checkpoint 中没有的张量调用_init_weights,其中专门重算这两个 buffer。HyperAutoModelForCausalLM.from_pretrained则是:在 meta 设备上建模型(没有数值)→ 切分并分配存储(内容未定义)→ 只加载 checkpoint 中的张量 → 加载收尾的_finalize_model_loading只初始化缺失的参数,跳过非持久 buffer。这两个 buffer 因此一直停留在未初始化的内存。from_pretrained构建时为全 0,经 Trainer 构建时为 NaN。from_config随机初始化不受影响,因为 HP 会调用 Transformers 的权重初始化。adapter/materialization.py的register_rotary_materialization:在 CPU 上用同一个 config 构造DeepseekV32RotaryEmbedding,由 Transformers 算出这两个 buffer,通过框架的register_rebuildable_buffer登记;builder 在加载权重后由rebuild_materialized_state写回。registration.py把它登记为ModelAdapterSpec.materialization。做法与 Qwen3.5 的register_rotary_materialization相同。hyper_parallel.components.functional按子模块同名懒导出dsa_indexer/dsa_sparse_attention。master 的 CP wrapper 直接 import 这两个子模块,包上的同名属性随之变成模块对象。YAML 中有when: cp条目时,解析配置就会 import CP wrapper,之后DeepseekV32DSAAttention从包里拿到的是模块,cp_size=1 时第一次前向报TypeError: 'module' object is not callable。master 的recipes/train.yaml带有该条目且默认 cp_size=1,同样受影响。改为从包导入。另外新增面向用户的模型族说明
hyper_parallel/models/deepseek_v32/README.md(英文)与README.zh.md(中文),结构参照 Kimi-K2.6:注册身份、目录结构、功能与训练行为、环境要求、单卡与多卡用法、用裁剪 checkpoint 快速验证、910B3 实机验证结果。Which issue(s) this PR fixes:
无
Test Plan and Test result:What scenarios were tested, and what were the verification results(Function, performance, reliability, etc.):
NPU 实验(910B3 × 8,CANN 9.2,Transformers 5.13.1;在本 PR 分支上运行,代码未改动;配置与日志未随 PR 提交)
公共配置:
HyperAutoModelForCausalLM.from_pretrained加载裁剪后的 BF16 checkpoint;各组使用同一份 Megatron.bin/.idx数据。seq_length=4096,global_batch_size=2,micro_batch_size=1,seed 1234,开启enable_full_determinism;AdamW,lr 1e-5 余弦衰减到 1e-7,无 warmup,max_grad_norm=1.0;全量重计算;开启优化器状态换出。deepseekv3_ep_compute_fn,grouped GEMM,shared expert 与通信重叠)。1. 单卡与 8 卡对齐:2 层裁剪(1 dense + 1 MoE,16 个路由专家,3.40B 参数),训练 500 步,两侧均完成 500/500 步。
500 步内 loss 最大绝对差 0.0054(相对 6.8e-4),grad_norm 最大绝对差 0.103(相对 1.4e-2)。
2. 高性能替换的收益:同一 2 层裁剪、8 卡拓扑与数据;对照组去掉 RMSNorm 和 GroupedExperts 两项替换,DSA、CP、EP 不变。
两项替换使步时下降 18.4%、吞吐提升 22.6%,显存基本不变。稳态取第 11 步之后的平均(全部替换取 500 步的运行,对照组取 50 步的运行)。对照组只用于比较性能:它与单卡参考使用的算子不同,loss 不作对齐比较。
3. 8 层裁剪:3 dense + 5 MoE,16 个路由专家,8.40B 参数;8 卡全部替换,训练 50 步。完成 50/50 步,无 NaN;loss 13.2769 → 12.0062;稳态 4.535 s/step,1806.5 tokens/s(每卡 225.8);峰值显存 16.90 / 23.36 GiB。
TFLOPS/MFU 未统计:框架的 FLOPs 统计(
trainer/runtime/flops.py)目前只支持qwen3_moe,对deepseek_v32不输出。CPU 检查
HyperAutoModelForCausalLM.from_pretrained构建后,与直接构建的模型比较inv_freq/original_inv_freq:不登记 provider 时全为 0(经 Trainer 构建时为 NaN),登记后完全一致。from_config随机初始化时由 Transformers 的权重初始化算出这两个 buffer,有无 provider 都正确。when: cp条目的配置在 cp_size=1 时第一次 DSA 前向报TypeError: 'module' object is not callable;改为从包导入后正常(本地 CPU/Gloo、DSA 用 CPU 参考 kernel 的 TP2 + EP2、cp_size=1 用例实测)。Self-checklist:(请自检,在[ ]内打上x,我们将检视你的完成情况,否则会导致pr无法合入)