Skip to content

Commit

Permalink
[Func Test] Upgrade func test of QuantMatMulTest related to 2.0 (open…
Browse files Browse the repository at this point in the history
…vinotoolkit#21103)

Signed-off-by: Zhai, Xuejun <[email protected]>
  • Loading branch information
zhaixuejun1993 authored and pull[bot] committed Sep 21, 2024
1 parent 61cf409 commit 1537543
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@

#include "subgraph_tests/quantized_mat_mul.hpp"

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

namespace {

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

const std::vector<std::vector<size_t>> shapesA = {
const std::vector<ov::Shape> shapesA = {
{1, 4, 5, 6}
};

const std::vector<std::vector<size_t>> shapesB = {
const std::vector<ov::Shape> shapesB = {
{1, 4, 6, 4}
};

Expand All @@ -43,38 +42,39 @@ const std::vector<QuantRange> ranges_i32 = {
const std::vector<uint64_t> levels_8 = {256};
const std::vector<uint64_t> levels_16 = {65536};
const std::vector<uint64_t> levels_32 = {4294967296};
const std::vector<QuantizationGranularity> granularity = {QuantizationGranularity::Pertensor};
const std::vector<ov::test::utils::QuantizationGranularity> granularity = {
ov::test::utils::QuantizationGranularity::Pertensor};

const auto quantParams_i8 = ::testing::Combine(
::testing::ValuesIn(levels_8),
::testing::ValuesIn(ranges_u8),
::testing::ValuesIn(ranges_i8),
::testing::ValuesIn(granularity),
::testing::Values(InferenceEngine::Precision::I8)
::testing::Values(ov::element::i8)
);

const auto quantParams_u8 = ::testing::Combine(
::testing::ValuesIn(levels_8),
::testing::ValuesIn(ranges_u8),
::testing::ValuesIn(ranges_u8),
::testing::ValuesIn(granularity),
::testing::Values(InferenceEngine::Precision::U8)
::testing::Values(ov::element::u8)
);

const auto quantParams_i16 = ::testing::Combine(
::testing::ValuesIn(levels_16),
::testing::ValuesIn(ranges_i32),
::testing::ValuesIn(ranges_i16),
::testing::ValuesIn(granularity),
::testing::Values(InferenceEngine::Precision::I16)
::testing::Values(ov::element::i16)
);

const auto quantParams_i32 = ::testing::Combine(
::testing::ValuesIn(levels_32),
::testing::ValuesIn(ranges_i32),
::testing::ValuesIn(ranges_i32),
::testing::ValuesIn(granularity),
::testing::Values(InferenceEngine::Precision::I32)
::testing::Values(ov::element::i32)
);

INSTANTIATE_TEST_SUITE_P(smoke_QuantMatMul_i8i8, QuantMatMulTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

#include "shared_test_classes/subgraph/quantized_mat_mul.hpp"

namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {

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

} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@

#pragma once

#include <cstdint>
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "common_test_utils/test_enums.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"

#include "shared_test_classes/base/layer_test_utils.hpp"

namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {

typedef std::pair<float, float> QuantRange;

Expand All @@ -21,22 +17,23 @@ typedef std::tuple<
QuantRange,
QuantRange,
ov::test::utils::QuantizationGranularity,
InferenceEngine::Precision> QuantParams;
ov::element::Type> QuantParams;

typedef std::tuple<
QuantParams,
QuantParams,
InferenceEngine::Precision,
InferenceEngine::SizeVector,
InferenceEngine::SizeVector,
LayerTestsUtils::TargetDevice> QuantMatMulLayerTestParamsSet;
ov::element::Type,
ov::Shape,
ov::Shape,
std::string> QuantMatMulLayerTestParamsSet;

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

protected:
void SetUp() override;
};

} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,28 @@
#include "shared_test_classes/subgraph/quantized_mat_mul.hpp"
#include "ov_models/builders.hpp"

namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {

std::string QuantMatMulTest::getTestCaseName(const testing::TestParamInfo<QuantMatMulLayerTestParamsSet> &obj) {
QuantParams quantParams0;
QuantParams quantParams1;
InferenceEngine::Precision netPrecision;
InferenceEngine::SizeVector inputShape0;
InferenceEngine::SizeVector inputShape1;
ov::element::Type element_type;
ov::Shape inputShape0;
ov::Shape inputShape1;
QuantRange inputRange0;
QuantRange inputRange1;
QuantRange outputRange0;
QuantRange outputRange1;
std::string targetDevice;
std::tie(quantParams0, quantParams1, netPrecision, inputShape0, inputShape1, targetDevice) = obj.param;
std::tie(quantParams0, quantParams1, element_type, inputShape0, inputShape1, targetDevice) = obj.param;

size_t quantLevels0;
size_t quantLevels1;
ov::test::utils::QuantizationGranularity quantGranularity0;
ov::test::utils::QuantizationGranularity quantGranularity1;
InferenceEngine::Precision fqPrec0;
InferenceEngine::Precision fqPrec1;
ov::element::Type fqPrec0;
ov::element::Type fqPrec1;
std::tie(quantLevels0, inputRange0, outputRange0, quantGranularity0, fqPrec0) = quantParams0;
std::tie(quantLevels1, inputRange1, outputRange1, quantGranularity1, fqPrec1) = quantParams1;

Expand All @@ -40,20 +41,20 @@ std::string QuantMatMulTest::getTestCaseName(const testing::TestParamInfo<QuantM
result << "outputRange1=" << outputRange1.first << "_" << outputRange1.second << "_";
result << "QuantGranularity0=" << quantGranularity0 << "_";
result << "QuantGranularity1=" << quantGranularity1 << "_";
result << "fq0PRC=" << fqPrec0.name() << "_";
result << "fq1PRC=" << fqPrec1.name() << "_";
result << "netPRC=" << netPrecision.name() << "_";
result << "fq0PRC=" << fqPrec0.get_type_name() << "_";
result << "fq1PRC=" << fqPrec1.get_type_name() << "_";
result << "ET=" << element_type.get_type_name() << "_";
result << "targetDevice=" << targetDevice;
return result.str();
}

void QuantMatMulTest::SetUp() {
QuantParams quantParams0;
QuantParams quantParams1;
InferenceEngine::SizeVector inputShape0;
InferenceEngine::SizeVector inputShape1;
auto netPrecision = InferenceEngine::Precision::UNSPECIFIED;
std::tie(quantParams0, quantParams1, netPrecision, inputShape0, inputShape1, targetDevice) = this->GetParam();
ov::Shape inputShape0;
ov::Shape inputShape1;
ov::element::Type element_type;
std::tie(quantParams0, quantParams1, element_type, inputShape0, inputShape1, targetDevice) = this->GetParam();

size_t quantLevels0;
size_t quantLevels1;
Expand All @@ -63,37 +64,37 @@ void QuantMatMulTest::SetUp() {
QuantRange outputRange1;
ov::test::utils::QuantizationGranularity quantGranularity0;
ov::test::utils::QuantizationGranularity quantGranularity1;
InferenceEngine::Precision fqPrec0;
InferenceEngine::Precision fqPrec1;
ov::element::Type fqPrec0;
ov::element::Type fqPrec1;
std::tie(quantLevels0, inputRange0, outputRange0, quantGranularity0, fqPrec0) = quantParams0;
std::tie(quantLevels1, inputRange1, outputRange1, quantGranularity1, fqPrec1) = quantParams1;

auto ngPrc = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
ov::ParameterVector params {std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(inputShape0)),
std::make_shared<ov::op::v0::Parameter>(ngPrc, ov::Shape(inputShape1))};
ov::ParameterVector params {std::make_shared<ov::op::v0::Parameter>(element_type, ov::Shape(inputShape0)),
std::make_shared<ov::op::v0::Parameter>(element_type, ov::Shape(inputShape1))};

auto makeFakeQuantizeNode = [ngPrc](size_t quantLevels, QuantRange inputRange, QuantRange outputRange,
ov::test::utils::QuantizationGranularity quantGranularity, const ngraph::Output<ngraph::Node> &in, std::vector<size_t> inputShape,
InferenceEngine::Precision prec) -> std::shared_ptr<ngraph::Node> {
auto makeFakeQuantizeNode = [element_type](size_t quantLevels, QuantRange inputRange, QuantRange outputRange,
ov::test::utils::QuantizationGranularity quantGranularity, const ov::Output<ov::Node> &in, ov::Shape inputShape,
ov::element::Type prec) -> std::shared_ptr<ngraph::Node> {
std::vector<size_t> dataFqConstShapes(inputShape.size(), 1);
if (quantGranularity == ov::test::utils::QuantizationGranularity::Perchannel)
dataFqConstShapes[1] = inputShape[1];
size_t constDataSize = ngraph::shape_size(dataFqConstShapes);
size_t constDataSize = ov::shape_size(dataFqConstShapes);
std::vector<float> inputLowData(constDataSize), inputHighData(constDataSize), outputLowData(constDataSize), outputHighData(constDataSize);
for (int i = 0; i < constDataSize; i++) {
inputLowData[i] = inputRange.first;
inputHighData[i] = inputRange.second;
outputLowData[i] = outputRange.first;
outputHighData[i] = outputRange.second;
}
return ngraph::builder::makeFakeQuantize(in, ngPrc, quantLevels, dataFqConstShapes, inputLowData, inputHighData, outputLowData, outputHighData);
return ngraph::builder::makeFakeQuantize(in, element_type, quantLevels, dataFqConstShapes, inputLowData, inputHighData, outputLowData, outputHighData);
};

auto dataFq0 = makeFakeQuantizeNode(quantLevels0, inputRange0, outputRange0, quantGranularity0, params[0], inputShape0, fqPrec0);
auto dataFq1 = makeFakeQuantizeNode(quantLevels1, inputRange1, outputRange1, quantGranularity1, params[1], inputShape1, fqPrec1);

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

0 comments on commit 1537543

Please sign in to comment.