已合并
fix(npu): 对齐searchsorted接口入参为side=right时的正确语义、补齐相关校验和告警信息 #4934
Margaret_wangrui创建于 5月12日
fix(npu): 对齐searchsorted接口入参为side=right时的正确语义、补齐相关校验和告警信息 #4934
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 Margaret_wangrui 的贡献)5月12日 创建了 pull request,commit cb30f0cb
ascend-robot
5月12日 评论:
5月12日 评论:
ascend-robot
5月12日 评论:
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
/approveor/lgtm- Commenting
/approveimplies 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. 👍


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


5月14日 添加了label:approvedlgtm
ascend-robot
5月14日 评论:
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.


5月14日 合入了pull request
【合入来源】
https://gitcode.com/Ascend/pytorch/issues/1910
涉及用例:
python test_reductions.py -v -k test_bucketization_npu
用例主要测试searchsorted接口不同入参和校验告警等情况,PR用于处理对齐side=right时的正确语义、补齐相关校验和告警信息。
right,未按 PyTorch 语义处理side(side存在时应覆盖right),易导致与 GPU 结果不一致(含边界与 NaN 场景)。searchsorted_pre_check不一致,不利于脚本与单测排障(例如outdtype、sorter、device 等应先抛出 PyTorch 风格RuntimeError)。TORCH_WARN_ONCE提示,行为不透明。【修改方案】
工具头文件(
op_plugin/utils/)SearchsortedSideUtil.h:resolve_searchsorted_effective_right,在 已完成searchsorted_pre_check_npu的前提下,将可选side解析为调用底层算子使用的有效right(避免与校验逻辑重复)。SearchsortedValidateUtil.h:镜像BucketizationUtils.h中searchsorted_pre_check,统一 dtype / shape / device / sorter /out与out_int32等约束及报错文案;提供searchsorted_validate_tensor_out_op、searchsorted_validate_core_no_output(functional、尚无out参数时)、searchsorted_validate_scalar_op等封装,便于 YAML 与内核复用。SearchsortedWarnUtil.h:searchsorted_tensor_is_row_major_contiguous与warn_if_searchsorted_*_noncontiguous,对齐 ATen 侧对非连续 boundary / values / sorter 的告警语义。ACL 内核(
SearchsortedKernelNpu.cpp)在
CheckOut/SearchSortedOpCommand 之前插入 validate → warn →right_eff,保证 acl_op 路径与 op_api 策略一致。op_api 生成配置(
op_plugin_functions.yaml)对
searchsorted.Scalar、searchsorted.Tensor、searchsorted.Tensor_out的gen_opapi增加new_params.right_eff:使用 C++ 逗号表达式(validate, warn, resolve)顺序执行,表达式值为最终bool传入 aclnn;Tensor重载不再仅structured_inherit,显式给出outsize/dtype 与带right_eff的exec,以便在分配out前做与 functional 匹配的校验链。公共头(
op_api_common_base.h)在文件末尾
#include上述三个 Searchsorted 工具头,供生成的 op_api 翻译单元在展开new_params时可见op_plugin::符号(通过npu_cpp_extension.h→op_api_common_base.h引入)。测试(
test/test_base_ops/test_searchsorted.py)补充与 CPU 对比的
side/right、非法side、side与right冲突、sorter dtype/shape/越界、跨 device、outdtype 错误、前置维度不匹配、非连续告警等用例。【资料变更】
不涉及
【接口变更】
不涉及
【功能验证】
【CheckList】