Skip to content

[Bug]: NPU 环境下 Dynamo 处理零参数 id() 时抛出 IndexError 而非 TypeError,与 PyTorch 原生行为不一致,影响设备测试解耦 #163

Description

@taochong123456

环境信息

环境问题如下

### Environment
| Item | Version |
|------|---------|
| CANN | 9.1.0 |
| PyTorch | 2.14.0+gitee7bc39 |
| torch_npu | 2.14.0+gitee7bc39 |

社区用例:
https://github.com/pytorch/pytorch/blob/main/test/dynamo/test_id.py

Image

报错信息

       ^^^^^^^^^^^^^^^^^^^^^^^^^

File "/opt/npu-env/pytorch/torch/_dynamo/variables/builtin.py", line 1388, in builtin_dispatch
rv = handler(tx, args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/npu-env/pytorch/torch/_dynamo/variables/builtin.py", line 1262, in call_self_handler
return self_handler(tx, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/miniconda/envs/npu/lib/python3.12/site-packages/torch_npu/utils/_dynamo.py", line 290, in _wrap_call_id
args[0], torch._dynamo.variables.streams.EventVariable
~~~~^^^
IndexError: tuple index out of range

from user code:
File "/workspace/dcp-work-dcp-tc/pytorch/test/dynamo/test_id.py", line 453, in wrapper
return fn(x)
^^^^^
File "/workspace/dcp-work-dcp-tc/pytorch/test/dynamo/test_id.py", line 443, in fn0
return id()
^^^^

Set TORCHDYNAMO_VERBOSE=1 for the internal stack trace (please do this especially if you're reporting a bug to PyTorch). For even more developer context, set TORCH_LOGS="+dynamo"

To execute this test, run the following from the base repo dir:
python test/dynamo/test_id.py IdTests.test_id_wrong_arg_count

This message can be suppressed by setting PYTORCH_PRINT_REPRO_ON_FAILURE=0



## 期望
和pytorch抛的异常一致

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions