From 8390f40788dcc28ad8f12f8f9ee6c07b9c83fcf8 Mon Sep 17 00:00:00 2001 From: Edward Shogulin Date: Thu, 17 Jun 2021 12:36:25 +0300 Subject: [PATCH] [LPT] Empty shape on weights handling: cherry-pick to master (#6170) * [LPT] empty shape on weights fix * [LPT] SplitTransformation naming fix * [LPT] tests Co-authored-by: Vladislav Golubev --- .../src/split.cpp | 6 +-- .../src/weightable_layer_transformation.cpp | 9 +++- ...nvolution_backprop_data_transformation.cpp | 41 +++++++++++++++++++ ...nvolution_backprop_data_transformation.cpp | 7 ++++ .../convolution_transformation.cpp | 8 ++++ ...nvolution_backprop_data_transformation.cpp | 7 ++++ .../convolution_transformation.cpp | 8 ++++ 7 files changed, 81 insertions(+), 5 deletions(-) diff --git a/inference-engine/src/low_precision_transformations/src/split.cpp b/inference-engine/src/low_precision_transformations/src/split.cpp index 486111dd73778a..919c6b5e87b185 100644 --- a/inference-engine/src/low_precision_transformations/src/split.cpp +++ b/inference-engine/src/low_precision_transformations/src/split.cpp @@ -111,13 +111,13 @@ void SplitTransformation::updateOutputs( updateOutput(context, lastNodes[0], originalNode); } else { const std::string originalName = originalNode->get_friendly_name(); - for (auto& lastNode : lastNodes) { + for (size_t outIdx = 0; outIdx < lastNodes.size(); ++outIdx) { for (size_t i = 0; i < outputSize; ++i) { std::shared_ptr result = context.function->get_output_op(i); std::shared_ptr outputNode = result->get_input_node_shared_ptr(0); - if (outputNode.get() == lastNode.get()) { + if (outputNode.get() == lastNodes[outIdx].get()) { originalNode->set_friendly_name(originalName + LayerTransformation::originalLayerPostfix); - lastNode->set_friendly_name(originalName + "." + std::to_string(i)); + lastNodes[outIdx]->set_friendly_name(originalName + "." + std::to_string(outIdx)); break; } } diff --git a/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp b/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp index ce0ae3473d92e5..babcc95303cffe 100644 --- a/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp +++ b/inference-engine/src/low_precision_transformations/src/weightable_layer_transformation.cpp @@ -157,10 +157,15 @@ bool WeightableLayerTransformation::canBeTransformed(const TransformationContext } const size_t outChannelsShapeIndex = is_type(layer) ? 1ul : 0ul; - if ( // Check if all dimensions of scale except the output channels are all ones + if ( + // expected, it's ok: return true + (shape_size(constOutputShape) != 1ul) && + // not expected, something wrong: return false + ((constOutputShape.size() <= outChannelsShapeIndex) || + // Check if all dimensions of scale except the output channels are all ones (shape_size(constOutputShape) != constOutputShape[outChannelsShapeIndex]) || ((constOutputShape[outChannelsShapeIndex] != 1ul) && - (fqFromWeights->get_output_shape(0)[outChannelsShapeIndex] != constOutputShape[outChannelsShapeIndex]))) { + (fqFromWeights->get_output_shape(0)[outChannelsShapeIndex] != constOutputShape[outChannelsShapeIndex])))) { return false; } } else { diff --git a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp index 8e89b952526462..10ba4513f20549 100644 --- a/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp +++ b/inference-engine/tests/functional/inference_engine/lp_transformations/convolution_backprop_data_transformation.cpp @@ -116,6 +116,7 @@ class ConvolutionBackpropDataTransformation : public LayerTransformation, public SimpleLowPrecisionTransformer transform; transform.add(testValues.params); transform.transform(actualFunction); + std::shared_ptr refWeights = pass::low_precision::fold( testValues.expected.weights, opset1::Constant::create( @@ -202,6 +203,26 @@ const std::vector testValues = true } }, + // with zero point + { + LayerTransformation::createParamsU8I8(), + // ActualValues + { + ngraph::element::u8, + {{ngraph::element::f32}, { 128.f }, { 0.02f }}, + { 255ul, Shape({}), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }, + op::Constant::create(ngraph::element::i8, ngraph::Shape{}, std::vector{ 2.f }) + }, + // ExpectedValues + { + ngraph::element::u8, + {{}, { { 128.f }, ngraph::element::f32, {}, false }, {}}, + {}, + {{}, {}, {{ 0.0002f }, ngraph::element::f32, { 1 }}}, + op::Constant::create(ngraph::element::i8, ngraph::Shape{}, std::vector{ -125.f }), + true + } + }, // updatePrecisions = false { LayerTransformation::createParamsU8I8().setUpdatePrecisions(false), @@ -262,6 +283,26 @@ const std::vector testValues = true } }, + // without zero point + { + LayerTransformation::createParamsU8I8(), + // ActualValues + { + ngraph::element::u8, + {{ngraph::element::f32}, {}, { 0.02f }}, + { 255ul, Shape({}), { 0.f }, { 254.f }, { -1.27f }, { 1.27f } }, + op::Constant::create(ngraph::element::i8, ngraph::Shape{}, std::vector{ 2.f }) + }, + // ExpectedValues + { + ngraph::element::u8, + {}, + {}, + {{}, {}, {{ 0.0002f }, ngraph::element::f32, { 1 }}}, + op::Constant::create(ngraph::element::i8, ngraph::Shape{}, std::vector{ -125.f }), + true + } + }, // QDq version { LayerTransformation::createParamsU8I8(), diff --git a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp index a6e2e93a37ebb8..223f9743a61888 100644 --- a/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp +++ b/inference-engine/tests/functional/plugin/cpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp @@ -27,6 +27,13 @@ const std::vector params "Convolution", "U8" }, + { + { 256ul, ngraph::Shape {}, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + false, + { 255ul, ngraph::Shape {}, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "U8" + }, { { 16ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, false, diff --git a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp index 2cf625b58628a6..697059e3ce24bf 100644 --- a/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp +++ b/inference-engine/tests/functional/plugin/gpu/shared_tests_instances/low_precision_transformations/convolution_backprop_data_transformation.cpp @@ -28,6 +28,13 @@ const std::vector params "Convolution", "U8" }, + { + { 256ul, ngraph::Shape {}, { 0.f }, { 255.f }, { 0.f }, { 25.5f } }, + false, + { 255ul, ngraph::Shape {}, { 0.f }, { 254.f }, { -12.7f }, { 12.7f } }, + false, + "Convolution", + "U8" + }, { { 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { -12.75f }, { 6.375f } }, true,