Skip to content

Commit 91701fa

Browse files
authored
Fix onnxfs2_test regression for onnx 1.13 (#307)
Root cause is new "Reduce ops" spec promotes `axes` from attributes to inputs, resulting in onnx test cases having more inputs than expected by these onnx-script tests. This PR updates these onnx-script test functions to match the signature of the updated onnx test cases. However, since onnx test cases are not versioned, I feel tests like this that seemingly want to represent ~~older opset~~ onnx operator with function should not depend on it. Fixes #249 Fixes #298
1 parent 42be235 commit 91701fa

File tree

4 files changed

+11
-29
lines changed

4 files changed

+11
-29
lines changed

azure-pipelines.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ steps:
2525
python -m pip install -r requirements-dev.txt
2626
displayName: 'Install dependencies'
2727

28-
# TODO(#249): Fix tests for onnx 1.13
2928
- script: |
3029
if [ '$(onnx.standard)' == '1' ]
3130
then

onnxscript/test/functions/onnxfns2_test.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ def setUpClass(cls):
1818
reason="onnxruntime does not support that scenario.",
1919
)
2020
def test_onnxfns_reduce_sum_square(self):
21-
default_axes = None
2221
default_keepdims = 1
2322

2423
self.run_onnx_test(
2524
onnxfns2.ReduceSumSquare,
26-
axes=default_axes,
2725
keepdims=default_keepdims,
2826
# default attributes are not supported yet.
2927
skip_test_names=[
@@ -37,12 +35,10 @@ def test_onnxfns_reduce_sum_square(self):
3735
reason="onnxruntime does not support that scenario.",
3836
)
3937
def test_onnxfns_reduce_l1(self):
40-
default_axes = None
4138
default_keepdims = 1
4239

4340
self.run_onnx_test(
4441
onnxfns2.ReduceL1,
45-
axes=default_axes,
4642
keepdims=default_keepdims,
4743
# default attributes are not supported yet.
4844
skip_test_names=[
@@ -56,12 +52,10 @@ def test_onnxfns_reduce_l1(self):
5652
reason="onnxruntime does not support that scenario.",
5753
)
5854
def test_onnxfns_reduce_l2(self):
59-
default_axes = None
6055
default_keepdims = 1
6156

6257
self.run_onnx_test(
6358
onnxfns2.ReduceL2,
64-
axes=default_axes,
6559
keepdims=default_keepdims,
6660
# default attributes are not supported yet.
6761
skip_test_names=[
@@ -75,12 +69,10 @@ def test_onnxfns_reduce_l2(self):
7569
reason="onnxruntime does not support that scenario.",
7670
)
7771
def test_onnxfns_reduce_log_sum(self):
78-
default_axes = None
7972
default_keepdims = 1
8073

8174
self.run_onnx_test(
8275
onnxfns2.ReduceLogSum,
83-
axes=default_axes,
8476
keepdims=default_keepdims,
8577
# default attributes are not supported yet.
8678
skip_test_names=["test_reduce_log_sum_default"],
@@ -91,12 +83,10 @@ def test_onnxfns_reduce_log_sum(self):
9183
reason="onnxruntime does not support that scenario.",
9284
)
9385
def test_onnxfns_reduce_log_sum_exp(self):
94-
default_axes = None
9586
default_keepdims = 1
9687

9788
self.run_onnx_test(
9889
onnxfns2.ReduceLogSumExp,
99-
axes=default_axes,
10090
keepdims=default_keepdims,
10191
# default attributes are not supported yet.
10292
skip_test_names=[

onnxscript/test/models/onnxfns2.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,18 @@
1515

1616

1717
@script()
18-
def ReduceSumSquare(data, axes: List[int], keepdims: int):
19-
# Note: attribute input is promoted to input when calling ReduceSum
20-
t_axes = op.Constant(value_ints=axes)
21-
return op.ReduceSum(data * data, t_axes, keepdims=keepdims)
18+
def ReduceSumSquare(data, axes, keepdims: int):
19+
return op.ReduceSum(data * data, axes, keepdims=keepdims)
2220

2321

2422
@script()
25-
def ReduceL1(data, axes: List[int], keepdims: int):
26-
t_axes = op.Constant(value_ints=axes)
27-
return op.ReduceSum(op.Abs(data), t_axes, keepdims=keepdims)
23+
def ReduceL1(data, axes, keepdims: int):
24+
return op.ReduceSum(op.Abs(data), axes, keepdims=keepdims)
2825

2926

3027
@script()
31-
def ReduceL2(data, axes: List[int], keepdims: int):
32-
t_axes = op.Constant(value_ints=axes)
33-
sum_square = op.ReduceSum(data * data, t_axes, keepdims=keepdims)
28+
def ReduceL2(data, axes, keepdims: int):
29+
sum_square = op.ReduceSum(data * data, axes, keepdims=keepdims)
3430
# We need to cast integral types to floating point before taking square root.
3531
# Unfortunately, there is no way to do this, depending on the input type.
3632
# So, we uniformly cast to double, which is potentially less efficient.
@@ -40,15 +36,13 @@ def ReduceL2(data, axes: List[int], keepdims: int):
4036

4137

4238
@script()
43-
def ReduceLogSum(data, axes: List[int], keepdims: int):
44-
t_axes = op.Constant(value_ints=axes)
45-
return op.Log(op.ReduceSum(data, t_axes, keepdims=keepdims))
39+
def ReduceLogSum(data, axes, keepdims: int):
40+
return op.Log(op.ReduceSum(data, axes, keepdims=keepdims))
4641

4742

4843
@script()
49-
def ReduceLogSumExp(data, axes: List[int], keepdims: int):
50-
t_axes = op.Constant(value_ints=axes)
51-
return op.Log(op.ReduceSum(op.Exp(data), t_axes, keepdims=keepdims))
44+
def ReduceLogSumExp(data, axes, keepdims: int):
45+
return op.Log(op.ReduceSum(op.Exp(data), axes, keepdims=keepdims))
5246

5347

5448
@script()

requirements-onnx.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Requirements for testing with the release version of onnx and onnxruntime
22

3-
# TODO(#249): Fix tests for onnx 1.13
43
numpy==1.22.0
5-
onnx==1.12
4+
onnx==1.13
65
onnxruntime

0 commit comments

Comments
 (0)