[Func Test] Upgrade func test of QuantizedConvolutionBatchNorm related to 2.0 (#21053)

* [Func Test] Upgrade func test of QuantizedConvolutionBatchNorm related to 2.0

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] fix QuantizedConvolutionBatchNorm test error, caused by error input

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] fix format issue

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] Fix errors

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] Fix format issue

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] Fix TransformationTestsF test error

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] Fix test error

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

* [Func Test] Fix review comments

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>

---------

Signed-off-by: Zhai, Xuejun <xuejun.zhai@intel.com>
This commit is contained in:
Xuejun Zhai 2023-11-24 17:07:15 +08:00 committed by GitHub
parent 63e7e2dd3e
commit 807b77c38e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 73 deletions

View File

@ -4,7 +4,7 @@
#include "subgraph_tests/quantized_convolution_batch_norm.hpp"
using namespace SubgraphTestsDefinitions;
using namespace ov::test;
namespace {

View File

@ -5,12 +5,15 @@
#pragma once
#include "shared_test_classes/subgraph/quantized_convolution_batch_norm.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {
TEST_P(QuantizedConvolutionBatchNorm, CompareWithRefs) {
SKIP_IF_CURRENT_TEST_IS_DISABLED();
Run();
run();
}
} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov

View File

@ -4,9 +4,10 @@
#pragma once
#include "shared_test_classes/base/layer_test_utils.hpp"
#include "shared_test_classes/base/ov_subgraph.hpp"
namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {
enum class ConvType {
CONVOLUTION,
@ -28,7 +29,7 @@ enum class IntervalsType {
using QuantizedConvolutionBatchNormParams = std::tuple<ConvType, QuantizeType, IntervalsType, bool, std::string>;
class QuantizedConvolutionBatchNorm : public testing::WithParamInterface<QuantizedConvolutionBatchNormParams>,
virtual public LayerTestsUtils::LayerTestsCommon {
virtual public SubgraphBaseStaticTest {
public:
static std::string getTestCaseName(const testing::TestParamInfo<QuantizedConvolutionBatchNormParams>& obj);
@ -37,4 +38,5 @@ protected:
void TearDown() override;
};
} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov

View File

@ -220,10 +220,8 @@ ov::runtime::Tensor generate(const std::shared_ptr<ngraph::op::v0::FakeQuantize>
case 4:
return ov::test::utils::create_tensor<float>(elemType, targetShape, outputHighData, outputHighData.size());
default: {
float min = +5.f, max = +25.f;
InputGenerateData inGenData;
inGenData.range = max - min;
inGenData.range = 10.f;
inGenData.resolution = 1.0f;
inGenData.seed = seed;

View File

@ -3,10 +3,12 @@
//
#include "shared_test_classes/subgraph/quantized_convolution_batch_norm.hpp"
#include "functional_test_utils/skip_tests_config.hpp"
#include "openvino/runtime/exec_model_info.hpp"
#include "ov_models/builders.hpp"
#include <exec_graph_info.hpp>
namespace SubgraphTestsDefinitions {
namespace ov {
namespace test {
std::ostream& operator<<(std::ostream& os, ConvType type) {
switch (type) {
@ -60,8 +62,6 @@ std::string QuantizedConvolutionBatchNorm::getTestCaseName(const testing::TestPa
return name.str();
}
using namespace ngraph;
void QuantizedConvolutionBatchNorm::SetUp() {
ConvType conv_type;
QuantizeType quantize_type;
@ -71,7 +71,7 @@ void QuantizedConvolutionBatchNorm::SetUp() {
size_t input_channels = 3;
size_t output_channels = 4;
auto parameter = std::make_shared<opset8::Parameter>(element::f32, Shape{1, input_channels, 14, 14});
auto parameter = std::make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, input_channels, 14, 14});
Shape input_intervals_shape;
Shape weights_intervals_shape;
Shape weights_shape{output_channels, input_channels, 1, 1};
@ -93,89 +93,89 @@ void QuantizedConvolutionBatchNorm::SetUp() {
weights_intervals_shape = {weights_intervals_shape[2], weights_intervals_shape[0], weights_intervals_shape[3], weights_intervals_shape[1]};
}
}
auto low_act = opset8::Constant::create(element::f32, input_intervals_shape, {0});
auto high_act = opset8::Constant::create(element::f32, input_intervals_shape, {20});
auto low_weights = opset8::Constant::create(element::f32, weights_intervals_shape, {-0.72519057});
auto high_weights = opset8::Constant::create(element::f32, weights_intervals_shape, {0.72519057});
auto low_act = ov::op::v0::Constant::create(element::f32, input_intervals_shape, {0});
auto high_act = ov::op::v0::Constant::create(element::f32, input_intervals_shape, {20});
auto low_weights = ov::op::v0::Constant::create(element::f32, weights_intervals_shape, {-0.72519057});
auto high_weights = ov::op::v0::Constant::create(element::f32, weights_intervals_shape, {0.72519057});
std::shared_ptr<Node> activations = nullptr;
std::shared_ptr<Node> weights = builder::makeConstant(element::f32, weights_shape, {}, true, 0.5f, -0.5f);
std::shared_ptr<Node> weights = ngraph::builder::makeConstant(element::f32, weights_shape, {}, true, 0.5f, -0.5f);
if (quantize_type == QuantizeType::FAKE_QUANTIZE) {
activations = std::make_shared<opset8::FakeQuantize>(parameter, low_act, high_act, low_act, high_act, 256);
weights = std::make_shared<opset8::FakeQuantize>(weights, low_weights, high_weights, low_weights, high_weights, 255);
activations = std::make_shared< ov::op::v0::FakeQuantize>(parameter, low_act, high_act, low_act, high_act, 256);
weights = std::make_shared< ov::op::v0::FakeQuantize>(weights, low_weights, high_weights, low_weights, high_weights, 255);
} else if (quantize_type == QuantizeType::QUANTIZE_DEQUANTIZE) {
auto output_low_act = opset8::Constant::create(element::f32, Shape{}, {0});
auto output_high_act = opset8::Constant::create(element::f32, Shape{}, {255});
activations = std::make_shared<opset8::FakeQuantize>(parameter, low_act, high_act, output_low_act, output_high_act, 256);
activations = std::make_shared<opset8::Convert>(activations, element::u8);
activations = std::make_shared<opset8::Convert>(activations, element::f32);
std::shared_ptr<Node> shift_act = opset8::Constant::create(element::u8, input_intervals_shape, {0});
shift_act = std::make_shared<opset8::Convert>(shift_act, element::f32);
activations = std::make_shared<opset8::Subtract>(activations, shift_act);
auto scale_act = opset8::Constant::create(element::f32, input_intervals_shape, {20.0 / 255.0});
activations = std::make_shared<opset8::Multiply>(activations, scale_act);
auto output_low_act = ov::op::v0::Constant::create(element::f32, Shape{}, {0});
auto output_high_act = ov::op::v0::Constant::create(element::f32, Shape{}, {255});
activations = std::make_shared< ov::op::v0::FakeQuantize>(parameter, low_act, high_act, output_low_act, output_high_act, 256);
activations = std::make_shared< ov::op::v0::Convert>(activations, element::u8);
activations = std::make_shared< ov::op::v0::Convert>(activations, element::f32);
std::shared_ptr<Node> shift_act = ov::op::v0::Constant::create(element::u8, input_intervals_shape, {0});
shift_act = std::make_shared< ov::op::v0::Convert>(shift_act, element::f32);
activations = std::make_shared<ov::op::v1::Subtract>(activations, shift_act);
auto scale_act = ov::op::v0::Constant::create(element::f32, input_intervals_shape, {20.0 / 255.0});
activations = std::make_shared<ov::op::v1::Multiply>(activations, scale_act);
auto output_low_weights = opset8::Constant::create(element::f32, Shape{}, {0});
auto output_high_weights = opset8::Constant::create(element::f32, Shape{}, {254});
weights = std::make_shared<opset8::FakeQuantize>(weights, low_weights, high_weights, output_low_weights, output_high_weights, 255);
weights = std::make_shared<opset8::Convert>(weights, element::i8);
weights = std::make_shared<opset8::Convert>(weights, element::f32);
std::shared_ptr<Node> shift_weights = opset8::Constant::create(element::i8, weights_intervals_shape, {0});
shift_weights = std::make_shared<opset8::Convert>(shift_weights, element::f32);
weights = std::make_shared<opset8::Subtract>(weights, shift_weights);
auto scale_weights = opset8::Constant::create(element::f32, weights_intervals_shape, {2.0 / 255.0});
weights = std::make_shared<opset8::Multiply>(weights, scale_weights);
auto output_low_weights = ov::op::v0::Constant::create(element::f32, Shape{}, {0});
auto output_high_weights = ov::op::v0::Constant::create(element::f32, Shape{}, {254});
weights = std::make_shared<ov::op::v0::FakeQuantize>(weights, low_weights, high_weights, output_low_weights, output_high_weights, 255);
weights = std::make_shared<ov::op::v0::Convert>(weights, element::i8);
weights = std::make_shared<ov::op::v0::Convert>(weights, element::f32);
std::shared_ptr<Node> shift_weights = ov::op::v0::Constant::create(element::i8, weights_intervals_shape, {0});
shift_weights = std::make_shared<ov::op::v0::Convert>(shift_weights, element::f32);
weights = std::make_shared<ov::op::v1::Subtract>(weights, shift_weights);
auto scale_weights = ov::op::v0::Constant::create(element::f32, weights_intervals_shape, {2.0 / 255.0});
weights = std::make_shared<ov::op::v1::Multiply>(weights, scale_weights);
} else if (quantize_type == QuantizeType::COMPRESSED_WEIGHTS) {
auto output_low_act = opset8::Constant::create(element::f32, Shape{}, {0});
auto output_high_act = opset8::Constant::create(element::f32, Shape{}, {255});
activations = std::make_shared<opset8::FakeQuantize>(parameter, low_act, high_act, output_low_act, output_high_act, 256);
activations = std::make_shared<opset8::Convert>(activations, element::u8);
activations = std::make_shared<opset8::Convert>(activations, element::f32);
std::shared_ptr<Node> shift_act = opset8::Constant::create(element::u8, input_intervals_shape, {0});
shift_act = std::make_shared<opset8::Convert>(shift_act, element::f32);
activations = std::make_shared<opset8::Subtract>(activations, shift_act);
auto scale_act = opset8::Constant::create(element::f32, input_intervals_shape, {20.0 / 255.0});
activations = std::make_shared<opset8::Multiply>(activations, scale_act);
auto output_low_act = ov::op::v0::Constant::create(element::f32, Shape{}, {0});
auto output_high_act = ov::op::v0::Constant::create(element::f32, Shape{}, {255});
activations = std::make_shared<ov::op::v0::FakeQuantize>(parameter, low_act, high_act, output_low_act, output_high_act, 256);
activations = std::make_shared<ov::op::v0::Convert>(activations, element::u8);
activations = std::make_shared<ov::op::v0::Convert>(activations, element::f32);
std::shared_ptr<Node> shift_act = ov::op::v0::Constant::create(element::u8, input_intervals_shape, {0});
shift_act = std::make_shared<ov::op::v0::Convert>(shift_act, element::f32);
activations = std::make_shared<ov::op::v1::Subtract>(activations, shift_act);
auto scale_act = ov::op::v0::Constant::create(element::f32, input_intervals_shape, {20.0 / 255.0});
activations = std::make_shared<ov::op::v1::Multiply>(activations, scale_act);
auto output_low_weights = opset8::Constant::create(element::f32, Shape{}, {0});
auto output_high_weights = opset8::Constant::create(element::f32, Shape{}, {254});
weights = std::make_shared<opset8::FakeQuantize>(weights, low_weights, high_weights, output_low_weights, output_high_weights, 255);
weights = std::make_shared<opset8::Convert>(weights, element::i8);
auto output_low_weights = ov::op::v0::Constant::create(element::f32, Shape{}, {0});
auto output_high_weights = ov::op::v0::Constant::create(element::f32, Shape{}, {254});
weights = std::make_shared<ov::op::v0::FakeQuantize>(weights, low_weights, high_weights, output_low_weights, output_high_weights, 255);
weights = std::make_shared<ov::op::v0::Convert>(weights, element::i8);
OPENVINO_SUPPRESS_DEPRECATED_START
weights = get_constant_from_source(weights);
OPENVINO_SUPPRESS_DEPRECATED_END
weights = std::make_shared<opset8::Convert>(weights, element::f32);
auto scale_weights = opset8::Constant::create(element::f32, weights_intervals_shape, {2.0 / 255.0});
weights = std::make_shared<opset8::Multiply>(weights, scale_weights);
weights = std::make_shared<ov::op::v0::Convert>(weights, element::f32);
auto scale_weights = ov::op::v0::Constant::create(element::f32, weights_intervals_shape, {2.0 / 255.0});
weights = std::make_shared<ov::op::v1::Multiply>(weights, scale_weights);
}
if (transpose_on_weights) {
weights = std::make_shared<opset8::Transpose>(weights, opset8::Constant::create(element::i32, Shape{4}, {1, 3, 0, 2}));
weights = std::make_shared<ov::op::v1::Transpose>(weights, ov::op::v0::Constant::create(element::i32, Shape{4}, {1, 3, 0, 2}));
}
std::shared_ptr<Node> conv;
if (conv_type == ConvType::CONVOLUTION) {
conv = std::make_shared<opset8::Convolution>(activations, weights, Strides{1, 1},
conv = std::make_shared<ov::op::v1::Convolution>(activations, weights, Strides{1, 1},
CoordinateDiff{0, 0}, CoordinateDiff{0, 0}, Strides{1, 1});
} else {
conv = std::make_shared<opset8::ConvolutionBackpropData>(activations, weights, Strides{1, 1},
conv = std::make_shared<ov::op::v1::ConvolutionBackpropData>(activations, weights, Strides{1, 1},
CoordinateDiff{0, 0}, CoordinateDiff{0, 0}, Strides{1, 1});
}
auto gamma = builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto beta = builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto mean = builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto var = builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto batch_norm = std::make_shared<opset8::BatchNormInference>(conv, gamma, beta, mean, var, 0.00001);
function = std::make_shared<ngraph::Function>(batch_norm, ParameterVector{parameter});
auto gamma = ngraph::builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto beta = ngraph::builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto mean = ngraph::builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto var = ngraph::builder::makeConstant(element::f32, Shape{output_channels}, {}, true, 1.0f, 0.1f);
auto batch_norm = std::make_shared<ov::op::v5::BatchNormInference>(conv, gamma, beta, mean, var, 0.00001);
function = std::make_shared<ov::Model>(batch_norm, ParameterVector{parameter});
}
void QuantizedConvolutionBatchNorm::TearDown() {
SKIP_IF_CURRENT_TEST_IS_DISABLED();
auto get_layer_type = [] (const std::shared_ptr<ngraph::Node>& node) -> const std::string& {
auto get_layer_type = [] (const std::shared_ptr<ov::Node>& node) -> const std::string& {
const auto& rt_info = node->get_rt_info();
auto it = rt_info.find(ExecGraphInfoSerialization::LAYER_TYPE);
auto it = rt_info.find(ov::exec_model_info::LAYER_TYPE);
IE_ASSERT(it != rt_info.end());
return it->second.as<std::string>();
};
auto runtime_function = executableNetwork.GetExecGraphInfo().getFunction();
auto runtime_function = compiledModel.get_runtime_model();
int ops_found = 0;
for (const auto& node : runtime_function->get_ordered_ops()) {
const auto& layer_type = get_layer_type(node);
@ -189,4 +189,5 @@ void QuantizedConvolutionBatchNorm::TearDown() {
ASSERT_GT(ops_found, 0);
}
} // namespace SubgraphTestsDefinitions
} // namespace test
} // namespace ov

View File

@ -570,6 +570,7 @@ void fill_tensor_random(ov::Tensor& tensor,
CASE(ov::element::i16)
CASE(ov::element::i32)
CASE(ov::element::i64)
CASE(ov::element::boolean)
default:
OPENVINO_THROW("Wrong precision specified: ", element_type);
}