Skip to content

Commit 2b56ce6

Browse files
[Relax][Frontend][Onnx] fix expand bug in onnx frontend (#17309)
* fix expand bug in onnx frontend * add test expand_with_diff_dim
1 parent 6ca0bea commit 2b56ce6

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

python/tvm/relax/frontend/onnx/onnx_frontend.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,8 @@ def _impl_v13(cls, bb, inputs, attr, params):
11351135
# For some reason, onnx allows target shapes to be smaller than input shapes.
11361136
# We need to go correct it.
11371137
data_shape = [dim.value for dim in data.struct_info.shape]
1138+
# Dimensions are right alignment.
1139+
data_shape = [1] * (len(new_shape) - len(data_shape)) + data_shape
11381140
# Fix small target shapes.
11391141
for i, s in enumerate(new_shape):
11401142
if i < len(data_shape) and s < data_shape[i]:

tests/python/relax/test_frontend_onnx.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,12 @@ def _test_expand(name, data, shape, ref_data):
11181118
ref_data = np.tile(data, 4)
11191119
_test_expand("expand_with_dim_unchanged_test", data, shape, ref_data)
11201120

1121+
in_shape = (3, 1)
1122+
shape = (1, 3, 4)
1123+
data = np.random.uniform(size=in_shape).astype(np.float32)
1124+
ref_data = np.tile(data, (1, 1, 4))
1125+
_test_expand("expand_with_diff_dim", data, shape, ref_data)
1126+
11211127

11221128
# TODO(jwfromm) Current approach to dynamic expand is technically not well formed. Reenable once fixed.
11231129
@pytest.mark.skip("Produces ill-formed IR")

0 commit comments

Comments
 (0)