Skip to content

Update OpenVINO init of new GEMM layer#24309

Merged
asmorkalov merged 4 commits intoopencv:4.xfrom
dkurt:gemm_ov_hotfix
Sep 27, 2023
Merged

Update OpenVINO init of new GEMM layer#24309
asmorkalov merged 4 commits intoopencv:4.xfrom
dkurt:gemm_ov_hotfix

Conversation

@dkurt
Copy link
Copy Markdown
Member

@dkurt dkurt commented Sep 21, 2023

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

CI validation:

Checklist:

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Custom

build_image:Custom=ubuntu-openvino-2021.4.2:20.04
Xbuild_image:Custom=ubuntu-openvino-2022.1.0:20.04

test_modules:Custom=dnn,python2,python3,java,gapi,video

buildworker:Custom=linux-4
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@dkurt dkurt requested a review from fengyuentau September 21, 2023 13:01
@asmorkalov asmorkalov added this to the 4.9.0 milestone Sep 21, 2023
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Build with OpenVINO 2022.1.1.

@asmorkalov
Copy link
Copy Markdown
Contributor

Locally failed tests:

[  PASSED  ] 9440 tests.
[  FAILED  ] 17 tests, listed below:
[  FAILED  ] DNNTestNetwork.FastNeuralStyle_eccv16/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] DNNTestNetwork.FastNeuralStyle_eccv16/1, where GetParam() = OCV/OCL
[  FAILED  ] Test_Model.Keypoints_face/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_Model.TextRecognitionWithCTCPrefixBeamSearch/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Linear/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Multiplication/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Constant/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.LinearWithConstant/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.MatmulWithTwoInputs/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Gemm/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Gemm_bias/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Conformance_Gemm_all_attributes/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Conformance_Gemm_alpha/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Conformance_Gemm_beta/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_layers.Conformance_Gemm_default_matrix_bias/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_nets.LResNet100E_IR/0, where GetParam() = NGRAPH/CPU
[  FAILED  ] Test_ONNX_nets.Resnet34_kinetics/0, where GetParam() = NGRAPH/CPU

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Sep 21, 2023

@asmorkalov, thanks, I will fix it.

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Sep 21, 2023

Remaining failed test: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100366

[  FAILED  ] 1 test, listed below:
[  FAILED  ] Test_ONNX_nets.Googlenet/0, where GetParam() = NGRAPH/CPU

perf:

[  FAILED  ] 6 tests, listed below:
[  FAILED  ] Gemm.innerproduct/0, where GetParam() = (A=[768, 768], B=[768, 768], C=[768], trans_a=0, trans_b=0, NGRAPH/CPU)
[  FAILED  ] Gemm.innerproduct/2, where GetParam() = (A=[1024, 1024], B=[1024, 1024], C=[1024], trans_a=0, trans_b=0, NGRAPH/CPU)
[  FAILED  ] Gemm.innerproduct/4, where GetParam() = (A=[50, 768], B=[768, 2304], trans_a=0, trans_b=0, NGRAPH/CPU)
[  FAILED  ] Gemm.innerproduct/6, where GetParam() = (A=[197, 768], B=[768, 2304], trans_a=0, trans_b=0, NGRAPH/CPU)
[  FAILED  ] Gemm.innerproduct/8, where GetParam() = (A=[50, 1024], B=[1024, 3072], trans_a=0, trans_b=0, NGRAPH/CPU)
[  FAILED  ] Gemm.innerproduct/10, where GetParam() = (A=[197, 1024], B=[1024, 3072], trans_a=0, trans_b=0, NGRAPH/CPU)

