You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "OmarAzizi (via GitHub)" <gi...@apache.org> on 2026/08/25 23:52:26 UTC
[PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
OmarAzizi opened a new pull request, #20188:
URL: https://github.com/apache/tvm/pull/20188
TVM's ONNX Squeeze converter accepted axes with non-unit dimensions instead of raising, silently passing tensors through unchanged. This adds a check in the ONNX frontend that raises ValueError when a squeeze axis's statically known size isn't 1, matching the ONNX spec.
Fixes #20185
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on code in PR #20188:
URL: https://github.com/apache/tvm/pull/20188#discussion_r3874846173
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2173,6 +2173,23 @@ def _impl_v13(cls, bb, inputs, attr, params):
axis = tuple([int(x) for x in axis.data.numpy()])
return cls._squeeze(bb, data, axis)
+ @classmethod
+ def _check_squeeze_axes_are_unit_dims(cls, data, axes):
+ """Raise if any axis to be squeezed has a statically known extent other than 1."""
+ rank = _get_known_tensor_rank(data)
+ if rank is None:
+ return
+ ty = data.ty
+ if not (isinstance(ty, relax.TensorType) and isinstance(ty.shape, relax.ShapeExpr)):
+ return
+ for axis in _normalize_constant_axes(list(axes), rank, "Squeeze"):
+ extent = ty.shape.values[axis]
+ if isinstance(extent, tirx.IntImm) and int(extent.value) != 1:
Review Comment:
Thanks for handling symbolic dimensions. Runtime axes still bypass this check though, so invalid non-unit axes remain accepted. Please add a runtime assertion or reject non-constant axes during import, with a regression test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #20188:
URL: https://github.com/apache/tvm/pull/20188#issuecomment-5445132696
LGTM
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "OmarAzizi (via GitHub)" <gi...@apache.org>.
OmarAzizi commented on code in PR #20188:
URL: https://github.com/apache/tvm/pull/20188#discussion_r3875377184
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2173,6 +2173,23 @@ def _impl_v13(cls, bb, inputs, attr, params):
axis = tuple([int(x) for x in axis.data.numpy()])
return cls._squeeze(bb, data, axis)
+ @classmethod
+ def _check_squeeze_axes_are_unit_dims(cls, data, axes):
+ """Raise if any axis to be squeezed has a statically known extent other than 1."""
+ rank = _get_known_tensor_rank(data)
+ if rank is None:
+ return
+ ty = data.ty
+ if not (isinstance(ty, relax.TensorType) and isinstance(ty.shape, relax.ShapeExpr)):
+ return
+ for axis in _normalize_constant_axes(list(axes), rank, "Squeeze"):
+ extent = ty.shape.values[axis]
+ if isinstance(extent, tirx.IntImm) and int(extent.value) != 1:
Review Comment:
You're welcome.
Correct me if I'm worng, but regarding a runtime assertion I don't see `assert_op` used in any frontend and `match_cast` only used to bind symbolic vars, never to assert a value. The usual pattern is to reject an import when a value isn't a compile-time constant. Should I just do that here as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "OmarAzizi (via GitHub)" <gi...@apache.org>.
OmarAzizi commented on code in PR #20188:
URL: https://github.com/apache/tvm/pull/20188#discussion_r3870876674
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2173,6 +2173,23 @@ def _impl_v13(cls, bb, inputs, attr, params):
axis = tuple([int(x) for x in axis.data.numpy()])
return cls._squeeze(bb, data, axis)
+ @classmethod
+ def _check_squeeze_axes_are_unit_dims(cls, data, axes):
+ """Raise if any axis to be squeezed has a statically known extent other than 1."""
+ rank = _get_known_tensor_rank(data)
+ if rank is None:
+ return
+ ty = data.ty
+ if not (isinstance(ty, relax.TensorType) and isinstance(ty.shape, relax.ShapeExpr)):
+ return
+ for axis in _normalize_constant_axes(list(axes), rank, "Squeeze"):
+ extent = ty.shape.values[axis]
+ if isinstance(extent, tirx.IntImm) and int(extent.value) != 1:
Review Comment:
You're right, thank you. I went with the second approach because it's similar to how other parts in the frontend handle these cases.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on code in PR #20188:
URL: https://github.com/apache/tvm/pull/20188#discussion_r3858858559
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2173,6 +2173,23 @@ def _impl_v13(cls, bb, inputs, attr, params):
axis = tuple([int(x) for x in axis.data.numpy()])
return cls._squeeze(bb, data, axis)
+ @classmethod
+ def _check_squeeze_axes_are_unit_dims(cls, data, axes):
+ """Raise if any axis to be squeezed has a statically known extent other than 1."""
+ rank = _get_known_tensor_rank(data)
+ if rank is None:
+ return
+ ty = data.ty
+ if not (isinstance(ty, relax.TensorType) and isinstance(ty.shape, relax.ShapeExpr)):
+ return
+ for axis in _normalize_constant_axes(list(axes), rank, "Squeeze"):
+ extent = ty.shape.values[axis]
+ if isinstance(extent, tirx.IntImm) and int(extent.value) != 1:
Review Comment:
This only rejects statically known non-unit extents, so the same ONNX violation remains for symbolic dimensions. For an input declared as `(N, 3)` with constant axes `[0]`, running with shape `(2, 3)` correctly raises in ONNX Runtime, while TVM imports it and silently returns a `(3,)` view containing the first row. Please add a runtime check that selected extents equal 1, or reject the import when this cannot be proven, and add a symbolic-dimension regression test. The runtime-axes path needs the same validation.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #20188:
URL: https://github.com/apache/tvm/pull/20188#issuecomment-5443720670
you can rebase the main since the lint issue is fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "OmarAzizi (via GitHub)" <gi...@apache.org>.
OmarAzizi commented on code in PR #20188:
URL: https://github.com/apache/tvm/pull/20188#discussion_r3875377184
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2173,6 +2173,23 @@ def _impl_v13(cls, bb, inputs, attr, params):
axis = tuple([int(x) for x in axis.data.numpy()])
return cls._squeeze(bb, data, axis)
+ @classmethod
+ def _check_squeeze_axes_are_unit_dims(cls, data, axes):
+ """Raise if any axis to be squeezed has a statically known extent other than 1."""
+ rank = _get_known_tensor_rank(data)
+ if rank is None:
+ return
+ ty = data.ty
+ if not (isinstance(ty, relax.TensorType) and isinstance(ty.shape, relax.ShapeExpr)):
+ return
+ for axis in _normalize_constant_axes(list(axes), rank, "Squeeze"):
+ extent = ty.shape.values[axis]
+ if isinstance(extent, tirx.IntImm) and int(extent.value) != 1:
Review Comment:
You're welcome.
Correct me if I'm worng, but regarding a runtime assertion I don't see `assert_op` used in any frontend and `match_cast` only used to bind symbolic vars, never to assert a value. The usual pattern is to reject an import when a value isn't a compile-time constant. Should I do that here as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] [Fix][Relax] Raise error on non-unit dim ONNX Squeeze axis [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex merged PR #20188:
URL: https://github.com/apache/tvm/pull/20188
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org