Open
[Bug-Report|缺陷反馈]: `CompileEntry` rejects a valid postponed String shape attribute #3525
KaranocaVeAdd on Oct 9
Oct 9 Associated pull request
Oct 9 Modify description of issue
Oct 10 Assign make_pto as responsible person
Oct 10 Added label: infrastructure
Oct 12 Associated pull request
hid22900163
Oct 13 Comments:
Oct 13 Comments:
1 day ago changed custom category from 任务 to 缺陷
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".
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".
1 day ago Added label: bug-report


CompileEntryrejects a valid postponed String shape attributeAt
cann/pypto@c12abe1d04d9ddaad8970c8cd69ec05c53c519de, a custom operator can declare aStringattribute withAttrSpecand use it as a trailing parameter ofinfer_shape. When the author module enablesfrom __future__ import annotations, Python exposes the parameter annotation as the string"str".CompileEntrypasses that unresolved value to_convert_shape_attr, which treats it as an unannotated JSON value. A validlayout="NHWC"therefore raisesValueErrorbefore the compile factory or kernel build runs.The control path with the same input and an eagerly resolved
strannotation reaches the factory and returns the compiled-kernel path. The narrow fix resolvesinfer_shapeannotations withtyping.get_type_hintsbefore 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/pyptosource commitc12abe1d04d9ddaad8970c8cd69ec05c53c519de, the baseline probe reproducedcannot convert 'NHWC' for infer_shapebefore the factory was called. With the fix, the same input reached the factory and returned the compiled-kernel path. An eagerly evaluatedstrannotation also succeeded on the baseline.The focused test
pytest -q python/tests/ut/torch_custom_op_litenpu/test_op_compile_selftest.pypassed (8 tests) on Python 3.11.15 with CPU-only PyTorch 2.10.0. It coversAttrSpec("layout", "String")and a postponedstrannotation. No native build or NPU run was needed for this host-side annotation failure.On the current
masterbase, PyPTO pre-commit passed, including Ruff lint, whitespace, EOF, merge-conflict, slice-spacing, and codespell checks.clang-formatis 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 --checkpassed.关联 PR: https://gitcode.com/cann/pypto/merge_requests/6851