diff options
author | Xusong Wang <xusongw@google.com> | 2020-03-18 16:57:35 -0700 |
---|---|---|
committer | Xusong Wang <xusongw@google.com> | 2020-03-18 17:20:14 -0700 |
commit | c0f74da9faad6671bda8d947f8122bfd5141220f (patch) | |
tree | e40e2f433bbf03761173b887926705cd049538fd /nn/runtime/test | |
parent | 8b98abf69eb9dffef705bee72bbc85d66a9b42a1 (diff) | |
download | ml-c0f74da9faad6671bda8d947f8122bfd5141220f.tar.gz |
Document and test L2_NORMALIZATION with input of all zeros.
Fixes: 143985908
Test: NNT_static
Change-Id: I97e662612947895e0244a8242728d362c0063f89
Diffstat (limited to 'nn/runtime/test')
5 files changed, 832 insertions, 40 deletions
diff --git a/nn/runtime/test/fuzzing/TestRandomGraph.cpp b/nn/runtime/test/fuzzing/TestRandomGraph.cpp index 25cf86a40..7facc363a 100644 --- a/nn/runtime/test/fuzzing/TestRandomGraph.cpp +++ b/nn/runtime/test/fuzzing/TestRandomGraph.cpp @@ -205,6 +205,11 @@ class RandomGraphTest : public ::testing::TestWithParam<uint32_t> { featureLevel <= __ANDROID_API_Q__) { return true; } + // L2_NORMALIZATION on axis of all zeros is undefined before R. + if (op.type == TestOperationType::L2_NORMALIZATION && + featureLevel <= __ANDROID_API_Q__) { + return true; + } // TODO(xusongw): Remove after b/151328024 is resolved. if (op.type == TestOperationType::ROI_ALIGN) { return true; diff --git a/nn/runtime/test/generated/spec_V1_2/l2_normalization_axis.example.cpp b/nn/runtime/test/generated/spec_V1_2/l2_normalization_axis.example.cpp index e68339edd..ad15c7d04 100644 --- a/nn/runtime/test/generated/spec_V1_2/l2_normalization_axis.example.cpp +++ b/nn/runtime/test/generated/spec_V1_2/l2_normalization_axis.example.cpp @@ -11855,8 +11855,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0() { .inputIndexes = {0}, .operands = {{ .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -11875,8 +11875,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0() { .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -11913,7 +11913,7 @@ const TestModel& get_test_model_corner_case_dim2_axis0_all_inputs_as_internal() .operands = {{ .channelQuant = {}, .data = TestBuffer::createFromVector<uint8_t>({}), - .dimensions = {1, 3}, + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, .numberOfConsumers = 1, @@ -11932,8 +11932,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0_all_inputs_as_internal() .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -11942,8 +11942,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0_all_inputs_as_internal() .zeroPoint = 128 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -12003,8 +12003,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0_neg() { .inputIndexes = {0}, .operands = {{ .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -12023,8 +12023,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0_neg() { .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -12061,7 +12061,7 @@ const TestModel& get_test_model_corner_case_dim2_axis0_neg_all_inputs_as_interna .operands = {{ .channelQuant = {}, .data = TestBuffer::createFromVector<uint8_t>({}), - .dimensions = {1, 3}, + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, .numberOfConsumers = 1, @@ -12080,8 +12080,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0_neg_all_inputs_as_interna .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -12090,8 +12090,8 @@ const TestModel& get_test_model_corner_case_dim2_axis0_neg_all_inputs_as_interna .zeroPoint = 128 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {1, 3}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {1, 2}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -12151,8 +12151,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1() { .inputIndexes = {0}, .operands = {{ .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -12171,8 +12171,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1() { .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -12209,7 +12209,7 @@ const TestModel& get_test_model_corner_case_dim2_axis1_all_inputs_as_internal() .operands = {{ .channelQuant = {}, .data = TestBuffer::createFromVector<uint8_t>({}), - .dimensions = {3, 1}, + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, .numberOfConsumers = 1, @@ -12228,8 +12228,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1_all_inputs_as_internal() .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -12238,8 +12238,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1_all_inputs_as_internal() .zeroPoint = 128 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -12299,8 +12299,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1_neg() { .inputIndexes = {0}, .operands = {{ .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, @@ -12319,8 +12319,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1_neg() { .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -12357,7 +12357,7 @@ const TestModel& get_test_model_corner_case_dim2_axis1_neg_all_inputs_as_interna .operands = {{ .channelQuant = {}, .data = TestBuffer::createFromVector<uint8_t>({}), - .dimensions = {3, 1}, + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, .numberOfConsumers = 1, @@ -12376,8 +12376,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1_neg_all_inputs_as_interna .zeroPoint = 0 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({0, 255, 128}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({0, 255}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, .numberOfConsumers = 0, @@ -12386,8 +12386,8 @@ const TestModel& get_test_model_corner_case_dim2_axis1_neg_all_inputs_as_interna .zeroPoint = 128 }, { .channelQuant = {}, - .data = TestBuffer::createFromVector<uint8_t>({245, 247, 246}), - .dimensions = {3, 1}, + .data = TestBuffer::createFromVector<uint8_t>({245, 247}), + .dimensions = {2, 1}, .isIgnored = false, .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, .numberOfConsumers = 1, diff --git a/nn/runtime/test/generated/spec_V1_3/l2_normalization_zeros.example.cpp b/nn/runtime/test/generated/spec_V1_3/l2_normalization_zeros.example.cpp new file mode 100644 index 000000000..72734f615 --- /dev/null +++ b/nn/runtime/test/generated/spec_V1_3/l2_normalization_zeros.example.cpp @@ -0,0 +1,746 @@ +// Generated from l2_normalization_zeros.mod.py +// DO NOT EDIT +// clang-format off +#include "TestHarness.h" +using namespace test_helper; + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model = TestModelManager::get().add("l2_normalization_zeros", get_test_model()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_all_inputs_as_internal = TestModelManager::get().add("l2_normalization_zeros_all_inputs_as_internal", get_test_model_all_inputs_as_internal()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_relaxed() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = true, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::UNKNOWN, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_relaxed = TestModelManager::get().add("l2_normalization_zeros_relaxed", get_test_model_relaxed()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_relaxed_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = true, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<float>({0.0f}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::UNKNOWN, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_relaxed_all_inputs_as_internal = TestModelManager::get().add("l2_normalization_zeros_relaxed_all_inputs_as_internal", get_test_model_relaxed_all_inputs_as_internal()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_float16() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_float16 = TestModelManager::get().add("l2_normalization_zeros_float16", get_test_model_float16()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_float16_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({0.0f, 0.0f}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<_Float16>({0.0f}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::TENSOR_FLOAT16, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_float16_all_inputs_as_internal = TestModelManager::get().add("l2_normalization_zeros_float16_all_inputs_as_internal", get_test_model_float16_all_inputs_as_internal()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_quant8() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({32, 32}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 32 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({128, 128}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0078125f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 128 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_quant8 = TestModelManager::get().add("l2_normalization_zeros_quant8", get_test_model_quant8()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_quant8_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 32 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({128, 128}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0078125f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 128 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({32, 32}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 32 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<uint8_t>({32}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM, + .zeroPoint = 32 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_2, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_quant8_all_inputs_as_internal = TestModelManager::get().add("l2_normalization_zeros_quant8_all_inputs_as_internal", get_test_model_quant8_all_inputs_as_internal()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_quant8_signed() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {0}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-96, -96}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -96 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({0, 0}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0078125f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_3, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_quant8_signed = TestModelManager::get().add("l2_normalization_zeros_quant8_signed", get_test_model_quant8_signed()); + +} // namespace generated_tests::l2_normalization_zeros + +namespace generated_tests::l2_normalization_zeros { + +const TestModel& get_test_model_quant8_signed_all_inputs_as_internal() { + static TestModel model = { + .expectFailure = false, + .expectedMultinomialDistributionTolerance = 0, + .isRelaxed = false, + .main = { + .inputIndexes = {3}, + .operands = {{ + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::TEMPORARY_VARIABLE, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -96 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({-1}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({0, 0}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_OUTPUT, + .numberOfConsumers = 0, + .scale = 0.0078125f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = 0 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-96, -96}), + .dimensions = {2}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::SUBGRAPH_INPUT, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -96 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int8_t>({-96}), + .dimensions = {1}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.1f, + .type = TestOperandType::TENSOR_QUANT8_ASYMM_SIGNED, + .zeroPoint = -96 + }, { + .channelQuant = {}, + .data = TestBuffer::createFromVector<int32_t>({0}), + .dimensions = {}, + .isIgnored = false, + .lifetime = TestOperandLifeTime::CONSTANT_COPY, + .numberOfConsumers = 1, + .scale = 0.0f, + .type = TestOperandType::INT32, + .zeroPoint = 0 + }}, + .operations = {{ + .inputs = {3, 4, 5}, + .outputs = {0}, + .type = TestOperationType::ADD + }, { + .inputs = {0, 1}, + .outputs = {2}, + .type = TestOperationType::L2_NORMALIZATION + }}, + .outputIndexes = {2} + }, + .minSupportedVersion = TestHalVersion::V1_3, + .referenced = {} + }; + return model; +} + +const auto dummy_test_model_quant8_signed_all_inputs_as_internal = TestModelManager::get().add("l2_normalization_zeros_quant8_signed_all_inputs_as_internal", get_test_model_quant8_signed_all_inputs_as_internal()); + +} // namespace generated_tests::l2_normalization_zeros + diff --git a/nn/runtime/test/specs/V1_2/l2_normalization_axis.mod.py b/nn/runtime/test/specs/V1_2/l2_normalization_axis.mod.py index 036e17482..24852a697 100644 --- a/nn/runtime/test/specs/V1_2/l2_normalization_axis.mod.py +++ b/nn/runtime/test/specs/V1_2/l2_normalization_axis.mod.py @@ -49,12 +49,12 @@ Example(example0).AddAllDimsAndAxis(i1, o1, axis).AddVariations("relaxed", "floa # TEST 2: Corner cases for TENSOR_QUANT8_ASYMM data type. -i2 = Input("op1", "TENSOR_QUANT8_ASYMM", "{3, 1}, 0.904414f, 246") -o2 = Output("op2", "TENSOR_QUANT8_ASYMM", "{3, 1}, 0.0078125f, 128") +i2 = Input("op1", "TENSOR_QUANT8_ASYMM", "{2, 1}, 0.904414f, 246") +o2 = Output("op2", "TENSOR_QUANT8_ASYMM", "{2, 1}, 0.0078125f, 128") axis = Int32Scalar("axis", -1) # last axis Model("corner_case").Operation("L2_NORMALIZATION", i2, axis).To(o2) Example({ - i2: [245, 247, 246], - o2: [0, 255, 128], + i2: [245, 247], + o2: [0, 255], }).AddAllDimsAndAxis(i2, o2, axis) diff --git a/nn/runtime/test/specs/V1_3/l2_normalization_zeros.mod.py b/nn/runtime/test/specs/V1_3/l2_normalization_zeros.mod.py new file mode 100644 index 000000000..6af710795 --- /dev/null +++ b/nn/runtime/test/specs/V1_3/l2_normalization_zeros.mod.py @@ -0,0 +1,41 @@ +# +# 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 L2_NORMALIZATION with inputs of all zeros. +i1 = Input("op1", "TENSOR_FLOAT32", "{2}") # input 0 +o1 = Output("op2", "TENSOR_FLOAT32", "{2}") # output 0 +axis = Int32Scalar("axis", -1) # last axis + +quant8 = DataTypeConverter().Identify({ + i1: ("TENSOR_QUANT8_ASYMM", 0.1, 32), + o1: ("TENSOR_QUANT8_ASYMM", 1.0 / 128, 128) +}) + +quant8_signed = DataTypeConverter().Identify({ + i1: ("TENSOR_QUANT8_ASYMM_SIGNED", 0.1, -96), + o1: ("TENSOR_QUANT8_ASYMM_SIGNED", 1.0 / 128, 0) +}) + +Model().IntroducedIn("V1_2").Operation("L2_NORMALIZATION", i1, axis).To(o1) +Example({ + i1: [0, 0], + o1: [0, 0] +}).AddVariations("relaxed", "float16", quant8, quant8_signed) + +# TENSOR_QUANT8_ASYMM_SIGNED is a new data type in V1_3. +Example.SetVersion("V1_3", + "l2_normalization_zeros_quant8_signed", + "l2_normalization_zeros_quant8_signed_all_inputs_as_internal") |