已合并
fix(npu): 对齐searchsorted接口入参为side=right时的正确语义、补齐相关校验和告警信息 #4934
Margaret_wangrui创建于 5月12日
fix(npu): 对齐searchsorted接口入参为side=right时的正确语义、补齐相关校验和告警信息 #4934
已合并
Margaret_wangrui创建于 5月12日
Margaret_wangrui
5月12日

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

https://gitcode.com/Ascend/pytorch/issues/1910

涉及用例:
python test_reductions.py -v -k test_bucketization_npu
用例主要测试searchsorted接口不同入参和校验告警等情况,PR用于处理对齐side=right时的正确语义、补齐相关校验和告警信息。

  • 此前 NPU 侧多直接透传 right,未按 PyTorch 语义处理 sideside 存在时应覆盖 right),易导致与 GPU 结果不一致(含边界与 NaN 场景)。
  • 设备编排与 CANN / aclnn 侧报错信息与 ATen searchsorted_pre_check 不一致,不利于脚本与单测排障(例如 out dtype、sorter、device 等应先抛出 PyTorch 风格 RuntimeError)。
  • 非连续输入缺少与 GPU 类似的 TORCH_WARN_ONCE 提示,行为不透明。

【修改方案】

请描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列
如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)

  1. 工具头文件(op_plugin/utils/

    • SearchsortedSideUtil.hresolve_searchsorted_effective_right,在 已完成 searchsorted_pre_check_npu 的前提下,将可选 side 解析为调用底层算子使用的有效 right(避免与校验逻辑重复)。
    • SearchsortedValidateUtil.h:镜像 BucketizationUtils.hsearchsorted_pre_check,统一 dtype / shape / device / sorter / outout_int32 等约束及报错文案;提供 searchsorted_validate_tensor_out_opsearchsorted_validate_core_no_output(functional、尚无 out 参数时)、searchsorted_validate_scalar_op 等封装,便于 YAML 与内核复用。
    • SearchsortedWarnUtil.hsearchsorted_tensor_is_row_major_contiguouswarn_if_searchsorted_*_noncontiguous,对齐 ATen 侧对非连续 boundary / values / sorter 的告警语义。
  2. ACL 内核(SearchsortedKernelNpu.cpp
    CheckOut / SearchSorted OpCommand 之前插入 validate → warn → right_eff,保证 acl_op 路径与 op_api 策略一致。

  3. op_api 生成配置(op_plugin_functions.yaml
    searchsorted.Scalarsearchsorted.Tensorsearchsorted.Tensor_outgen_opapi 增加 new_params.right_eff:使用 C++ 逗号表达式 (validate, warn, resolve) 顺序执行,表达式值为最终 bool 传入 aclnn;Tensor 重载不再仅 structured_inherit,显式给出 out size/dtype 与带 right_effexec,以便在分配 out 前做与 functional 匹配的校验链。

  4. 公共头(op_api_common_base.h
    在文件末尾 #include 上述三个 Searchsorted 工具头,供生成的 op_api 翻译单元在展开 new_params 时可见 op_plugin:: 符号(通过 npu_cpp_extension.hop_api_common_base.h 引入)。

  5. 测试(test/test_base_ops/test_searchsorted.py
    补充与 CPU 对比的 side / right、非法 sidesideright 冲突、sorter dtype/shape/越界、跨 device、out dtype 错误、前置维度不匹配、非连续告警等用例。

【资料变更】

请确认是否涉及资料变更。如涉及,需要在PR中体现,并简要说明修改内容。如不涉及,需填写“不涉及”

不涉及

【接口变更】

请确认是否涉及跨代码仓或者客户面可见的接口变更。如涉及,需要详细说明接口以及对应的变更内容,同时需要在资料中体现。如不涉及,需填写“不涉及”

不涉及

【功能验证】

说明测试场景,测试方法。如果本次测试方式与常规单元测试不同,请详细说明您的测试步骤
新增/变更内容是否已新增/适配UT测试用例看护,并补充测试自验证截图
自验结果
image.png

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Margaret_wangrui 的贡献)
Margaret_wangruiMargaret_wangrui
5月12日 创建了 pull request,commit cb30f0cb
ascend-robot
ascend-robot成员
5月12日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/op-plugin sunyu-xuan, wangmin0104 (2/2) wangmin0104 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

Margaret_wangrui, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
Margaret_wangruiMargaret_wangrui
5月12日 修改了pull request 的描述
ascend-robotascend-robot成员
5月12日 添加了label:ascend-cla/yes
此处折叠了126条消息 查看更多
atomgit-bot
atomgit-bot
5月14日 评论:

代码审查

✅ 未发现问题

likedislike
wangmin0104
wangmin0104成员
5月14日 评论:

/approve

likedislike
ascend-robotascend-robot成员
5月14日 添加了label:approvedlgtm
ascend-robot
ascend-robot成员
5月14日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: wangmin0104.
Reviewers who wrote a comment of /lgtm are: wangmin0104, sunyu-xuan.

likedislike
ascend-robotascend-robot成员
5月14日 合入了pull request