-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Relax] Add affine_grid operator with PyTorch and ONNX frontend support #18933
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
e27d55d
6823684
54d65d8
53fd534
8b67f12
d6bd6ea
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 |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
| # pylint: disable=invalid-name | ||
| """Default legalization function for image operators.""" | ||
|
|
||
| from tvm import topi | ||
| from tvm import tirx, topi | ||
|
|
||
| from ...block_builder import BlockBuilder | ||
| from ...expr import Call, Expr | ||
|
|
@@ -54,6 +54,22 @@ def _image_grid_sample(bb: BlockBuilder, call: Call) -> Expr: | |
| ) | ||
|
|
||
|
|
||
| @register_legalize("relax.image.affine_grid") | ||
| def _image_affine_grid(bb: BlockBuilder, call: Call) -> Expr: | ||
| for v in call.args[1].values: | ||
| if not isinstance(v, (int, tirx.IntImm)): | ||
| raise ValueError( | ||
| "affine_grid legalization requires static target_shape, " | ||
| f"got symbolic value: {v}" | ||
| ) | ||
| target_shape = [int(v) for v in call.args[1].values] | ||
|
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. Converting
Member
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. int(v) will crash with an unhelpful error on symbolic shapes. Consider adding an explicit check with a clear message, e.g.: |
||
| return bb.call_te( | ||
| topi.image.affine_grid, | ||
| call.args[0], | ||
| target_shape=target_shape, | ||
| ) | ||
|
|
||
|
|
||
| @register_legalize("relax.image.resize3d") | ||
| def _image_resize3d(bb: BlockBuilder, call: Call) -> Expr: | ||
| return bb.call_te( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of treating a single
intorPrimExprforsizeas(size, size)(i.e., square dimensions) is an implicit convention. It would be beneficial to explicitly document this behavior in the docstring for clarity, or add a comment here.