Skip to content

Commit

Permalink
Set UT to use nightly for opset 13 testing
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wildenhain <tomwi@microsoft.com>
  • Loading branch information
TomWildenhain-Microsoft committed Dec 17, 2020
1 parent ac2f675 commit 2924ec7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ci_build/azure_pipelines/templates/unit_test.yml
@@ -1,7 +1,7 @@
# Run unit test

parameters:
onnx_opsets: ['12', '11', '10', '9', '8', '7']
onnx_opsets: ['13', '12', '11', '10', '9', '8', '7']

steps:
- ${{ each onnx_opset in parameters.onnx_opsets }}:
Expand Down
3 changes: 3 additions & 0 deletions ci_build/azure_pipelines/unit_test-matrix.yml
Expand Up @@ -9,6 +9,7 @@ stages:
python_versions: [3.6']
tf_versions: ['1.13.1', '1.12.3']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand All @@ -20,6 +21,7 @@ stages:
python_versions: ['3.7', '3.6']
tf_versions: ['1.14.0']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand All @@ -31,6 +33,7 @@ stages:
python_versions: ['3.7']
tf_versions: ['1.15.2','2.1.0']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand Down
4 changes: 4 additions & 0 deletions ci_build/azure_pipelines/unit_test.yml
Expand Up @@ -8,6 +8,7 @@ stages:
python_versions: ['3.8']
tf_versions: ['2.4.0']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand All @@ -18,6 +19,7 @@ stages:
python_versions: ['3.7']
tf_versions: ['1.14.0','1.15.2','2.2.0','2.3.0']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand All @@ -28,6 +30,7 @@ stages:
python_versions: [3.6']
tf_versions: ['1.12.3']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand All @@ -38,6 +41,7 @@ stages:
platforms: ['windows']
tf_versions: ['1.14.0']
onnx_opsets: ['']
onnx_backends: {onnxruntime: ['nightly']}
job:
steps:
- template: 'unit_test.yml'
Expand Down
17 changes: 5 additions & 12 deletions tf2onnx/onnx_opset/controlflow.py
Expand Up @@ -286,24 +286,17 @@ class TensorListGetItem:
def version_7(cls, ctx, node, **kwargs):
ctx.ta_reads.append(node.input[0])
node.type = "Gather"
ctx.replace_inputs(node, [node.input[0], node.input[1]])
ctx.insert_new_node_on_input(node, "Unsqueeze", node.input[1], name=node.child_name(), axes=[0])
ctx.insert_new_node_on_output("Squeeze", node.output[0], name=node.child_name(), axes=[0])

@classmethod
def version_13(cls, ctx, node, **kwargs):
ctx.ta_reads.append(node.input[0])
node.type = "Gather"
ctx.replace_inputs(node, [node.input[0], node.input[1]])

g = GraphBuilder(ctx)

usq_node = g.make_unsqueeze({"axes": [0], 'data': node.input[1]}, name=node.child_name(), return_node=True)
ctx.insert_node_on_output(usq_node)

ctx.replace_inputs(node, [node.input[0], usq_node.output[0]])
sq_node = g.make_squeeze({"axes": [0], 'data': node.output[0]}, name=node.child_name(), return_node=True)
ctx.insert_node_on_output(sq_node)

@classmethod
def version_13(cls, ctx, node, **kwargs):
cls.version_7(ctx, node, **kwargs)


@tf_op(["TensorListLength"])
class TensorListLength:
Expand Down
2 changes: 1 addition & 1 deletion tf2onnx/onnx_opset/nn.py
Expand Up @@ -353,7 +353,7 @@ def any_version(cls, opset, ctx, node, **kwargs):
if len(input_shape) == spatial + 1:
gb = GraphBuilder(ctx)
usq_node = gb.make_unsqueeze({"axes": [0], 'data': node.input[0]}, return_node=True)
ctx.insert_node_on_output(usq_node, node.input[0])
ctx.replace_inputs(node, [usq_node.output[0]] + node.input[1:])

# Set padding.
add_padding(
Expand Down
44 changes: 22 additions & 22 deletions tf2onnx/onnx_opset/tensor.py
Expand Up @@ -1192,7 +1192,8 @@ def version_1(cls, ctx, node, **kwargs):
# for each output we need to squeeze axis
for n in node.output:
op_name = utils.make_name(node.name)
squeeze_node = ctx.insert_new_node_on_output("Squeeze", n, name=op_name, axes=[axis])
squeeze_node = GraphBuilder(ctx).make_squeeze({'data': n, 'axes': [axis]}, name=op_name, return_node=True)
ctx.insert_node_on_output(squeeze_node, n)
ctx.copy_shape(n, squeeze_node.output[0])
ctx.copy_dtype(n, squeeze_node.output[0])

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

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

Expand Down Expand Up @@ -2385,15 +2387,17 @@ def normalize():
pad_length_2 = body_graph.make_node('Concat', [zeo, pad_length.output[0]], attr={'axis': 0})
padded_range = body_graph.make_node('Pad', [sliced_range.output[0], pad_length_2.output[0]])
# opset == 11, no need to change unsqueeze
unsqueezed_range = body_graph.make_node('Unsqueeze', [padded_range.output[0]], attr={'axes': [1]})
unsqueezed_range = GraphBuilder(body_graph).make_unsqueeze(
{'data': padded_range.output[0], 'axes': [1]}, return_node=True)
half_shape_x = body_graph.make_node('Slice',
[new_shape.output[0], zeo, minus_two])
shape_range = body_graph.make_node('Shape', [unsqueezed_range.output[0]])
full_shape = body_graph.make_node('Concat', [half_shape_x.output[0], shape_range.output[0]], attr={'axis': 0})
expanded_range = body_graph.make_node('Expand', [unsqueezed_range.output[0], full_shape.output[0]])
gathered_input = body_graph.make_node('GatherElements', [processed_input.output[0], expanded_range.output[0]],
attr={'axis': -1})
squeezed_input = body_graph.make_node('Squeeze', [gathered_input.output[0]], attr={'axes': [-1]})
squeezed_input = GraphBuilder(body_graph).make_squeeze(
{'data': gathered_input.output[0], 'axes': [-1]}, return_node=True)
left_width = body_graph.make_node('Sub', [new_width.output[0], abs_k.output[0]])
dims = body_graph.make_node('Concat', [left_width.output[0], new_depth.output[0]], attr={'axis': 0})
valid_dim = body_graph.make_node('ReduceMin', [dims.output[0]])
Expand Down Expand Up @@ -2505,8 +2509,8 @@ def normalize():
raw_output_shape + [-1])
squeeze_sliced_graph = ctx.create_new_graph_with_same_config()
squeeze_sliced_graph.parent_graph = ctx
squeeze_sliced = squeeze_sliced_graph.make_node('Squeeze', [final_output_right_sliced.output[0]],
attr={'axes': [-2]})
squeeze_sliced = GraphBuilder(squeeze_sliced_graph).make_squeeze(
{'data': final_output_right_sliced.output[0], 'axes': [-2]}, return_node=True)
squeeze_sliced_graph.add_graph_output(squeeze_sliced.output[0], ctx.get_dtype(node.input[0]), raw_output_shape)
shapes = node.output_shapes
dtypes = node.output_dtypes
Expand Down Expand Up @@ -2680,14 +2684,14 @@ def version_13(cls, ctx, node, **kwargs):
@tf_op(["MatrixDiag", "MatrixDiagV2", "MatrixDiagV3"])
class MatrixDiag:
@classmethod
def any_version(cls, opset, ctx, node, **kwargs):
def version_12(cls, ctx, node, **kwargs):
# Assemble MatrixDiagV3 by ReverseSequence
argc = len(node.input)

if opset >= 13:
squeeze_axes0 = ctx.make_const(utils.make_name("const_axes"), np.array([0], dtype=np.int64))
squeeze_axes_1 = ctx.make_const(utils.make_name("const_axes"), np.array([-1], dtype=np.int64))
squeeze_axes_2 = ctx.make_const(utils.make_name("const_axes"), np.array([-2], dtype=np.int64))
if ctx.opset >= 13:
squeeze_axes0 = ctx.make_const(utils.make_name("const_axes"), np.array([0], dtype=np.int64)).output[0]
squeeze_axes_1 = ctx.make_const(utils.make_name("const_axes"), np.array([-1], dtype=np.int64)).output[0]
squeeze_axes_2 = ctx.make_const(utils.make_name("const_axes"), np.array([-2], dtype=np.int64)).output[0]

minus_two, minus_one, zeo, one, two = \
[n.output[0] for n in ctx.make_consts([[-2], [-1], [0], [1], [2]])]
Expand All @@ -2712,7 +2716,7 @@ def processdiag():
diag = node.input[0]
shape = ctx.get_shape(diag)
if len(shape) == 1:
if opset < 13:
if ctx.opset < 13:
diag = mknode("Unsqueeze", [diag], attr={"axes": [0]})
else:
diag = mknode("Unsqueeze", [diag, squeeze_axes0])
Expand All @@ -2737,7 +2741,7 @@ def id_diag():
def ex_diag():
g = ctx.create_new_graph_with_same_config()
g.parent_graph = ctx
if opset < 13:
if ctx.opset < 13:
ex = mknode2(g, "Unsqueeze", [diag], attr={"axes": [-2]})
else:
ex = mknode2(g, "Unsqueeze", [diag, squeeze_axes_2])
Expand All @@ -2755,7 +2759,7 @@ def squeeze_12(name):
def squeeze_13(name):
return ctx.make_node("Squeeze", [name, squeeze_axes_1]).output[0]

squeeze = squeeze_12 if opset < 13 else squeeze_13
squeeze = squeeze_12 if ctx.opset < 13 else squeeze_13

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

@classmethod
def version_12(cls, ctx, node, **kwargs):
cls.any_version(12, ctx, node, **kwargs)

@classmethod
def version_13(cls, ctx, node, **kwargs):
# Parameters moved to inputs for operator Squeeze, Unsqueeze.
cls.any_version(13, ctx, node, **kwargs)
cls.version_12(ctx, node, **kwargs)


@tf_op("MatrixSetDiagV3")
Expand Down
3 changes: 2 additions & 1 deletion tf2onnx/rewriter/gru_rewriter.py
Expand Up @@ -211,7 +211,8 @@ def process_var_init_nodes(self, context):
const_node = self.g.make_const(initial_name, new_val)
context.onnx_input_ids["initial_state"] = const_node.output[0]
return
squeeze_node = self.g.make_node("Unsqueeze", [initializer_input_id], attr={"axes": [0]})
squeeze_node = GraphBuilder(self.g).make_unsqueeze(
{'data': initializer_input_id, 'axes': [0]}, return_node=True)
to_replace = [n for n in self.g.get_nodes() if n != squeeze_node]
self.g.replace_all_inputs(initializer_input_id, squeeze_node.output[0], ops=to_replace)
context.onnx_input_ids["initial_state"] = squeeze_node.output[0]
Expand Down

0 comments on commit 2924ec7

Please sign in to comment.