ScatterUpdate, Select layer tests to API2.0 (#20010)

* `SelectLayerTest` to API2.0

* `ScatterUpdateLayerTest` to API2.0
This commit is contained in:
Vitaliy Urusovskij 2023-09-26 15:27:20 +04:00 committed by GitHub
parent 47dec42ca0
commit a519770a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 279 additions and 41 deletions

View File

@ -3,47 +3,79 @@
//
#include <vector>
#include <ngraph/opsets/opset3.hpp>
#include "single_layer_tests/scatter_update.hpp"
#include "single_op_tests/scatter_update.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using namespace ngraph::opset3;
using ov::test::ScatterUpdateLayerTest;
namespace {
const std::vector<InferenceEngine::Precision> inputPrecisions = {
InferenceEngine::Precision::FP32,
InferenceEngine::Precision::FP16,
InferenceEngine::Precision::I32,
const std::vector<ov::element::Type> model_types = {
ov::element::f32,
ov::element::f16,
ov::element::i32,
};
const std::vector<InferenceEngine::Precision> idxPrecisions = {
InferenceEngine::Precision::I32,
InferenceEngine::Precision::I64,
const std::vector<ov::element::Type> idx_types = {
ov::element::i32,
ov::element::i64,
};
// map<inputShape, map<indicesShape, axis>>
std::map<std::vector<size_t>, std::map<std::vector<size_t>, std::vector<int>>> axesShapeInShape {
// map<input_shape, map<indices_shape, axis>>
std::map<std::vector<size_t>, std::map<std::vector<size_t>, std::vector<int>>> axes_shape_in_shape {
{{10, 16, 12, 15}, {{{2, 2, 2}, {0, 1, 2, 3}}, {{2, 4}, {0, 1, 2, 3}}, {{8}, {0, 1, 2, 3}}}},
{{10, 9, 10, 9, 10}, {{{8}, {0, 1, 2, 3, 4}}, {{4, 2}, {0, 1, 2, 3, 4}}}},
{{10, 9, 10, 9, 10, 12}, {{{8}, {0, 1, 2, 3, 4, 5}}}},
{{10, 16, 12, 15}, {{{2, 4}, {0, 1, 2, 3}}, {{8}, {-1, -2, -3, -4}}}},
{{10, 9, 10, 9, 10}, {{{8}, {-3, -1, 0, 2, 4}}, {{4, 2}, {-2, 2}}}},
};
std::vector<ov::test::axisUpdateShapeInShape> combine_shapes(
const std::map<std::vector<size_t>, std::map<std::vector<size_t>, std::vector<int>>>& input_shapes) {
std::vector<ov::test::axisUpdateShapeInShape> res_vec;
for (auto& input_shape : input_shapes) {
auto src_shape = input_shape.first;
auto srcRank = src_shape.size();
for (auto& item : input_shape.second) {
auto indices_shape = item.first;
auto indices_rank = indices_shape.size();
for (auto& axis : item.second) {
auto axisP = axis < 0 ? axis + srcRank : axis;
std::vector<size_t> update_shape;
for (size_t rs = 0; rs < srcRank; rs++) {
if (rs != axisP) {
update_shape.push_back(src_shape[rs]);
} else {
for (size_t ri = 0; ri < indices_rank; ri++) {
update_shape.push_back(indices_shape[ri]);
}
}
}
std::vector<ov::Shape> in_shapes{src_shape, update_shape};
res_vec.push_back(
ov::test::axisUpdateShapeInShape{
ov::test::static_shapes_to_test_representation(in_shapes),
ov::Shape{indices_shape},
axis});
}
}
}
return res_vec;
}
//indices should not be random value
const std::vector<std::vector<int64_t>> idxValue = {
const std::vector<std::vector<int64_t>> idx_value = {
{0, 2, 4, 6, 1, 3, 5, 7}
};
const auto ScatterUpdateCase = ::testing::Combine(
::testing::ValuesIn(ScatterUpdateLayerTest::combineShapes(axesShapeInShape)),
::testing::ValuesIn(idxValue),
::testing::ValuesIn(inputPrecisions),
::testing::ValuesIn(idxPrecisions),
const auto scatter_update_case = ::testing::Combine(
::testing::ValuesIn(combine_shapes(axes_shape_in_shape)),
::testing::ValuesIn(idx_value),
::testing::ValuesIn(model_types),
::testing::ValuesIn(idx_types),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_ScatterUpdate, ScatterUpdateLayerTest, ScatterUpdateCase, ScatterUpdateLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_ScatterUpdate, ScatterUpdateLayerTest, scatter_update_case, ScatterUpdateLayerTest::getTestCaseName);
} // namespace

View File

@ -4,21 +4,19 @@
#include <vector>
#include "single_layer_tests/select.hpp"
#include "single_op_tests/select.hpp"
#include "common_test_utils/test_constants.hpp"
using namespace LayerTestsDefinitions;
using ov::test::SelectLayerTest;
const std::vector<InferenceEngine::Precision> inputPrecision = {
InferenceEngine::Precision::I8,
InferenceEngine::Precision::I16,
InferenceEngine::Precision::I32,
InferenceEngine::Precision::FP32
// CPU plug-in doesn't support I64 and U64 precisions at the moment
// InferenceEngine::Precision::I64
const std::vector<ov::element::Type> model_types = {
ov::element::i8,
ov::element::i16,
ov::element::i32,
ov::element::f32
};
const std::vector<std::vector<std::vector<size_t>>> noneShapes = {
const std::vector<std::vector<ov::Shape>> none_shapes = {
{{1}, {1}, {1}},
{{8}, {8}, {8}},
{{4, 5}, {4, 5}, {4, 5}},
@ -27,14 +25,14 @@ const std::vector<std::vector<std::vector<size_t>>> noneShapes = {
{{2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}, {2, 3, 4, 5, 6}}
};
const auto noneCases = ::testing::Combine(
::testing::ValuesIn(noneShapes),
::testing::ValuesIn(inputPrecision),
::testing::Values(ngraph::op::AutoBroadcastType::NONE),
const auto none_cases = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(none_shapes)),
::testing::ValuesIn(model_types),
::testing::Values(ov::op::AutoBroadcastType::NONE),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
const std::vector<std::vector<std::vector<size_t>>> numpyShapes = {
const std::vector<std::vector<ov::Shape>> numpy_shapes = {
{{1}, {1}, {1}},
{{1}, {16}, {1}},
{{1}, {1}, {16}},
@ -74,13 +72,13 @@ const std::vector<std::vector<std::vector<size_t>>> numpyShapes = {
{{7, 6, 5, 8}, {4, 7, 6, 5, 8}, {6, 1, 8}}
};
const auto numpyCases = ::testing::Combine(
::testing::ValuesIn(numpyShapes),
::testing::ValuesIn(inputPrecision),
::testing::Values(ngraph::op::AutoBroadcastType::NUMPY),
const auto numpy_cases = ::testing::Combine(
::testing::ValuesIn(ov::test::static_shapes_to_test_representation(numpy_shapes)),
::testing::ValuesIn(model_types),
::testing::Values(ov::op::AutoBroadcastType::NUMPY),
::testing::Values(ov::test::utils::DEVICE_CPU)
);
INSTANTIATE_TEST_SUITE_P(smoke_TestsSelect_none, SelectLayerTest, noneCases, SelectLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsSelect_none, SelectLayerTest, none_cases, SelectLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsSelect_numpy, SelectLayerTest, numpyCases, SelectLayerTest::getTestCaseName);
INSTANTIATE_TEST_SUITE_P(smoke_TestsSelect_numpy, SelectLayerTest, numpy_cases, SelectLayerTest::getTestCaseName);

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/scatter_update.hpp"
namespace ov {
namespace test {
TEST_P(ScatterUpdateLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,15 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include "shared_test_classes/single_op/select.hpp"
namespace ov {
namespace test {
TEST_P(SelectLayerTest, Inference) {
run();
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,37 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
using axisUpdateShapeInShape = std::tuple<
std::vector<InputShape>, // input, update shapes
ov::Shape, // indices shape
int64_t>; // axis
using scatterUpdateParamsTuple = typename std::tuple<
axisUpdateShapeInShape,
std::vector<int64_t>, // Indices value
ov::element::Type, // Model type
ov::element::Type, // Indices type
ov::test::TargetDevice // Device name
>;
class ScatterUpdateLayerTest : public testing::WithParamInterface<scatterUpdateParamsTuple>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<scatterUpdateParamsTuple> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,30 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <tuple>
#include <string>
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace ov {
namespace test {
typedef std::tuple<
std::vector<InputShape>, // mask, then, else shapes
ov::element::Type, // then, else types
ov::op::AutoBroadcastSpec, // broadcast
ov::test::TargetDevice // Device name
> selectTestParams;
class SelectLayerTest : public testing::WithParamInterface<selectTestParams>,
virtual public ov::test::SubgraphBaseTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo <selectTestParams> &obj);
protected:
void SetUp() override;
};
} // namespace test
} // namespace ov

View File

@ -0,0 +1,61 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/scatter_update.hpp"
namespace ov {
namespace test {
std::string ScatterUpdateLayerTest::getTestCaseName(const testing::TestParamInfo<scatterUpdateParamsTuple> &obj) {
auto shapes_ss = [](const InputShape& shape) {
std::stringstream ss;
ss << "_IS=(" << ov::test::utils::partialShape2str({shape.first}) << ")_TS=";
for (size_t j = 0lu; j < shape.second.size(); j++)
ss << "{" << ov::test::utils::vec2str(shape.second[j]) << "}";
return ss;
};
axisUpdateShapeInShape shapes_desc;
std::vector<InputShape> input_shapes;
int64_t axis;
ov::Shape indices_shape;
std::vector<int64_t> indices_value;
ov::element::Type model_type, indices_type;
std::string target_device;
std::tie(shapes_desc, indices_value, model_type, indices_type, target_device) = obj.param;
std::tie(input_shapes, indices_shape, axis) = shapes_desc;
std::ostringstream result;
result << "InputShape=" << shapes_ss(input_shapes.at(0)).str() << "_";
result << "IndicesShape=" << ov::test::utils::vec2str(indices_shape) << "_";
result << "IndicesValue=" << ov::test::utils::vec2str(indices_value) << "_";
result << "UpdateShape=" << shapes_ss(input_shapes.at(1)).str() << "_";
result << "Axis=" << axis << "_";
result << "modelType=" << model_type.to_string() << "_";
result << "idxType=" << indices_type.to_string() << "_";
result << "trgDev=" << target_device;
return result.str();
}
void ScatterUpdateLayerTest::SetUp() {
axisUpdateShapeInShape shapes_desc;
std::vector<InputShape> input_shapes;
int64_t axis;
ov::Shape indices_shape;
std::vector<int64_t> indices_value;
ov::element::Type model_type, indices_type;
std::tie(shapes_desc, indices_value, model_type, indices_type, targetDevice) = this->GetParam();
std::tie(input_shapes, indices_shape, axis) = shapes_desc;
init_input_shapes(input_shapes);
auto param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.at(0));
auto update_param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes.at(1));
auto indices_const = std::make_shared<ov::op::v0::Constant>(indices_type, indices_shape, indices_value);
auto axis_const =
std::make_shared<ov::op::v0::Constant>(ov::element::i64, ov::Shape{}, std::vector<int64_t>{axis});
auto scatter = std::make_shared<ov::op::v3::ScatterUpdate>(param, indices_const, update_param, axis_const);
function = std::make_shared<ov::Model>(scatter->outputs(), ov::ParameterVector{param, update_param}, "ScatterUpdate");
}
} // namespace test
} // namespace ov

View File

@ -0,0 +1,50 @@
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "shared_test_classes/single_op/select.hpp"
namespace ov {
namespace test {
std::string SelectLayerTest::getTestCaseName(const testing::TestParamInfo<selectTestParams> &obj) {
auto shapes_ss = [](const InputShape& shape) {
std::stringstream ss;
ss << "_IS=(" << ov::test::utils::partialShape2str({shape.first}) << ")_TS=";
for (size_t j = 0lu; j < shape.second.size(); j++)
ss << "{" << ov::test::utils::vec2str(shape.second[j]) << "}";
return ss;
};
std::vector<InputShape> input_shapes;
ov::element::Type model_type;
ov::op::AutoBroadcastSpec broadcast;
std::string target_device;
std::tie(input_shapes, model_type, broadcast, target_device) = obj.param;
std::ostringstream result;
result << "COND=BOOL" << shapes_ss(input_shapes[0]).str() <<
"_THEN=" << model_type.to_string() << shapes_ss(input_shapes[1]).str() <<
"_ELSE=" << model_type.to_string() << shapes_ss(input_shapes[2]).str();
result << "_broadcastSpec=" << broadcast.m_type;
result << "_trgDev=" << target_device;
return result.str();
}
void SelectLayerTest::SetUp() {
std::vector<InputShape> input_shapes;
ov::element::Type model_type;
ov::op::AutoBroadcastSpec broadcast;
std::tie(input_shapes, model_type, broadcast, targetDevice) = this->GetParam();
init_input_shapes(input_shapes);
auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::boolean, inputDynamicShapes[0]);
ov::ParameterVector params{param};
for (size_t i = 1; i < inputDynamicShapes.size(); i++) {
param = std::make_shared<ov::op::v0::Parameter>(model_type, inputDynamicShapes[i]);
params.push_back(param);
}
auto select = std::make_shared<ov::op::v1::Select>(params[0], params[1], params[2], broadcast);
function = std::make_shared<ov::Model>(select->outputs(), params, "Select");
}
} // namespace test
} // namespace ov