[GPU] fix normalize dynamic shape support (#18956)

* fix normalize dynamic shape support

* remove redundant code
This commit is contained in:
Wilson Seok 2023-08-04 02:37:41 +09:00 committed by GitHub
parent a064fa6c27
commit 3a1f45e70e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 211 additions and 0 deletions

View File

@ -49,6 +49,8 @@ std::string normalize_inst::to_string(normalize_node const& node) {
}
normalize_inst::typed_primitive_inst(network& network, normalize_node const& node) : parent(network, node) {
if (node.input().is_dynamic() || node.scale().is_dynamic())
return;
/// Scale f dimension should be 1 (if all channels have the same scale) or equal to input feature size (one scale per channel).
auto scale_layout = node.scale().get_output_layout();
auto scale_size = scale_layout.get_tensor();

View File

@ -0,0 +1,209 @@
// Copyright (C) 2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include <shared_test_classes/single_layer/normalize_l2.hpp>
#include "ngraph_functions/builders.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
using namespace InferenceEngine;
using namespace ov::test;
namespace GPULayerTestsDefinitions {
using NormalizeL2LayerGPUTestParams = std::tuple<
InputShape, // Input shapes
ElementType, // Input precision
std::vector<int64_t>, // Reduction axes
ngraph::op::EpsMode, // EpsMode
float>; // Epsilon
class NormalizeL2LayerGPUTest : public testing::WithParamInterface<NormalizeL2LayerGPUTestParams>,
virtual public SubgraphBaseTest {
public:
static std::string getTestCaseName(testing::TestParamInfo<NormalizeL2LayerGPUTestParams> obj) {
InputShape inputShapes;
ElementType netPrecision;
std::vector<int64_t> axes;
ngraph::op::EpsMode epsMode;
float eps;
std::tie(inputShapes, netPrecision, axes, epsMode, eps) = obj.param;
std::ostringstream result;
result << "IS=" << ov::test::utils::partialShape2str({inputShapes.first}) << "_";
result << "TS=";
for (const auto& shape : inputShapes.second) {
result << "(" << ov::test::utils::vec2str(shape) << ")_";
}
result << "Precision=" << netPrecision << "_";
result << "ReductionAxes=" << ov::test::utils::vec2str(axes) << "_";
result << "EpsMode=" << epsMode << "_";
result << "Epsilon=" << eps;
return result.str();
}
protected:
void SetUp() override {
targetDevice = ov::test::utils::DEVICE_GPU;
InputShape inputShapes;
ElementType netPrecision;
std::vector<int64_t> axes;
ngraph::op::EpsMode epsMode;
float eps;
std::tie(inputShapes, netPrecision, axes, epsMode, eps) = this->GetParam();
init_input_shapes({inputShapes});
auto param = ngraph::builder::makeDynamicParams(netPrecision, inputDynamicShapes);
auto paramOuts = ngraph::helpers::convert2OutputVector(ngraph::helpers::castOps2Nodes<ngraph::op::Parameter>(param));
auto normalize = ngraph::builder::makeNormalizeL2(paramOuts[0], axes, eps, epsMode);
ngraph::ResultVector results{std::make_shared<ngraph::opset4::Result>(normalize)};
function = std::make_shared<ngraph::Function>(results, param, "NormalizeL2");
}
};
TEST_P(NormalizeL2LayerGPUTest, CompareWithRefs) {
SKIP_IF_CURRENT_TEST_IS_DISABLED()
run();
}
namespace {
const std::vector<InputShape> inputShapes_1D = {
{
// dynamic
{{1, 20}},
// target
{
{1},
{16},
{4},
{16}
}
}
};
const std::vector<InputShape> inputShapes_3D = {
{
// dynamic
{-1, -1, -1},
// target
{
{2, 16, 6},
{4, 16, 2},
{2, 16, 6},
{4, 16, 2}
}
},
{
// dynamic
{{1, 5}, {1, 20}, {1, 7}},
// target
{
{1, 1, 1},
{2, 16, 6},
{4, 16, 2},
{2, 16, 6}
}
}
};
const std::vector<InputShape> inputShapes_4D = {
{
// dynamic
{-1, -1, -1, -1},
// target
{
{2, 16, 10, 6},
{4, 16, 2, 2},
{2, 16, 10, 6},
{4, 16, 2, 2}
}
},
{
// dynamic
{{1, 5}, {1, 20}, {1, 10}, {1, 7}},
// target
{
{1, 1, 1, 1},
{2, 16, 10, 6},
{4, 16, 2, 2},
{2, 16, 10, 6}
}
}
};
const std::vector<InputShape> inputShapes_5D = {
{
// dynamic
{-1, -1, -1, -1, -1},
// target
{
{2, 16, 5, 10, 6},
{4, 16, 7, 2, 2},
{2, 16, 5, 10, 6},
{4, 16, 7, 2, 2}
}
},
{
// dynamic
{{1, 5}, {1, 20}, {1, 7}, {1, 10}, {1, 7}},
// target
{
{1, 1, 1, 1, 1},
{2, 16, 5, 10, 6},
{4, 16, 7, 2, 2},
{2, 16, 5, 10, 6}
}
}
};
const std::vector<ngraph::op::EpsMode> epsMode = {
ngraph::op::EpsMode::ADD, ngraph::op::EpsMode::MAX
};
const std::vector<float> epsilon = {
0.000000001
};
const std::vector<int64_t> reduction_axes_1234 = {1, 2, 3, 4};
const std::vector<int64_t> reduction_axes_234 = {2, 3, 4};
const std::vector<int64_t> reduction_axes_123 = {1, 2, 3};
const std::vector<int64_t> reduction_axes_23 = {2, 3};
const std::vector<int64_t> reduction_axes_12 = {1, 2};
const std::vector<int64_t> reduction_axes_3 = {3};
const std::vector<int64_t> reduction_axes_2 = {2};
std::vector<ElementType> nrtPrecision = {ElementType::f16, ElementType::f32};
const auto NormalizeL2_3D = ::testing::Combine(
::testing::ValuesIn(inputShapes_3D),
::testing::ValuesIn(nrtPrecision),
::testing::ValuesIn({reduction_axes_12, reduction_axes_2}),
::testing::ValuesIn(epsMode),
::testing::ValuesIn(epsilon));
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NormalizeL2_3D, NormalizeL2LayerGPUTest, NormalizeL2_3D, NormalizeL2LayerGPUTest::getTestCaseName);
const auto NormalizeL2_4D = ::testing::Combine(
::testing::ValuesIn(inputShapes_4D),
::testing::ValuesIn(nrtPrecision),
::testing::ValuesIn({reduction_axes_2, reduction_axes_3, reduction_axes_12, reduction_axes_23, reduction_axes_123}),
::testing::ValuesIn(epsMode),
::testing::ValuesIn(epsilon));
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NormalizeL2_4D, NormalizeL2LayerGPUTest, NormalizeL2_4D, NormalizeL2LayerGPUTest::getTestCaseName);
const auto NormalizeL2_5D = ::testing::Combine(
::testing::ValuesIn(inputShapes_5D),
::testing::ValuesIn(nrtPrecision),
::testing::ValuesIn({reduction_axes_3, reduction_axes_23, reduction_axes_123, reduction_axes_1234}),
::testing::ValuesIn(epsMode),
::testing::ValuesIn(epsilon));
INSTANTIATE_TEST_SUITE_P(smoke_CompareWithRefs_NormalizeL2_5D, NormalizeL2LayerGPUTest, NormalizeL2_5D, NormalizeL2LayerGPUTest::getTestCaseName);
} // namespace
} // namespace GPULayerTestsDefinitions