[LPT] Zero point insertion in case of zero value on FQ output high (#5467)
* [LPT] Zero point insertion in case of zero value on FQ output high * [LPT] Change precision in test on the real default precision[0]
This commit is contained in:
parent
a8289b58c4
commit
8645c08396
@ -221,20 +221,22 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(c
|
|||||||
bool hasZeroPoint = false;
|
bool hasZeroPoint = false;
|
||||||
for (size_t i = 0; i < quantizationDetails.outputLowValues.size(); ++i) {
|
for (size_t i = 0; i < quantizationDetails.outputLowValues.size(); ++i) {
|
||||||
const bool signedInterval = std::signbit(quantizationDetails.outputLowValues[i]) != std::signbit(quantizationDetails.outputHighValues[i]);
|
const bool signedInterval = std::signbit(quantizationDetails.outputLowValues[i]) != std::signbit(quantizationDetails.outputHighValues[i]);
|
||||||
const bool boundaryValuesAreNotZero =
|
const bool outputLowValueIsNotZero = std::fabs(quantizationDetails.outputLowValues[i]) >= zeroThreshold;
|
||||||
(std::fabs(quantizationDetails.outputLowValues[i]) >= zeroThreshold) &&
|
if (signedInterval && outputLowValueIsNotZero) {
|
||||||
(std::fabs(quantizationDetails.outputHighValues[i]) >= zeroThreshold);
|
|
||||||
if (signedInterval && boundaryValuesAreNotZero) {
|
|
||||||
// signed
|
// signed
|
||||||
unsignedPrecision = false;
|
unsignedPrecision = false;
|
||||||
hasNegative = true;
|
hasNegative = true;
|
||||||
|
|
||||||
|
if (quantizationDetails.outputHighValues[i] != 0.f) {
|
||||||
const float expectedRatio = quantizationDetails.levels == 256 ? asymmetricIntervalSideRatio256 : -1.f;
|
const float expectedRatio = quantizationDetails.levels == 256 ? asymmetricIntervalSideRatio256 : -1.f;
|
||||||
const float actualRatio = quantizationDetails.outputLowValues[i] / quantizationDetails.outputHighValues[i];
|
const float actualRatio = quantizationDetails.outputLowValues[i] / quantizationDetails.outputHighValues[i];
|
||||||
const float actual = std::fabs((actualRatio - expectedRatio) / std::min(actualRatio, expectedRatio));
|
const float actual = std::fabs((actualRatio - expectedRatio) / std::min(actualRatio, expectedRatio));
|
||||||
if (actual > quantizationIntervalAsymmetryThreshold) {
|
if (actual > quantizationIntervalAsymmetryThreshold) {
|
||||||
hasZeroPoint = true;
|
hasZeroPoint = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
hasZeroPoint = true;
|
||||||
|
}
|
||||||
#ifdef LPT_PRINT_DEQUANTIZATION_INFO
|
#ifdef LPT_PRINT_DEQUANTIZATION_INFO
|
||||||
if (hasZeroPoint) {
|
if (hasZeroPoint) {
|
||||||
std::cout << " actual: " << actual << ", threshold: " << quantizationIntervalAsymmetryThreshold << std::endl;
|
std::cout << " actual: " << actual << ", threshold: " << quantizationIntervalAsymmetryThreshold << std::endl;
|
||||||
@ -244,8 +246,8 @@ LayerTransformation::PrecisionDetails LayerTransformation::getPrecisionDetails(c
|
|||||||
} else {
|
} else {
|
||||||
// unsigned
|
// unsigned
|
||||||
signedPrecision = false;
|
signedPrecision = false;
|
||||||
if (boundaryValuesAreNotZero) {
|
if (outputLowValueIsNotZero) {
|
||||||
hasZeroPoint = boundaryValuesAreNotZero;
|
hasZeroPoint = outputLowValueIsNotZero;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LPT_PRINT_DEQUANTIZATION_INFO
|
#ifdef LPT_PRINT_DEQUANTIZATION_INFO
|
||||||
|
@ -42,6 +42,10 @@ const std::vector<FakeQuantizeTransformationParam> fakeQuantizeOnDataValues = {
|
|||||||
{ 256ul, {}, { 0.f }, { 2.55f }, { 2.55f }, { 2.55f } },
|
{ 256ul, {}, { 0.f }, { 2.55f }, { 2.55f }, { 2.55f } },
|
||||||
"Pooling", "U8"
|
"Pooling", "U8"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
{ 256ul, {}, { -127.5f }, { 0.f }, { -127.5f }, { 0.f } },
|
||||||
|
"Pooling", "U8"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
{ 16ul, {}, { 0.f }, { 1.5f }, { 0.f }, { 1.5f } },
|
{ 16ul, {}, { 0.f }, { 1.5f }, { 0.f }, { 1.5f } },
|
||||||
"Pooling", "FP32"
|
"Pooling", "FP32"
|
||||||
|
@ -42,6 +42,10 @@ const std::vector<FakeQuantizeTransformationParam> fakeQuantizeOnDataValues = {
|
|||||||
{ 256ul, {}, { 0.f }, { 2.55f }, { 2.55f }, { 2.55f } },
|
{ 256ul, {}, { 0.f }, { 2.55f }, { 2.55f }, { 2.55f } },
|
||||||
"Pooling", "U8"
|
"Pooling", "U8"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
{ 256ul, {}, { -127.5f }, { 0.f }, { -127.5f }, { 0.f } },
|
||||||
|
"Pooling", "U8"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
{ 16ul, {}, { 0.f }, { 1.5f }, { 0.f }, { 1.5f } },
|
{ 16ul, {}, { 0.f }, { 1.5f }, { 0.f }, { 1.5f } },
|
||||||
"Pooling", "FP32"
|
"Pooling", "FP32"
|
||||||
|
Loading…
Reference in New Issue
Block a user