This is an automated email from the ASF dual-hosted git repository.
syfeng pushed a commit to branch unity
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/unity by this push:
new 1c90ca7c7c [Unity][Frontends][Onnx] fixup resize2d dynamic input
support (#15692)
1c90ca7c7c is described below
commit 1c90ca7c7c9874a7feb79d34cc1d197296bbea5e
Author: leiwen83 <[email protected]>
AuthorDate: Mon Sep 11 14:26:30 2023 +0800
[Unity][Frontends][Onnx] fixup resize2d dynamic input support (#15692)
If Resize take shape like input's shape is dynamic one, and we use
scales sampling mode, then it would report error like below, for
currently relax onnx frontend still deem all shape in input a const
value. Then the dynamic tir.Var would has no value to extract out.
AttributeError: <class 'tvm.tir.expr.SizeVar'> has no attribute value
Use tir expr to get calculation result for scaled size.
Signed-off-by: Lei Wen <[email protected]>
Co-authored-by: Lei Wen <[email protected]>
---
python/tvm/relax/frontend/onnx/onnx_frontend.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/python/tvm/relax/frontend/onnx/onnx_frontend.py
b/python/tvm/relax/frontend/onnx/onnx_frontend.py
index af7decbc13..fbd478ee5a 100644
--- a/python/tvm/relax/frontend/onnx/onnx_frontend.py
+++ b/python/tvm/relax/frontend/onnx/onnx_frontend.py
@@ -44,6 +44,7 @@ import tvm
from tvm import relax, tir, topi
from tvm.ir import IRModule
from tvm.ir.supply import NameSupply
+from tvm.tir.generic import cast
def get_type(elem_type: Union[str, int]) -> str:
@@ -1302,8 +1303,11 @@ class Resize(OnnxOpConverter):
if scales is not None:
assert isinstance(scales, relax.Constant), "Only constant scales
currently supported."
scales = scales.data.numpy()
- sizes_shape = [dim.value for dim in x.struct_info.shape]
- sizes = (sizes_shape * scales)[2:].astype("int64").tolist()
+ sizes = []
+
+ for i, dim in enumerate(x.struct_info.shape):
+ sizes.append(cast(scales[i] * dim, "int64"))
+ sizes = sizes[2:]
else:
assert isinstance(
sizes, relax.Constant