From 44bf6a2db3ecaac2136dc68e8d8a02c22349b5f4 Mon Sep 17 00:00:00 2001 From: Shiyu Xie <125947016+ShiyuXie0116@users.noreply.github.com> Date: Tue, 31 Mar 2026 01:49:01 -0400 Subject: [PATCH] Merge pull request #28714 from ShiyuXie0116:fix/onnx-dispatch-and-rotary-embedding-bugs dnn: fix missing ONNX dispatch entries and RotaryEmbedding bugs #28714 - Wire RMSNormalization and RotaryEmbedding parsers into the ONNX dispatch map. Both parse functions were declared and implemented but never registered, causing the importer to fall through to the generic path and skip constant-folding of cos/sin caches. - Fix NonMaxSuppression dispatch key typo ("NonMaxSuprression" -> "NonMaxSuppression") so the ONNX op name matches the registered layer class. Also fix the type string set inside the parser. - Fix tautological self-comparison in RotaryEmbeddingLayer::getMemoryShapes (cos_cache_shape.dims == cos_cache_shape.dims -> sin_cache_shape.dims). - Fix typo in RotaryEmbedding error message ("cos_cahe" -> "cos_cache"). ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [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 - [ ] 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 --- modules/dnn/src/layers/rotary_embedding_layer.cpp | 4 ++-- modules/dnn/src/onnx/onnx_importer2.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/dnn/src/layers/rotary_embedding_layer.cpp b/modules/dnn/src/layers/rotary_embedding_layer.cpp index 83d0e05a01..aa0beeb5a3 100644 --- a/modules/dnn/src/layers/rotary_embedding_layer.cpp +++ b/modules/dnn/src/layers/rotary_embedding_layer.cpp @@ -231,10 +231,10 @@ class RotaryEmbeddingLayerImpl CV_FINAL : public RotaryEmbeddingLayer { ); CV_CheckTrue( cos_cache_shape.dims == 3 || inputs.size() > 3, - "RotaryEmbeddingLayer: provide position_ids or specify sin_cache and cos_cahe in format BxTxD" + "RotaryEmbeddingLayer: provide position_ids or specify sin_cache and cos_cache in format BxTxD" ); CV_CheckTrue( - cos_cache_shape.dims == cos_cache_shape.dims, + cos_cache_shape.dims == sin_cache_shape.dims, "RotaryEmbeddingLayer: cos_cache and sin_cache must have the same number of dimensions" ); for (int i = 0; i < cos_cache_shape.dims; ++i) diff --git a/modules/dnn/src/onnx/onnx_importer2.cpp b/modules/dnn/src/onnx/onnx_importer2.cpp index 0762b3188e..da2dad5808 100644 --- a/modules/dnn/src/onnx/onnx_importer2.cpp +++ b/modules/dnn/src/onnx/onnx_importer2.cpp @@ -2726,6 +2726,8 @@ void ONNXImporter2::buildDispatchMap_ONNX_AI() dispatch["Tile"] = &ONNXImporter2::parseTile; dispatch["LayerNormalization"] = &ONNXImporter2::parseLayerNorm; dispatch["GroupNormalization"] = &ONNXImporter2::parseInstanceNormalization; + dispatch["RMSNormalization"] = &ONNXImporter2::parseRMSNormalization; + dispatch["RotaryEmbedding"] = &ONNXImporter2::parseRotaryEmbedding; dispatch["NegativeLogLikelihoodLoss"] = &ONNXImporter2::parseNegativeLogLikelihoodLoss; dispatch["SoftmaxCrossEntropyLoss"] = &ONNXImporter2::parseSoftmaxCrossEntropyLoss; // @TODO@ONNX: Add support for SDPA