已合并
test(meta_registrations): add testcase for torch._meta_registrations.register_meta #42118
木路折创建于 7月19日
test(meta_registrations): add testcase for torch._meta_registrations.register_meta #42118
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 木路折 的贡献)7月19日 关联了issue:【社区任务】7月社区任务第二期-Ascend for PyTorch API 一致性开发(3)
atomgit-bot
7月19日 评论:
7月19日 评论:
变更摘要
本次 PR 新增测试文件 test/test_library_meta_registrations.py,针对 torch._meta_registrations.register_meta 装饰器的核心注册行为补充测试用例,覆盖单算子注册、多算子共享注册函数以及装饰器返回值等关键场景,弥补社区测试覆盖空缺。
主要改动
- 新增
TestLibraryMetaRegistrations测试类:继承自TestCase,包含两个测试方法,分别验证register_meta的单算子注册和多算子批量注册行为。 - 单算子注册测试
test_register_meta_adds_to_meta_table:验证register_meta能将装饰函数正确注册到meta_table,且装饰器返回原函数;测试结束后通过finally块恢复meta_table原状态。 - 多算子注册测试
test_register_meta_supports_op_list:验证传入算子列表时,同一函数可被注册到多个算子的meta_table条目中,装饰器同样返回原函数;测试结束后逐条恢复各算子对应的原始 meta 注册。


ascend-robot
7月19日 评论:
7月19日 评论:
atomgit-bot
7月19日 评论:
7月19日 评论:
此处折叠了124条消息 查看更多
22 天前 添加了label:approved
Jingwei Huang
21 天前 评论:
21 天前 评论:
/lgtm


21 天前 添加了label:lgtm
21 天前 合入了pull request
ascend-robot
21 天前 评论:
21 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#13357 [ commitID:f8437070 ] 已完成


【合入来源】
关联 issue: https://gitcode.com/Ascend/pytorch/issues/2902
pytorch 社区没有针对
torch._meta_registrations.register_meta的独立测试用例,故新增该测试文件,用于验证该 API 的正确性。【修改方案】
一、API 功能说明
torch._meta_registrations.register_meta(op_or_ops)是 PyTorch 内部装饰器,用于将一个函数注册为一个或多个 ATen 算子的 meta 内核,并写入全局meta_table。注册后,调用对应算子的 meta 实现时会执行被装饰的函数。该 API 为 PyTorch 私有接口。二、测试用例完备性说明
PyTorch 官方
test/目录中没有直接调用torch._meta_registrations.register_meta的测试用例,现有测试仅通过elementwise_meta等内部路径间接使用,无法验证装饰器本身的注册行为。本次新增test/test_library_meta_registrations.py,直接验证:meta_table;meta_table原状态,避免跨测试副作用。三、版本适用范围
torch._meta_registrations.register_meta为 PyTorch 内部私有接口,在 PyTorch v2.7.1、v2.9.0、v2.10.0、v2.11.0、v2.12.0、master 各目标分支均存在且函数签名一致,因此本测试用例需提交到上述全部分支。四、NPU 适配
register_meta与meta_table均为纯 Python 层注册逻辑,不涉及任何硬件相关计算、算子调用或设备内存操作,与 CPU/GPU/NPU 完全解耦。昇腾 NPU 环境下无需修改 API 源码,也不需要在测试中导入torch_npu或创建 NPU 张量,可直接复用。【资料变更】
【接口变更】
【功能验证】
test-register-meta-v2.12.0推送到 fork,由 CI 进行运行时验证【CheckList】