-
Notifications
You must be signed in to change notification settings - Fork 67
feat: deprecate pl.Tensor[..., pl.DN] + strict TensorViewCanonical (RFC #1300 §2.4 + supplementary 1) #1347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
83ae26b
e131355
c317320
d884712
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| """Type annotation resolution for IR parsing.""" | ||
|
|
||
| import ast | ||
| import warnings | ||
| from collections.abc import Callable, Sequence | ||
| from typing import TYPE_CHECKING, Any, cast | ||
|
|
||
|
|
@@ -441,6 +442,7 @@ def _resolve_subscript_type(self, subscript_node: ast.Subscript) -> ir.Type: # | |
| tensor_view = self._resolve_tensorview(third) | ||
| return tensor_ctor(shape, dtype, None, tensor_view) | ||
| layout = self.resolve_layout(third) | ||
| self._warn_on_user_facing_dn_layout(layout, type_name) | ||
| tensor_view = ir.TensorView([], layout) | ||
| return tensor_ctor(shape, dtype, None, tensor_view) | ||
|
|
||
|
|
@@ -450,6 +452,7 @@ def _resolve_subscript_type(self, subscript_node: ast.Subscript) -> ir.Type: # | |
| tensor_view = self._resolve_tensorview(third) | ||
| else: | ||
| layout = self.resolve_layout(third) | ||
| self._warn_on_user_facing_dn_layout(layout, type_name) | ||
| tensor_view = ir.TensorView([], layout) | ||
| memref_node = slice_value.elts[3] | ||
| if not self._is_memref_node(memref_node): | ||
|
|
@@ -986,6 +989,35 @@ def resolve_dtype(self, dtype_node: ast.expr) -> DataType: | |
| hint="Use pl.FP32, pl.INT32, or other supported dtype constants", | ||
| ) | ||
|
|
||
| def _warn_on_user_facing_dn_layout(self, layout: "ir.TensorLayout", type_name: str) -> None: | ||
| """Emit a ``DeprecationWarning`` when the user writes the layout-only DN | ||
| shorthand on a tensor type annotation (RFC #1300 supplementary 1). | ||
|
|
||
| Suppressed for ``ir.TensorLayout.ND`` (default, no-op marker) and for | ||
| explicit ``pl.TensorView(stride=..., layout=DN)`` forms (which carry | ||
| their own stride and don't rely on the shorthand's implicit coordinate | ||
| flip). Tile-side layouts are never seen here — Tile annotations route | ||
| through ``_resolve_tile_annotation_args``. | ||
| """ | ||
| if layout != ir.TensorLayout.DN: | ||
| return | ||
| warnings.warn( | ||
| f"pl.{type_name}[..., pl.DN] is deprecated (RFC #1300 supplementary 1). " | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The warning message uses |
||
| "Writing the DN layout-only shorthand requires the user to mentally hold " | ||
| "two coordinate systems at once (IR-logical post-view vs. runtime " | ||
| "row-major), which is exactly the ambiguity RFC #1300 aims to eliminate. " | ||
| "Three migration patterns cover every DN scenario without writing pl.DN:\n" | ||
| " * source tensor shape, no layout marker: pl.Tensor[[N, K], pl.FP32]\n" | ||
| " * derive DN at use site: xt = pl.transpose(x, -2, -1) # ND -> DN\n" | ||
| " * inherit DN through slice/reshape from a DN-producing op\n" | ||
| "If you must express a strided-DN view (e.g. canonical pretty-print " | ||
| "round-trip), use pl.TensorView(stride=[...], layout=pl.TensorLayout.DN) " | ||
| "instead — it forces explicit stride and avoids the implicit-coord-flip " | ||
| "hazard.", | ||
| DeprecationWarning, | ||
| stacklevel=4, | ||
| ) | ||
|
|
||
| def resolve_layout(self, layout_node: ast.expr) -> "ir.TensorLayout": | ||
| """Resolve layout annotation to ir.TensorLayout. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.