PyTorch Dynamo Adds Helper Functions for CPython Size and Index Operations
English summary
A new pull request (#187377) merged into PyTorch adds three helper functions to Dynamo: `long_as_ssize_t`, `number_as_ssize_t`, and `number_index`. These helpers mirror the CPython API functions `PyLong_AsSsize_t`, `PyNumber_AsSsize_t`, and `PyNumber_Index` respectively. The addition improves Dynamo's ability to correctly handle Python size (ssize_t) and index operations during graph tracing, enhancing the compiler's accuracy and compatibility. The change was co-authored by the AI assistant Claude Opus 4.8 (1M context) and approved by a maintainer.
Chinese summary
PyTorch 合并了一个 PR(#187377),为 Dynamo 添加了三个辅助函数:`long_as_ssize_t`、`number_as_ssize_t` 和 `number_index`。这些辅助函数分别对应 CPython API 中的 `PyLong_AsSsize_t`、`PyNumber_AsSsize_t` 和 `PyNumber_Index`。该改动增强了 Dynamo 在图追踪期间正确处理 Python 大小(ssize_t)与索引操作的能力,提升了编译器的准确性与兼容性。此提交由 AI 助手 Claude Opus 4.8 (1M 上下文) 共同编写,并由维护者审核通过。
Key points
PyTorch Dynamo now includes `long_as_ssize_t`, `number_as_ssize_t`, and `number_index` helper functions.
PyTorch Dynamo 现包含 `long_as_ssize_t`、`number_as_ssize_t` 和 `number_index` 辅助函数。
These helpers wrap CPython's `PyLong_AsSsize_t`, `PyNumber_AsSsize_t`, and `PyNumber_Index` APIs.
这些辅助函数封装了 CPython 的 `PyLong_AsSsize_t`、`PyNumber_AsSsize_t` 和 `PyNumber_Index` API。
The improvement enables the Dynamo compiler to more accurately trace operations involving Python size and index semantics.
该改进使 Dynamo 编译器能更准确地追踪涉及 Python 大小和索引语义的操作。
The pull request was co-authored by the AI assistant Claude Opus 4.8 (1M context).
该拉取请求由 AI 助手 Claude Opus 4.8 (1M 上下文) 共同编写。