[LPT] NNCF GroupConvolution 5D on weights support (#16336)
* [LPT] NNCF GroupConvolution 5D on weights support * PullReshapeThroughDequantization rollback
This commit is contained in:
1 parent
8a246a8bf2
commit
fb24e91416
9 files changed
+1171
-595
No files matched your search
@@ -237,8 +237,15 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph
|
||||
Shape newScaleShape = newScalePShape.to_shape();
|
||||
|
||||
if (!newScaleShape.empty()) {
|
||||
// that's all we need: [C, 1, 1, 1] => [C, 1, 1]
|
||||
newScaleShape.pop_back();
|
||||
const auto input_shape = convolution->get_input_partial_shape(0);
|
||||
const auto diff = newScaleShape.size() - input_shape.size();
|
||||
OPENVINO_ASSERT(
|
||||
newScaleShape.empty() || ((0 <= diff) && (diff <= 2ull)),
|
||||
"unexpected shape size on weights");
|
||||
|
||||
for (size_t i = 0; i <= diff; ++i) {
|
||||
newScaleShape.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
if (reshapeFromWeights != nullptr) {
|
||||
@@ -282,7 +289,12 @@ bool ConvolutionTransformation::transform(TransformationContext &context, ngraph
|
||||
|
||||
const size_t weightsRankValue = weightsPShape.rank().get_length();
|
||||
Shape zeroPointShape(weightsRankValue, 1ul);
|
||||
// output channel or group
|
||||
zeroPointShape[0] = static_cast<size_t>(weightsPShape[0].get_length());
|
||||
if ((reshapeFromWeights == nullptr) && (weightsRankValue == 5ull)) {
|
||||
// output channel
|
||||
zeroPointShape[1] = static_cast<size_t>(weightsPShape[1].get_length());
|
||||
}
|
||||
|
||||
auto zeroPointConstant = fold<opset1::Broadcast>(
|
||||
subtractFromWeights->input_value(1),
|
||||
|
||||
@@ -230,16 +230,16 @@ bool WeightableLayerTransformation::isQuantizedStatic(const std::shared_ptr<cons
|
||||
FakeQuantizeDequantization dequantizationOnWeights;
|
||||
if (reshapeIsRequired) {
|
||||
const auto reshape = layer->get_input_node_shared_ptr(1);
|
||||
if (!ov::is_type<opset1::Reshape>(reshape)) {
|
||||
return false;
|
||||
}
|
||||
std::shared_ptr<Node> parent = ov::is_type<opset1::Reshape>(reshape) ?
|
||||
reshape->get_input_node_shared_ptr(0) :
|
||||
reshape;
|
||||
|
||||
if (ov::is_type<opset1::FakeQuantize>(reshape->get_input_node_shared_ptr(0))) {
|
||||
const std::shared_ptr<opset1::FakeQuantize> fq = ov::as_type_ptr<opset1::FakeQuantize>(reshape->get_input_node_shared_ptr(0));
|
||||
const auto fq = ov::as_type_ptr<opset1::FakeQuantize>(parent);
|
||||
if (fq != nullptr) {
|
||||
return NetworkHelper::isQuantizeSupported(fq);
|
||||
}
|
||||
|
||||
dequantizationOnWeights = NetworkHelper::getDequantization(reshape, defaultPrecisions, 0);
|
||||
dequantizationOnWeights = NetworkHelper::getDequantization(parent, defaultPrecisions, 0, true);
|
||||
} else if (ov::is_type<opset1::FakeQuantize>(layer->get_input_node_shared_ptr(1))) {
|
||||
const std::shared_ptr<opset1::FakeQuantize> fq = ov::as_type_ptr<opset1::FakeQuantize>(layer->get_input_node_shared_ptr(1));
|
||||
return NetworkHelper::isQuantizeSupported(fq);
|
||||
|
||||
+719
-463
File diff suppressed because it is too large.
Load diff
+101
-64
@@ -133,11 +133,17 @@ TEST_P(PullReshapeThroughDequantizationTransformation, CompareFunctions) {
|
||||
ASSERT_TRUE(res.first) << res.second;
|
||||
}
|
||||
|
||||
const std::vector<ngraph::Shape> inputShapes = {ngraph::Shape({1, 960, 7, 7}), ngraph::Shape({4, 960, 7, 7})};
|
||||
// clang-format off
|
||||
|
||||
const std::vector<ngraph::Shape> inputShapes = {
|
||||
ngraph::Shape({1, 960, 7, 7}),
|
||||
ngraph::Shape({4, 960, 7, 7})
|
||||
};
|
||||
|
||||
const std::vector<std::pair<ngraph::Shape, ngraph::Shape>> dequantizationOnWeightElementwiseConstantShapes = {
|
||||
{ngraph::Shape({1, 960}), ngraph::Shape({960, 1, 1, 1})},
|
||||
{ngraph::Shape({9, 960}), ngraph::Shape({960, 1, 3, 3})}};
|
||||
{ngraph::Shape({9, 960}), ngraph::Shape({960, 1, 3, 3})}
|
||||
};
|
||||
|
||||
const std::vector<ngraph::Shape> multiplyShapes = {ngraph::Shape({1, 1, 960, 1})};
|
||||
|
||||
@@ -193,37 +199,51 @@ const std::vector<PullReshapeThroughDequantizationTestValues> testValues = {
|
||||
// \ /
|
||||
// Multiply
|
||||
//
|
||||
{LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),
|
||||
// ActualValues
|
||||
{ngraph::element::u8,
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {9, 960}},
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false},
|
||||
{{0.03f}, element::f32, {/* from parameter */}, false}},
|
||||
{{3, 3, 960, 1}},
|
||||
{{2}, element::f32, {/* from parameter: multiplyShapes */}, false},
|
||||
{{2, 3, 0, 1}},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}},
|
||||
// ExpectedValues
|
||||
{ngraph::element::u8,
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {960, 1, 3, 3}},
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false},
|
||||
{{0.06f}, element::f32, {/* from parameter */}, false}},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}}},
|
||||
{
|
||||
LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),
|
||||
// ActualValues
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {}, false, 1ul, element::u8, true },
|
||||
{ {0.02f}, element::f32, {}, false }
|
||||
},
|
||||
{ std::vector<float>{ 2.f }, ngraph::element::i8, {9, 960}},
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {/* from parameter */}, false },
|
||||
{ {0.03f}, element::f32, {/* from parameter */}, false }
|
||||
},
|
||||
{ {3, 3, 960, 1} },
|
||||
{ {2}, element::f32, {/* from parameter: multiplyShapes */}, false },
|
||||
{ {2, 3, 0, 1} },
|
||||
{ {960, 1, 1, 3, 3} },
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
},
|
||||
// ExpectedValues
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {}, false, 1ul, element::u8, true },
|
||||
{ {0.02f}, element::f32, {}, false }
|
||||
},
|
||||
{ std::vector<float>{ 2.f }, ngraph::element::i8, {960, 1, 3, 3}},
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {/* from parameter */}, false },
|
||||
{ {0.06f}, element::f32, {/* from parameter */}, false }
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
}
|
||||
},
|
||||
|
||||
// Subtract with Convert + Constant
|
||||
// Actual:
|
||||
@@ -276,37 +296,54 @@ const std::vector<PullReshapeThroughDequantizationTestValues> testValues = {
|
||||
// \ /
|
||||
// Multiply
|
||||
//
|
||||
{LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),
|
||||
// ActualValues
|
||||
{ngraph::element::u8,
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {9, 960}},
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false, 1ul, element::i8, true},
|
||||
{{0.03f}, element::f32, {/* from parameter */}, false}},
|
||||
{{3, 3, 960, 1}},
|
||||
{{2}, element::f32, {/* from parameter: multiplyShapes */}, false},
|
||||
{{2, 3, 0, 1}},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}},
|
||||
// ExpectedValues
|
||||
{ngraph::element::u8,
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {960, 1, 3, 3}},
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false, 1ul, element::i8, true},
|
||||
{{0.06f}, element::f32, {/* from parameter */}, false}},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}}}};
|
||||
{
|
||||
LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),
|
||||
// ActualValues
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {}, false, 1ul, element::u8, true },
|
||||
{ {0.02f}, element::f32, {}, false }
|
||||
},
|
||||
{ std::vector<float>{ 2.f }, ngraph::element::i8, {9, 960}},
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {/* from parameter */}, false, 1ul, element::i8, true },
|
||||
{ {0.03f}, element::f32, {/* from parameter */}, false }
|
||||
},
|
||||
{ {3, 3, 960, 1} },
|
||||
{ {2}, element::f32, {/* from parameter: multiplyShapes */}, false },
|
||||
{ {2, 3, 0, 1} },
|
||||
{ {960, 1, 1, 3, 3} },
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
},
|
||||
// ExpectedValues
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {}, false, 1ul, element::u8, true },
|
||||
{ {0.02f}, element::f32, {}, false }
|
||||
},
|
||||
{ std::vector<float>{ 2.f }, ngraph::element::i8, {960, 1, 3, 3}},
|
||||
{
|
||||
{ ngraph::element::f32, false },
|
||||
{ {127.f}, element::f32, {/* from parameter */}, false, 1ul, element::i8, true },
|
||||
{ {0.06f}, element::f32, {/* from parameter */}, false }
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LPT,
|
||||
PullReshapeThroughDequantizationTransformation,
|
||||
|
||||
+54
-32
@@ -126,7 +126,12 @@ TEST_P(PullTransposeThroughDequantizationTransformation, CompareFunctions) {
|
||||
ASSERT_TRUE(res.first) << res.second;
|
||||
}
|
||||
|
||||
const std::vector<ngraph::Shape> inputShapes = {ngraph::Shape({1, 960, 7, 7}), ngraph::Shape({4, 960, 7, 7})};
|
||||
// clang-format off
|
||||
|
||||
const std::vector<ngraph::Shape> inputShapes = {
|
||||
ngraph::Shape({1, 960, 7, 7}),
|
||||
ngraph::Shape({4, 960, 7, 7})
|
||||
};
|
||||
|
||||
const std::vector<std::pair<ngraph::Shape, ngraph::Shape>> dequantizationOnWeightElementwiseConstantShapes = {
|
||||
{ngraph::Shape({}), ngraph::Shape({1, 1, 1, 1})},
|
||||
@@ -178,37 +183,54 @@ const std::vector<PullTransposeThroughDequantizationTestValues> testValues = {
|
||||
// \ /
|
||||
// Multiply
|
||||
//
|
||||
{LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),
|
||||
// ActualValues
|
||||
{ngraph::element::u8,
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {3, 3, 960, 1}},
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false},
|
||||
{{0.03f}, element::f32, {/* from parameter */}, false}},
|
||||
{}, // reshape1
|
||||
{}, // multiply
|
||||
{{2, 3, 0, 1}},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}},
|
||||
// ExpectedValues
|
||||
{ngraph::element::u8,
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {960, 1, 3, 3}},
|
||||
{{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false},
|
||||
{{0.03f}, element::f32, {/* from parameter */}, false}},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}}}};
|
||||
{
|
||||
LayerTransformation::createParamsU8I8().setSupportAsymmetricQuantization(true),
|
||||
// ActualValues
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}
|
||||
},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {3, 3, 960, 1}},
|
||||
{
|
||||
{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false},
|
||||
{{0.03f}, element::f32, {/* from parameter */}, false}
|
||||
},
|
||||
{}, // reshape1
|
||||
{}, // multiply
|
||||
{{2, 3, 0, 1}},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
},
|
||||
// ExpectedValues
|
||||
{
|
||||
ngraph::element::u8,
|
||||
{
|
||||
{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {}, false, 1ul, element::u8, true},
|
||||
{{0.02f}, element::f32, {}, false}
|
||||
},
|
||||
{std::vector<float>{2.f}, ngraph::element::i8, {960, 1, 3, 3}},
|
||||
{
|
||||
{ngraph::element::f32, false},
|
||||
{{127.f}, element::f32, {/* from parameter */}, false},
|
||||
{{0.03f}, element::f32, {/* from parameter */}, false}
|
||||
},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{{960, 1, 1, 3, 3}},
|
||||
ngraph::element::f32,
|
||||
{}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(smoke_LPT,
|
||||
PullTransposeThroughDequantizationTransformation,
|
||||
|
||||
Reference in new issue
Block a user