Skip to content

Commit

Permalink
[LPT] LPT CNNNetwork usage macros: part #1: source code
Browse files Browse the repository at this point in the history
  • Loading branch information
eshoguli committed Oct 18, 2020
1 parent bdf93e1 commit 4021c8c
Show file tree
Hide file tree
Showing 190 changed files with 255 additions and 2,598 deletions.
7 changes: 0 additions & 7 deletions inference-engine/src/cldnn_engine/cldnn_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ void Config::UpdateFromMap(const std::map<std::string, std::string>& configMap)
} else {
THROW_IE_EXCEPTION << NOT_FOUND_str << "Unsupported property value by plugin: " << val;
}
} else if (key.compare(PluginConfigInternalParams::KEY_LP_TRANSFORMS_VERSION) == 0) {
if (val == PluginConfigInternalParams::LP_TRANSFORMS_CNNNETWORK)
lptVersion = LptVersion::cnnNetwork;
else if (val == PluginConfigInternalParams::LP_TRANSFORMS_NGRAPH)
lptVersion = LptVersion::nGraph;
else
THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigInternalParams::KEY_LP_TRANSFORMS_MODE;
} else if (key.compare(CLDNNConfigParams::KEY_CLDNN_NV12_TWO_INPUTS) == 0) {
if (val.compare(PluginConfigParams::YES) == 0) {
nv12_two_inputs = true;
Expand Down
6 changes: 0 additions & 6 deletions inference-engine/src/cldnn_engine/cldnn_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
namespace CLDNNPlugin {

struct Config {
enum LptVersion {
cnnNetwork,
nGraph
};

Config() : throughput_streams(1),
useProfiling(false),
dumpCustomKernels(false),
Expand Down Expand Up @@ -54,7 +49,6 @@ struct Config {
bool memory_pool_on;
bool enableDynamicBatch;
bool enableInt8;
LptVersion lptVersion = LptVersion::nGraph;
bool nv12_two_inputs;
bool enable_fp16_for_quantized_models;
cldnn::priority_mode_types queuePriority;
Expand Down
10 changes: 7 additions & 3 deletions inference-engine/src/cldnn_engine/cldnn_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In
// Disable shape inference (WA for generic operations)
::ngraph::op::GenericIE::DisableReshape noReshape(nGraphFunc);

#ifndef USE_CNNNETWORK_LPT
bool enableInt8;
#endif

{
// Note: instead of running all Conversion Transformations you can make up your own transformation pipeline
Expand All @@ -165,13 +167,13 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In

ngraph::pass::Manager conversion_manager;

enableInt8 = config.enableInt8 &&
(config.lptVersion == Config::LptVersion::nGraph) &&
ngraph::pass::low_precision::LowPrecisionTransformer::isFunctionQuantized(nGraphFunc);
#ifndef USE_CNNNETWORK_LPT
enableInt8 = config.enableInt8 && ngraph::pass::low_precision::LowPrecisionTransformer::isFunctionQuantized(nGraphFunc);
if (enableInt8) {
// [WA part1] Convert quantized FP16 model to FP32 to avoid possible overflow and mixed precision errors
conversion_manager.register_pass<ngraph::pass::ConvertPrecision>(ngraph::element::f16, ngraph::element::f32);
}
#endif

conversion_manager.set_callback(fp16_callback);
conversion_manager.run_passes(nGraphFunc);
Expand All @@ -183,6 +185,7 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In
ti_manager.run_passes(nGraphFunc);
}

#ifndef USE_CNNNETWORK_LPT
using namespace ngraph::pass::low_precision;
if (enableInt8) {
auto params = LayerTransformation::Params(
Expand All @@ -195,6 +198,7 @@ InferenceEngine::ICNNNetwork::Ptr clDNNEngine::CloneAndTransformNetwork(const In

transformer.transform(nGraphFunc);
}
#endif

{
ngraph::pass::Manager manager = ngraph::pass::Manager();
Expand Down
4 changes: 3 additions & 1 deletion inference-engine/src/cldnn_engine/cldnn_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ Program::Program(InferenceEngine::ICNNNetwork& network, std::shared_ptr<const cl
baselineIsFP16 = true;
}

#ifdef USE_CNNNETWORK_LPT
bool fqFound = false;
bool allFQareSupported = true;
if (config.enableInt8) {
Expand All @@ -429,7 +430,7 @@ Program::Program(InferenceEngine::ICNNNetwork& network, std::shared_ptr<const cl
}
}

if (config.enableInt8 && (config.lptVersion == Config::LptVersion::cnnNetwork)) {
if (config.enableInt8) {
auto params = LayerTransformation::Params(true, // updatePrecisions
true, // quantizeOutputs
true, // weightsToConst
Expand Down Expand Up @@ -522,6 +523,7 @@ Program::Program(InferenceEngine::ICNNNetwork& network, std::shared_ptr<const cl
}
}
}
#endif

NetPass::CombineRNNSeq(network);
for (int i = 0; i < 2; i++) {
Expand Down
7 changes: 0 additions & 7 deletions inference-engine/src/mkldnn_plugin/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ void Config::readProperties(const std::map<std::string, std::string> &prop) {
lpTransformsMode = LPTransformsMode::On;
else
THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigInternalParams::KEY_LP_TRANSFORMS_MODE;
} else if (key.compare(PluginConfigInternalParams::KEY_LP_TRANSFORMS_VERSION) == 0) {
if (val == PluginConfigInternalParams::LP_TRANSFORMS_CNNNETWORK)
lptVersion = LptVersion::cnnNetwork;
else if (val == PluginConfigInternalParams::LP_TRANSFORMS_NGRAPH)
lptVersion = LptVersion::nGraph;
else
THROW_IE_EXCEPTION << "Wrong value for property key " << PluginConfigInternalParams::KEY_LP_TRANSFORMS_MODE;
} else if (key.compare(PluginConfigParams::KEY_DUMP_QUANTIZED_GRAPH_AS_DOT) == 0) {
dumpQuantizedGraphToDot = val;
} else if (key.compare(PluginConfigParams::KEY_DUMP_QUANTIZED_GRAPH_AS_IR) == 0) {
Expand Down
6 changes: 0 additions & 6 deletions inference-engine/src/mkldnn_plugin/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ struct Config {
On,
};

enum LptVersion {
cnnNetwork,
nGraph
};

bool collectPerfCounters = false;
bool exclusiveAsyncRequests = false;
bool enableDynamicBatch = false;
Expand All @@ -38,7 +33,6 @@ struct Config {
bool enforceBF16 = false;
#else
LPTransformsMode lpTransformsMode = LPTransformsMode::On;
LptVersion lptVersion = LptVersion::nGraph;
bool enforceBF16 = true;
#endif

Expand Down
4 changes: 3 additions & 1 deletion inference-engine/src/mkldnn_plugin/mkldnn_exec_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ MKLDNNExecNetwork::MKLDNNExecNetwork(const InferenceEngine::ICNNNetwork &network
// we are cloning network if we have statistics and we can transform network.
_clonedNetwork = cloneNet(network);

if ((cfg.lptVersion == Config::LptVersion::cnnNetwork) && (_cfg.lpTransformsMode == Config::LPTransformsMode::On)) {
#ifdef USE_CNNNETWORK_LPT
if (_cfg.lpTransformsMode == Config::LPTransformsMode::On) {
auto params = LayerTransformation::Params(true, // updatePrecisions
true, // quantizeOutputs
true, // weightsToConst
Expand Down Expand Up @@ -95,6 +96,7 @@ MKLDNNExecNetwork::MKLDNNExecNetwork(const InferenceEngine::ICNNNetwork &network
bf16Transformer.convertToFloat(cnnetwork);
}
}
#endif

MKLDNNGraph::ApplyUnrollPasses(static_cast<ICNNNetwork&>(*_clonedNetwork));

Expand Down
4 changes: 3 additions & 1 deletion inference-engine/src/mkldnn_plugin/mkldnn_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ static void Transformation(ICNNNetwork::Ptr& clonedNetwork, const Config& conf)

manager.run_passes(nGraphFunc);

#ifndef USE_CNNNETWORK_LPT
using namespace ngraph::pass::low_precision;
if ((conf.lptVersion == Config::LptVersion::nGraph) && (conf.lpTransformsMode == Config::LPTransformsMode::On)) {
if (conf.lpTransformsMode == Config::LPTransformsMode::On) {
auto params = LayerTransformation::Params(
true, // updatePrecisions
LayerTransformation::QuantizedTensorAlignment::UpdateLevel, // quantizedTensorAlignmentOnActivations
Expand All @@ -164,6 +165,7 @@ static void Transformation(ICNNNetwork::Ptr& clonedNetwork, const Config& conf)

transformer.transform(nGraphFunc);
}
#endif

ngraph::pass::Manager legacyManager;
legacyManager.register_pass<ngraph::pass::ConvertOpSet1ToLegacy>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ namespace PluginConfigInternalParams {
*/
DECLARE_CONFIG_KEY(LP_TRANSFORMS_MODE);

/**
* @brief Defines a low precision version key
* @ingroup ie_dev_api_plugin_api
*/
DECLARE_CONFIG_KEY(LP_TRANSFORMS_VERSION);
/**
* @brief generic KEY_LP_TRANSFORMS_VERSION values
*/
DECLARE_CONFIG_VALUE(LP_TRANSFORMS_CNNNETWORK);
DECLARE_CONFIG_VALUE(LP_TRANSFORMS_NGRAPH);

/**
* @brief This key should be used to mark input executable subnetworks
* @ingroup ie_dev_api_plugin_api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,4 @@ const std::vector<DepthToSpaceTransformationTestValues> testValues = {
},
};

INSTANTIATE_TEST_CASE_P(LPT, DepthToSpaceTransformation, ::testing::ValuesIn(testValues), DepthToSpaceTransformation::getTestCaseName);
INSTANTIATE_TEST_CASE_P(smoke_LPT, DepthToSpaceTransformation, ::testing::ValuesIn(testValues), DepthToSpaceTransformation::getTestCaseName);
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef std::tuple<
// mulDataInput
size_t> GetDequantizationTestValues;

class GetDequantization : public LayerTransformation, public testing::WithParamInterface<GetDequantizationTestValues> {
class GetDequantizationTransformation : public LayerTransformation, public testing::WithParamInterface<GetDequantizationTestValues> {
public:
void SetUp() override {
bool isConvert;
Expand Down Expand Up @@ -70,19 +70,19 @@ std::vector<size_t> subDataInput = { 0ul, 1ul };
std::vector<size_t> mulDataInput = { 0ul, 1ul };


TEST_P(GetDequantization, CompareFunctions) {
TEST_P(GetDequantizationTransformation, CompareFunctions) {
InitNodeInfo().run_on_function(actualFunction);
actualFunction->validate_nodes_and_infer_types();

auto res = compare_functions(referenceFunction, actualFunction, true);
ASSERT_TRUE(res.first) << res.second;
}

INSTANTIATE_TEST_CASE_P(LPT, GetDequantization,
INSTANTIATE_TEST_CASE_P(smoke_LPT, GetDequantizationTransformation,
::testing::Combine(
::testing::ValuesIn(isConvert),
::testing::ValuesIn(isSubtract),
::testing::ValuesIn(subDataInput),
::testing::ValuesIn(mulDataInput)),
GetDequantization::getTestCaseName);
GetDequantizationTransformation::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ const std::vector<ngraph::element::Type> netPrecisions = {
//ngraph::element::f16
};

const std::vector<LayerTestsUtils::LayerTransformation::LptVersion> versions = {
LayerTestsUtils::LayerTransformation::LptVersion::cnnNetwork,
LayerTestsUtils::LayerTransformation::LptVersion::nGraph
};

const std::vector<LayerTestsDefinitions::AddTestValues> params = {
{
{ 256ul, ngraph::Shape { 1, 1, 1, 1 }, { 0.f }, { 255.f }, { 0.f }, { 255.f } },
Expand Down Expand Up @@ -73,12 +68,11 @@ const std::vector<LayerTestsDefinitions::AddTestValues> params = {
{ {}, {}, false }, { {}, {}, true },
};

INSTANTIATE_TEST_CASE_P(LPT, AddTransformation,
INSTANTIATE_TEST_CASE_P(smoke_LPT, AddTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(InferenceEngine::SizeVector({ 1, 3, 16, 16 })),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(versions),
::testing::ValuesIn(params)),
AddTransformation::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> tras
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8()
};

const std::vector<LayerTestsUtils::LayerTransformation::LptVersion> versions = {
LayerTestsUtils::LayerTransformation::LptVersion::nGraph
};

const std::vector<LayerTestsDefinitions::ClampTransformationParam> params{
// tensor quantization
{
Expand Down Expand Up @@ -80,13 +76,12 @@ const std::vector<LayerTestsDefinitions::ClampTransformationParam> params{
}
};

INSTANTIATE_TEST_CASE_P(LPT, ClampTransformation,
INSTANTIATE_TEST_CASE_P(smoke_LPT, ClampTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(ngraph::Shape({ 1, 3, 16, 16 })),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(versions),
::testing::ValuesIn(params)),
ClampTransformation::getTestCaseName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ const std::vector<ngraph::element::Type> precisions = {
// ngraph::element::f16
};

const std::vector<LayerTestsUtils::LayerTransformation::LptVersion> versions = {
LayerTestsUtils::LayerTransformation::LptVersion::cnnNetwork,
LayerTestsUtils::LayerTransformation::LptVersion::nGraph
};

const std::vector<ConcatTransformationTestValues> testValues = {
// U8
{
Expand Down Expand Up @@ -54,7 +49,6 @@ INSTANTIATE_TEST_CASE_P(smoke_LPT, ConcatTransformation,
::testing::ValuesIn(precisions),
::testing::ValuesIn(shapes),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(testValues),
::testing::ValuesIn(versions)),
::testing::ValuesIn(testValues)),
ConcatTransformation::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> tras
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8()
};

const std::vector<LayerTestsUtils::LayerTransformation::LptVersion> versions = {
LayerTestsUtils::LayerTransformation::LptVersion::nGraph,
LayerTestsUtils::LayerTransformation::LptVersion::cnnNetwork
};

const std::vector<ConcatWithDifferentChildsTransformationParam> testValues = {
// U8
{
Expand All @@ -50,14 +45,13 @@ const std::vector<ConcatWithDifferentChildsTransformationParam> testValues = {

const std::vector<bool> multiChannel = { true/*, false*/ };

INSTANTIATE_TEST_CASE_P(LPT, ConcatWithDifferentChildsTransformation,
INSTANTIATE_TEST_CASE_P(smoke_LPT, ConcatWithDifferentChildsTransformation,
::testing::Combine(
::testing::ValuesIn(netPrecisions),
::testing::Values(ngraph::Shape({ 1, 6, 10, 10 })),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(testValues),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(versions),
::testing::ValuesIn(multiChannel)),
ConcatWithDifferentChildsTransformation::getTestCaseName);
} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> tras
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8()
};

const std::vector<LayerTestsUtils::LayerTransformation::LptVersion> versions = {
LayerTestsUtils::LayerTransformation::LptVersion::cnnNetwork,
LayerTestsUtils::LayerTransformation::LptVersion::nGraph
};

const std::vector<bool> transparentIntermediateValues = { true, false };
const std::vector<bool> multiChannelValues = { /*true,*/ false };

Expand All @@ -42,7 +37,6 @@ INSTANTIATE_TEST_CASE_P(smoke_LPT, ConcatWithIntermediateTransformation,
::testing::ValuesIn(shapes),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(versions),
::testing::ValuesIn(transparentIntermediateValues),
::testing::ValuesIn(multiChannelValues)),
ConcatWithIntermediateTransformation::getTestCaseName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,16 @@ const std::vector<ngraph::pass::low_precision::LayerTransformation::Params> tras
LayerTestsUtils::LayerTransformationParamsNGraphFactory::createParamsU8I8()
};

const std::vector<LayerTestsUtils::LayerTransformation::LptVersion> versions = {
LayerTestsUtils::LayerTransformation::LptVersion::cnnNetwork,
LayerTestsUtils::LayerTransformation::LptVersion::nGraph
};

const std::vector<ngraph::Shape> shapes = {
{ 1, 3, 16, 16 },
{ 4, 3, 16, 16 }
};

INSTANTIATE_TEST_CASE_P(LPT, ConcatWithNeighborsGraphTransformation,
INSTANTIATE_TEST_CASE_P(smoke_LPT, ConcatWithNeighborsGraphTransformation,
::testing::Combine(
::testing::ValuesIn(precisions),
::testing::ValuesIn(shapes),
::testing::Values(CommonTestUtils::DEVICE_CPU),
::testing::ValuesIn(trasformationParamValues),
::testing::ValuesIn(versions)),
::testing::ValuesIn(trasformationParamValues)),
ConcatWithNeighborsGraphTransformation::getTestCaseName);
} // namespace
Loading

0 comments on commit 4021c8c

Please sign in to comment.