Open
[Bug-Report|缺陷反馈]: `CompileEntry` rejects a valid postponed String shape attribute #3525
KaranocaVeAdd on  Oct 9
KaranocaVe
KaranocaVe
Oct 9 Create

CompileEntry rejects a valid postponed String shape attribute

At cann/pypto@c12abe1d04d9ddaad8970c8cd69ec05c53c519de, a custom operator can declare a String attribute with AttrSpec and use it as a trailing parameter of infer_shape. When the author module enables from __future__ import annotations, Python exposes the parameter annotation as the string "str". CompileEntry passes that unresolved value to _convert_shape_attr, which treats it as an unannotated JSON value. A valid layout="NHWC" therefore raises ValueError before the compile factory or kernel build runs.

The control path with the same input and an eagerly resolved str annotation reaches the factory and returns the compiled-kernel path. The narrow fix resolves infer_shape annotations with typing.get_type_hints before converting shape attributes; unresolved annotations retain the existing fallback.

Evidence was collected on a CPU-only host using the CompileEntry.__call__ path and a mock backend. The focused PyPTO unit file passes after the fix. No PyPTO native rebuild or NPU run was needed for this host-side Python failure.

Validation

Validation

At cann/pypto source commit c12abe1d04d9ddaad8970c8cd69ec05c53c519de, the baseline probe reproduced cannot convert 'NHWC' for infer_shape before the factory was called. With the fix, the same input reached the factory and returned the compiled-kernel path. An eagerly evaluated str annotation also succeeded on the baseline.

The focused test pytest -q python/tests/ut/torch_custom_op_litenpu/test_op_compile_selftest.py passed (8 tests) on Python 3.11.15 with CPU-only PyTorch 2.10.0. It covers AttrSpec("layout", "String") and a postponed str annotation. No native build or NPU run was needed for this host-side annotation failure.

On the current master base, PyPTO pre-commit passed, including Ruff lint, whitespace, EOF, merge-conflict, slice-spacing, and codespell checks. clang-format is not applicable because the patch changes no C/C++ files. Ruff 0.14.14 format-check reports pre-existing formatting in both files, also present on the unmodified baseline; no unrelated reformatting was added, and the new test block has no formatter-only changes.

OAT 1.0.3 reported no invalid license headers or incompatible licenses. It reported two existing copyright-header warnings, one for each changed file; the same warnings were present on the unmodified baseline. git diff --check passed.

关联 PR: https://gitcode.com/cann/pypto/merge_requests/6851

likedislike
KaranocaVeKaranocaVe
Oct 9 Associated pull request
KaranocaVeKaranocaVe
Oct 9 Modify description of issue
Jie YinJie YinCollaborators
Oct 10 Assign make_pto as responsible person
Jie YinJie YinCollaborators
Oct 10 Added label: infrastructure
Jie Yin
Jie YinCollaborators
Oct 10 Comments:

@hid22900163 @make_pto 看一下这个问题

likedislike
Jie Yin
Jie YinCollaborators
Oct 12 Comments:

@Nikita17 看一下这个问题

likedislike
hid22900163hid22900163
Oct 12 Associated pull request
hid22900163
hid22900163
Oct 13 Comments:
宋乐宋乐Collaborators
1 day ago changed custom category from 任务 to 缺陷
宋乐宋乐Collaborators
1 day ago Change title to "[Bug-Report|缺陷反馈]: `CompileEntry` rejects a valid postponed String shape attribute", originally titled "`CompileEntry` rejects a valid postponed String shape attribute".
宋乐宋乐Collaborators
1 day ago Added label: bug-report