-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LPT] Quantized LSTMSequence & GRUSequence extended support (#25654)
### Details: - *Low Precision Transformations: Quantized LSTMSequence & GRUSequence extended support* ### Tickets: - Current implementation for: *CVS-146067* - Will be changed in feature request: *CVS-147588*
- Loading branch information
Showing
16 changed files
with
608 additions
and
76 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/common/low_precision_transformations/include/low_precision/broadcast.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#pragma once | ||
|
||
#include "transparent_base_transformation.hpp" | ||
|
||
namespace ov { | ||
namespace pass { | ||
namespace low_precision { | ||
|
||
/** | ||
* @ingroup ov_transformation_common_api | ||
* @brief BroadcastTransformation propagates dequantization operations through Broadcast operation. | ||
* | ||
* For more details about the transformation, refer to | ||
* [BroadcastTransformation](@ref openvino_docs_OV_UG_lpt_BroadcastTransformation) page | ||
* in the OpenVINO Developer Guide. | ||
*/ | ||
class LP_TRANSFORMATIONS_API BroadcastTransformation : public TransparentBaseTransformation { | ||
public: | ||
OPENVINO_RTTI("BroadcastTransformation", "0"); | ||
BroadcastTransformation(const Params& params = Params()); | ||
bool canBeTransformed(const TransformationContext& context, std::shared_ptr<ov::Node> layer) const override; | ||
}; | ||
|
||
} // namespace low_precision | ||
} // namespace pass | ||
} // namespace ov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/common/low_precision_transformations/src/broadcast.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (C) 2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "low_precision/broadcast.hpp" | ||
|
||
#include <memory> | ||
|
||
#include "openvino/opsets/opset1.hpp" | ||
#include "openvino/opsets/opset3.hpp" | ||
#include "openvino/pass/pattern/op/or.hpp" | ||
#include "openvino/pass/pattern/op/wrap_type.hpp" | ||
#include "low_precision/network_helper.hpp" | ||
|
||
#include "itt.hpp" | ||
|
||
using namespace ov::pass::low_precision; | ||
|
||
BroadcastTransformation::BroadcastTransformation(const Params& params) : TransparentBaseTransformation(params) { | ||
MATCHER_SCOPE(BroadcastTransformation); | ||
auto broadcast1 = pattern::wrap_type<ov::opset1::Broadcast>({ | ||
pattern::wrap_type<ov::opset1::Multiply>(), | ||
ov::pass::pattern::any_input(), | ||
ov::pass::pattern::any_input() }); | ||
|
||
auto broadcast3 = pattern::wrap_type<ov::opset3::Broadcast>({ | ||
pattern::wrap_type<ov::opset1::Multiply>(), | ||
ov::pass::pattern::any_input(), | ||
ov::pass::pattern::any_input() }); | ||
|
||
const auto matcher = std::make_shared<ov::pass::pattern::op::Or>(ov::OutputVector{ broadcast1, broadcast3 }); | ||
|
||
ov::graph_rewrite_callback callback = [this](pattern::Matcher& m) { | ||
auto op = m.get_match_root(); | ||
if (transformation_callback(op)) { | ||
return false; | ||
} | ||
return transform(*context, m); | ||
}; | ||
|
||
auto m = std::make_shared<ov::pass::pattern::Matcher>(matcher, matcher_name); | ||
this->register_matcher(m, callback); | ||
} | ||
|
||
bool BroadcastTransformation::canBeTransformed(const TransformationContext& context, std::shared_ptr<ov::Node> layer) const { | ||
if (!LayerTransformation::canBeTransformed(context, layer)) { | ||
return false; | ||
} | ||
|
||
const auto& dequantization = NetworkHelper::getDequantization(layer, defaultPrecisions); | ||
if (dequantization.empty()) { | ||
return false; | ||
} | ||
|
||
if (dequantization.isPerTensor()) { | ||
return true; | ||
} | ||
|
||
const auto& inputShape = layer->get_input_partial_shape(0); | ||
if (inputShape.rank().is_dynamic() || inputShape[dequantization.channelDimIndex].is_dynamic()) { | ||
return false; | ||
} | ||
|
||
const auto targetShapeConstant = ov::as_type_ptr<ov::opset1::Constant>(layer->get_input_node_shared_ptr(1)); | ||
const auto& targetShape = targetShapeConstant->cast_vector<int64_t>(); | ||
if (targetShape[dequantization.channelDimIndex] != inputShape[dequantization.channelDimIndex].get_length()) { | ||
return false; | ||
} | ||
|
||
const auto axesMappingConstant = ov::as_type_ptr<ov::opset1::Constant>(layer->get_input_node_shared_ptr(2)); | ||
const auto& axesMapping = axesMappingConstant->cast_vector<int64_t>(); | ||
if (static_cast<size_t>(axesMapping[dequantization.channelDimIndex]) != dequantization.channelDimIndex) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.