Skip to content

[Feature] Qwen 模型 Triton SwiGLU 激活函数优化 (2.58x 加速)#2769

Open
autism-ip wants to merge 2 commits into
candle-org:masterfrom
autism-ip:feature/triton-swiglu-optimization
Open

[Feature] Qwen 模型 Triton SwiGLU 激活函数优化 (2.58x 加速)#2769
autism-ip wants to merge 2 commits into
candle-org:masterfrom
autism-ip:feature/triton-swiglu-optimization

Conversation

@autism-ip

Copy link
Copy Markdown

摘要

基于 MindSpore 框架,使用 Triton 技术栈为 Qwen 模型开发高性能替换算子:

  • SwiGLU 激活函数:Qwen2/Qwen2.5 使用,2.58x 加速
  • GELU 激活函数:LLaMA 使用(0.80x,不推荐)

性能数据(Ascend NPU,公平对比)

算子 PyTorch Native Triton 加速比
SwiGLU 3.06ms 1.19ms 2.58x
GELU 0.75ms 0.94ms 0.80x
测试配置: (24, 512, 4864) - Qwen2-0.5B 24层批量

新增 API

from mindnlp.triton import MSGELU, MSSWiGLU, gelu, swiglu
# MindSpore Cell 方式
swiglu_act = MSSWiGLU()
output = swiglu_act(gate, up)
# 函数方式
output = swiglu(gate, up)
文件变更
- mindnlp/triton/kernels/activations.py - Triton GELU/SwiGLU 内核
- mindnlp/triton/kernels/mindspore_adapter.py - MindSpore Cell 适配层
- mindnlp/triton/kernels/benchmark.py - 性能测试工具
- mindnlp/triton/__init__.py - 模块入口
环境要求
- Atlas 800I A2 / 800T A2
- CANN8.1.RC1
- MindSpore2.7.0
- Triton3.2.0 (Ascend 适配版)

- Add Triton SwiGLU kernel (2.58x speedup on Ascend NPU)
- Add Triton GELU kernel (0.80x - PyTorch native is faster)
- Add MindSpore adapter (MSGELU, MSSwiGLU)
- Add complete optimization pipeline (profiling, testing, benchmark, e2e)
- Add detailed documentation and performance reports

Performance data (Ascend NPU, fair comparison):
- SwiGLU: 3.06ms (Native) -> 1.19ms (Triton) = 2.58x
- GELU: 0.75ms (Native) -> 0.94ms (Triton) = 0.80x

Compatible with MindSpore 2.8.0 + torch 2.7.1+npu
	modified:   src/mindnlp/triton/docs/ANALYSIS_REPORT.md
	new file:   src/mindnlp/triton/docs/ISSUE_ANALYSIS_DRAFT.md
	modified:   src/mindnlp/triton/kernels/activations.py
@autism-ip

Copy link
Copy Markdown
Author

【开源实习】Triton算子开发/接入 #1817
链接:https://gitcode.com/mindspore/community/issues/1817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant