CANN/cann-recipes-infer: Gemma-4-26B-A4B 模型优化报告

CANN/cann-recipes-infer: Gemma-4-26B-A4B 模型优化报告 Gemma-4-26B-A4B 模型优化报告【免费下载链接】cann-recipes-infer本项目针对LLM与多模态模型推理业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-infer初版生成: 2026-04-15基于 Atlas A2 / 910B432 GB HBM 更新: 2026-04-27追加 Atlas A3 / 910 A3 8 卡迁移性能数据见第 7.1 节1. 模型概况项目内容模型名称Gemma-4-26B-A4B (google/gemma-4-26B-A4B)架构类型多模态 MoE本次仅适配 Language Decoder跳过 Vision Tower总参数量26.5B活跃 ~3.8B/token128 experts top-8权重BF16 ~51.6 GB部署8 卡EP8embed/lmhead_tp8attn_tp1执行模式eagerPrefill GE graphDecode架构特点Token Embedding (vocab262144, shared with LM Head) └─ Decoder Block × 30 ├─ Attention双模式 │ ├─ Sliding (25 层): GQA, N_h16, N_kv8, head_dim256, window1024 │ └─ Full (5 层): GQA, N_h16, N_kv2, head_dim512, k_eq_vTrue ├─ Dense MLP: gateupdown, intermediate2112, GELU ├─ MoE: 128 experts, top-8, intermediate704, GEGLU │ 每层同时有 Dense MLP 和 MoE非交替式 └─ 6× LayerNorm layer_scalar └─ LM Head (shared with Embedding)关键特殊点双模式 Attention 导致 KV cache 维度异构k_eq_v 使 full 层无 v_projQK RMSNorm 使 FA scale1.0。2. 性能基线指标值条件Prefill312.51 msBS8, seq_len256, 8 卡 eagerDecode98.47 msBS8, 8 卡 eager3. 阶段 1并行化改造配置值理由attn_tp1full_attention N_kv2 限制 TP 上限DP8 最大化吞吐dense_tp1intermediate2112 过小TP 碎片化无收益EP8128 experts / 8 16/rankembed/lmhead_tp8大词表 262144 切分精度: 通过 | Prefill 313ms, Decode 97ms4. 阶段 2KVCache FA项目内容KVCache连续缓存按层异构sliding kv_dim2048, full kv_dim1024FAFA v1, BSH, scale1.0改动sliding 层 Prefill sparse_mode4 pre_tokens1024PA 不采用双 Attention head_dim 不同256/512需两套 block_table复杂度高于收益精度: 与基线一致 | Prefill 310ms, Decode 97ms5. 阶段 3融合算子已实施模块替换为频次/stepResidual Normnpu_add_rms_norm60Sliding RoPE (25 层)npu_rotary_mul50MoE Routernpu_moe_gating_top_k_softmax30不适配项模块候选算子阻塞原因Dense FFN GEGLUnpu_gelu_muldim 上限 1024需 4224Dense FFN GEGLUnpu_ffngeglu不支持 bf16精度: 无损 | Decode: 97 → 92ms (-5.4%)6. 阶段 4图模式适配6.1 方案项目内容后端GE graph (torchair), fullgraphTrue, Decode onlyMoEDecode: local-expert AllReduce; Prefill: double_routingFADecode: torchair FA; Prefill: torch.ops.npu FAGEGLUPrefill: npu_geglu; Decode: 手动 F.gelu图模式兼容MoE 图模式方案EP 场景下 double_routing 的 AllToAll split sizes 是 contenteditable="false">【免费下载链接】cann-recipes-infer本项目针对LLM与多模态模型推理业务中的典型模型、加速算法提供基于CANN平台的优化样例项目地址: https://gitcode.com/cann/cann-recipes-infer创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考