已关闭
【API一致性任务】 API一致性:torch.testing._comparison.TensorLikePair NPU 适配 #3602
jerry lee创建于 7月31日关闭于 8月15日
7月31日 关联了pull request:test(npu): add TensorLikePair NPU validation
7月31日 添加了label:bot-triaged
TorchNPU-Bot
7月31日 评论:
7月31日 评论:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


7月31日 关联了pull request:test(npu): add TensorLikePair NPU validation
此处折叠了12条事件消息 查看更多
8月15日 添加了label:event: api-consistency
TorchNPU-Bot
8月15日 评论:
8月15日 评论:
检测到社区任务相关 issue,自动添加标签:event: api-consistency


8月15日 关闭了 issue
8月15日 添加了label:resolved
API 一致性:torch.testing._comparison.TensorLikePair
API 功能与上游覆盖
torch.testing._comparison.TensorLikePair.compare()用于校验张量值、shape、layout、stride、device 和 dtype,失败时抛出ErrorMeta。社区test/test_testing.py的相关测试仅 mock 构造或比较阶段的异常传播,未直接执行 NPU 张量的真实比较。维护分支的调用路径为
TestAssertClose.test_tensor_like_pair_npu->TensorLikePair(actual, expected)->TensorLikePair.compare();master 为TestTesting.test_tensor_like_pair->TensorLikePair(actual, expected)->TensorLikePair.compare()。适配方案与必要性
测试现在覆盖默认 NPU 比较、
check_device=False、check_dtype=False、check_layout=False、check_stride=True、非默认rtol/atol和equal_nan=True,并验证 dtype、layout、stride、shape、数值失配均抛出ErrorMeta。若缺少这些断言,比较选项与元数据检查的 NPU 行为没有直接回归保护。v2.7.1、v2.11.0、v2.12.0 均先将已有
test_upstream/test/test_testing.py.patch应用于对应官方 PyTorch tag,在结果上扩展目标用例后使用git diff --unified=1生成完整 patch,保留历史有效 hunks。三份 patch 分别在 v2.7.1e2d141dbde55c2a4370fac5165b0561b6af4798b、v2.11.070d99e998b4955e0049d13a98d77ae1b14db1f45、v2.12.00d62256a2b23365f8e1604297eb23a6545102aa8通过git apply --check。master 已同步至当前源分支,只修改 torch-npu 自有测试。资料检查
torch.testing._comparison.TensorLikePair属于 PyTorch 内部/私有接口,不属于面向用户的 native API 支持清单范围,因此无需更新支持文档。各版本 PR 概括
test_upstream/test/test_testing.py.patch并保留历史有效 hunks。test_upstream/test/test_testing.py.patch并保留历史有效 hunks。test_upstream/test/test_testing.py.patch并保留历史有效 hunks。test/npu/test_testing.py扩展 torch-npu 自有直接用例。功能验证
v2.7.1
命令:
source /usr/local/Ascend/cann-9.0.0/set_env.sh export PATH=/usr/local/python3.12.13/bin:$PATH python3.12 ./tensorlike_v271_standalone.py环境:
torch 2.7.1,torch_npu 2.7.1.post8,npu_available=True,设备Ascend910B4。输出:
结论:官方 test/test_testing.py 在目标方法执行前因与本 API 无关的空 @ops 列表注册失败;以与修复后目标方法逐项一致的独立执行完成 1 项断言验证。CANN 对齐告警不影响断言。
v2.11.0
命令:
source /usr/local/Ascend/cann-9.0.0/set_env.sh export PATH=/usr/local/python3.12.13/bin:$PATH python3.12 ./pytorch-official-2.11.0/test/test_testing.py TestAssertClose.test_tensor_like_pair_npu环境:
torch 2.11.0,torch_npu 2.11.0,npu_available=True,设备Ascend910B4。输出:
结论:目标用例通过,CANN 对齐告警不影响 TensorLikePair 断言。
v2.12.0
命令:
source /usr/local/Ascend/cann-9.0.0/set_env.sh export PATH=/usr/local/python3.12.13/bin:$PATH python3.12 ./pytorch-official-2.12.0/test/test_testing.py TestAssertClose.test_tensor_like_pair_npu环境:
torch 2.12.0+cu130,torch_npu 2.12.0,npu_available=True,设备Ascend910B4。输出:
结论:目标用例通过;CuTeDSL 可选依赖和 CANN 对齐告警不影响 TensorLikePair 断言。
master
命令:
source /usr/local/Ascend/cann-9.0.0/set_env.sh export PATH=/usr/local/python3.12.13/bin:$PATH python3.12 ./test_testing_master_fixed.py TestTesting.test_tensor_like_pair环境:
torch 2.12.0+cu130,torch_npu 2.12.0,npu_available=True,设备Ascend910B4。输出:
结论:torch-npu 自有目标用例通过;CuTeDSL 可选依赖和 CANN 对齐告警不影响断言。