[LPT] FullyConnected & Gemm tests

This commit is contained in:
Edward Shogulin 2020-06-08 17:15:45 +03:00 committed by Alexander Peskov
parent c7313bab7f
commit 92e5e010b9
4 changed files with 59 additions and 31 deletions

View File

@ -22,7 +22,7 @@ const std::vector<InferenceEngine::SizeVector> dimensions = {
const std::vector<LayerTransformation::Params> trasformationParamValues = { const std::vector<LayerTransformation::Params> trasformationParamValues = {
LayerTestsUtils::LayerTransformationParamsFactory::createParams(), LayerTestsUtils::LayerTransformationParamsFactory::createParams(),
// LayerTestsUtils::LayerTransformationParamsFactory::createParamsI8I8(), LayerTestsUtils::LayerTransformationParamsFactory::createParamsI8I8(),
LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8() LayerTestsUtils::LayerTransformationParamsFactory::createParamsU8I8()
}; };

View File

@ -41,12 +41,16 @@ void FullyConnectedTransformation::SetUp() {
auto ngPrecision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision); auto ngPrecision = FuncTestUtils::PrecisionUtils::convertIE2nGraphPrc(netPrecision);
const auto paramNode = std::make_shared<ngraph::opset1::Parameter>(ngPrecision, ngraph::Shape(inputShape)); const auto paramNode = std::make_shared<ngraph::opset1::Parameter>(ngPrecision, ngraph::Shape(inputShape));
const std::vector<size_t> constShapes(inputShape.size(), 1ul);
const auto fakeQuantizeOnAcitvations = ngraph::builder::makeFakeQuantize( const auto fakeQuantizeOnAcitvations = ngraph::builder::makeFakeQuantize(
paramNode, ngPrecision, 256ul, { 1ul }, paramNode, ngPrecision, 256ul, constShapes,
{ 0.f }, { 255.f / 4.f }, { 0.f }, { 255.f / 4.f }); { 0.f }, { 255.f / 4.f }, { 0.f }, { 255.f / 4.f });
fakeQuantizeOnAcitvations->set_friendly_name("fakeQuantizeOnAcitvations"); fakeQuantizeOnAcitvations->set_friendly_name("fakeQuantizeOnAcitvations");
auto weightsConst = std::make_shared<ngraph::op::Constant>(ngPrecision, ngraph::Shape{ inputShape[1], inputShape[1] }, std::vector<float>({ 1.f })); auto weightsConst = std::make_shared<ngraph::op::Constant>(
ngPrecision,
ngraph::Shape { inputShape[inputShape.size() - 1ul], inputShape[inputShape.size() - 1ul] },
std::vector<float>({ 1.f }));
const auto fakeQuantizeOnWeights = ngraph::builder::makeFakeQuantize( const auto fakeQuantizeOnWeights = ngraph::builder::makeFakeQuantize(
weightsConst, ngPrecision, 256ul, { 1ul, 1ul }, weightsConst, ngPrecision, 256ul, { 1ul, 1ul },
{ -128.f / 8.f }, { 127.f / 8.f }, { -128.f / 8.f }, { 127.f / 8.f }); { -128.f / 8.f }, { 127.f / 8.f }, { -128.f / 8.f }, { 127.f / 8.f });
@ -90,10 +94,22 @@ void FullyConnectedTransformation::validate() {
const InferenceEngine::CNNLayerPtr layer = InferenceEngine::details::CNNNetworkHelper::getParent(*outputLayer); const InferenceEngine::CNNLayerPtr layer = InferenceEngine::details::CNNNetworkHelper::getParent(*outputLayer);
if (params.updatePrecisions) { if (params.updatePrecisions) {
const bool asymmetricQuantizationOnData = std::all_of(
params.precisionsOnActivations.begin(),
params.precisionsOnActivations.end(),
[](const InferenceEngine::Precision precision) { return precision != InferenceEngine::Precision::U8; });
const bool asymmetricQuantizationOnWeights = std::all_of(
params.precisionsOnWeights.begin(),
params.precisionsOnWeights.end(),
[](const InferenceEngine::Precision precision) { return precision != InferenceEngine::Precision::I8; });
checkPrecisions( checkPrecisions(
*layer, *layer,
{ { InferenceEngine::Precision::U8 }, { InferenceEngine::Precision::I8 }, { netPrecision } }, { { params.precisionsOnActivations[0] }, { params.precisionsOnWeights[0] }, { netPrecision } },
{ getDeviceInternalPrecision(netPrecision) }); { getDeviceInternalPrecision(netPrecision) },
asymmetricQuantizationOnData,
asymmetricQuantizationOnWeights);
} else { } else {
checkPrecisions(*layer, netPrecision); checkPrecisions(*layer, netPrecision);
} }
@ -104,10 +120,6 @@ void FullyConnectedTransformation::validate() {
TEST_P(FullyConnectedTransformation, CompareWithRefImpl) { TEST_P(FullyConnectedTransformation, CompareWithRefImpl) {
Run(); Run();
if (targetDevice == std::string{CommonTestUtils::DEVICE_GPU}) {
PluginCache::get().reset();
}
}; };
} // namespace LayerTestsDefinitions } // namespace LayerTestsDefinitions

View File

@ -108,35 +108,49 @@ void LayerTransformation::checkPrecisions(const InferenceEngine::CNNLayer& layer
void LayerTransformation::checkPrecisions( void LayerTransformation::checkPrecisions(
const InferenceEngine::CNNLayer& layer, const InferenceEngine::CNNLayer& layer,
const std::vector<std::vector<InferenceEngine::Precision>>& expectedInputPrecisions, const std::vector<std::vector<InferenceEngine::Precision>>& expectedInputPrecisions,
const std::vector<InferenceEngine::Precision>& expectedOutputPrecisions) { const std::vector<InferenceEngine::Precision>& expectedOutputPrecisions,
const bool asymmetricQuantizationOnData,
const bool asymmetricQuantizationOnWeights) {
EXPECT_EQ(expectedInputPrecisions.size(), layer.insData.size()) << "insert data count is no expected: " << layer.insData.size(); EXPECT_EQ(expectedInputPrecisions.size(), layer.insData.size()) << "insert data count is no expected: " << layer.insData.size();
for (size_t inputIndex = 0ul; inputIndex < layer.insData.size(); ++inputIndex) { const auto checkPrecision = [](
const std::vector<InferenceEngine::Precision>& precisions = expectedInputPrecisions[inputIndex]; const InferenceEngine::CNNLayer& layer,
const InferenceEngine::DataPtr insData = layer.insData[inputIndex].lock(); const std::vector<InferenceEngine::Precision>& expectedPrecisions,
EXPECT_TRUE(insData != nullptr) << "insert data is nullable"; const size_t index,
const InferenceEngine::Precision actualPrecision = insData->getTensorDesc().getPrecision(); const bool input) {
const InferenceEngine::DataPtr data = input ? layer.insData[index].lock() : layer.outData[index];
EXPECT_TRUE(data != nullptr) << "data is nullable";
const InferenceEngine::Precision actualPrecision = data->getTensorDesc().getPrecision();
EXPECT_FALSE(std::all_of( EXPECT_FALSE(std::all_of(
precisions.begin(), expectedPrecisions.begin(),
precisions.end(), expectedPrecisions.end(),
[&](const InferenceEngine::Precision precision) { return getDeviceInternalPrecision(precision) != actualPrecision; })) << [&](const InferenceEngine::Precision precision) { return getDeviceInternalPrecision(precision) != actualPrecision; })) <<
"expected input precisions on " << inputIndex << " input port " << precisions << "expected precisions on " << index << (input ? " input" : " output") << " port " << expectedPrecisions <<
" actual precision " << actualPrecision; " actual precision " << actualPrecision;
};
if (asymmetricQuantizationOnData || asymmetricQuantizationOnWeights) {
if (asymmetricQuantizationOnData) {
const InferenceEngine::CNNLayerPtr parentOnData = InferenceEngine::details::CNNNetworkHelper::getParent(layer, 0);
checkPrecision(*parentOnData, expectedInputPrecisions[0], 0, true);
} else {
checkPrecision(layer, expectedInputPrecisions[0], 0, true);
}
if (asymmetricQuantizationOnWeights) {
const InferenceEngine::CNNLayerPtr parentOnWeights = InferenceEngine::details::CNNNetworkHelper::getParent(layer, 1);
checkPrecision(*parentOnWeights, expectedInputPrecisions[1], 1, true);
} else {
checkPrecision(layer, expectedInputPrecisions[1], 1, true);
}
} else {
for (size_t inputIndex = 0ul; inputIndex < layer.insData.size(); ++inputIndex) {
checkPrecision(layer, expectedInputPrecisions[inputIndex], inputIndex, true);
}
} }
{ checkPrecision(layer, expectedOutputPrecisions, 0, false);
const InferenceEngine::DataPtr outData = layer.outData[0];
EXPECT_TRUE(outData != nullptr) << "output data is nullable";
const InferenceEngine::Precision actualPrecision = outData->getTensorDesc().getPrecision();
EXPECT_FALSE(std::all_of(
expectedOutputPrecisions.begin(),
expectedOutputPrecisions.end(),
[&](const InferenceEngine::Precision expectedPrecision) { return getDeviceInternalPrecision(expectedPrecision) != actualPrecision; })) <<
"expected output precisions " << expectedOutputPrecisions <<
" actual precision " << actualPrecision;
}
} }
std::pair<float, float> LayerTransformation::getQuantizationInterval(const InferenceEngine::Precision precision) { std::pair<float, float> LayerTransformation::getQuantizationInterval(const InferenceEngine::Precision precision) {

View File

@ -56,7 +56,9 @@ protected:
static void checkPrecisions( static void checkPrecisions(
const InferenceEngine::CNNLayer& layer, const InferenceEngine::CNNLayer& layer,
const std::vector<std::vector<InferenceEngine::Precision>>& expectedInputPrecisions, const std::vector<std::vector<InferenceEngine::Precision>>& expectedInputPrecisions,
const std::vector<InferenceEngine::Precision>& expectedOutputPrecisions); const std::vector<InferenceEngine::Precision>& expectedOutputPrecisions,
const bool asymmetricQuantizationOnData = false,
const bool asymmetricQuantizationOnWeights = false);
static std::pair<float, float> getQuantizationInterval(const InferenceEngine::Precision precision); static std::pair<float, float> getQuantizationInterval(const InferenceEngine::Precision precision);