已开启
【测试用例解耦(9)】test_fake_quantize.py 在 Ascend NPU 环境运行 2 个用例失败(test_forward / test_backward,经定位为社区上游用例缺陷) #461
olpk创建于 12 天前
12 天前 添加了label:triage-review
TorchNPU-Bot
12 天前 评论:
12 天前 评论:
issue待分派,添加triage-review标签


12 天前 修改了issue 的描述
12 天前 添加了label:bot-triaged;删除了label:triage-review
TorchNPU-Bot
12 天前 评论:
12 天前 评论:
检测到当前 issue 已关联 PR,自动添加标签:bot-triaged


环境信息
🐛 问题描述
问题现象
目标测试文件:
test/quantization/core/experimental/test_fake_quantize.py(TestFakeQuantize类,共 4 个用例)。在 Ascend NPU 软件栈环境下运行该社区原生测试文件,结果为 2 passed / 2 failed:
test_fake_calc_qparams、test_forward_exceptiontest_forward、test_backwardA2/A3(Ascend 910B3 + CANN 9.1.0 + torch 2.9.0 / torch_npu 2.9.0.post6)与 A5(Ascend 950PR + CANN 9.0.0 + torch 2.12.0 / torch_npu 2.12.0.post2)两个平台结果逐字一致(同为 2 passed / 2 failed),
pytest --collect-only均为4 tests collected。该文件无任何硬件耦合:未使用
@onlyCUDA/@deviceCountAtLeast等设备装饰器,未写死cuda设备字符串,未调用.cuda()或torch.cuda.*,未使用 pytestis_cuda参数,未接收device参数,Tensor 默认创建在 CPU 上,用例数值计算全部发生在 CPU。按社区分类框架属于「无设备参数化,Tensor 默认在 CPU」类型(HardwareClassification.GENERIC)。复现步骤
git clone https://github.com/pytorch/pytorch.git cd pytorch/test/quantization/core/experimental # 全量运行(与社区原文件运行方式一致) python test_fake_quantize.py -v # 用例收集 python -m pytest test_fake_quantize.py --collect-only -q环境说明:910 环境的 torch 2.9.0 已移除
torch.ao.quantization.experimental模块,验证时以社区 main 分支同名模块补齐后运行,测试文件本身未做任何修改。实际结果
(1)test_forward —— TypeError: APoTFakeQuantize.forward() takes 2 positional arguments but 3 were given
(2)test_backward —— TypeError: only integer tensors of a single element can be converted to an index
说明:上述报错堆栈全部位于 unittest / torch 内部,不含任何 torch_npu 栈帧。
定位结论(该失败非 NPU 平台问题)
test_forward调用forward(X, False)(2 个位置参数),而社区实现为forward(self, X)(仅 1 个位置参数),API 签名不匹配,属纯 Python 层错误fake_quantize_function.py实现逐字一致,测试与实现的 API 不匹配在社区 main 分支上即存在tools/testing/discover_tests.pyblocklist 排除quantization目录、test/test_quantization.py聚合入口未 import 本文件)补充:
test_forward_exception之所以「通过」,是因为其assertRaises(Exception)恰好捕获了test_forward中的同一个 TypeError。期望结果
社区原生测试文件在 NPU 软件栈环境下运行结果应与 CPU/CUDA 环境一致,即 4 个用例全部通过。
关联信息
hw_classification = HardwareClassification.GENERIC元数据标签):pytorch/pytorch#193013