hy3-preview Baseline【免费下载链接】cann-recipes-infer本项目针对LLM与多模态模型推理业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-infer采集时间2026-04-27 ~ 2026-04-28 基线目的记录 hy3-preview (Hunyuan3) 模型在 NPU 上的初始部署性能以及各优化阶段的性能演进1. 硬件环境项目规格NPU 型号Ascend 910C (Atlas A3)部署卡数16 die (8 物理卡 × 2 die/卡)单 die HBM64 GB (65536 MB)总 HBM1024 GB实际可用/die~61.27 GiBCANN 版本8.5.0 (25.5.1)PyTorch2.8.0torch_npu2.8.0推理框架cann-recipes-infer (ModelRunner)2. 模型信息参数值模型名称Hunyuan3 (Hy3 preview)开发者Tencent Hy Team架构类型MoE Transformer (Dense Sparse MoE Shared Expert)总参数量295B (295,033,543,488)激活参数量~21B / tokenBF16 参数占用~590 GB总层数80 (layer 0 Dense FFN layers 1-79 MoE)MTP 层layer 80 (~3.8B params, 推理跳过)Hidden Size4096AttentionGQA: 64 Q heads, 8 KV heads, head_dim128Dense FFN Intermediate13312 (layer 0)MoE Expert Intermediate1536专家总数192每 token 激活专家8 (top-8 sigmoid routing)Shared Expert1 per MoE layer词表大小120,832最大上下文长度262,144 (256K)RoPE Theta11,158,840激活函数SiLU归一化RMSNorm, eps1e-5特殊设计QK Norm (per-head RMSNorm before RoPE), sigmoid router expert bias3. 部署配置3.1 并行策略参数值说明world_size168 卡 × 2 die/卡attn_tp_size4N_kv8 约束, 均衡 Prefill/Decodedense_tp_size4与 attn_tp 对齐moe_tp_size1Expert intermediate1536 太小moe_ep_size16全卡 EP, 192/16 12 experts/rankembed_tp_size4120K 大词表切分lmhead_tp_size4与 embed 对齐3.2 执行配置参数值执行模式ge_graph (图模式, Decode 阶段)量化模式BF16enable_online_split_weightTrueenable_superkernelTrueenable_cache_compileTruebatch_size164. 性能基线4.1 原始基线 (阶段 1 并行化后, eager mode)指标数值测试条件Prefill 耗时2,070 ms1024 tokens, batch4, 16 die A3, eagerDecode 单步耗时293 ms/teager mode, 16 die A3显存占用~54.5 GB/dieBF16, 295B EPTP 分布后采集时间2026-04-27。这是完成并行化部署后的第一个可运行版本作为所有后续优化的对比基准。4.2 各阶段性能演进阶段配置Prefill (1024t)Decode (ms/t)累计加速阶段 1eager (并行化基线)2,070 ms2931.0x阶段 3eager P0P1 融合算子1,041 ms2461.19x阶段 4ge_graph MC2 dispatch/combine GMM—33.38.8x阶段 4 compile cache1,397 ms31.59.3x阶段 4 SuperKernel1,408 ms30.89.5x最终ge_graph compile cache SuperKernel1,452 ms28.4410.3x最终性能采集时间2026-04-2832 tokens decode 实测 (range: 27.4-29.4 ms/t)。4.3 最终性能 vs 目标指标最终值目标达成Decode 单步耗时28.44 ms/t100 ms/t3.5x marginPrefill 耗时 (1024t)1,452 ms——输出质量正常—✓5. 关键优化项5.1 融合算子 (阶段 3)算子替换前替换后调用频率RMSNorm (全部)Pythonpow(2).mean().rsqrt()npu_rms_norm321次/forwardResidual RMSNormx ynorm(y)分离npu_add_rms_norm160次/forwardFFN SiLU 激活F.silu(gate) * upnpu_swiglu80次/forwardMoE RouterPython sigmoidtopkgathernorm (7 ops)npu_moe_gating_top_k(norm_type1)79次/forward5.2 图模式 (阶段 4)项目说明图模式后端ge_graph (torchair CompilerConfig)Decode 路由MC2 dispatch/combine 替代手动 all_to_all专家计算npu_grouped_matmul(split_item2)GMMFA 接口torchair FA (ge_graph Decode) / torch.ops.npu FA (eager Prefill)SuperKernelenable_superkernelTrue, decode 层循环外包Compile Cacheenable_cache_compileTrue, 持久化 compile_cache/, 二次 warmup ~8s6. 关键修复记录序号阶段问题影响修复F-11QKV 权重静默跳过输出完全乱码q/k/v_proj → merged_qkv_proj 映射F-21dist.broadcast(src0)ranks 4-15 崩溃Decode 完全阻塞移除 broadcastF-34GMM_prepare_gmm_weights权重副本 OOMge_graph 编译失败inline transpose viewF-44手动 EP all_to_all 数据依赖 graph breakfullgraph 编译失败MC2 dispatch/combine 替代F-54SuperKernel superkernel_scope 图捕获失败SuperKernel 未生效移至 torch.compile 外部7. 已知限制限制项说明multi-streamshared expert 计算量太小 (intermediate1536), 无法有效 overlap, enable_multi_streamsFalseP2 融合算子npu_ffnswiglu 模式不接受 expert_tokens 仅支持 fp16, 不可行shared_expert_x与 SuperKernel 冲突 (CANN 8.5.0 stream 限制), 已回退长序列 (128K)KV Cache 增长到 ~10.7 GB/卡, 256K 时 ~21.4 GB/卡 可能超限量化若减至 8 卡部署需 W8A8 量化, 当前 BF16 16 卡可行8. 显存分布 (ge_graph 最终配置)模块参数量BF16 显存占比Embedding495M0.99 GB0.17%Attention (80层)6.04B12.08 GB2.05%Dense FFN (layer 0)164M0.33 GB0.06%MoE Experts (79层×192专家)286.29B572.57 GB97.04%MoE 非专家 (RouterSharedBias)1.55B3.11 GB0.53%LM Head495M0.99 GB0.17%总计295.03B590.07 GB100%attn_tp4 moe_ep16 分布后每卡参数约 39.8 GBKV Cache (32K) ~2.7 GB总约 47.5 GB/die。【免费下载链接】cann-recipes-infer本项目针对LLM与多模态模型推理业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-infer创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考