[LPT] Security fixes (#10243)

This commit is contained in:
Vladislav Golubev
2022-02-09 20:46:39 +03:00
committed by GitHub
parent aedd902cd8
commit d28f8b7857
9 changed files with 32 additions and 18 deletions

View File

@@ -37,16 +37,16 @@ public:
static bool checkElementwise(const std::shared_ptr<ngraph::Node>& elementwise);
static bool checkShape(const std::shared_ptr<ngraph::Node>& elementwise) noexcept;
static bool checkShape(const std::shared_ptr<ngraph::Node>& elementwise);
static int fillDequantizationParams(
const std::shared_ptr<ngraph::Node>& elementwise,
std::shared_ptr<ngraph::opset1::Convert>& convert,
std::shared_ptr<ngraph::opset1::Constant>& constant) noexcept;
std::shared_ptr<ngraph::opset1::Constant>& constant);
static int fillDequantizationParams(
const std::shared_ptr<ngraph::Node>& elementwise,
std::shared_ptr<ngraph::opset1::Constant>& constant) noexcept;
std::shared_ptr<ngraph::opset1::Constant>& constant);
Output<Node> data;
std::shared_ptr<opset1::Convert> convert;

View File

@@ -34,7 +34,7 @@ public:
bool transform(TransformationContext& context, ngraph::pattern::Matcher &m) override;
bool isPrecisionPreserved(std::shared_ptr<Node> layer) const noexcept override;
bool canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> layer) const override;
static bool isQuantizedStatic(const std::shared_ptr<const Node>& layer) noexcept;
static bool isQuantizedStatic(const std::shared_ptr<const Node>& layer);
protected:
static bool isHandled(

View File

@@ -22,7 +22,7 @@ public:
bool canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> layer) const override;
bool isPrecisionPreserved(std::shared_ptr<Node> layer) const noexcept override;
static bool isBroadcasted(const PartialShape& shape) noexcept;
static bool isBroadcasted(const PartialShape& shape);
protected:
int getNotEmpty(const std::shared_ptr<Node>& eltwise) const;
// Return indexes:

View File

@@ -31,8 +31,8 @@ public:
bool transform(TransformationContext& context, ngraph::pattern::Matcher &m) override;
bool canBeTransformed(const TransformationContext& context, std::shared_ptr<Node> layer) const override;
bool isPrecisionPreserved(std::shared_ptr<Node> layer) const noexcept override;
bool isQuantized(const std::shared_ptr<const Node>& layer) const noexcept override;
static bool canBeTransformedToGroupConvolution(const std::shared_ptr<const Node>& layer) noexcept;
bool isQuantized(const std::shared_ptr<const Node>& layer) const override;
static bool canBeTransformedToGroupConvolution(const std::shared_ptr<const Node>& layer);
static bool isDynamicOrScalar(const std::shared_ptr<const Node>& node);
void setGroupSize(const size_t groupSize);

View File

@@ -331,7 +331,7 @@ bool ConcatTransformation::isHandled(const TransformationContext& context, const
return false;
}
bool ConcatTransformation::isQuantizedStatic(const std::shared_ptr<const Node>& layer) noexcept {
bool ConcatTransformation::isQuantizedStatic(const std::shared_ptr<const Node>& layer) {
const auto concat = as_type_ptr<const opset1::Concat>(layer);
if (concat == nullptr) {
return false;
@@ -342,8 +342,8 @@ bool ConcatTransformation::isQuantizedStatic(const std::shared_ptr<const Node>&
return false;
}
const size_t normalizedAxis = ngraph::normalize_axis(concat->get_friendly_name(), concat->get_axis(), outputRank);
return normalizedAxis == 1ul;
const auto normalizedAxis = ngraph::normalize_axis(concat->get_friendly_name(), concat->get_axis(), outputRank);
return normalizedAxis == 1;
}
} // namespace low_precision

View File

@@ -15,7 +15,7 @@ using namespace ngraph;
using namespace ngraph::pass;
using namespace ngraph::pass::low_precision;
bool EltwiseBaseTransformation::isBroadcasted(const PartialShape& shape) noexcept {
bool EltwiseBaseTransformation::isBroadcasted(const PartialShape& shape) {
const auto rank = shape.rank();
if (rank.is_dynamic()) {
return false;

View File

@@ -75,7 +75,7 @@ bool FakeQuantizeDequantization::isLowPrecision() const {
return DataPrecision::isSupported(data.get_element_type());
}
bool FakeQuantizeDequantization::checkShape(const std::shared_ptr<ngraph::Node>& elementwise) noexcept {
bool FakeQuantizeDequantization::checkShape(const std::shared_ptr<ngraph::Node>& elementwise) {
std::shared_ptr<ngraph::opset1::Convert> convert;
std::shared_ptr<ngraph::opset1::Constant> constant;
const int branchIndex = FakeQuantizeDequantization::fillDequantizationParams(elementwise, convert, constant);
@@ -90,7 +90,7 @@ bool FakeQuantizeDequantization::checkShape(const std::shared_ptr<ngraph::Node>&
}
if (!inPShape.rank().is_dynamic()) {
for (int i = 0; i < inPShape.rank().get_length(); ++i) {
for (int i = 0; i < inPShape.size(); ++i) {
if (inPShape[i] != outPShape[i] && !inPShape[i].is_dynamic()) {
return false;
}
@@ -178,7 +178,7 @@ std::shared_ptr<Node> FakeQuantizeDequantization::copyWithNewInput(const std::sh
int FakeQuantizeDequantization::fillDequantizationParams(
const std::shared_ptr<ngraph::Node>& elementwise,
std::shared_ptr<ngraph::opset1::Convert>& convert,
std::shared_ptr<ngraph::opset1::Constant>& constant) noexcept {
std::shared_ptr<ngraph::opset1::Constant>& constant) {
auto fill = [](
const std::shared_ptr<ngraph::Node>& elementwise,
const size_t branchIndex,
@@ -211,7 +211,7 @@ int FakeQuantizeDequantization::fillDequantizationParams(
int FakeQuantizeDequantization::fillDequantizationParams(
const std::shared_ptr<ngraph::Node>& elementwise,
std::shared_ptr<ngraph::opset1::Constant>& constant) noexcept {
std::shared_ptr<ngraph::opset1::Constant>& constant) {
constant = elementwise->get_input_element_type(1ul).is_real() ?
ov::as_type_ptr<opset1::Constant>(elementwise->get_input_node_shared_ptr(1ul)) :
nullptr;

View File

@@ -201,11 +201,11 @@ bool MultiplyToGroupConvolutionTransformation::canBeTransformed(const Transforma
return true;
}
bool MultiplyToGroupConvolutionTransformation::isQuantized(const std::shared_ptr<const Node>& layer) const noexcept {
bool MultiplyToGroupConvolutionTransformation::isQuantized(const std::shared_ptr<const Node>& layer) const {
return MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolution(layer);
}
bool MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolution(const std::shared_ptr<const Node>& layer) noexcept {
bool MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolution(const std::shared_ptr<const Node>& layer) {
const auto parent0 = layer->get_input_node_shared_ptr(0);
const auto parent1 = layer->get_input_node_shared_ptr(1);
@@ -219,7 +219,7 @@ bool MultiplyToGroupConvolutionTransformation::canBeTransformedToGroupConvolutio
return false;
}
return (pShape.rank().get_length() == 4ul) || (pShape.rank().get_length() == 5ul);
return (pShape.size() == 4ul) || (pShape.size() == 5ul);
}
bool MultiplyToGroupConvolutionTransformation::isDynamicOrScalar(const std::shared_ptr<const Node>& node) {

View File

@@ -92,6 +92,20 @@ bool ShuffleChannelsTransformation::canBeTransformed(const TransformationContext
return false;
}
// It's impossible to normalize a negative axis in case of dynamic rank
// but it's necessary when dequantization operations are per channel
if (shuffleChannels->get_input_partial_shape(0).rank().is_dynamic() && shuffleChannels->get_axis() < 0) {
const bool perChannelSub = dequantization.subtractConstant ?
ov::shape_size(dequantization.subtractConstant->get_shape()) > 0 :
false;
const bool perChannelMul = dequantization.multiplyConstant ?
ov::shape_size(dequantization.multiplyConstant->get_shape()) > 0 :
false;
if (perChannelMul || perChannelSub) {
return false;
}
}
return true;
}