torch_npu_ops_1374:基于 Triton 的 NPU 算子适配项目

torch_npu_ops is an ops library built with torch_npu for npu.

Branch1Tags0
FilesLast commitLast update
10 months ago
9 months ago
9 months ago
9 months ago
9 months ago

torch_npu_ops

triton_npu安装

当前qwen3-next模型线性注意力部分算子仅有triton实现,故通过离线编译triton算子的二进制来进行适配

依赖

pip install triton-ascend

准备

python setup.py

setup主要步骤如下

  1. 识别triton kernel白名单,当前仅支持每种kernel的数量等于1,若存在多个同名的triton kernel,会进行检查并报错。
  2. pytest triton_src/*.py, 相当于离线编译triton 二进制kernel。
  3. 拷贝 triton二进制及json文件(算子加载时需要)到$ENV{TRITON_BINARY_PATH}中, 默认路径在${user_path}/xllm/third_party/torch_npu_ops/binary

当前白名单中的kernel如下,通过kernel_launchers中的REG_KERNEL_LAUNCHER关键字识别提取得到

  • fused_gdn_gating_head8_kernel
  • fused_recurrent_gated_delta_rule_fwd_kernel
  • _causal_conv1d_update_kernel_no_cache_len_no_mtp
  • layer_norm_fwd_kernel

setup成功后会有如下提示

INFO: Found 4 unique kernel(s)
INFO: Validating and copying kernels to ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/...
INFO: Copied layer_norm_fwd_kernel.npubin -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/layer_norm_fwd_kernel.npubin
INFO: Copied layer_norm_fwd_kernel.json -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/layer_norm_fwd_kernel.json
INFO: Copied _causal_conv1d_update_kernel_no_cache_len_no_mtp.npubin -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/_causal_conv1d_update_kernel_no_cache_len_no_mtp.npubin
INFO: Copied _causal_conv1d_update_kernel_no_cache_len_no_mtp.json -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/_causal_conv1d_update_kernel_no_cache_len_no_mtp.json
INFO: Copied fused_gdn_gating_head8_kernel.npubin -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/fused_gdn_gating_head8_kernel.npubin
INFO: Copied fused_gdn_gating_head8_kernel.json -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/fused_gdn_gating_head8_kernel.json
INFO: Copied fused_recurrent_gated_delta_rule_fwd_kernel.npubin -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/fused_recurrent_gated_delta_rule_fwd_kernel.npubin
INFO: Copied fused_recurrent_gated_delta_rule_fwd_kernel.json -> ${user_path}/xllm/third_party/torch_npu_ops/triton_npu/binary/fused_recurrent_gated_delta_rule_fwd_kernel.json
INFO: Summary - Copied: 4, Skipped: 0
INFO: Script completed successfully

Introduction

torch_npu_ops is an ops library built with torch_npu for npu.

Customize your domain