LudovicoYIN commented on code in PR #18878:
URL: https://github.com/apache/tvm/pull/18878#discussion_r2893472786
##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -1974,14 +1974,49 @@ def _impl_v11(cls, bb, inputs, attr, params):
class Tile(OnnxOpConverter):
"""Converts an onnx Tile node into an equivalent Relax expression."""
+ @staticmethod
+ def _tensor_length(expr):
+ shape = expr.struct_info.shape
+ if not isinstance(shape, relax.ShapeExpr):
+ return None
+
+ length = shape.values[0]
+ if not isinstance(length, tir.IntImm):
+ return None
+ return length.value
+
@classmethod
def _impl_v13(cls, bb, inputs, attr, params):
reps = get_constant(inputs[1], params)
if isinstance(reps, relax.Constant):
reps = reps.data.numpy().tolist()
- else:
- raise ValueError("Dynamic reps for Tile are supported yet.")
- return bb.emit_te(topi.tile, inputs[0], reps)
+ return bb.emit_te(topi.tile, inputs[0], reps)
+
+ data = inputs[0]
+ data_ndim = data.struct_info.ndim
+ reps_len = cls._tensor_length(reps)
+ if data_ndim == -1 or reps_len is None:
+ raise ValueError("Dynamic Tile requires known input rank and
repeats length.")
+
+ if reps.struct_info.dtype != "int64":
+ reps = bb.normalize(relax.op.astype(reps, "int64"))
+
+ data_shape = list(data.struct_info.shape.values)
+ data_shape_tensor =
bb.normalize(relax.op.shape_to_tensor(relax.ShapeExpr(data_shape)))
Review Comment:
I updated the implementation to use `relax.op.shape_of(data)` followed by
`shape_to_tensor`, instead of assuming `data.struct_info.shape` is always a
`ShapeExpr`. This makes the dynamic Tile path more robust when only runtime
shape information is available.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]