Skip to content

Commit

Permalink
[Func Test] Upgrade func test of QuantGroupConvBackpropDataLayerTest …
Browse files Browse the repository at this point in the history
…related to 2.0 (openvinotoolkit#21094)

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
  • Loading branch information
zhaixuejun1993 authored Nov 15, 2023
1 parent 6755a7e commit 8eb529c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
#include "subgraph_tests/quantized_group_convolution_backprop_data.hpp"
#include "common_test_utils/test_constants.hpp"

using namespace SubgraphTestsDefinitions;
using namespace ov::test;
using namespace ov::test::utils;

namespace {

const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32
};
const std::vector<ov::element::Type> netPrecisions = {ov::element::f32};

const std::vector<size_t> numOutChannels = {16, 32};
const std::vector<size_t> numGroups = {2, 8, 16};
Expand All @@ -24,12 +23,12 @@ const std::vector<ov::test::utils::QuantizationGranularity> granularity = {
ov::test::utils::QuantizationGranularity::Perchannel};

/* ============= 2D GroupConvolutionBackpropData ============= */
const std::vector<std::vector<size_t >> inputShapes2D = {{1, 16, 10, 10}, {1, 32, 10, 10}};
const std::vector<std::vector<size_t >> kernels2D = {{1, 1}, {3, 3}};
const std::vector<std::vector<size_t >> strides2D = {{1, 1}};
const std::vector<ov::Shape> inputShapes2D = {{1, 16, 10, 10}, {1, 32, 10, 10}};
const std::vector<ov::Shape> kernels2D = {{1, 1}, {3, 3}};
const std::vector<ov::Shape> strides2D = {{1, 1}};
const std::vector<std::vector<ptrdiff_t>> padBegins2D = {{0, 0}};
const std::vector<std::vector<ptrdiff_t>> padEnds2D = {{0, 0}};
const std::vector<std::vector<size_t >> dilations2D = {{1, 1}};
const std::vector<ov::Shape> dilations2D = {{1, 1}};


const auto quantGroupConvBackpropData2DParams = ::testing::Combine(
Expand All @@ -40,7 +39,7 @@ const auto quantGroupConvBackpropData2DParams = ::testing::Combine(
::testing::ValuesIn(dilations2D),
::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups),
::testing::Values(ngraph::op::PadType::AUTO),
::testing::Values(ov::op::PadType::AUTO),
::testing::ValuesIn(levels),
::testing::ValuesIn(granularity)
);
Expand All @@ -54,12 +53,12 @@ INSTANTIATE_TEST_SUITE_P(smoke_QuantGroupConvBackpropData2D, QuantGroupConvBackp
QuantGroupConvBackpropDataLayerTest::getTestCaseName);

/* ============= 3D GroupConvolutionBackpropData ============= */
const std::vector<std::vector<size_t >> inputShapes3D = {{1, 16, 5, 5, 5}, {1, 32, 5, 5, 5}};
const std::vector<std::vector<size_t >> kernels3D = {{3, 3, 3}};
const std::vector<std::vector<size_t >> strides3D = {{1, 1, 1}};
const std::vector<ov::Shape> inputShapes3D = {{1, 16, 5, 5, 5}, {1, 32, 5, 5, 5}};
const std::vector<ov::Shape> kernels3D = {{3, 3, 3}};
const std::vector<ov::Shape> strides3D = {{1, 1, 1}};
const std::vector<std::vector<ptrdiff_t>> padBegins3D = {{0, 0, 0}};
const std::vector<std::vector<ptrdiff_t>> padEnds3D = {{0, 0, 0}};
const std::vector<std::vector<size_t >> dilations3D = {{1, 1, 1}};
const std::vector<ov::Shape> dilations3D = {{1, 1, 1}};

const auto quantGroupConvBackpropData3DParams = ::testing::Combine(
::testing::ValuesIn(kernels3D),
Expand All @@ -69,7 +68,7 @@ const auto quantGroupConvBackpropData3DParams = ::testing::Combine(
::testing::ValuesIn(dilations3D),
::testing::ValuesIn(numOutChannels),
::testing::ValuesIn(numGroups),
::testing::Values(ngraph::op::PadType::AUTO),
::testing::Values(ov::op::PadType::AUTO),
::testing::ValuesIn(levels),
::testing::ValuesIn(granularity)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@
#include "subgraph_tests/quantized_group_convolution_backprop_data.hpp"
#include "common_test_utils/test_constants.hpp"

using namespace SubgraphTestsDefinitions;
using namespace ngraph::helpers;
using namespace ov::test;
using namespace ov::test::utils;

namespace {

const std::vector<InferenceEngine::Precision> netPrecisions = {
InferenceEngine::Precision::FP32
};
const std::vector<ov::element::Type> element_types = {ov::element::f32};

const std::vector<size_t> numOutChannels = {16, 32};
const std::vector<size_t> numGroups = {2, 8, 16};

const std::vector<size_t > levels = {256};
const std::vector<size_t> levels = {256};
const std::vector<QuantizationGranularity > granularity = {QuantizationGranularity::Pertensor, QuantizationGranularity::Perchannel};

/* ============= 2D GroupConvolutionBackpropData ============= */
const std::vector<std::vector<size_t >> inputShapes2D = {{1, 16, 10, 10}, {1, 32, 10, 10}};
const std::vector<std::vector<size_t >> kernels2D = {{1, 1}, {3, 3}};
const std::vector<std::vector<size_t >> strides2D = {{1, 1}};
const std::vector<ov::Shape> inputShapes2D = {{1, 16, 10, 10}, {1, 32, 10, 10}};
const std::vector<ov::Shape> kernels2D = {{1, 1}, {3, 3}};
const std::vector<ov::Shape> strides2D = {{1, 1}};
const std::vector<std::vector<ptrdiff_t>> padBegins2D = {{0, 0}};
const std::vector<std::vector<ptrdiff_t>> padEnds2D = {{0, 0}};
const std::vector<std::vector<size_t >> dilations2D = {{1, 1}};
const std::vector<ov::Shape> dilations2D = {{1, 1}};

const auto quantGroupConvBackpropData2DParams = ::testing::Combine(
::testing::ValuesIn(kernels2D),
Expand All @@ -46,18 +44,18 @@ const auto quantGroupConvBackpropData2DParams = ::testing::Combine(
INSTANTIATE_TEST_SUITE_P(smoke_QuantGroupConvBackpropData2D, QuantGroupConvBackpropDataLayerTest,
::testing::Combine(
quantGroupConvBackpropData2DParams,
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(element_types),
::testing::ValuesIn(inputShapes2D),
::testing::Values(ov::test::utils::DEVICE_GPU)),
QuantGroupConvBackpropDataLayerTest::getTestCaseName);

/* ============= 3D GroupConvolutionBackpropData ============= */
const std::vector<std::vector<size_t >> inputShapes3D = {{1, 16, 5, 5, 5}, {1, 32, 5, 5, 5}};
const std::vector<std::vector<size_t >> kernels3D = {{3, 3, 3}};
const std::vector<std::vector<size_t >> strides3D = {{1, 1, 1}};
const std::vector<ov::Shape> inputShapes3D = {{1, 16, 5, 5, 5}, {1, 32, 5, 5, 5}};
const std::vector<ov::Shape> kernels3D = {{3, 3, 3}};
const std::vector<ov::Shape> strides3D = {{1, 1, 1}};
const std::vector<std::vector<ptrdiff_t>> padBegins3D = {{0, 0, 0}};
const std::vector<std::vector<ptrdiff_t>> padEnds3D = {{0, 0, 0}};
const std::vector<std::vector<size_t >> dilations3D = {{1, 1, 1}};
const std::vector<ov::Shape> dilations3D = {{1, 1, 1}};

const auto quantGroupConvBackpropData3DParams = ::testing::Combine(
::testing::ValuesIn(kernels3D),
Expand All @@ -75,7 +73,7 @@ const auto quantGroupConvBackpropData3DParams = ::testing::Combine(
INSTANTIATE_TEST_SUITE_P(smoke_QuantGroupConvBackpropData3D, QuantGroupConvBackpropDataLayerTest,
::testing::Combine(
quantGroupConvBackpropData3DParams,
::testing::ValuesIn(netPrecisions),
::testing::ValuesIn(element_types),
::testing::ValuesIn(inputShapes3D),
::testing::Values(ov::test::utils::DEVICE_GPU)),
QuantGroupConvBackpropDataLayerTest::getTestCaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#include "shared_test_classes/subgraph/quantized_group_convolution_backprop_data.hpp"

namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {

TEST_P(QuantGroupConvBackpropDataLayerTest, CompareWithRefs) {
Run();
run();
}

} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,37 @@
#include <string>
#include <memory>

#include "shared_test_classes/base/layer_test_utils.hpp"
#include "ov_models/builders.hpp"
#include "ov_models/utils/ov_helpers.hpp"
#include "common_test_utils/test_enums.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"

namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {

typedef std::tuple<
InferenceEngine::SizeVector,
InferenceEngine::SizeVector,
ov::Shape,
ov::Shape,
std::vector<ptrdiff_t>,
std::vector<ptrdiff_t>,
InferenceEngine::SizeVector,
ov::Shape,
size_t,
size_t,
ngraph::op::PadType,
ov::op::PadType,
size_t,
ov::test::utils::QuantizationGranularity> quantGroupConvBackpropDataSpecificParams;
typedef std::tuple<
quantGroupConvBackpropDataSpecificParams,
InferenceEngine::Precision,
InferenceEngine::SizeVector,
LayerTestsUtils::TargetDevice> quantGroupConvBackpropDataLayerTestParamsSet;
ov::element::Type,
ov::Shape,
std::string> quantGroupConvBackpropDataLayerTestParamsSet;

class QuantGroupConvBackpropDataLayerTest : public testing::WithParamInterface<quantGroupConvBackpropDataLayerTestParamsSet>,
virtual public LayerTestsUtils::LayerTestsCommon {
virtual public ov::test::SubgraphBaseStaticTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<quantGroupConvBackpropDataLayerTestParamsSet>& obj);

protected:
void SetUp() override;
};

} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
//

#include "shared_test_classes/subgraph/quantized_group_convolution_backprop_data.hpp"
#include "ov_models/builders.hpp"
#include "ov_models/utils/ov_helpers.hpp"

namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {

std::string QuantGroupConvBackpropDataLayerTest::getTestCaseName(const testing::TestParamInfo<quantGroupConvBackpropDataLayerTestParamsSet>& obj) {
quantGroupConvBackpropDataSpecificParams groupConvBackpropDataParams;
InferenceEngine::Precision netPrecision;
InferenceEngine::SizeVector inputShapes;
ov::element::Type element_type;
ov::Shape inputShapes;
std::string targetDevice;
std::tie(groupConvBackpropDataParams, netPrecision, inputShapes, targetDevice) = obj.param;
ngraph::op::PadType padType;
InferenceEngine::SizeVector kernel, stride, dilation;
std::tie(groupConvBackpropDataParams, element_type, inputShapes, targetDevice) = obj.param;
ov::op::PadType padType;
ov::Shape kernel, stride, dilation;
std::vector<ptrdiff_t> padBegin, padEnd;
size_t convOutChannels, numGroups;
size_t quantLevels;
Expand All @@ -32,32 +35,29 @@ std::string QuantGroupConvBackpropDataLayerTest::getTestCaseName(const testing::
result << "AP=" << padType << "_";
result << "Levels=" << quantLevels << "_";
result << "QG=" << quantGranularity << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "ET=" << element_type.get_type_name() << "_";
result << "targetDevice=" << targetDevice;
return result.str();
}

void QuantGroupConvBackpropDataLayerTest::SetUp() {
threshold = 0.5f;

quantGroupConvBackpropDataSpecificParams groupConvBackpropDataParams;
std::vector<size_t> inputShape;
auto netPrecision = InferenceEngine::Precision::UNSPECIFIED;
std::tie(groupConvBackpropDataParams, netPrecision, inputShape, targetDevice) = this->GetParam();
ngraph::op::PadType padType;
InferenceEngine::SizeVector kernel, stride, dilation;
ov::Shape inputShape;
ov::element::Type element_type = ov::element::undefined;
std::tie(groupConvBackpropDataParams, element_type, inputShape, targetDevice) = this->GetParam();
ov::op::PadType padType;
ov::Shape kernel, stride, dilation;
std::vector<ptrdiff_t> padBegin, padEnd;
size_t convOutChannels, numGroups;
size_t quantLevels;
ov::test::utils::QuantizationGranularity quantGranularity;
std::tie(kernel, stride, padBegin, padEnd, dilation, convOutChannels, numGroups, padType, quantLevels, quantGranularity) = groupConvBackpropDataParams;
auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(inputShape))};
ov::ParameterVector params{std::make_shared<ov::op::v0::Parameter>(element_type, ov::Shape(inputShape))};

std::vector<size_t> dataFqConstShapes(inputShape.size(), 1);
if (quantGranularity == ov::test::utils::QuantizationGranularity::Perchannel)
dataFqConstShapes[1] = inputShape[1];
auto dataFq = ngraph::builder::makeFakeQuantize(params[0], ngPrc, quantLevels, dataFqConstShapes);
auto dataFq = ngraph::builder::makeFakeQuantize(params[0], element_type, quantLevels, dataFqConstShapes);

std::vector<size_t> weightsShapes = {inputShape[1], convOutChannels};
if (weightsShapes[0] % numGroups || weightsShapes[1] % numGroups)
Expand All @@ -68,18 +68,19 @@ void QuantGroupConvBackpropDataLayerTest::SetUp() {
weightsShapes.insert(weightsShapes.end(), kernel.begin(), kernel.end());

std::vector<float> weightsData;
auto weightsNode = ngraph::builder::makeConstant(ngPrc, weightsShapes, weightsData, weightsData.empty());
auto weightsNode = ngraph::builder::makeConstant(element_type, weightsShapes, weightsData, weightsData.empty());

std::vector<size_t> weightsFqConstShapes(weightsShapes.size(), 1);
if (quantGranularity == ov::test::utils::QuantizationGranularity::Perchannel)
weightsFqConstShapes[0] = weightsShapes[0];

auto weightsFq = ngraph::builder::makeFakeQuantize(weightsNode, ngPrc, quantLevels, weightsFqConstShapes);
auto weightsFq = ngraph::builder::makeFakeQuantize(weightsNode, element_type, quantLevels, weightsFqConstShapes);

auto groupConvBackpropData = std::dynamic_pointer_cast<ngraph::opset1::GroupConvolutionBackpropData>(
ngraph::builder::makeGroupConvolutionBackpropData(dataFq, weightsFq, ngPrc, stride, padBegin, padEnd, dilation, padType));
ngraph::builder::makeGroupConvolutionBackpropData(dataFq, weightsFq, element_type, stride, padBegin, padEnd, dilation, padType));

ngraph::ResultVector results{std::make_shared<ngraph::opset1::Result>(groupConvBackpropData)};
function = std::make_shared<ngraph::Function>(results, params, "QuantGroupConvolutionBackpropData");
ov::ResultVector results{std::make_shared<ov::op::v0::Result>(groupConvBackpropData)};
function = std::make_shared<ov::Model>(results, params, "QuantGroupConvolutionBackpropData");
}
} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov

0 comments on commit 8eb529c

Please sign in to comment.