OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] Fix reorder format mismatch in convolution weights. (#31732)
Jade Chob786c16166a4
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cppindex cb24943c2c2..fe0c585d8e5 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/utils.cpp@@ -715,6 +715,10 @@ cldnn::format_traits convert_memory_desc_to_traits(const dnnl::memory::desc& desreturn traits;}+/*+ * This function checks the consistency between the input and output shapes of the onednn reorder.+ * If the shape is expanded from 4D to 5D, the format of the input layout is also updated accordingly.+ */bool keep_weights_reorder_shape_consistent(cldnn::layout& layout, const dnnl::memory::desc& desc) {if (layout.is_dynamic())return false;@@ -740,20 +744,25 @@ bool keep_weights_reorder_shape_consistent(cldnn::layout& layout, const dnnl::melayout.set_partial_shape(desc_dims);if (layout.get_rank() == desc_dims.size()) {- return true; // Shapes are now consistent- } else {+ return true;+ } else if (layout.get_rank() == 4 && desc_dims.size() == 3) {+ // In the case of a 3D shape, cldnn::layout::get_rank() returns 4.+ return true;+ } else if (layout.get_rank() == 4 && desc_dims.size() == 5) {+ // Since onednn does not support 1D group convolution, a z-axis is added, and format change is required in this case.auto is_weights = cldnn::format::is_weights_format(layout.format);auto is_grouped = cldnn::format::is_grouped(layout.format);- auto expected_format = cldnn::format::get_default_format(cldnn::format::dimension(layout.format), is_weights, is_grouped);- if (layout.format == expected_format) {- // Dimension expansion is only allowed when the input layout is in the default format.+ auto expected_default_format = cldnn::format::get_default_format(layout.get_rank(), is_weights, is_grouped);+ // Dimension expansion is only allowed when the input layout is in the default format.+ if (layout.format == expected_default_format) {layout.format = cldnn::format::get_default_format(desc_dims.size(), is_weights, is_grouped);+ return true;} else {- // The expected format is not default format.- return false;+ OPENVINO_ASSERT(false, "Need default format for axis expansion.");}+ } else {+ return false;}- return true;}size_t get_post_ops_count(const program_node& node) {diff --git a/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cpp b/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cppindex b2853f4368b..c9e247f5d64 100644--- a/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cpp+++ b/src/plugins/intel_gpu/tests/unit/onednn/utils_test.cpp@@ -259,3 +259,40 @@ INSTANTIATE_TEST_SUITE_P(smoke, memory_desc_to_fmt_conversion_test,},}),memory_desc_to_fmt_conversion_test::PrintToString);++// Test for keep_weights_reorder_shape_consistent function+TEST(keep_weights_reorder_shape_consistent_test, simple_data_formats) {+ // Test case 1: bfyx format with matching shapes+ {+ auto layout = cldnn::layout{ov::PartialShape{512, 1024, 16}, data_types::f16, format::bfyx};+ dnnl::memory::desc desc({512, 1024, 16}, dnnl::memory::data_type::f16, dnnl::memory::format_tag::abc);+ bool result = onednn::keep_weights_reorder_shape_consistent(layout, desc);+ EXPECT_TRUE(result);+ EXPECT_EQ(layout.get_shape(), ov::Shape({512, 1024, 16}));+ }+ // Test case 2: fbyx format with matching shapes+ {+ auto layout = cldnn::layout{ov::PartialShape{512, 1024, 16}, data_types::f16, format::fbyx};+ dnnl::memory::desc desc({512, 1024, 16}, dnnl::memory::data_type::f16, dnnl::memory::format_tag::abc);+ bool result = onednn::keep_weights_reorder_shape_consistent(layout, desc);+ EXPECT_TRUE(result);+ EXPECT_EQ(layout.get_shape(), ov::Shape({512, 1024, 16}));+ }+ // Test case 3: ioyx format with matching shapes+ {+ auto layout = cldnn::layout{ov::PartialShape{512, 1024, 16}, data_types::f16, format::ioyx};+ dnnl::memory::desc desc({512, 1024, 16}, dnnl::memory::data_type::f16, dnnl::memory::format_tag::abc);+ bool result = onednn::keep_weights_reorder_shape_consistent(layout, desc);+ EXPECT_TRUE(result);+ EXPECT_EQ(layout.get_partial_shape(), ov::Shape({512, 1024, 16}));+ }+ // Test case 4: oizyx format with matching shapes+ {+ auto layout = cldnn::layout{ov::PartialShape{16, 1, 16, 16}, data_types::f16, format::oiyx};+ dnnl::memory::desc desc({16, 1, 1, 16, 16}, dnnl::memory::data_type::f16, dnnl::memory::format_tag::abcde);+ bool result = onednn::keep_weights_reorder_shape_consistent(layout, desc);+ EXPECT_TRUE(result);+ EXPECT_EQ(layout.format, cldnn::format::oizyx);+ EXPECT_EQ(layout.get_partial_shape(), ov::Shape({16, 1, 1, 16, 16}));+ }+}