Closed
补全 LayerNorm/LayerNormV3 golden 并对齐空归一化输出语义 #8336
rkAdd on  16 days agoClosed at  15 days ago
rk
rkCollaborators
16 days ago Create

一、背景信息

LayerNorm(V1)与 LayerNormV3 缺少 tests/assets/golden.py,对应 Kernel/GEIR 用例无法加载参考实现。现有 AddLayerNorm / InplaceAddLayerNorm golden 也存在覆盖缺口:AddLayerNorm 仅按最后一维归一化、固定返回 x 输出、dtype 规则仅参考 x1;InplaceAddLayerNorm 在空归一化维度将 mean 填为 NaN,且 additional_output=false 时丢掉可选输出槽位。

二、价值/作用

  • 补全 LayerNorm/LayerNormV3 的 golden,使对应 ST/GEIR 用例具备可加载的参考实现;
  • AddLayerNorm golden 支持多维归一化、FP64/FP32 dtype 组合、空归一化维度与可选输出开关;
  • 统一空归一化维度语义(mean=0、rstd=NaN)及可选输出槽位(None),避免 golden 与算子定义不一致导致的误判。

三、设计方案

  1. 新增 norm/layer_norm/tests/assets/golden.py 与 norm/layer_norm_v3/tests/assets/golden.py,注册 __golden__/__spec__,FP64 计算、统计量 dtype 跟随 gamma,epsilon 分别取 1e-12 / 1e-5;
  2. 重写 AddLayerNorm golden:归一化维度由 gamma.shape 决定,按 x1/x2 dtype 提升选择累积与输出 dtype,空归一化维度输出 y 空/mean=0/rstd=NaN,additional_output=false 返回 None 槽位;
  3. InplaceAddLayerNorm golden 空归一化维度 mean 改为 0,additional_output=false 返回四元组并补 None;
  4. 各 golden 注册 third_party torch 对照用于自校验。

关联 PR:https://gitcode.com/cann/ops-nn/pull/13856

likedislike
rkrkCollaborators
16 days ago Added label: requirement
yuning_chenyuning_chenCollaborators
16 days ago Assign wangpengbo26 as responsible person
CANN-robotCANN-robotCollaborators
15 days ago Close issue
CANN-robotCANN-robotCollaborators
15 days ago changed custom state from 待办的 to 已完成
CANN-robotCANN-robotCollaborators
15 days ago Added label: resolved