if (have_bias && const_C) {
auto bias_node = std::make_shared<ngraph::op::Constant>(ngraph::element::f32,
ngraph::Shape{(size_t)blobs.back().size[1]}, blobs.back().data);
Mat bias = blobs.back();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the GoogleNet test, I suspect a manual broadcast is needed for bias. I saw somewhere before that it seems openvino nodes cannot perform auto-broadcast.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Problem was in OpenVINO iterpretation of the batch dimension. Adding reshape from [2, 1, 1024] back to [2, 1024] solved it.

@fengyuentau
Copy link
Copy Markdown
Member

As for the perf tests, maybe you need to change initialization to pass the check:

if (ld.id == 0)
{
CV_Assert((netInputLayer->outNames.empty() && ld.outputBlobsWrappers.size() == 1) ||
(netInputLayer->outNames.size() == ld.outputBlobsWrappers.size()));
for (int i = 0; i < ld.outputBlobsWrappers.size(); ++i)
{
std::string outputName = netInputLayer->outNames.empty() ? ld.name : netInputLayer->outNames[i];
outputName = ld.outputBlobsWrappers.size() > 1 ? (outputName + "." + std::to_string(i)) : outputName;
ld.outputBlobsWrappers[i].dynamicCast<NgraphBackendWrapper>()->name = outputName;
}
}

@fengyuentau
Copy link
Copy Markdown
Member

I guess it does not make a lot of senses to run both Gemm.gemm and Gemm.innerproduct on the ngraph backend? They are both basically calling the same openvino nodes. If so, keep only one is ok to save time running tests, e.g. Gemm.gemm.

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Sep 22, 2023

@fengyuentau, we can keep for compatibility. There are small differences in nGraph construction related to the reshapes and others before MatMul.

@fengyuentau
Copy link
Copy Markdown
Member

ok, makes sense then.

@asmorkalov
Copy link
Copy Markdown
Contributor

the last issue on my side:

[ RUN      ] DNNTestNetwork.FastNeuralStyle_eccv16/0, where GetParam() = NGRAPH/CPU
/home/alexander/Projects/OpenCV/opencv-master/modules/dnn/test/test_common.impl.hpp:79: Failure
Expected: (normInf) <= (lInf), actual: 0.00276947 vs 0.002
First run  |ref| = 148.53863525390625
/home/alexander/Projects/OpenCV/opencv-master/modules/dnn/test/test_common.impl.hpp:79: Failure
Expected: (normInf) <= (lInf), actual: 0.00216675 vs 0.002
Second run  |ref| = 148.02413940429688
[  FAILED  ] DNNTestNetwork.FastNeuralStyle_eccv16/0, where GetParam() = NGRAPH/CPU (1371 ms)

@asmorkalov
Copy link
Copy Markdown
Contributor

OpenVINO 2022.1.1 with old host (no AVX2). Not sure if the failure is related.

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Sep 22, 2023

@asmorkalov, that's right, model is from Torch frameworks and this PR is only related to ONNX models.

@asmorkalov asmorkalov self-assigned this Sep 22, 2023
Copy link
Copy Markdown
Member

@fengyuentau fengyuentau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I guess failed tests in gapi does not relate to these changes, right?

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Sep 23, 2023

@fengyuentau , yes, the problem is old: #24049

@asmorkalov
Copy link
Copy Markdown
Contributor

@dkurt Could you take a look on the BuildBot test failure:

[ RUN      ] Test_ONNX_layers.OpenAI_CLIP_head/0, where GetParam() = NGRAPH/CPU
[ INFO:0@88.629] global onnx_importer.cpp:828 populateNet DNN/ONNX: loading ONNX v8 model produced by 'clip-vit-base-head'. Number of nodes = 5, initializers = 5, inputs = 1, outputs = 1
[ INFO:0@88.629] global onnx_importer.cpp:729 parseOperatorSet DNN/ONNX: ONNX opset version = 18
[ INFO:0@88.629] global onnx_importer.cpp:1002 handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Mul]:(onnx_node_output_0!input_mul) from domain='ai.onnx'
[ INFO:0@88.629] global onnx_importer.cpp:1002 handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Expand]:(onnx_node_output_0!expand) from domain='ai.onnx'
[ INFO:0@88.629] global onnx_importer.cpp:1002 handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Concat]:(onnx_node_output_0!concat) from domain='ai.onnx'
[ INFO:0@88.629] global onnx_importer.cpp:1002 handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Gather]:(onnx_node_output_0!gather) from domain='ai.onnx'
[ INFO:0@88.629] global onnx_importer.cpp:1002 handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Add]:(onnx_node_output_0!output) from domain='ai.onnx'
[ INFO:0@88.629] global net_openvino.cpp:705 switchToOpenVINOBackend DNN: switching to OpenVINO backend... (networkID=16678)
[ INFO:0@88.629] global ie_ngraph.cpp:766 initPlugin DNN/IE: Calling LoadNetwork(device=CPU)...
/build/precommit_custom_linux/4.x/opencv/modules/dnn/test/test_common.impl.hpp:76: Failure
Expected: (normL1) <= (l1), actual: 2.5 vs 1e-05
clip-vit-base-head  |ref| = 6.8675580024719238
/build/precommit_custom_linux/4.x/opencv/modules/dnn/test/test_common.impl.hpp:79: Failure
Expected: (normInf) <= (lInf), actual: 6 vs 0.0001
clip-vit-base-head  |ref| = 6.8675580024719238
[  FAILED  ] Test_ONNX_layers.OpenAI_CLIP_head/0, where GetParam() = NGRAPH/CPU (5 ms)

@fengyuentau
Copy link
Copy Markdown
Member

Test_ONNX_layers.OpenAI_CLIP_head/0

Reference outputs of clip head is fixed via #24295. You can rebase opencv_extra and see whether it fixes the problem.

@fengyuentau
Copy link
Copy Markdown
Member

DNN crash is being fixed in #24315

@asmorkalov asmorkalov merged commit 2b6d0f3 into opencv:4.x Sep 27, 2023
@dkurt dkurt deleted the gemm_ov_hotfix branch September 27, 2023 07:26
@asmorkalov asmorkalov mentioned this pull request Sep 28, 2023
hanliutong pushed a commit to hanliutong/opencv that referenced this pull request Oct 7, 2023
Update OpenVINO init of new GEMM layer opencv#24309

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

CI validation:

- [x] 2022.1.0: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100368
- [ ] 2021.4.2: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100373

Checklist:
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Update OpenVINO init of new GEMM layer opencv#24309

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

CI validation:

- [x] 2022.1.0: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100368
- [ ] 2021.4.2: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100373

Checklist:
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Update OpenVINO init of new GEMM layer opencv#24309

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

CI validation:

- [x] 2022.1.0: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100368
- [ ] 2021.4.2: https://pullrequest.opencv.org/buildbot/builders/precommit_custom_linux/builds/100373

Checklist:
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants