Merged
fix(lamb_next_right): 修正空 Tensor tiling data 有效长度 #14193
陈思Add on 11 days ago
fix(lamb_next_right): 修正空 Tensor tiling data 有效长度 #14193
Merged
Pull Request has been successfully merged by CANN-robot.
(Thank you for 陈思's contribution.)atomgit-bot
11 days ago Comments:
11 days ago Comments:
变更摘要
本次变更修复 lamb_next_right 算子在合法空 Tensor 输入下静态编译失败的问题,并严格落实“任一输入含 0 维时输出为空、全部输入为零维时输出归一为 (1,)”的 shape 约束。核心在于:tiling 阶段改为按六个输入独立推导广播结果并校验 y1/y2,空输出改用与 schMode=1 匹配的 BroadcastBaseTilingData 类型化写入,kernel 侧在进入广播调度器前对零工作量提前返回,同时补充了 host UT 与 infershape 回归用例。
主要改动
- 输入广播推导与双输出校验:新增
MergeInputShape,在GetShapeAttrsInfo中按六个输入逐步合并广播形状(显式处理0与1的广播结果为0),并对y1、y2分别与EnsureNotScalar后的期望形状比对,拒绝()等非法输出描述。 - 空 Tensor 走类型化 tiling 分支:删除原先“整块缓冲区清零并把容量当作有效长度”的做法,新增模板函数
SetEmptyTiling<T>,以BroadcastBaseTilingData<OpDag>结构体赋值方式设置scheMode=1、blockNum=1,仅序列化结构体自身大小,工作区置 0、blockDim为 1。 - 空输出判定与 dtype 校验前移:
DoOpTiling先校验input_square的 dtype 必须为DT_FLOAT16/DT_FLOAT,再逐维扫描输出 shape 判断是否含 0(避免维度乘积溢出掩盖后续零维),命中后按 dtype 分派SetEmptyTiling<half>或SetEmptyTiling<float>。 - Kernel 零工作量提前返回:
lamb_next_right入口在schMode == 1时先加载 tiling 数据,若elemNum == 0直接return,避免 NDDMA 调度器在检查循环次数前初始化零长度 UB 或访问空输入输出。 - 补充回归测试:host tiling UT 新增 shape 校验与空 tiling 用例(各输入位置为零、FP16/FP32、不同容量、容量不足、非法 dtype),infershape UT 新增全标量输出
(1,)、空 Tensor 保持广播维度、系数为空与混合标量场景的用例。
🧩 本次 Review 已使用自定义 Skill:


Incorrect?
atomgit-bot
11 days ago Comments:
11 days ago Comments:
代码审查
审查结论(已逐个文件审阅,工具输出仅为分析与已上报条目的记录,不再赘述推理过程)
已上报问题(3 条)
| 优先级 | 文件 | 问题 |
|---|---|---|
| P2 | op_kernel/lamb_next_right.cpp:30-38 |
kernel 新增 elemNum == 0 早退对所有 schMode=1 的正常启动都生效,但 UT 只断言空场景 elemNum == 0,非空路径 elemNum > 0 无任何断言;一旦某 tiling 分支漏填该字段,整条正常路径会静默不写输出(且本 PR 未做真机验证) |
| P3 | op_host/arch35/lamb_next_right_tiling_arch35.cpp:36-52 |
tiling 侧 MergeInputShape 复刻了 infershape 的 Ops::Base::BroadcastShape 广播语义(0/1 广播为 0、rank0→(1,) 归一),但新增 UT 把期望 shape 写成字面量、未与 infer_shape 交叉校验,两份实现漂移时会把合法图判成 tiling 失败 |
| P3 | tests/ut/op_host/arch35/test_lamb_next_right_tiling.cpp:114-117 |
FP16 空 tiling 用例仍用 float DAG 的结构体类型断言 GetDataSize()==sizeof(Data),未按 dtype 参数化,可能掩盖 host/kernel 结构体布局不一致 |
各文件审阅确认
optim/lamb_next_right/op_host/arch35/lamb_next_right_tiling_arch35.cpp:审阅GetShapeAttrsInfo(dtype 一致性 + 六输入广播合并 + y1/y2 严格校验、kInputNames/kOutputNames下标均在界内)、DoOpTiling(dtype 前置校验、按维度扫描判空避免乘积溢出、空分支提前返回)、SetEmptyTiling(零值化结构体、scheMode=1、blockNum=1、workspace=0、SetBlockDim(1),与 kernelBroadcastSch读取的结构体一致)——逻辑正确,仅 1 条 P3。optim/lamb_next_right/op_kernel/lamb_next_right.cpp:早退分支仅在schMode==1生效,与 host 下发的GET_TPL_TILING_KEY(1)一致;OpDag作用域与后续if constexpr分支不冲突;1 条 P2(覆盖缺口)。optim/lamb_next_right/tests/ut/op_host/arch35/test_lamb_next_right_tiling.cpp:helper 的 vector/指针生命周期、workspace/blockDim/tilingKey 断言、容量不足与非法 dtype 用例核验无误;1 条 P3。optim/lamb_next_right/tests/ut/op_host/test_lamb_next_right_infershape.cpp:no issues(新用例的std::array/临时gert::Shape生命周期、双 dtype 循环、ASSERT用法均正确)。
总体风险判断
低。变更方向与 infershape 现有语义(滚动输出、全标量归一 (1,))一致,空 Tensor 路径替换掉了原先“把缓冲区容量写成有效长度”的错误做法;剩余主要风险是新增 kernel 早退分支在无 NPU 环境下缺乏正向与精度验证。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论
🧩 本次 Review 已使用自定义 Skill:


Incorrect?
11 days ago restored source branch `fix/lamb-next-right-empty-scalar`
11 days ago Pre merge succeeded (commit_id: a3ece0424619316507bc3f989e1063ea7a3fcfcb)
62 messages are collapsed here。 See more
CANN-robot
6 days ago Comments:
6 days ago Comments:
The MR can not be merged, because of CodeReview discussion not resolved
If you want to solve this problem, you can click here to do it in the FAQs.


6 days ago Resolved final issue
6 days ago Closed associated issue
6 days ago Merged pull request
CANN-robot
6 days ago Comments:
6 days ago Comments:
Pull Request 已合并或已关闭。
If you want to solve this problem, you can click here to do it in the FAQs.


描述
修复 LambNextRight 空 Tensor 用例的静态编译失败。
原实现将
GetRawTilingData()->GetCapacity()(测试环境中为 2 MB)作为有效 tiling data 长度,而编译器为 tiling 保留的空间只有 64 KB,导致静态编译导出 tiling 结果失败。本 PR 通过新增提交恢复初版执行路径,最终差异仅在一个 tiling 源文件中:将
SetDataSize(emptyCap)改为SetDataSize(sizeof(EmptyTilingData));EmptyTilingData使用与schMode=1对应的BroadcastBaseTilingData。空 Tensor 的其余处理和 kernel 均保留初版实现。关联的Issue
#8853
https://gitcode.com/cann/ops-nn/issues/8853
测试
/home/c00947812/Ascend_9.1.0/cann-9.1.0。bash build.sh --pkg --soc=ascend950 --ops=lamb_next_right --vendor_name=lamb_next_right -j8。LambNextRight_L1_empty_highpre_028,DYN/CST、--compare=mixed --dl=1 --xpu-perf,精度、性能、确定性及内存检查均 PASS。DYN:2.271 μs、100%,100%、OK,OK,OK;CST:1.088 μs、100%,100%、OK,OK。静态编译产物opParaSize=1472字节。--expect-impl-source=custom=lamb_next_right_nn确认加载来源。文档更新
无。
类型标签
AI/Agent生成声明