Skip to content

feat: add GammaAddRmsNorm custom operator.#10

Open
Fengfengst123 wants to merge 1 commit into
xLLM-AI:mainfrom
Fengfengst123:codex/gamma-add-rmsnorm-upstream-draft
Open

feat: add GammaAddRmsNorm custom operator.#10
Fengfengst123 wants to merge 1 commit into
xLLM-AI:mainfrom
Fengfengst123:codex/gamma-add-rmsnorm-upstream-draft

Conversation

@Fengfengst123

@Fengfengst123 Fengfengst123 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

功能概述

  • 新增 GammaAddRmsNorm 自定义算子及 ACLNN 接口
    aclnnGammaAddRmsNorm,将 x = x1 + x2 与 RMSNorm 融合执行。
  • 新增可选属性 addGammaOffset,支持在 kernel 内执行 Gemma 风格的
    gamma + 1,避免额外的 Add 算子下发。
  • 将算子加入 Ascend 910B (ascend910b)、Ascend 910C (ascend910_93) 和 Ascend 950 (ascend950)
    的自定义算子构建列表。
  • 将 RMSNorm 与 reduction 的直接 kernel 源码依赖放入算子目录,使其能够在
    xllm-ops 中独立构建,不依赖外部 ops-nn 源码树。

性能测试

在本机 Ascend 910B3 上使用 ATK performance_device 测量 BF16 device
task latency。候选链路为 GammaAddRmsNorm(addGammaOffset=true),原链路为
Add(gamma, 1) + AddRmsNorm。两条链路使用相同的 shape、dtype、输入范围和
随机种子;每个 case 执行 100 次 warmup、20 次测量,并由 ATK 重复 10 轮。

模型相关 shape(归一化维度 D >= 1024)结果如下:

Shape Add(gamma, 1) (us) AddRmsNorm (us) 原链路合计 (us) GammaAddRmsNorm (us) 加速比
1x5120 1.745 2.658 4.403 2.848 1.546x
2x5120 1.727 2.743 4.470 2.918 1.532x
16x1024 1.358 3.472 4.830 3.684 1.311x
64x4096 1.596 6.914 8.510 7.484 1.137x
512x2048 1.417 15.413 16.830 15.940 1.056x
256x7168 1.959 17.132 19.091 17.606 1.084x

Qwen3.5 实际 decode 小 shape 的本机 msprof device-task 结果如下:

Model Shape Add(gamma, 1) (us) AddRmsNorm (us) 原链路合计 (us) GammaAddRmsNorm (us) 加速比
Qwen3.5-0.8B 4x1024 1.652 2.596 4.248 2.580 1.647x
Qwen3.5-2B 4x2048 1.722 2.801 4.523 2.792 1.620x

精度验证

  • Ascend 950:ATK 240/240 用例执行成功,GammaAddRmsNorm 精度通过,
    与原链路 Add(gamma, 1) + AddRmsNorm 一致。
  • Ascend 910B:ATK 414/414 用例执行成功,413/414 达到精度阈值。

Summary

  • Add the GammaAddRmsNorm custom operator and the
    aclnnGammaAddRmsNorm ACLNN API, fusing x = x1 + x2 with RMSNorm.
  • Add the optional addGammaOffset attribute to apply the Gemma-style
    gamma + 1 inside the kernel and eliminate a separate Add launch.
  • Add the operator to the Ascend 910B (ascend910b), Ascend 910C
    (ascend910_93), and Ascend 950 (ascend950) custom-op build lists.
  • Vendor the direct RMSNorm and reduction kernel source dependencies so the
    operator builds independently in xllm-ops without an external ops-nn source
    tree.

Performance

BF16 device-task latency was measured locally on Ascend 910B3 with ATK
performance_device. The candidate is
GammaAddRmsNorm(addGammaOffset=true) and the previous chain is
Add(gamma, 1) + AddRmsNorm. Both paths use identical shapes, dtypes, input
ranges, and random seeds. Each case uses 100 warmups, 20 measured iterations,
and 10 ATK performance repeats.

Results for model-relevant shapes with normalized dimension D >= 1024:

Shape Add(gamma, 1) (us) AddRmsNorm (us) Previous chain total (us) GammaAddRmsNorm (us) Speedup
1x5120 1.745 2.658 4.403 2.848 1.546x
2x5120 1.727 2.743 4.470 2.918 1.532x
16x1024 1.358 3.472 4.830 3.684 1.311x
64x4096 1.596 6.914 8.510 7.484 1.137x
512x2048 1.417 15.413 16.830 15.940 1.056x
256x7168 1.959 17.132 19.091 17.606 1.084x

Qwen3.5 decode small-shape device-task results from the local msprof runs:

Model Shape Add(gamma, 1) (us) AddRmsNorm (us) Previous chain total (us) GammaAddRmsNorm (us) Speedup
Qwen3.5-0.8B 4x1024 1.652 2.596 4.248 2.580 1.647x
Qwen3.5-2B 4x2048 1.722 2.801 4.523 2.792 1.620x

Accuracy validation

  • Ascend 950: all 240 ATK cases executed successfully;
    GammaAddRmsNorm accuracy matches the previous
    Add(gamma, 1) + AddRmsNorm chain.
  • Ascend 910B: all 414 ATK cases executed successfully, with 413/414 meeting the accuracy threshold.

@Fengfengst123 Fengfengst123 marked this pull request as ready for review July 15, 2026 01:44
@@ -0,0 +1,163 @@
{
"op_type": "GammaAddRmsNorm",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥要有各种芯片型号的json

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他算子都是在def函数中直接设置兼容的config就行

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的 ,当前已优化

@LMX-xin

LMX-xin commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

这个是cann中的算子,还是你们自己写的,是cann版本的算子的话,当前cann包中没有吗

@LMX-xin LMX-xin changed the title feat: add GammaAddRmsNorm custom operator feat: add GammaAddRmsNorm custom operator. Jul 15, 2026
@Fengfengst123 Fengfengst123 marked this pull request as draft July 15, 2026 03:58
@Fengfengst123 Fengfengst123 force-pushed the codex/gamma-add-rmsnorm-upstream-draft branch 3 times, most recently from 6cf02eb to eefcb2e Compare July 15, 2026 07:42
@Fengfengst123 Fengfengst123 marked this pull request as ready for review July 16, 2026 09:15
@Sinle4Cat

Copy link
Copy Markdown
Contributor

需要补充算子的测试代码

@Fengfengst123 Fengfengst123 force-pushed the codex/gamma-add-rmsnorm-upstream-draft branch 2 times, most recently from ce18890 to 1f03b79 Compare July 16, 2026 13:02
@Fengfengst123

Copy link
Copy Markdown
Contributor Author

这个是cann中的算子,还是你们自己写的,是cann版本的算子的话,当前cann包中没有吗

这个是ops-nn的AddRMSNorm, 本次现在qwen3.5的路径中,有一处gamma +1 的Add操作 + 加 AddRmsNorm,本次加了一个参数,做了融合,然后省去了这一部分Add的时间

@Fengfengst123

Copy link
Copy Markdown
Contributor Author

需要补充算子的测试代码

好的,已添加

namespace OpTiling {
static const gert::Shape g_vec_1_shape = {1};

static bool IsRegbaseSocVersion(platform_ascendc::SocVersion version)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这些参数调整的背景是什么

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本地用的cann包版本太低了,AI自动做了下兼容,已经修复去掉了

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不涉及 310p 9030 x90 不要在这里体现

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经删除掉

this->AICore().AddConfig("ascend910_93");

OpAICoreConfig config310P;
config310P.Input("x1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

去除所有310p兼容代码

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经删除

uint32_t curElementByte = dtypeByteIterator->second;
numColAlign = CeilDiv(numCol * curElementByte, ubBlockSize) * ubBlockSize / curElementByte;

// 计算 二分累加 分界点

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep all comments in English.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改~

@yingxudeng yingxudeng requested review from LMX-xin and Sinle4Cat July 16, 2026 14:00
@Fengfengst123 Fengfengst123 force-pushed the codex/gamma-add-rmsnorm-upstream-draft branch from 1f03b79 to 8d587d9 Compare July 16, 2026 14:45
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.

4 participants