[LPT] Legacy compliance restrictions removal all: Reshape (#6870)
* [LPT] Reshape: legacy compliance restrictions removal * [LPT] comment fixes
This commit is contained in:
parent
fc39303677
commit
43f18da413
@ -151,7 +151,7 @@ public:
|
||||
|
||||
static bool isQuantizeSupported(const std::shared_ptr<opset1::FakeQuantize>& fakeQuantize);
|
||||
|
||||
static FakeQuantizeDequantization getDequantization(const std::shared_ptr<Node>& node, const size_t parentIndex = 0ul, const bool inPlace = false);
|
||||
static FakeQuantizeDequantization getDequantization(const std::shared_ptr<const Node>& node, const size_t parentIndex = 0ul, const bool inPlace = false);
|
||||
|
||||
static FakeQuantizeDequantization getDequantizationBelow(const std::shared_ptr<Node>& node, const bool convertIsMandatory = false);
|
||||
|
||||
|
@ -5,9 +5,7 @@
|
||||
#include "low_precision/concat.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@ -189,7 +187,6 @@ bool ConcatTransformation::canBeTransformed(const TransformationContext& context
|
||||
const auto outPShape = concat->get_output_partial_shape(0);
|
||||
const size_t normalizedAxis = ngraph::normalize_axis(concat->get_friendly_name(), axis, outPShape.rank());
|
||||
|
||||
// TODO: LPT: to support current flow: #58269
|
||||
if (normalizedAxis != 1ul) {
|
||||
return false;
|
||||
}
|
||||
@ -198,8 +195,6 @@ bool ConcatTransformation::canBeTransformed(const TransformationContext& context
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool perTensorQuantizationIsRequired = normalizedAxis != 1ul;
|
||||
|
||||
element::Type precision;
|
||||
for (size_t i = 0ul; i < concat->get_input_size(); i++) {
|
||||
const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(concat, i);
|
||||
@ -212,12 +207,6 @@ bool ConcatTransformation::canBeTransformed(const TransformationContext& context
|
||||
} else if (precision != dequantization.data.get_element_type()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (perTensorQuantizationIsRequired &&
|
||||
(((dequantization.subtractConstant != nullptr) && !NetworkHelper::isScalarLike(dequantization.subtractConstant)) ||
|
||||
((dequantization.multiplyConstant != nullptr) && !NetworkHelper::isScalarLike(dequantization.multiplyConstant)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1268,7 +1268,7 @@ bool NetworkHelper::isQuantizeSupported(const std::shared_ptr<opset1::FakeQuanti
|
||||
return QuantizationDetails::outputLayoutIsSupported(fakeQuantize) && QuantizationDetails::isSupportedLevel(fakeQuantize->get_levels());
|
||||
}
|
||||
|
||||
FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_ptr<Node>& node, const size_t parentIndex, const bool inPlace) {
|
||||
FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_ptr<const Node>& node, const size_t parentIndex, const bool inPlace) {
|
||||
auto getDataIndex = [](const std::shared_ptr<ngraph::Node>& node) {
|
||||
if (is_type<opset1::Constant>(node->get_input_node_ptr(1))) {
|
||||
return 0ul;
|
||||
@ -1285,7 +1285,7 @@ FakeQuantizeDequantization NetworkHelper::getDequantization(const std::shared_pt
|
||||
return 1ul;
|
||||
};
|
||||
|
||||
Output<Node> dataNode = inPlace ? node->output(0) : node->input_value(parentIndex);
|
||||
Output<Node> dataNode = inPlace ? std::const_pointer_cast<Node>(node)->output(0) : node->input_value(parentIndex);
|
||||
|
||||
const std::shared_ptr<ngraph::opset1::Multiply> multiply = as_type_ptr<ngraph::opset1::Multiply>(dataNode.get_node_shared_ptr());
|
||||
std::shared_ptr<opset1::Constant> multiplyConstant;
|
||||
|
@ -38,131 +38,80 @@ ReshapeTransformation::ReshapeTransformation(const Params& params) : LayerTransf
|
||||
}
|
||||
|
||||
void reshapeDequantizationConstant(const std::shared_ptr<opset1::Reshape>& reshape) {
|
||||
const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(reshape, 0);
|
||||
if (dequantization.multiplyConstant->get_shape().size() > 1ul) {
|
||||
// Reshape Subtract or Multiply operation Constant.
|
||||
// 1. modify reshape parameters to avoid reshape by spatial dimensions
|
||||
// 2. broadcast element-wise constant if channels are changed
|
||||
// 3. reshape element-wise constant with modified reshape parameters
|
||||
auto replaceConstant = [](const std::shared_ptr<opset1::Reshape>& reshape, const std::shared_ptr<Node>& op) {
|
||||
const size_t constantIndex = as_type<ngraph::opset1::Constant>(op->get_input_node_ptr(1)) ? 1 : 0;
|
||||
const auto originalConstant = as_type_ptr<opset1::Constant>(op->get_input_node_shared_ptr(constantIndex));
|
||||
const auto constantShape = originalConstant->get_shape();
|
||||
|
||||
// Reshape dequantization operation Constant.
|
||||
// 1. Calculate result dequantization Constant shape for broadcast based on original dequantization Constant shape and Reshape output.
|
||||
// For example: dequantization shape {1, 3, 1, 1}, output Reshape shape {1, 12, 3, 3}, result for broadcast: {1, 3, 4, 1},
|
||||
// where '4' calculated for temporary broadcast before reshape.
|
||||
// 2. Broadcast dequantization Constant, if channels are changed
|
||||
// 3. Reshape and replace
|
||||
auto replaceConstant = [](const std::shared_ptr<opset1::Reshape>& reshape, const std::shared_ptr<opset1::Constant>& originalConstant) {
|
||||
// reshape for element-wise constant is not required
|
||||
auto constantShape = originalConstant->get_shape();
|
||||
if (shape_size(constantShape) == 1ul) {
|
||||
if (constantShape.size() > 1ul) {
|
||||
const Shape newConstShape = Shape(reshape->get_output_partial_shape(0).rank().get_length(), 1ul);
|
||||
const auto newConstant = opset1::Constant::create(
|
||||
originalConstant->get_element_type(), newConstShape, originalConstant->cast_vector<float>());
|
||||
replace_node(op->get_input_node_shared_ptr(constantIndex), newConstant);
|
||||
if (!constantShape.empty()) {
|
||||
const auto newConstant = NetworkHelper::toScalar(originalConstant);
|
||||
replace_node(originalConstant, newConstant);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// simple broadcast operation Constant shape to shape on activations
|
||||
auto newOperationConstantShape = constantShape;
|
||||
auto const reshapeInputPShape = reshape->get_input_partial_shape(0);
|
||||
PartialShape newOperationConstantBroadcastedShape(reshapeInputPShape);
|
||||
newOperationConstantBroadcastedShape[0] = 1ul;
|
||||
|
||||
if ((reshapeInputPShape.rank().get_length() - newOperationConstantShape.size()) == 1ul) {
|
||||
newOperationConstantShape.insert(newOperationConstantShape.begin(), 1ul);
|
||||
}
|
||||
const std::shared_ptr<opset1::Constant> newOperationConstant = std::make_shared<opset1::Constant>(
|
||||
op->input(constantIndex).get_element_type(),
|
||||
newOperationConstantShape,
|
||||
originalConstant->cast_vector<float>());
|
||||
|
||||
// reshape -1 value handling
|
||||
auto getOverallValue = [](const Shape& shape, const std::vector<int>& reshapeValues, const bool specialZero) -> size_t {
|
||||
size_t overallValue = shape_size(shape);
|
||||
for (size_t i = 0; i < reshapeValues.size(); ++i) {
|
||||
auto reshapeValue = reshapeValues[i];
|
||||
if ((reshapeValue == 1ul) || (reshapeValue == -1) || ((reshapeValue == 0ul) && !specialZero)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((reshapeValue == 0ul) && specialZero) {
|
||||
reshapeValue = shape[i];
|
||||
}
|
||||
|
||||
overallValue = overallValue / reshapeValue;
|
||||
}
|
||||
return overallValue;
|
||||
};
|
||||
|
||||
// modify reshape constant for element-wise constant reshape
|
||||
// element-wise constant doesn't have spatial dimensions, as result we should remove spatial dimensions from reshape parameters
|
||||
const std::vector<int> reshapeConstValues = as_type_ptr<opset1::Constant>(reshape->get_input_node_shared_ptr(1))->cast_vector<int>();
|
||||
|
||||
size_t overallValue = 0;
|
||||
for (size_t i = 0; i < reshapeConstValues.size(); ++i) {
|
||||
if (reshapeConstValues[i] == -1) {
|
||||
overallValue = getOverallValue(
|
||||
reshapeInputPShape.to_shape(),
|
||||
reshapeConstValues,
|
||||
as_type_ptr<opset1::Reshape>(reshape)->get_special_zero());
|
||||
break;
|
||||
auto const reshapeInputRank = reshape->get_input_partial_shape(0).rank();
|
||||
assert(reshapeInputRank.is_static());
|
||||
if (constantShape.size() > 1ul) {
|
||||
while (constantShape.size() < static_cast<size_t>(reshapeInputRank.get_length())) {
|
||||
constantShape.insert(constantShape.begin(), 1ul);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> newReshapeConstValues(reshapeConstValues);
|
||||
for (int i = static_cast<int>(newReshapeConstValues.size() - 1); i >= 0; --i) {
|
||||
if (static_cast<int64_t>(newOperationConstantShape.size()) <= i) {
|
||||
// new dimension was added
|
||||
newReshapeConstValues[i] = 1;
|
||||
} else if (newOperationConstantShape[i] == 1ul) {
|
||||
// keep the same
|
||||
newReshapeConstValues[i] = 1;
|
||||
} else if (newReshapeConstValues[i] == -1) {
|
||||
// modified reshape parameters are different, but value instead '-1' has to be equal as original reshape
|
||||
newReshapeConstValues[i] = overallValue;
|
||||
}
|
||||
const auto reshapeOutputPShape = reshape->output(0).get_partial_shape();
|
||||
const auto reshapeOutputRank = reshapeOutputPShape.rank();
|
||||
assert(reshapeOutputRank.is_static());
|
||||
assert(reshapeOutputRank.get_length() >= 2);
|
||||
assert(reshapeOutputPShape[1].is_static());
|
||||
assert(static_cast<size_t>(reshapeOutputPShape[1].get_length()) >= constantShape[1]);
|
||||
assert(reshapeOutputPShape[1].get_length() % constantShape[1] == 0);
|
||||
const size_t dimensionsToBroadcast = reshapeOutputPShape[1].get_length() / constantShape[1];
|
||||
if (dimensionsToBroadcast == 0ul) {
|
||||
return;
|
||||
}
|
||||
|
||||
const std::shared_ptr<opset1::Constant> newReshapeConstant = std::make_shared<opset1::Constant>(
|
||||
reshape->input(1).get_element_type(),
|
||||
Shape({ newReshapeConstValues.size() }),
|
||||
newReshapeConstValues);
|
||||
|
||||
// if channels are different then broadcast spatial dimensions to reshape channels correctly
|
||||
// limitation which has to be covered by canBeTransformed:
|
||||
// 1. spatial dimensions have to be absent or equal to 1 after reshape
|
||||
// 2. only second dimension can be changed
|
||||
|
||||
const bool shouldBroadcast = (shape_size(newReshapeConstValues) != 1ul) && (reshapeConstValues[1] != 0) &&
|
||||
(((reshapeConstValues[1] != -1) &&
|
||||
(static_cast<int64_t>(newOperationConstantShape[1]) != reshapeConstValues[1])) ||
|
||||
((reshapeConstValues[1] == -1) &&
|
||||
(newOperationConstantShape[1] != overallValue)));
|
||||
|
||||
const std::shared_ptr<Node> broadcastedConstant = shouldBroadcast ?
|
||||
fold<opset1::Broadcast>(
|
||||
newOperationConstant,
|
||||
Shape newOperationConstantBroadcastedShape = originalConstant->output(0).get_shape();
|
||||
// add dimensions to broadcast values
|
||||
if (newOperationConstantBroadcastedShape.size() == 2ul) {
|
||||
newOperationConstantBroadcastedShape.push_back(dimensionsToBroadcast);
|
||||
} else {
|
||||
newOperationConstantBroadcastedShape[2] = dimensionsToBroadcast;
|
||||
}
|
||||
const std::shared_ptr<Node> broadcastedConstant = fold<opset1::Broadcast>(
|
||||
originalConstant,
|
||||
std::make_shared<opset1::Constant>(
|
||||
element::i32,
|
||||
Shape({static_cast<size_t>(newOperationConstantBroadcastedShape.rank().get_length())}),
|
||||
// TODO: investigate behaviour
|
||||
newOperationConstantBroadcastedShape.to_shape())) :
|
||||
newOperationConstant;
|
||||
Shape({ newOperationConstantBroadcastedShape.size() }),
|
||||
newOperationConstantBroadcastedShape));
|
||||
|
||||
std::vector<int> newReshapeConstValues(reshapeOutputRank.get_length(), 1ul);
|
||||
newReshapeConstValues[1] = reshapeOutputPShape[1].get_length();
|
||||
const std::shared_ptr<opset1::Constant> newReshapeConstant = std::make_shared<opset1::Constant>(
|
||||
element::i32,
|
||||
Shape({ newReshapeConstValues.size() }),
|
||||
newReshapeConstValues);
|
||||
|
||||
const std::shared_ptr<Node> resultConstant = fold<opset1::Reshape>(
|
||||
broadcastedConstant,
|
||||
newReshapeConstant,
|
||||
reshape->get_special_zero());
|
||||
|
||||
replace_node(op->get_input_node_shared_ptr(constantIndex), resultConstant);
|
||||
replace_node(originalConstant, resultConstant);
|
||||
};
|
||||
|
||||
const FakeQuantizeDequantization dequantization = NetworkHelper::getDequantization(reshape, 0);
|
||||
|
||||
if (dequantization.subtract != nullptr) {
|
||||
replaceConstant(reshape, dequantization.subtract);
|
||||
replaceConstant(reshape, dequantization.subtractConstant);
|
||||
}
|
||||
|
||||
if (dequantization.multiply != nullptr) {
|
||||
replaceConstant(reshape, dequantization.multiply);
|
||||
}
|
||||
replaceConstant(reshape, dequantization.multiplyConstant);
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,7 +135,7 @@ bool ReshapeTransformation::isPrecisionPreserved(std::shared_ptr<Node> op) const
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t getLastNotBroadcastedChannel(const Shape& shape) {
|
||||
size_t getLastNotBroadcastedDimension(const Shape& shape) {
|
||||
for (int i = static_cast<int>(shape.size()) - 1; i >= 0; --i) {
|
||||
if (shape[i] != 1ul) {
|
||||
return i;
|
||||
@ -195,7 +144,7 @@ size_t getLastNotBroadcastedChannel(const Shape& shape) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t getFirstChangedChannel(const PartialShape& shape1, const PartialShape& shape2) {
|
||||
size_t getFirstChangedDimension(const PartialShape& shape1, const PartialShape& shape2) {
|
||||
const size_t minSize = std::min(shape1.rank().get_length(), shape2.rank().get_length());
|
||||
size_t i = 0;
|
||||
for (; i < minSize; ++i) {
|
||||
@ -216,11 +165,15 @@ bool ReshapeTransformation::canBeTransformed(const TransformationContext& contex
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: LPT: to support current flow: #58269
|
||||
//if (((dequantization.subtractConstant != nullptr) && NetworkHelper::isScalarLike(dequantization.subtractConstant)) ||
|
||||
// ((dequantization.multiplyConstant != nullptr) && NetworkHelper::isScalarLike(dequantization.multiplyConstant))) {
|
||||
// return true;
|
||||
//}
|
||||
if (((dequantization.subtract == nullptr) || NetworkHelper::isScalarLike(dequantization.subtractConstant)) &&
|
||||
((dequantization.multiply == nullptr) || NetworkHelper::isScalarLike(dequantization.multiplyConstant))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const PartialShape outputPShape = op->get_output_partial_shape(0);
|
||||
if (outputPShape[1].is_dynamic()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const Shape subtractShape = dequantization.subtract == nullptr ? Shape{} : dequantization.subtractConstant->get_shape();
|
||||
Shape subtractShapeWithBatch = subtractShape;
|
||||
@ -245,26 +198,23 @@ bool ReshapeTransformation::canBeTransformed(const TransformationContext& contex
|
||||
multiplyShapeWithBatch.insert(multiplyShapeWithBatch.begin(), 1ul);
|
||||
}
|
||||
|
||||
const PartialShape outputPShape = op->get_output_partial_shape(0);
|
||||
// if we have per-channel dq, dynamic shape, and "-1" reshape value - don't transform
|
||||
if (outputPShape.is_dynamic() && (shape_size(subtractShape) > 1ul || shape_size(multiplyShape) > 1ul)) {
|
||||
const auto reshapeConstant = as_type_ptr<opset1::Constant>(op->get_input_node_shared_ptr(1))->cast_vector<int>();
|
||||
if (std::any_of(reshapeConstant.cbegin(), reshapeConstant.cend(), [](const int value) { return value == -1; })) {
|
||||
const size_t outputChannel = static_cast<size_t>(outputPShape[1].get_length());
|
||||
if (!subtractShapeWithBatch.empty() && (outputChannel < subtractShapeWithBatch[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!multiplyShapeWithBatch.empty() && (outputChannel < multiplyShapeWithBatch[1])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (outputPShape.is_static() &&
|
||||
((!subtractShapeWithBatch.empty() && ((outputChannel % subtractShapeWithBatch[1]) != 0)) ||
|
||||
(!multiplyShapeWithBatch.empty() && (outputChannel % multiplyShapeWithBatch[1] != 0)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return canBeTransformed(subtractShapeWithBatch, multiplyShapeWithBatch, inputPShape, outputPShape);
|
||||
}
|
||||
|
||||
size_t getChannelVolume(const PartialShape& shape) {
|
||||
size_t volume = 1ul;
|
||||
for (int i = 2; i < shape.rank().get_length(); ++i) {
|
||||
volume = volume * shape[i].get_length();
|
||||
}
|
||||
return volume;
|
||||
}
|
||||
|
||||
bool ReshapeTransformation::canBeTransformed(
|
||||
const ngraph::Shape& subtractShape,
|
||||
const ngraph::Shape& multiplyShape,
|
||||
@ -277,69 +227,16 @@ bool ReshapeTransformation::canBeTransformed(
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: story 38439
|
||||
if ((inputRank == 4ul) && (outputRank == 2ul)) {
|
||||
auto checkSpatialDimensions = [](const Shape& dequantizationConstShape) {
|
||||
for (size_t i = (dequantizationConstShape.size() - 2); i < dequantizationConstShape.size(); ++i) {
|
||||
if (dequantizationConstShape[i] != 1ul) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const size_t lastNotBroadcastedDimension = std::max(getLastNotBroadcastedDimension(subtractShape), getLastNotBroadcastedDimension(multiplyShape));
|
||||
const size_t firstChangedDimension = getFirstChangedDimension(inputShape, outputShape);
|
||||
// LPT supports channel on the second dimension natively <= reshape transformation supports more shapes for this case
|
||||
if ((lastNotBroadcastedDimension == 1ul) && (firstChangedDimension == 1ul)) {
|
||||
return true;
|
||||
};
|
||||
|
||||
if (((subtractShape.size() >= 3ul) && (!checkSpatialDimensions(subtractShape))) ||
|
||||
((multiplyShape.size() >= 3ul) && (!checkSpatialDimensions(multiplyShape)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (inputRank > 1ul) {
|
||||
if (inputShape[1].is_dynamic()) {
|
||||
if (lastNotBroadcastedDimension >= firstChangedDimension) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (inputShape[0].is_dynamic()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (outputRank > 1ul) {
|
||||
if (outputShape[1].is_dynamic()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (outputShape[0].is_dynamic()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// custom validation for Layout::NCHW => Layout::NC
|
||||
const size_t inputChannelsCount = inputRank > 1ul ? inputShape[1].get_length() : inputShape[0].get_length();
|
||||
const size_t outputChannelsCount = outputRank > 1ul ? outputShape[1].get_length() : outputShape[0].get_length();
|
||||
for (size_t i = 2; i < inputRank; ++i) {
|
||||
if (inputShape[i].is_dynamic()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((inputShape[0] != outputShape[0]) || ((inputChannelsCount * getChannelVolume(inputShape)) != outputChannelsCount)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (ngraph::shape_size(subtractShape) > 1 || ngraph::shape_size(multiplyShape) > 1) {
|
||||
for (size_t i = 0; i < 2ul; ++i) {
|
||||
if (inputShape[i] != outputShape[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const size_t lastNotBroadcastedChannel = std::max(getLastNotBroadcastedChannel(subtractShape), getLastNotBroadcastedChannel(multiplyShape));
|
||||
const size_t firstChangedChannel = getFirstChangedChannel(inputShape, outputShape);
|
||||
if (lastNotBroadcastedChannel >= firstChangedChannel) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -7,22 +7,18 @@
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <transformations/utils/utils.hpp>
|
||||
#include <transformations/init_node_info.hpp>
|
||||
|
||||
#include <low_precision/low_precision.hpp>
|
||||
#include <low_precision/rt_info/precision_preserved_attribute.hpp>
|
||||
#include <low_precision/rt_info/intervals_alignment_attribute.hpp>
|
||||
#include <low_precision/rt_info/quantization_alignment_attribute.hpp>
|
||||
|
||||
#include <low_precision/common/operation_precision_restriction.hpp>
|
||||
#include <low_precision/common/operation_per_tensor_quantization_restriction.hpp>
|
||||
#include <low_precision/concat.hpp>
|
||||
#include <low_precision/fake_quantize_decomposition.hpp>
|
||||
#include <low_precision/rt_info/precision_preserved_attribute.hpp>
|
||||
#include <low_precision/align_quantization_parameters.hpp>
|
||||
#include <low_precision/fuse_subtract_to_fake_quantize.hpp>
|
||||
#include <low_precision/fuse_multiply_to_fake_quantize.hpp>
|
||||
#include <low_precision/markup_can_be_quantized.hpp>
|
||||
#include <low_precision/markup_per_tensor_quantization.hpp>
|
||||
|
||||
#include "common_test_utils/ngraph_test_utils.hpp"
|
||||
#include "lpt_ngraph_functions/concat_function.hpp"
|
||||
|
@ -140,7 +140,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
{{ngraph::element::f32}, {}, {0.1f}}
|
||||
}
|
||||
},
|
||||
// U8: 3D -> 4D: dynamic rank
|
||||
// U8: 3D -> 4D: dynamic rank: per tensor quantization
|
||||
{
|
||||
PartialShape::dynamic(),
|
||||
{ 0, 384, 16, 64 },
|
||||
@ -151,7 +151,39 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {0.1f}},
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {0.1f}}
|
||||
}
|
||||
},
|
||||
// U8: 3D -> 4D: dynamic rank: per tensor quantization
|
||||
{
|
||||
PartialShape::dynamic(),
|
||||
{ 0, 384, 16, 64 },
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {128}, {0.1f}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {128}, {0.1f}}
|
||||
}
|
||||
},
|
||||
// U8: 3D -> 4D: dynamic rank
|
||||
{
|
||||
PartialShape::dynamic(),
|
||||
{ 0, 3, 16, 64 },
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, element::f32, {1, 3, 1, 1}}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, element::f32, {1, 3, 1, 1}}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
}
|
||||
@ -340,8 +372,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
{}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 2D -> 4D: channels are affected: per tensor quantization
|
||||
// TODO: story 38439
|
||||
// U8: no subtract 4D -> 2D: channels are affected: per tensor quantization
|
||||
{
|
||||
{ 1, 16, 384, 384 },
|
||||
{ 6144, -1 },
|
||||
@ -352,12 +383,12 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {0.1f}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {0.1f}}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 2D -> 4D: channels are affected: per channel quantization
|
||||
// U8: no subtract 4D -> 2D: channels are affected: per channel quantization
|
||||
{
|
||||
{ 1, 3, 4, 5 },
|
||||
{ 12, -1 },
|
||||
@ -437,8 +468,83 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
{}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 5D: channels are not affected: no subtract
|
||||
{
|
||||
{ 1, 3, 4, 5 },
|
||||
{ 1, 3, 20, 1, 1},
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, ngraph::element::f32, {1, 3, 1, 1}}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, ngraph::element::f32, {1, 3, 1, 1, 1}}},
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 5D: channels are affected: no subtract
|
||||
{
|
||||
{ 1, 3, 2, 3 },
|
||||
{ 1, 18, 1, 1, 1},
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, ngraph::element::f32, {1, 3, 1, 1}}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ngraph::element::f32},
|
||||
{},
|
||||
{
|
||||
{0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.2f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f, 0.3f},
|
||||
ngraph::element::f32,
|
||||
{1, 18, 1, 1, 1}
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 5D: channels are affected: no subtract
|
||||
{
|
||||
{ 1, 3, 4, 5 },
|
||||
{ 1, 12, 1, 1, 5},
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {}}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {}}},
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 5D: channels are affected: no subtract
|
||||
{
|
||||
{ 1, 3, 4, 5 },
|
||||
{ 1, 12, 1, 1, 5},
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f, 0.2f, 0.3f}, ngraph::element::f32, {1, 3, 1, 1}}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ngraph::element::f32},
|
||||
{},
|
||||
{{0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.2f, 0.2f, 0.2f, 0.3f, 0.3f, 0.3f, 0.3f}, ngraph::element::f32, {1, 12, 1, 1, 1}}
|
||||
}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D: channels are not affected: per tensor quantization
|
||||
// TODO: story 38439
|
||||
{
|
||||
{ 1, 3, 4, 5 },
|
||||
{ 0, -1 },
|
||||
@ -454,7 +560,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
{{ngraph::element::f32}, {{128.f}, ngraph::element::f32, {}}, {{0.1f}, ngraph::element::f32, {}}}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D: channels are not affected: per tensor quantization
|
||||
// U8: no subtract 4D -> 2D: channels are affected: per channel quantization
|
||||
{
|
||||
{ 1, 3, 2, 2 },
|
||||
{ 0, -1 },
|
||||
@ -474,6 +580,26 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D: channels are affected: per channel quantization
|
||||
{
|
||||
{ 1, 3, 2, 2 },
|
||||
{ 0, -1 },
|
||||
LayerTransformation::createParamsU8I8(),
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {{0.f, 128.f, 255.f}, ngraph::element::f32, {3, 1, 1}}, {{0.1f, 0.2f, 0.3f}, ngraph::element::f32, {3, 1, 1}}}
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ngraph::element::f32},
|
||||
{{0.f, 0.f, 0.f, 0.f, 128.f, 128.f, 128.f, 128.f, 255.f, 255.f, 255.f, 255.f}, ngraph::element::f32, {1, 12}},
|
||||
{{0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.2f, 0.2f, 0.2f, 0.3f, 0.3f, 0.3f, 0.3f}, ngraph::element::f32, {1, 12}}
|
||||
}
|
||||
}
|
||||
},
|
||||
// U8: 4D -> 2D: per channel dq and dynamic batch
|
||||
{
|
||||
{ Dimension::dynamic(), 3, 2, 2 },
|
||||
@ -485,9 +611,13 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
},
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {{0.f, 128.f, 255.f}, ngraph::element::f32, {1, 3, 1, 1}}, {{0.1f, 0.2f, 0.3f}, ngraph::element::f32, {1, 3, 1, 1}}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
{},
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ngraph::element::f32},
|
||||
{{0.f, 0.f, 0.f, 0.f, 128.f, 128.f, 128.f, 128.f, 255.f, 255.f, 255.f, 255.f}, ngraph::element::f32, {1, 12}},
|
||||
{{0.1f, 0.1f, 0.1f, 0.1f, 0.2f, 0.2f, 0.2f, 0.2f, 0.3f, 0.3f, 0.3f, 0.3f}, ngraph::element::f32, {1, 12}}
|
||||
}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D: channels are not affected: per tensor quantization
|
||||
@ -603,7 +733,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
ngraph::element::u8,
|
||||
{{}, {}, {}},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {1ul}}}
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {}}}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D
|
||||
@ -619,7 +749,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
ngraph::element::u8,
|
||||
{{}, {}, {}},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {1, 1}}}
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {}}}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D: channels are not affected
|
||||
@ -635,7 +765,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
ngraph::element::u8,
|
||||
{{}, {}, {}},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {1, 1}}}
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {}}}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 2D: channels are not affected, dynamic batch
|
||||
@ -651,7 +781,7 @@ const std::vector<ReshapeTransformationTestValues> testValues = {
|
||||
ngraph::element::u8,
|
||||
{{}, {}, {}},
|
||||
ngraph::element::u8,
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {1, 1}}}
|
||||
{{ngraph::element::f32}, {}, {{0.1f}, ngraph::element::f32, {}}}
|
||||
}
|
||||
},
|
||||
// U8: no subtract 4D -> 4D: channels are affected
|
||||
|
@ -11,14 +11,12 @@ using namespace LayerTestsDefinitions;
|
||||
|
||||
namespace {
|
||||
const std::vector<ngraph::element::Type> netPrecisions = {
|
||||
ngraph::element::f32
|
||||
// ngraph::element::f16
|
||||
ngraph::element::f32,
|
||||
ngraph::element::f16
|
||||
};
|
||||
|
||||
const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
|
||||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams(),
|
||||
// LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false),
|
||||
// LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8()
|
||||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams()
|
||||
};
|
||||
|
||||
const std::vector<ReshapeTransformationParam> params = {
|
||||
@ -27,29 +25,87 @@ const std::vector<ReshapeTransformationParam> params = {
|
||||
{ 1, 3, 32 },
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 256ul, ngraph::Shape{ 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 3D -> 1D
|
||||
{
|
||||
{ 1, 3, 32 },
|
||||
{ -1 },
|
||||
{ 256ul, ngraph::Shape{}, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
"Reshape",
|
||||
"FP32"
|
||||
},
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 16, 16 },
|
||||
{ 1, 3, 256 },
|
||||
{ 256ul, ngraph::Shape{ 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 16, 16 },
|
||||
{ 0, 3, -1 },
|
||||
{ 256ul, ngraph::Shape{ 1, 3, 1, 1 }, { 0.f }, { 255.f }, { 0.f, 0.f, 0.f }, { 255.f, 25.5f, 2.55f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 2D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, -1 },
|
||||
{ 256ul, ngraph::Shape{ 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 2D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, -1 },
|
||||
{
|
||||
256ul,
|
||||
ngraph::Shape{ 1, 3, 1, 1 },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f/2.f, 255.f/3.f },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f/2.f, 255.f/3.f },
|
||||
},
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, 3, -1 },
|
||||
{
|
||||
256ul,
|
||||
ngraph::Shape{ 1, 3, 1, 1 },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f/2.f, 255.f/3.f },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f/2.f, 255.f/3.f },
|
||||
},
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// per-channel
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, -1, 8 },
|
||||
{
|
||||
256ul,
|
||||
ngraph::Shape{ 1, 3, 1, 1 },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f/2.f, 255.f/3.f },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f/2.f, 255.f/3.f },
|
||||
},
|
||||
"Reshape",
|
||||
"U8"
|
||||
}
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LPT, ReshapeTransformation,
|
||||
|
@ -19,16 +19,16 @@ const std::vector<ngraph::element::Type> precisions = {
|
||||
std::vector<MatMulWithConstantTransformationTestValues> testValues = {
|
||||
{
|
||||
{ 2, 3, 4 },
|
||||
{ 256ul, {{1, 1, 1}, {1, 1, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f}, {255.f}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 255.f} },
|
||||
{ 256ul, {{1, 3, 1}, {1, 3, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 2.55f}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 2.55f} },
|
||||
{ std::vector<float>(4 * 2, 2.f), ngraph::element::f32, ngraph::Shape{ 2, 4 } },
|
||||
{ 256ul, {{1}, {1}, {2, 1}, {2, 1}}, {-128.f}, {127.f}, {-128.f, -12.8f}, {127.f, 12.7f} },
|
||||
{ 256ul, {{2, 1}, {2, 1}, {2, 1}, {2, 1}}, {-128.f, -12.8f}, {127.f, 12.7f}, {-128.f, -12.8f}, {127.f, 12.7f} },
|
||||
{ {}, {}, {} },
|
||||
"FullyConnected",
|
||||
"FP32"
|
||||
},
|
||||
{
|
||||
{ 2, 3, 4 },
|
||||
{ 256ul, {{1, 1, 1}, {1, 1, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f}, {255.f}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 255.f} },
|
||||
{ 256ul, {{1, 3, 1}, {1, 3, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 2.f}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 2.f} },
|
||||
{ std::vector<float>(4 * 2, 2.f), ngraph::element::i8, ngraph::Shape{ 2, 4 } },
|
||||
{},
|
||||
{ ngraph::element::f32, {}, {0.1f} },
|
||||
@ -39,23 +39,23 @@ std::vector<MatMulWithConstantTransformationTestValues> testValues = {
|
||||
{ 1, 3, 4 },
|
||||
{ 256ul, {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, {-10.5f}, {4.5f}, {-10.5f}, {4.5f} },
|
||||
{ std::vector<float>(4 * 2, 2.f), ngraph::element::f32, ngraph::Shape{ 2, 4 } },
|
||||
{ 256ul, {{1}, {1}, {2, 1}, {2, 1}}, {-128.f}, {127.f}, {-128.f, -12.8f}, {127.f, 12.7f} },
|
||||
{ 256ul, {{2, 1}, {2, 1}, {2, 1}, {2, 1}}, {-128.f, -12.8f}, {127.f, 12.7f}, {-128.f, -12.8f}, {127.f, 12.7f} },
|
||||
{ {}, {}, {} },
|
||||
"FullyConnected",
|
||||
"FP32"
|
||||
},
|
||||
{
|
||||
{ 1, 1, 3, 4 },
|
||||
{ 256ul, {{1, 1, 1}, {1, 1, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f}, {255.f}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 255.f} },
|
||||
{ 256ul, {{1, 3, 1}, {1, 3, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f, 0.f, 0.f}, {25.f, 24.f, 25.f}, {0.f, 0.f, 0.f}, {25.f, 24.f, 25.f} },
|
||||
{ std::vector<float>(4 * 2, 2.f), ngraph::element::f32, ngraph::Shape{ 2, 4 } },
|
||||
{ 256ul, {{1}, {1}, {2, 1}, {2, 1}}, {-128.f}, {127.f}, {-128.f, -12.8f}, {127.f, 12.7f} },
|
||||
{ 256ul, {{2, 1}, {2, 1}, {2, 1}, {2, 1}}, {-128.f, -12.8f}, {127.f, 12.7f}, {-128.f, -12.8f}, {127.f, 12.7f} },
|
||||
{ {}, {}, {} },
|
||||
"FullyConnected",
|
||||
"U8"
|
||||
},
|
||||
{
|
||||
{ 1, 1, 3, 4 },
|
||||
{ 256ul, {{1, 1, 1}, {1, 1, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f}, {255.f}, {0.f, 0.f, 0.f}, {255.f, 25.5f, 255.f} },
|
||||
{ 256ul, {{1, 3, 1}, {1, 3, 1}, {1, 3, 1}, {1, 3, 1}}, {0.f, 0.f, 0.f}, {25.f, 24.f, 25.f}, {0.f, 0.f, 0.f}, {25.f, 24.f, 25.f} },
|
||||
{ std::vector<float>(4 * 2, 2.f), ngraph::element::i8, ngraph::Shape{ 2, 4 } },
|
||||
{},
|
||||
{ ngraph::element::f32, {}, {{0.1f, 0.01}, ngraph::element::f32, ngraph::Shape{ 2, 1 }} },
|
||||
@ -73,7 +73,7 @@ std::vector<MatMulWithConstantTransformationTestValues> testValues = {
|
||||
},
|
||||
{
|
||||
{ 2, 3 },
|
||||
{ 256ul, {{1}, {1}, {2, 1}, {2, 1}}, {-10.f}, {5.f}, {-10.f, -5.f}, {5.f, 5.f} },
|
||||
{ 256ul, {{2, 1}, {2, 1}, {2, 1}, {2, 1}}, {-10.f, -5.f}, {5.f, 5.f}, {-10.f, -5.f}, {5.f, 5.f} },
|
||||
{ std::vector<float>{1, 2, 3, 4, 5, 6}, ngraph::element::f32, ngraph::Shape{ 2, 3 } },
|
||||
{ 256ul, {{1}, {1}, {1}, {1}}, {-128.f}, {127.f}, {-12.8f}, {12.7f} },
|
||||
{ {}, {}, {} },
|
||||
@ -82,7 +82,7 @@ std::vector<MatMulWithConstantTransformationTestValues> testValues = {
|
||||
},
|
||||
{
|
||||
{ 2, 3 },
|
||||
{ 256ul, {{1}, {1}, {2, 1}, {2, 1}}, {-10.f}, {5.f}, {-10.f, -5.f}, {5.f, 5.f} },
|
||||
{ 256ul, {{2, 1}, {2, 1}, {2, 1}, {2, 1}}, {-10.f, -5.f}, {5.f, 5.f}, {-10.f, -5.f}, {5.f, 5.f} },
|
||||
{ std::vector<float>{1, 2, 3, 4, 5, 6}, ngraph::element::i8, ngraph::Shape{ 2, 3 } },
|
||||
{},
|
||||
{ ngraph::element::f32, {}, {0.1f} },
|
||||
|
@ -17,8 +17,6 @@ const std::vector<ngraph::element::Type> netPrecisions = {
|
||||
|
||||
const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
|
||||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams(),
|
||||
// LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false),
|
||||
// LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8()
|
||||
};
|
||||
|
||||
const std::vector<ReshapeTransformationParam> params = {
|
||||
@ -27,29 +25,87 @@ const std::vector<ReshapeTransformationParam> params = {
|
||||
{ 1, 3, 32 },
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 256ul, ngraph::Shape{ 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 3D -> 1D
|
||||
{
|
||||
{ 1, 3, 32 },
|
||||
{ -1 },
|
||||
{ 256ul, ngraph::Shape{}, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
"Reshape",
|
||||
"FP32"
|
||||
},
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 16, 16 },
|
||||
{ 1, 3, 256 },
|
||||
{ 256ul, ngraph::Shape{ 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 16, 16 },
|
||||
{ 0, 3, -1 },
|
||||
{ 256ul, ngraph::Shape{ 1, 3, 1, 1 }, { 0.f }, { 255.f }, { 0.f, 0.f, 0.f }, { 255.f, 25.5f, 2.55f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 2D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, -1 },
|
||||
{ 256ul, ngraph::Shape{ 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 25.5f } },
|
||||
true
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 2D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, -1 },
|
||||
{
|
||||
256ul,
|
||||
ngraph::Shape{ 1, 3, 1, 1 },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f / 2.f, 255.f / 3.f },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f / 2.f, 255.f / 3.f },
|
||||
},
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, 3, -1 },
|
||||
{
|
||||
256ul,
|
||||
ngraph::Shape{ 1, 3, 1, 1 },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f / 2.f, 255.f / 3.f },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f / 2.f, 255.f / 3.f },
|
||||
},
|
||||
"Reshape",
|
||||
"U8"
|
||||
},
|
||||
// per-channel
|
||||
// 4D -> 3D
|
||||
{
|
||||
{ 1, 3, 4, 8 },
|
||||
{ 1, -1, 8 },
|
||||
{
|
||||
256ul,
|
||||
ngraph::Shape{ 1, 3, 1, 1 },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f / 2.f, 255.f / 3.f },
|
||||
{ 0.f, 0.f, 0.f },
|
||||
{ 255.f, 255.f / 2.f, 255.f / 3.f },
|
||||
},
|
||||
"Reshape",
|
||||
"U8"
|
||||
}
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LPT, ReshapeTransformation,
|
||||
|
@ -17,7 +17,8 @@ public:
|
||||
ngraph::PartialShape inputShape;
|
||||
std::vector<int> reshapeConstValues;
|
||||
ngraph::builder::subgraph::FakeQuantizeOnData fakeQuantize;
|
||||
bool isTransformed;
|
||||
std::string layerType;
|
||||
std::string expectedKernelType;
|
||||
};
|
||||
|
||||
typedef std::tuple<
|
||||
@ -35,6 +36,7 @@ public:
|
||||
|
||||
protected:
|
||||
void SetUp() override;
|
||||
void Run() override;
|
||||
};
|
||||
|
||||
} // namespace LayerTestsDefinitions
|
||||
|
@ -6,15 +6,11 @@
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <ie_core.hpp>
|
||||
|
||||
#include "ngraph_functions/builders.hpp"
|
||||
#include <transformations/init_node_info.hpp>
|
||||
#include "lpt_ngraph_functions/reshape_function.hpp"
|
||||
|
||||
|
||||
namespace LayerTestsDefinitions {
|
||||
|
||||
std::string ReshapeTransformation::getTestCaseName(testing::TestParamInfo<ReshapeTransformationParams> obj) {
|
||||
@ -50,6 +46,18 @@ void ReshapeTransformation::SetUp() {
|
||||
param.fakeQuantize);
|
||||
}
|
||||
|
||||
void ReshapeTransformation::Run() {
|
||||
LayerTestsCommon::Run();
|
||||
|
||||
const auto params = std::get<3>(GetParam());
|
||||
auto actualPrecision = getRuntimePrecisionByType(params.layerType);
|
||||
const auto expectedPrecision = params.expectedKernelType;
|
||||
if ((expectedPrecision == "FP32") && (actualPrecision == "FP16")) {
|
||||
actualPrecision = "FP32";
|
||||
}
|
||||
EXPECT_EQ(actualPrecision, expectedPrecision);
|
||||
}
|
||||
|
||||
TEST_P(ReshapeTransformation, CompareWithRefImpl) {
|
||||
Run();
|
||||
};
|
||||
|
@ -83,6 +83,10 @@ public:
|
||||
std::string getRuntimePrecision(const std::string& layerName);
|
||||
std::string getRuntimePrecisionByType(const std::string& layerType);
|
||||
|
||||
#ifndef NDEBUG
|
||||
void showRuntimePrecisions();
|
||||
#endif
|
||||
|
||||
template<class T_IE, class T_NGRAPH>
|
||||
static void Compare(const T_NGRAPH *expected, const T_IE *actual, std::size_t size, float threshold) {
|
||||
for (std::size_t i = 0; i < size; ++i) {
|
||||
|
@ -474,6 +474,24 @@ std::string LayerTestsCommon::getRuntimePrecisionByType(const std::string& layer
|
||||
return "";
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
void LayerTestsCommon::showRuntimePrecisions() {
|
||||
const auto execGraph = executableNetwork.GetExecGraphInfo();
|
||||
const auto function = execGraph.getFunction();
|
||||
|
||||
for (const auto& op : function->get_ops()) {
|
||||
const auto& rtInfo = op->get_rt_info();
|
||||
const auto& typeIt = rtInfo.find("layerType");
|
||||
|
||||
const auto type = ngraph::as_type_ptr<ngraph::VariantWrapper<std::string>>(typeIt->second)->get();
|
||||
const auto& it = rtInfo.find("runtimePrecision");
|
||||
|
||||
const auto rtPrecisionPtr = ngraph::as_type_ptr<ngraph::VariantWrapper<std::string>>(it->second);
|
||||
std::cout << type << ": " << rtPrecisionPtr->get() << std::endl;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void LayerTestsCommon::SetRefMode(RefMode mode) {
|
||||
refMode = mode;
|
||||
}
|
||||
|
@ -152,7 +152,6 @@ TEST(LPT_ReshapeTransformation, canBeTransformed_4D_to_2D_perSpacial_TRUE) {
|
||||
ngraph::Shape({ 1, 9216 })));
|
||||
}
|
||||
|
||||
// TODO: story 38439
|
||||
TEST(LPT_ReshapeTransformation, canBeTransformed_5D_to_5D_perBatch) {
|
||||
ASSERT_FALSE(ngraph::pass::low_precision::ReshapeTransformation::canBeTransformed(
|
||||
ngraph::Shape({ 1, 16, 1, 1, 1 }),
|
||||
|
Loading…
Reference in New Issue
Block a user