[LPT] undefined precision for denormal values fix (#8430)
* [LPT] undefined precision for denormal values fix * [LPT] FakeQuantize tests extending
This commit is contained in:
parent
73226b0b99
commit
634e933c6d
@ -199,8 +199,8 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(
|
||||
const size_t quantizationLevels,
|
||||
const std::vector<float>& outputLowValues,
|
||||
const std::vector<float>& outputHighValues) {
|
||||
const float zeroThreshold = std::numeric_limits<float>::denorm_min();
|
||||
// TODO: workaround: hardcoded values
|
||||
const float zeroThreshold = 1.e-6f;
|
||||
const float quantizationIntervalAsymmetryThreshold = 0.002f;
|
||||
|
||||
float asymmetricIntervalSideRatio = -static_cast<float>(quantizationLevels) / (quantizationLevels - 2.f);
|
||||
@ -209,7 +209,15 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(
|
||||
bool unsignedPrecision = true;
|
||||
|
||||
bool hasZeroPoint = false;
|
||||
bool thereIsAtLeastOneNormalValue = false;
|
||||
for (size_t i = 0; i < outputLowValues.size(); ++i) {
|
||||
if ((std::fabs(outputLowValues[i]) < zeroThreshold) && (std::fabs(outputHighValues[i]) < zeroThreshold)) {
|
||||
// both values are too small to identify preferable precision
|
||||
continue;
|
||||
}
|
||||
|
||||
thereIsAtLeastOneNormalValue = true;
|
||||
|
||||
const bool signedInterval = std::signbit(outputLowValues[i]) != std::signbit(outputHighValues[i]);
|
||||
const bool outputLowValueIsNotZero = std::fabs(outputLowValues[i]) >= zeroThreshold;
|
||||
if (signedInterval && outputLowValueIsNotZero) {
|
||||
@ -253,16 +261,11 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use this implementation after merge <= not aligned with master
|
||||
// if (signedPrecision && (!unsignedPrecision)) {
|
||||
// return LayerTransformation::PrecisionDetails(element::i8, hasNegative, hasZeroPoint);
|
||||
// }
|
||||
//
|
||||
// if ((!signedPrecision) && unsignedPrecision) {
|
||||
// return LayerTransformation::PrecisionDetails(element::u8, hasNegative, hasZeroPoint);
|
||||
// }
|
||||
//
|
||||
// THROW_TRANSFORMATION_EXCEPTION << "unexpected interval";
|
||||
if (!thereIsAtLeastOneNormalValue) {
|
||||
// all values are small and didn't define 'signedPrecision'
|
||||
signedPrecision = std::any_of(outputLowValues.begin(), outputLowValues.end(), [](const float& value) { return value < 0.f; });
|
||||
unsignedPrecision = !signedPrecision;
|
||||
}
|
||||
|
||||
element::Type resultPrecision = element::undefined;
|
||||
if (!hasZeroPoint) {
|
||||
|
@ -244,11 +244,22 @@ const std::vector<FakeQuantizeTransformationTestValues> fakeQuantizeTransformati
|
||||
{
|
||||
LayerTransformation::createParamsU8I8AndI8(),
|
||||
{ 256ul, {}, { 0.f }, { 25.5f }, { -1.0686283872061019e-38 }, { 1.0686283872061019e-38 } },
|
||||
{ 256ul, {}, { 0.f }, { 25.5f }, { 0.f }, { 255.f } },
|
||||
{ 256ul, {}, { 0.f }, { 25.5f }, { -128.f }, { 127.f } },
|
||||
ngraph::element::i8,
|
||||
{
|
||||
{ ngraph::element::f32, {{ngraph::element::f32}, {}, { 1e-32f }} },
|
||||
{ ngraph::element::f16, {{ngraph::element::f16}, {}, { 1e-32f }} }
|
||||
}
|
||||
},
|
||||
// denormal values
|
||||
{
|
||||
LayerTransformation::createParamsU8I8AndI8(),
|
||||
{ 256ul, {}, { 0.f }, { 25.5f }, { 0.0 }, { 1.0686283872061019e-38 } },
|
||||
{ 256ul, {}, { 0.f }, { 25.5f }, { 0.0 }, { 255 } },
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ ngraph::element::f32, {{ngraph::element::f32}, { 127.5 }, { 1e-32f }} },
|
||||
{ ngraph::element::f16, {{ngraph::element::f16}, { 127.5 }, { 1e-32f }} }
|
||||
{ ngraph::element::f32, {{ngraph::element::f32}, {}, { 1e-32f }} },
|
||||
{ ngraph::element::f16, {{ngraph::element::f16}, {}, { 1e-32f }} }
|
||||
}
|
||||
},
|
||||
// U16
|
||||
|
@ -13,12 +13,11 @@ using namespace LayerTestsDefinitions;
|
||||
namespace {
|
||||
const std::vector<ngraph::element::Type> netPrecisions = {
|
||||
ngraph::element::f32,
|
||||
// ngraph::element::f16
|
||||
// ngraph::element::f16,
|
||||
};
|
||||
|
||||
const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> trasformationParamValues = {
|
||||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(true),
|
||||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams().setUpdatePrecisions(false),
|
||||
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParams()
|
||||
};
|
||||
|
||||
const std::vector<LayerTestsDefinitions::ConvolutionTransformationParam> params = {
|
||||
@ -97,8 +96,22 @@ const std::vector<LayerTestsDefinitions::ConvolutionTransformationParam> params
|
||||
{
|
||||
{ 256ul, ngraph::Shape { 1 }, { 0.f }, { 255.f }, { -18.7f }, { 18.8f } },
|
||||
true,
|
||||
{ 255ul, ngraph::Shape { 6, 1, 1, 1 }, { -0.6f }, { 0.6f },
|
||||
{ -1.52806e-39f, -0.2, -0.3, -0.3, -0.2, -0.1 }, { 1.52806e-39f, 0.2, 0.3, 0.3, 0.2, 0.1 } },
|
||||
{
|
||||
255ul, ngraph::Shape { 6, 1, 1, 1 }, { -0.6f }, { 0.6f },
|
||||
{ -1.52806e-39f, -0.2, -0.3, -0.3, -0.2, -0.1 }, { 1.52806e-39f, 0.2, 0.3, 0.3, 0.2, 0.1 }
|
||||
},
|
||||
false,
|
||||
"Convolution",
|
||||
"U8"
|
||||
},
|
||||
{
|
||||
{ 256ul, ngraph::Shape { 1 }, { 0.f }, { 255.f }, { -18.7f }, { 18.8f } },
|
||||
true,
|
||||
{
|
||||
255ul, ngraph::Shape { 6, 1, 1, 1 }, { -0.6f }, { 0.6f },
|
||||
{ -1.52806e-39f, -1.52806e-39f, -1.52806e-39f, -1.52806e-39f, -1.52806e-39f, -1.52806e-39f },
|
||||
{ 1.52806e-39f, 1.52806e-39f, 1.52806e-39f, 1.52806e-39f, 1.52806e-39f, 1.52806e-39f }
|
||||
},
|
||||
false,
|
||||
"Convolution",
|
||||
"U8"
|
||||
|
@ -17,8 +17,7 @@ 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::createParams()
|
||||
};
|
||||
|
||||
const std::vector<LayerTestsDefinitions::ConvolutionTransformationParam> params = {
|
||||
@ -61,7 +60,30 @@ const std::vector<LayerTestsDefinitions::ConvolutionTransformationParam> params
|
||||
false,
|
||||
"Convolution",
|
||||
"U8"
|
||||
}
|
||||
},
|
||||
{
|
||||
{ 256ul, ngraph::Shape { 1 }, { 0.f }, { 255.f }, { -18.7f }, { 18.8f } },
|
||||
true,
|
||||
{
|
||||
255ul, ngraph::Shape { 6, 1, 1, 1 }, { -0.6f }, { 0.6f },
|
||||
{ -1.52806e-39f, -0.2, -0.3, -0.3, -0.2, -0.1 }, { 1.52806e-39f, 0.2, 0.3, 0.3, 0.2, 0.1 }
|
||||
},
|
||||
false,
|
||||
"Convolution",
|
||||
"U8"
|
||||
},
|
||||
{
|
||||
{ 256ul, ngraph::Shape { 1 }, { 0.f }, { 255.f }, { -18.7f }, { 18.8f } },
|
||||
true,
|
||||
{
|
||||
255ul, ngraph::Shape { 6, 1, 1, 1 }, { -0.6f }, { 0.6f },
|
||||
{ -1.52806e-39f, -1.52806e-39f, -1.52806e-39f, -1.52806e-39f, -1.52806e-39f, -1.52806e-39f },
|
||||
{ 1.52806e-39f, 1.52806e-39f, 1.52806e-39f, 1.52806e-39f, 1.52806e-39f, 1.52806e-39f }
|
||||
},
|
||||
false,
|
||||
"Convolution",
|
||||
"U8"
|
||||
},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LPT, ConvolutionTransformation,
|
||||
|
Loading…
Reference in New Issue
Block a user