[LPT] FakeQuantize folding fix to support ConvolutionBackpropData with FQ on weights (#6160)

This commit is contained in:
Edward Shogulin 2021-06-15 16:59:10 +03:00 committed by GitHub
parent 58eef532e9
commit a16af0d2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 18 deletions

View File

@ -683,7 +683,7 @@ std::shared_ptr<Node> NetworkHelper::foldFakeQuantize(
auto levels_1 = fq->get_levels() - 1.f;
const size_t DHW = D * H * W;
const size_t IDHW = IC * D * H * W;
const size_t IDHW = outChannelsShapeIndex == 0 ? IC * D * H * W : OC * D * H * W;
const auto values = constant->cast_vector<float>();
std::vector<float> quantizedValues(OC * IC * D * H * W);

View File

@ -15,11 +15,17 @@ const std::vector<ngraph::element::Type> netPrecisions = {
};
const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true),
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false)
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true)
};
const std::vector<LayerTestsDefinitions::ConvolutionBackpropDataTransformationParam> params = {
// FQ on weights
{
{256ul, ngraph::Shape{1, 1, 1, 1}, { 0.f }, { 25.5f }, { 0.f }, { 25.5f }},
{255ul, ngraph::Shape{1, 1, 1, 1}, { -12.7f }, { 12.7f }, { -12.7f }, { 12.7f }},
"convolutionBackpropData_original",
"U8"
},
// FQ on weights
// with zero point
{
@ -87,8 +93,8 @@ const std::vector<LayerTestsDefinitions::ConvolutionBackpropDataTransformationPa
}
};
const std::vector<ngraph::Shape> inputShapes = {
{ 1, 8, 16, 16 }
const std::vector<std::pair<ngraph::Shape, bool>> inputShapes = {
{{ 1, 8, 16, 16 }, true}
};
const std::vector<ngraph::Shape> outputShapes = {

View File

@ -16,11 +16,24 @@ const std::vector<ngraph::element::Type> netPrecisions = {
};
const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true),
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false)
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true)
};
const std::vector<LayerTestsDefinitions::ConvolutionBackpropDataTransformationParam> params = {
// FQ on weights
{
{256ul, ngraph::Shape{1, 1, 1, 1}, { 0.f }, { 25.5f }, { 0.f }, { 25.5f }},
{255ul, ngraph::Shape{1, 1, 1, 1}, { -12.7f }, { 12.7f }, { -12.7f }, { 12.7f }},
"convolutionBackpropData_original",
"U8"
},
// FQ on weights
{
{256ul, ngraph::Shape{1, 1, 1, 1}, { -12.8f }, { 12.7f }, { -12.8f }, { 12.7f }},
{255ul, ngraph::Shape{1, 1, 1, 1}, { -12.7f }, { 12.7f }, { -12.7f }, { 12.7f }},
"convolutionBackpropData_original",
"I8"
},
// FQ on weights
// with zero point
{
@ -82,9 +95,9 @@ const std::vector<LayerTestsDefinitions::ConvolutionBackpropDataTransformationPa
}
};
const std::vector<ngraph::Shape> inputShapes = {
{ 1, 8, 16, 16 },
{ 1, 32, 16, 16 }
const std::vector<std::pair<ngraph::Shape, bool>> inputShapes = {
{{ 1, 8, 16, 16 }, false},
{{ 1, 32, 16, 16 }, true}
};
const std::vector<ngraph::Shape> outputShapes = {

View File

@ -43,7 +43,7 @@ public:
typedef std::tuple<
ngraph::element::Type, // netPrecision
ngraph::Shape, // inputShape
std::pair<ngraph::Shape, bool>, // input shape and shape support flag
ngraph::Shape, // outputShape
std::string, // targetDevice
ngraph::pass::low_precision::LayerTransformation::Params,

View File

@ -14,7 +14,7 @@ namespace LayerTestsDefinitions {
std::string ConvolutionBackpropDataTransformation::getTestCaseName(testing::TestParamInfo<ConvolutionBackpropDataTransformationParams> obj) {
ngraph::element::Type netPrecision;
ngraph::Shape inputShape;
std::pair<ngraph::Shape, bool> inputShape;
ngraph::Shape outputShape;
std::string targetDevice;
ngraph::pass::low_precision::LayerTransformation::Params params;
@ -22,7 +22,7 @@ std::string ConvolutionBackpropDataTransformation::getTestCaseName(testing::Test
std::tie(netPrecision, inputShape, outputShape, targetDevice, params, param) = obj.param;
std::ostringstream result;
result << getTestCaseNameByParams(netPrecision, inputShape, targetDevice, params) << "_" <<
result << getTestCaseNameByParams(netPrecision, inputShape.first, targetDevice, params) << "_" <<
outputShape << "_" <<
param.fakeQuantizeOnData << "_" <<
param.fakeQuantizeOnWeights << "_" <<
@ -34,14 +34,15 @@ void ConvolutionBackpropDataTransformation::SetUp() {
threshold = 0.1f;
ngraph::element::Type netPrecision;
ngraph::Shape inputShape;
std::pair<ngraph::Shape, bool> inputShapeAndHandling;
ngraph::Shape outputShape;
ngraph::pass::low_precision::LayerTransformation::Params params;
ConvolutionBackpropDataTransformationParam param;
std::tie(netPrecision, inputShape, outputShape, targetDevice, params, param) = this->GetParam();
std::tie(netPrecision, inputShapeAndHandling, outputShape, targetDevice, params, param) = this->GetParam();
std::shared_ptr<ngraph::Node> weights;
const auto inputShape = inputShapeAndHandling.first;
if (!param.fakeQuantizeOnWeights.empty()) {
weights = ngraph::builder::subgraph::ConvolutionBackpropDataFunction::getWeights(
ngraph::Shape{inputShape[1], inputShape[1] / 2, 1, 1},
@ -65,9 +66,12 @@ void ConvolutionBackpropDataTransformation::SetUp() {
void ConvolutionBackpropDataTransformation::Run() {
LayerTestsCommon::Run();
const auto params = std::get<5>(GetParam());
const auto actualType = getRuntimePrecision(params.layerName);
EXPECT_EQ(actualType, params.expectedKernelType);
const auto inputShape = std::get<1>(GetParam());
if (inputShape.second) {
const auto params = std::get<5>(GetParam());
const auto actualType = getRuntimePrecision(params.layerName);
EXPECT_EQ(actualType, params.expectedKernelType);
}
}
TEST_P(ConvolutionBackpropDataTransformation, CompareWithRefImpl) {

View File

@ -38,6 +38,7 @@ std::shared_ptr<Function> ConvolutionBackpropDataFunction::get(
CoordinateDiff{ 0, 0 },
CoordinateDiff{ 0, 0 },
Strides{ 1, 1 });
convolutionBackpropData->set_friendly_name("convolutionBackpropData");
ngraph::ResultVector results{ std::make_shared<opset1::Result>(convolutionBackpropData) };
return std::make_shared<ngraph::Function>(results, ParameterVector{ input }, "ConvolutionBackpropDataTransformation");