Skip to content

Commit 2924ec7

Browse files
Set UT to use nightly for opset 13 testing
Signed-off-by: Tom Wildenhain <[email protected]>
1 parent ac2f675 commit 2924ec7

File tree

7 files changed

+38
-37
lines changed

7 files changed

+38
-37
lines changed

ci_build/azure_pipelines/templates/unit_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Run unit test
22

33
parameters:
4-
onnx_opsets: ['12', '11', '10', '9', '8', '7']
4+
onnx_opsets: ['13', '12', '11', '10', '9', '8', '7']
55

66
steps:
77
- ${{ each onnx_opset in parameters.onnx_opsets }}:

ci_build/azure_pipelines/unit_test-matrix.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ stages:
99
python_versions: [3.6']
1010
tf_versions: ['1.13.1', '1.12.3']
1111
onnx_opsets: ['']
12+
onnx_backends: {onnxruntime: ['nightly']}
1213
job:
1314
steps:
1415
- template: 'unit_test.yml'
@@ -20,6 +21,7 @@ stages:
2021
python_versions: ['3.7', '3.6']
2122
tf_versions: ['1.14.0']
2223
onnx_opsets: ['']
24+
onnx_backends: {onnxruntime: ['nightly']}
2325
job:
2426
steps:
2527
- template: 'unit_test.yml'
@@ -31,6 +33,7 @@ stages:
3133
python_versions: ['3.7']
3234
tf_versions: ['1.15.2','2.1.0']
3335
onnx_opsets: ['']
36+
onnx_backends: {onnxruntime: ['nightly']}
3437
job:
3538
steps:
3639
- template: 'unit_test.yml'

ci_build/azure_pipelines/unit_test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ stages:
88
python_versions: ['3.8']
99
tf_versions: ['2.4.0']
1010
onnx_opsets: ['']
11+
onnx_backends: {onnxruntime: ['nightly']}
1112
job:
1213
steps:
1314
- template: 'unit_test.yml'
@@ -18,6 +19,7 @@ stages:
1819
python_versions: ['3.7']
1920
tf_versions: ['1.14.0','1.15.2','2.2.0','2.3.0']
2021
onnx_opsets: ['']
22+
onnx_backends: {onnxruntime: ['nightly']}
2123
job:
2224
steps:
2325
- template: 'unit_test.yml'
@@ -28,6 +30,7 @@ stages:
2830
python_versions: [3.6']
2931
tf_versions: ['1.12.3']
3032
onnx_opsets: ['']
33+
onnx_backends: {onnxruntime: ['nightly']}
3134
job:
3235
steps:
3336
- template: 'unit_test.yml'
@@ -38,6 +41,7 @@ stages:
3841
platforms: ['windows']
3942
tf_versions: ['1.14.0']
4043
onnx_opsets: ['']
44+
onnx_backends: {onnxruntime: ['nightly']}
4145
job:
4246
steps:
4347
- template: 'unit_test.yml'

tf2onnx/onnx_opset/controlflow.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -286,24 +286,17 @@ class TensorListGetItem:
286286
def version_7(cls, ctx, node, **kwargs):
287287
ctx.ta_reads.append(node.input[0])
288288
node.type = "Gather"
289-
ctx.replace_inputs(node, [node.input[0], node.input[1]])
290-
ctx.insert_new_node_on_input(node, "Unsqueeze", node.input[1], name=node.child_name(), axes=[0])
291-
ctx.insert_new_node_on_output("Squeeze", node.output[0], name=node.child_name(), axes=[0])
292-
293-
@classmethod
294-
def version_13(cls, ctx, node, **kwargs):
295-
ctx.ta_reads.append(node.input[0])
296-
node.type = "Gather"
297-
ctx.replace_inputs(node, [node.input[0], node.input[1]])
298-
299289
g = GraphBuilder(ctx)
300290

301291
usq_node = g.make_unsqueeze({"axes": [0], 'data': node.input[1]}, name=node.child_name(), return_node=True)
302-
ctx.insert_node_on_output(usq_node)
303-
292+
ctx.replace_inputs(node, [node.input[0], usq_node.output[0]])
304293
sq_node = g.make_squeeze({"axes": [0], 'data': node.output[0]}, name=node.child_name(), return_node=True)
305294
ctx.insert_node_on_output(sq_node)
306295

296+
@classmethod
297+
def version_13(cls, ctx, node, **kwargs):
298+
cls.version_7(ctx, node, **kwargs)
299+
307300

308301
@tf_op(["TensorListLength"])
309302
class TensorListLength:

tf2onnx/onnx_opset/nn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def any_version(cls, opset, ctx, node, **kwargs):
353353
if len(input_shape) == spatial + 1:
354354
gb = GraphBuilder(ctx)
355355
usq_node = gb.make_unsqueeze({"axes": [0], 'data': node.input[0]}, return_node=True)
356-
ctx.insert_node_on_output(usq_node, node.input[0])
356+
ctx.replace_inputs(node, [usq_node.output[0]] + node.input[1:])
357357

358358
# Set padding.
359359
add_padding(

tf2onnx/onnx_opset/tensor.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,8 @@ def version_1(cls, ctx, node, **kwargs):
11921192
# for each output we need to squeeze axis
11931193
for n in node.output:
11941194
op_name = utils.make_name(node.name)
1195-
squeeze_node = ctx.insert_new_node_on_output("Squeeze", n, name=op_name, axes=[axis])
1195+
squeeze_node = GraphBuilder(ctx).make_squeeze({'data': n, 'axes': [axis]}, name=op_name, return_node=True)
1196+
ctx.insert_node_on_output(squeeze_node, n)
11961197
ctx.copy_shape(n, squeeze_node.output[0])
11971198
ctx.copy_dtype(n, squeeze_node.output[0])
11981199

@@ -1256,8 +1257,8 @@ def any_version_after9(cls, opset, ctx, node, **kwargs):
12561257
depth = GraphBuilder(ctx).make_unsqueeze({'data': node.input[1], 'axes': [0]})
12571258
on_value = node.input[2]
12581259
off_value = node.input[3]
1259-
on_value = ctx.make_node("Unsqueeze", [on_value], attr={"axes": [0]}).output[0]
1260-
off_value = ctx.make_node("Unsqueeze", [off_value], attr={"axes": [0]}).output[0]
1260+
on_value = GraphBuilder(ctx).make_unsqueeze({'data': on_value, 'axes': [0]})
1261+
off_value = GraphBuilder(ctx).make_unsqueeze({'data': off_value, 'axes': [0]})
12611262
off_on_value = ctx.make_node("Concat", [off_value, on_value], attr={"axis": 0}).output[0]
12621263

12631264
indices = node.input[0]
@@ -1637,8 +1638,9 @@ def any_version(cls, opset, ctx, node, **kwargs):
16371638
# add valid_outputs count
16381639
output_idx = 2 if node.type in ["NonMaxSuppressionV5"] else 1
16391640
shape_op = ctx.make_node("Shape", inputs=[nms_output.output[0]])
1640-
reduce_op = ctx.make_node("ReduceSum", inputs=shape_op.output, attr={"axes": [0], "keepdims": 0})
1641-
ctx.make_node("Cast", inputs=[reduce_op.output[0]], attr={"to": onnx_pb.TensorProto.INT32},
1641+
reduce_op = GraphBuilder(ctx).make_reduce_sum(
1642+
{"data": shape_op.output[0], "axes": [0], "keepdims": 0, "noop_with_empty_axes": 1})
1643+
ctx.make_node("Cast", inputs=[reduce_op], attr={"to": onnx_pb.TensorProto.INT32},
16421644
outputs=[node.output[output_idx]], dtypes=dtypes[output_idx], shapes=shapes[output_idx],
16431645
op_name_scope=node.name)
16441646

@@ -2385,15 +2387,17 @@ def normalize():
23852387
pad_length_2 = body_graph.make_node('Concat', [zeo, pad_length.output[0]], attr={'axis': 0})
23862388
padded_range = body_graph.make_node('Pad', [sliced_range.output[0], pad_length_2.output[0]])
23872389
# opset == 11, no need to change unsqueeze
2388-
unsqueezed_range = body_graph.make_node('Unsqueeze', [padded_range.output[0]], attr={'axes': [1]})
2390+
unsqueezed_range = GraphBuilder(body_graph).make_unsqueeze(
2391+
{'data': padded_range.output[0], 'axes': [1]}, return_node=True)
23892392
half_shape_x = body_graph.make_node('Slice',
23902393
[new_shape.output[0], zeo, minus_two])
23912394
shape_range = body_graph.make_node('Shape', [unsqueezed_range.output[0]])
23922395
full_shape = body_graph.make_node('Concat', [half_shape_x.output[0], shape_range.output[0]], attr={'axis': 0})
23932396
expanded_range = body_graph.make_node('Expand', [unsqueezed_range.output[0], full_shape.output[0]])
23942397
gathered_input = body_graph.make_node('GatherElements', [processed_input.output[0], expanded_range.output[0]],
23952398
attr={'axis': -1})
2396-
squeezed_input = body_graph.make_node('Squeeze', [gathered_input.output[0]], attr={'axes': [-1]})
2399+
squeezed_input = GraphBuilder(body_graph).make_squeeze(
2400+
{'data': gathered_input.output[0], 'axes': [-1]}, return_node=True)
23972401
left_width = body_graph.make_node('Sub', [new_width.output[0], abs_k.output[0]])
23982402
dims = body_graph.make_node('Concat', [left_width.output[0], new_depth.output[0]], attr={'axis': 0})
23992403
valid_dim = body_graph.make_node('ReduceMin', [dims.output[0]])
@@ -2505,8 +2509,8 @@ def normalize():
25052509
raw_output_shape + [-1])
25062510
squeeze_sliced_graph = ctx.create_new_graph_with_same_config()
25072511
squeeze_sliced_graph.parent_graph = ctx
2508-
squeeze_sliced = squeeze_sliced_graph.make_node('Squeeze', [final_output_right_sliced.output[0]],
2509-
attr={'axes': [-2]})
2512+
squeeze_sliced = GraphBuilder(squeeze_sliced_graph).make_squeeze(
2513+
{'data': final_output_right_sliced.output[0], 'axes': [-2]}, return_node=True)
25102514
squeeze_sliced_graph.add_graph_output(squeeze_sliced.output[0], ctx.get_dtype(node.input[0]), raw_output_shape)
25112515
shapes = node.output_shapes
25122516
dtypes = node.output_dtypes
@@ -2680,14 +2684,14 @@ def version_13(cls, ctx, node, **kwargs):
26802684
@tf_op(["MatrixDiag", "MatrixDiagV2", "MatrixDiagV3"])
26812685
class MatrixDiag:
26822686
@classmethod
2683-
def any_version(cls, opset, ctx, node, **kwargs):
2687+
def version_12(cls, ctx, node, **kwargs):
26842688
# Assemble MatrixDiagV3 by ReverseSequence
26852689
argc = len(node.input)
26862690

2687-
if opset >= 13:
2688-
squeeze_axes0 = ctx.make_const(utils.make_name("const_axes"), np.array([0], dtype=np.int64))
2689-
squeeze_axes_1 = ctx.make_const(utils.make_name("const_axes"), np.array([-1], dtype=np.int64))
2690-
squeeze_axes_2 = ctx.make_const(utils.make_name("const_axes"), np.array([-2], dtype=np.int64))
2691+
if ctx.opset >= 13:
2692+
squeeze_axes0 = ctx.make_const(utils.make_name("const_axes"), np.array([0], dtype=np.int64)).output[0]
2693+
squeeze_axes_1 = ctx.make_const(utils.make_name("const_axes"), np.array([-1], dtype=np.int64)).output[0]
2694+
squeeze_axes_2 = ctx.make_const(utils.make_name("const_axes"), np.array([-2], dtype=np.int64)).output[0]
26912695

26922696
minus_two, minus_one, zeo, one, two = \
26932697
[n.output[0] for n in ctx.make_consts([[-2], [-1], [0], [1], [2]])]
@@ -2712,7 +2716,7 @@ def processdiag():
27122716
diag = node.input[0]
27132717
shape = ctx.get_shape(diag)
27142718
if len(shape) == 1:
2715-
if opset < 13:
2719+
if ctx.opset < 13:
27162720
diag = mknode("Unsqueeze", [diag], attr={"axes": [0]})
27172721
else:
27182722
diag = mknode("Unsqueeze", [diag, squeeze_axes0])
@@ -2737,7 +2741,7 @@ def id_diag():
27372741
def ex_diag():
27382742
g = ctx.create_new_graph_with_same_config()
27392743
g.parent_graph = ctx
2740-
if opset < 13:
2744+
if ctx.opset < 13:
27412745
ex = mknode2(g, "Unsqueeze", [diag], attr={"axes": [-2]})
27422746
else:
27432747
ex = mknode2(g, "Unsqueeze", [diag, squeeze_axes_2])
@@ -2755,7 +2759,7 @@ def squeeze_12(name):
27552759
def squeeze_13(name):
27562760
return ctx.make_node("Squeeze", [name, squeeze_axes_1]).output[0]
27572761

2758-
squeeze = squeeze_12 if opset < 13 else squeeze_13
2762+
squeeze = squeeze_12 if ctx.opset < 13 else squeeze_13
27592763

27602764
# gather inputs
27612765
diag, k, k_min, k_max, k_max_nxt = processdiag()
@@ -3018,14 +3022,10 @@ def paddiag():
30183022
ctx.make_node("Identity", [padded], name=node.name,
30193023
outputs=node.output, shapes=shapes, dtypes=dtypes)
30203024

3021-
@classmethod
3022-
def version_12(cls, ctx, node, **kwargs):
3023-
cls.any_version(12, ctx, node, **kwargs)
3024-
30253025
@classmethod
30263026
def version_13(cls, ctx, node, **kwargs):
30273027
# Parameters moved to inputs for operator Squeeze, Unsqueeze.
3028-
cls.any_version(13, ctx, node, **kwargs)
3028+
cls.version_12(ctx, node, **kwargs)
30293029

30303030

30313031
@tf_op("MatrixSetDiagV3")

tf2onnx/rewriter/gru_rewriter.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ def process_var_init_nodes(self, context):
211211
const_node = self.g.make_const(initial_name, new_val)
212212
context.onnx_input_ids["initial_state"] = const_node.output[0]
213213
return
214-
squeeze_node = self.g.make_node("Unsqueeze", [initializer_input_id], attr={"axes": [0]})
214+
squeeze_node = GraphBuilder(self.g).make_unsqueeze(
215+
{'data': initializer_input_id, 'axes': [0]}, return_node=True)
215216
to_replace = [n for n in self.g.get_nodes() if n != squeeze_node]
216217
self.g.replace_all_inputs(initializer_input_id, squeeze_node.output[0], ops=to_replace)
217218
context.onnx_input_ids["initial_state"] = squeeze_node.output[0]

0 commit comments

Comments
 (0)