Repository navigation
[GPU] Add UINT2 (2-bit) weight compression support via oneDNN fully_connected #37212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
isanghao
merged 25 commits into
openvinotoolkit:master
from
vmadananth:u2-onednn-support
Nov 2, 2026
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
7bc262d
Enable compiling dynmodels by adding path to UIN2 Horizontal FC Fusio…
vmadananth edcafa4
Enable U2 (2-bit) compressed weights for oneDNN fully_connected on GPU
vmadananth 4527d82
Code clean up
vmadananth b6887bd
code clean up
Kotomi-Du 36bdabf
Merge branch 'master' into u2-onednn-support
Kotomi-Du 24cc25b
Merge branch 'master' into u2-onednn-support
Kotomi-Du 7b3c131
Merge branch 'master' into u2-onednn-support
Kotomi-Du 63ffaa8
Update oneDNN GPU submodule to latest mdvoretc/u2
vmadananth b683805
GPU: disable dynamic quantization for u2 weights until oneDNN i8 acti…
vmadananth d080dcd
Merge remote-tracking branch 'upstream/master' into u2-onednn-support
vmadananth a926669
Merge branch 'master' into u2-onednn-support
vmadananth 10fe4ac
Add u2 coverage to FC transformation and primitive tests
vmadananth 48fa460
Point onednn_gpu submodule to mdvoretc-intel/oneDNN u2 branch tip
vmadananth 0c6d388
Merge remote-tracking branch 'myfork/u2-onednn-support' into u2-onedn…
vmadananth 28e2b68
revert u2 concat packing - covered in #38357; fix clang-tidy pointer …
vmadananth 12106a5
Address remaining u2 review comments
vmadananth ad39810
Point onednn_gpu submodule to mdvoretc-intel/oneDNN u2_gemmstone
vmadananth ef555e1
Merge remote-tracking branch 'upstream/master' into u2-onednn-support
vmadananth 528239e
Reject non-16-aligned u2 group size in oneDNN FC validate_impl instea…
vmadananth 8eb39df
[GPU] Address u2 review: shared group-size helper, one_of checks, str…
vmadananth 8512af3
[GPU] Update oneDNN GPU submodule to uxlfoundation/oneDNN#6296 (07804…
vmadananth a927d2a
Merge remote-tracking branch 'upstream/master' into u2-onednn-support
vmadananth 2f2c66a
[GPU] Use shared weight-rank helper in oneDNN FC load(), add grouped …
vmadananth fe75a61
Merge remote-tracking branch 'upstream/master' into u2-onednn-support
vmadananth cf30772
Merge remote-tracking branch 'upstream/master' into u2-onednn-support
vmadananth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,22 +23,6 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> { | |
| static constexpr int COMMON = 0; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. random spot)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perf results attached here - https://jira.devtools.intel.com/browse/CVS-198829 |
||
| static constexpr int PER_OC = 2; | ||
|
|
||
| // Group (IFM) axis is last for [N, groups] (transpose_b) and second-to-last for [groups, N]. | ||
| static int64_t get_ifm_dim_idx(const layout& param_layout, bool transpose_b_param, size_t weights_rank) { | ||
| const auto& pshape = param_layout.get_partial_shape(); | ||
| const auto rank = static_cast<int64_t>(pshape.size()); | ||
| // 1D [N] holds only OC; point past it so get_dim() hits the padded 1 (one IFM group). | ||
| if (rank <= 1) | ||
| return rank; | ||
| const auto logical_rank = std::min<int64_t>(rank, std::max<int64_t>(2, static_cast<int64_t>(weights_rank))); | ||
| // Extra dims are either legacy trailing padding (all 1) or leading broadcast dims. | ||
| const bool trailing_padded = std::all_of(pshape.begin() + logical_rank, pshape.end(), [](const ov::Dimension& d) { | ||
| return d.is_static() && d.get_length() == 1; | ||
| }); | ||
| const int64_t base = trailing_padded ? 0 : rank - logical_rank; | ||
| return std::max<int64_t>(0, base + (transpose_b_param ? logical_rank - 1 : logical_rank - 2)); | ||
| } | ||
|
|
||
| DECLARE_OBJECT_TYPE_SERIALIZATION(cldnn::onednn::fully_connected_onednn) | ||
|
|
||
| private: | ||
|
|
@@ -69,8 +53,7 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> { | |
| if (prim->compressed_weights) { | ||
| const auto weights_dt = instance.get_input_layout(1).data_type; | ||
| auto weight_bitwidth = ov::element::Type(weights_dt).bitwidth(); | ||
| OPENVINO_ASSERT(weight_bitwidth == 8 || weight_bitwidth == 4 || weight_bitwidth == 3, | ||
| "[GPU] oneDNN supports only 3bit/4bit/8bit compressed weights"); | ||
| OPENVINO_ASSERT(one_of(weight_bitwidth, {8, 4, 3, 2}), "[GPU] oneDNN supports only 2bit/3bit/4bit/8bit compressed weights"); | ||
| int idx = prim->bias.is_valid() ? 3 : 2; | ||
|
|
||
| if (prim->decompression_scale.is_valid()) { | ||
|
|
@@ -181,7 +164,7 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> { | |
| dnnl::memory::desc weights_md; | ||
| if (weights_layout.data_padding | ||
| && format::is_default_format(weights_layout.format) | ||
| && (weights_layout.data_type == data_types::i4 || weights_layout.data_type == data_types::u4)) { | ||
| && one_of(weights_layout.data_type, {data_types::i4, data_types::u4, data_types::u2})) { | ||
| weights_md = onednn::layout_to_memory_desc_strides(weights_layout, weights_fmt); | ||
| } else { | ||
| weights_md = onednn::layout_to_memory_desc(weights_layout, weights_fmt); | ||
|
|
@@ -285,11 +268,7 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> { | |
|
|
||
| const kernel_impl_params* impl_params = reinterpret_cast<kernel_impl_params*>(ib.getKernelImplParams()); | ||
| auto prim = impl_params->typed_desc<fully_connected>(); | ||
| auto weights_layout = impl_params->get_input_layout(1); | ||
| const auto& weight_shape = weights_layout.get_partial_shape(); | ||
| auto weight_rank = std::count_if(weight_shape.begin(), weight_shape.end(), | ||
| [](ov::Dimension d) { return d.get_length() > 1; }); | ||
| weight_rank = std::max(static_cast<int64_t>(2), weight_rank); | ||
| const auto weight_rank = get_compressed_weights_rank(impl_params->get_input_layout(1)); | ||
|
|
||
| auto shift_size = std::max<size_t>(prim->input_size - 2, 0); | ||
| const auto& arg = impl_params->get_program().get_node(impl_params->desc->id).as<fully_connected>(); | ||
|
|
@@ -393,9 +372,7 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> { | |
| } | ||
|
|
||
| auto weights_layout = impl_params.get_input_layout(1); | ||
| auto weight_shape = weights_layout.get_partial_shape(); | ||
| auto weight_rank = std::count_if(weight_shape.begin(), weight_shape.end(), [](ov::Dimension d) { return d.get_length() > 1; }); | ||
| weight_rank = std::max(static_cast<int64_t>(2), weight_rank); | ||
| const auto weight_rank = get_compressed_weights_rank(weights_layout); | ||
|
v-Golubev marked this conversation as resolved.
Resolved
|
||
| OPENVINO_ASSERT(weight_rank <= 3, "Currently only weights with equal to or less than 3D is supported"); | ||
| auto shift_size = std::max<size_t>(prim->input_size - 2, 0); | ||
| int per_oc = PER_OC << shift_size; | ||
|
|
@@ -405,13 +382,10 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> { | |
| auto decompression_scale_idx = ++idx; | ||
| auto scale_layout = arg.get_dependency(decompression_scale_idx).get_output_layout(); | ||
| ds_data_type = convert_data_type(scale_layout.data_type); | ||
| // IFM (K) dimension position depends on weight layout orientation. | ||
| const auto ifm_dim_idx = prim->weights_transposed ? (weight_rank - 1) : (weight_rank - 2); | ||
| const auto ifm = arg.get_dependency(1).get_output_layout().get_dim(ifm_dim_idx); | ||
| const auto scale_ifm_dim_idx = get_ifm_dim_idx(scale_layout, prim->transpose_b_scale, weight_rank); | ||
| const auto ngroups = scale_layout.get_dim(scale_ifm_dim_idx); | ||
| group_size = static_cast<int>(ifm / ngroups); | ||
| OPENVINO_ASSERT((group_size == 1 || ngroups == 1 || group_size % 16 == 0), | ||
| const auto groups = get_scale_groups(weights_layout, scale_layout, prim->weights_transposed, prim->transpose_b_scale); | ||
| const auto ngroups = groups.first; | ||
| group_size = static_cast<int>(groups.second); | ||
| OPENVINO_ASSERT(is_supported_scale_group(ngroups, group_size), | ||
| "[GPU] group_size should be aligned to 16 if it is not a single scale group or the group_size is not one."); | ||
| if (scale_layout.count() == 1) { | ||
| attr->set_scales(DNNL_ARG_WEIGHTS, COMMON, dnnl::memory::dims{}, ds_data_type); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.