do not change names while replacing FQ nodes (#17936)

* do not change names while replacing FQ nodes

* more solid fix

* even more solid fix

* fix UT failure
This commit is contained in:
Pavel Esir 2023-06-16 13:51:50 +02:00 committed by GitHub
parent a4519f0a2c
commit cb63b39c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 9 deletions

View File

@ -36,7 +36,9 @@ public:
const std::vector<ngraph::element::Type>& defaultPrecisions = precision_set::int8_support);
protected:
bool decomposeFakeQuantizeForWeightsPath(const std::shared_ptr<Node>& weightableLayer, size_t outChannelsShapeIndex = 0ul) const;
std::tuple<bool, std::shared_ptr<Node>, std::shared_ptr<Node>> decomposeFakeQuantizeForWeightsPath(
const std::shared_ptr<Node>& weightableLayer,
size_t outChannelsShapeIndex = 0ul) const;
static bool isGroup(const std::shared_ptr<Node>& node);
static bool isDepthwise(const std::shared_ptr<Node>& node);
virtual size_t getInputChannels(const std::shared_ptr<ngraph::Node> conv) const = 0;

View File

@ -88,7 +88,14 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph
convolution = NetworkHelper::separateInStandaloneBranch(convolution, defaultPrecisions);
const bool fqOnWeightsWasDecomposed = decomposeFakeQuantizeForWeightsPath(convolution);
const auto& res_tuple = decomposeFakeQuantizeForWeightsPath(convolution);
auto fqOnWeightsWasDecomposed = std::get<0>(res_tuple);
auto newFQ = std::get<1>(res_tuple);
auto dequantize = std::get<2>(res_tuple);
if (newFQ != nullptr && dequantize != nullptr)
updateOutput(context, dequantize, newFQ);
if (updatePrecisions && !fqOnWeightsWasDecomposed) {
return false;
}

View File

@ -141,7 +141,12 @@ bool ConvolutionBackpropDataTransformation::transform(TransformationContext &con
}
{
decomposeFakeQuantizeForWeightsPath(convolutionBackpropData, 1ul);
const auto& res_tuple = decomposeFakeQuantizeForWeightsPath(convolutionBackpropData, 1ul);
auto newFQ = std::get<1>(res_tuple);
auto dequantize = std::get<2>(res_tuple);
if (newFQ != nullptr && dequantize != nullptr)
updateOutput(context, dequantize, newFQ);
dequantization = NetworkHelper::getDequantization(convolutionBackpropData, defaultPrecisions, 1ul);
if (const auto fq = ov::as_type_ptr<ov::opset1::FakeQuantize>(dequantization.data.get_node_shared_ptr())) {

View File

@ -324,11 +324,13 @@ bool WeightableLayerTransformation::isPrecisionPreserved(std::shared_ptr<Node> l
return false;
}
bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const std::shared_ptr<Node>& node, const size_t outChannelsShapeIndex) const {
std::tuple<bool, std::shared_ptr<Node>, std::shared_ptr<Node>> WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(
const std::shared_ptr<Node>& node,
const size_t outChannelsShapeIndex) const {
const auto fq = getFakeQuantizeOnWeights(node);
if (fq == nullptr) {
// FakeQuantize has been decomposed already
return true;
return std::make_tuple(true, nullptr, nullptr);
}
const QuantizationDetails quantizationDetails = QuantizationDetails::getDetails(fq);
@ -339,7 +341,7 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st
const DataPrecision dataPrecision = getDataPrecision(fq, quantizationDetails, precisions);
if (dataPrecision.empty()) {
return false;
return std::make_tuple(false, nullptr, nullptr);
}
auto tuple = NetworkHelper::decomposeFakeQuantize(
@ -352,17 +354,19 @@ bool WeightableLayerTransformation::decomposeFakeQuantizeForWeightsPath(const st
element::f32,
outChannelsShapeIndex);
std::shared_ptr<ngraph::Node> fqOnWeights = std::get<0>(tuple);
std::shared_ptr<Node> fqOnWeights = std::get<0>(tuple);
std::shared_ptr<Node> dequantize = std::get<1>(tuple);
// TODO: LPT: issue #58685
if ((!updatePrecisions) && (fqOnWeights == nullptr)) {
return false;
return std::make_tuple(false, nullptr, nullptr);
}
if (ov::as_type_ptr<ov::opset1::Constant>(fqOnWeights) == nullptr) {
THROW_IE_LPT_EXCEPTION(*fqOnWeights) << "FakeQuantize on weights was not folded to constant";
}
return true;
return std::make_tuple(true, fqOnWeights, dequantize);
}
bool WeightableLayerTransformation::isGroup(const std::shared_ptr<Node>& layer) {