From fa37af3890fcf25c56fc0ff58f85b2ca3a9328b0 Mon Sep 17 00:00:00 2001 From: Slava Shklyaev Date: Tue, 10 Mar 2020 17:51:48 +0000 Subject: Add AllOutputsAsInternalCoverter The variation is used in control flow tests. Bug: 149199424 Test: generate_all_tests.sh Test: NNT_static Change-Id: I542f7be5338d878a822f9ae69edea23e387fdf08 Merged-In: I542f7be5338d878a822f9ae69edea23e387fdf08 (cherry picked from commit 6883f803060f6dd81c90359ff6512845ad8b40ea) --- .../test/specs/V1_3/if_same_branch_model.mod.py | 43 ++++++++++++++++++++++ nn/runtime/test/specs/V1_3/if_simple.mod.py | 29 +++++++-------- nn/runtime/test/specs/V1_3/while_fib.mod.py | 27 ++++++++------ .../test/specs/V1_3/while_sum_of_powers.mod.py | 29 +++++++++------ 4 files changed, 88 insertions(+), 40 deletions(-) create mode 100644 nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py (limited to 'nn/runtime/test/specs/V1_3') diff --git a/nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py b/nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py new file mode 100644 index 000000000..189b67c6f --- /dev/null +++ b/nn/runtime/test/specs/V1_3/if_same_branch_model.mod.py @@ -0,0 +1,43 @@ +# +# Copyright (C) 2020 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# Test with multiple references to the same referenced model. +# Model: z = if (x) then (y + 100) else (y + 100) + +input_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] +output_add = [y + 100 for y in input_data] + +ValueType = ["TENSOR_FLOAT32", [3, 4]] +BoolType = ["TENSOR_BOOL8", [1]] + +def MakeBranchModel(operation_name): + y = Input("y", ValueType) + z = Output("z", ValueType) + return Model().Operation(operation_name, y, [100.0], 0).To(z) + +def Test(x, y, z, name): + x_data, y_data, z_data = x, y, z + x = Input("x", BoolType) + y = Input("y", ValueType) + z = Output("z", ValueType) + then_model = MakeBranchModel("ADD") + else_model = then_model + model = Model().Operation("IF", x, then_model, else_model, y).To(z) + example = Example({x: [x_data], y: y_data, z: z_data}, name=name) + example.AddVariations(AllOutputsAsInternalCoverter()) + +Test(x=True, y=input_data, z=output_add, name="true") +Test(x=False, y=input_data, z=output_add, name="false") diff --git a/nn/runtime/test/specs/V1_3/if_simple.mod.py b/nn/runtime/test/specs/V1_3/if_simple.mod.py index c13446588..1cc717374 100644 --- a/nn/runtime/test/specs/V1_3/if_simple.mod.py +++ b/nn/runtime/test/specs/V1_3/if_simple.mod.py @@ -28,19 +28,16 @@ def MakeBranchModel(operation_name): z = Output("z", ValueType) return Model().Operation(operation_name, y, [100.0], 0).To(z) -x = Input("x", BoolType) -y = Input("y", ValueType) -z = Output("z", ValueType) -then_model = MakeBranchModel("ADD") -else_model = MakeBranchModel("SUB") -model = Model().Operation("IF", x, then_model, else_model, y).To(z) - -Example({x: [True], y: input_data, z: output_add}, name="true", model=model) -Example({x: [False], y: input_data, z: output_sub}, name="false", model=model) - -# Test with multiple references to the same referenced model. -model = Model(name="same_branch_model") -model.Operation("IF", x, then_model, then_model, y).To(z) - -Example({x: [True], y: input_data, z: output_add}, name="true", model=model) -Example({x: [False], y: input_data, z: output_add}, name="false", model=model) +def Test(x, y, z, name): + x_data, y_data, z_data = x, y, z + x = Input("x", BoolType) + y = Input("y", ValueType) + z = Output("z", ValueType) + then_model = MakeBranchModel("ADD") + else_model = MakeBranchModel("SUB") + model = Model().Operation("IF", x, then_model, else_model, y).To(z) + example = Example({x: [x_data], y: y_data, z: z_data}, name=name) + example.AddVariations(AllOutputsAsInternalCoverter()) + +Test(x=True, y=input_data, z=output_add, name="true") +Test(x=False, y=input_data, z=output_sub, name="false") diff --git a/nn/runtime/test/specs/V1_3/while_fib.mod.py b/nn/runtime/test/specs/V1_3/while_fib.mod.py index 9f36b06b2..f8f058133 100644 --- a/nn/runtime/test/specs/V1_3/while_fib.mod.py +++ b/nn/runtime/test/specs/V1_3/while_fib.mod.py @@ -53,17 +53,20 @@ def MakeBodyModel(): model.Operation("FULLY_CONNECTED", fib, matrix, zero_bias, 0).To(fib_out) return model -n = Input("n", CounterType) -fib_out = Output("fib_out", FibType) -cond = MakeConditionModel() -body = MakeBodyModel() -fib_init = Parameter("fib_init", FibType, [1, 1]) -i_init = [1] -model = Model().Operation("WHILE", cond, body, fib_init, i_init, n).To(fib_out) +def Test(n, fib): + n_ = Input("n", CounterType) + fib_out = Output("fib_out", FibType) + cond = MakeConditionModel() + body = MakeBodyModel() + fib_init = Parameter("fib_init", FibType, [1, 1]) + i_init = [1] + model = Model().Operation("WHILE", cond, body, fib_init, i_init, n_).To(fib_out) + example = Example({n_: [n], fib_out: fib}, name=str(n), model=model) + example.AddVariations(AllOutputsAsInternalCoverter()) # Fibonacci numbers: 1 1 2 3 5 8 -Example({n: [1], fib_out: [1, 1]}, name="1", model=model) -Example({n: [2], fib_out: [1, 2]}, name="2", model=model) -Example({n: [3], fib_out: [2, 3]}, name="3", model=model) -Example({n: [4], fib_out: [3, 5]}, name="4", model=model) -Example({n: [5], fib_out: [5, 8]}, name="5", model=model) +Test(n=1, fib=[1, 1]) +Test(n=2, fib=[1, 2]) +Test(n=3, fib=[2, 3]) +Test(n=4, fib=[3, 5]) +Test(n=5, fib=[5, 8]) diff --git a/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py b/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py index 3f8a6344f..0adaec476 100644 --- a/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py +++ b/nn/runtime/test/specs/V1_3/while_sum_of_powers.mod.py @@ -89,16 +89,21 @@ def MakeOuterBodyModel(): model.Operation("ADD", sum, xi, 0).To(sum_out) return model -x = Input("x", DataType) -n = Input("n", CounterType) -sum = Output("sum", DataType) -cond = MakeOuterConditionModel() -body = MakeOuterBodyModel() -sum_init = Parameter("sum_init", DataType, [1, 1]) -i_init = [1] -model = Model().Operation("WHILE", cond, body, sum_init, i_init, n, x).To(sum) +def Test(x, n, sum): + x_data, n_data, sum_data = x, n, sum + x = Input("x", DataType) + n = Input("n", CounterType) + sum = Output("sum", DataType) + cond = MakeOuterConditionModel() + body = MakeOuterBodyModel() + sum_init = Parameter("sum_init", DataType, [1, 1]) + i_init = [1] + model = Model().Operation("WHILE", cond, body, sum_init, i_init, n, x).To(sum) + example = Example({x: x_data, n: [n_data], sum: sum_data}, name=str(n_data)) + example.AddVariations(AllOutputsAsInternalCoverter()) -Example({x: [2, 3], n: [1], sum: [1 + 2, 1 + 3]}, name="1", model=model) -Example({x: [2, 3], n: [2], sum: [1 + 2 + 4, 1 + 3 + 9]}, name="2", model=model) -Example({x: [2, 3], n: [3], sum: [1 + 2 + 4 + 8, 1 + 3 + 9 + 27]}, name="3", model=model) -Example({x: [2, 3], n: [4], sum: [1 + 2 + 4 + 8 + 16, 1 + 3 + 9 + 27 + 81]}, name="4", model=model) +Test(x=[2, 3], n=1, sum=[1 + 2, 1 + 3]) +Test(x=[2, 3], n=1, sum=[1 + 2, 1 + 3]) +Test(x=[2, 3], n=2, sum=[1 + 2 + 4, 1 + 3 + 9]) +Test(x=[2, 3], n=3, sum=[1 + 2 + 4 + 8, 1 + 3 + 9 + 27]) +Test(x=[2, 3], n=4, sum=[1 + 2 + 4 + 8 + 16, 1 + 3 + 9 + 27 + 81]) -- cgit v1.2.3