-
Couldn't load subscription status.
- Fork 2.8k
[CPU] Introduce GatherMatmul operation to optimize MoE pattern #32450
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
Open
maxnick
wants to merge
50
commits into
openvinotoolkit:master
Choose a base branch
from
maxnick:cpu_moe_op_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,015
−185
Open
Changes from all commits
Commits
Show all changes
50 commits
Select commit
Hold shift + click to select a range
0cc7848
First working subgraph test
maxnick f15e27e
Add din shapes
maxnick 53a406c
Add batch gather matmul internal op
maxnick abbc740
Use the new transformation name
maxnick 875e60c
Make shapes dynamic and the patter closer to gpt-oss
maxnick 3ead725
Fix the batch gather matmul shapes check
maxnick 9a3028a
Yet another shape inference fix
maxnick 9628560
Fixed the matmul shape inference reuse
maxnick ad97d62
Introduce GatherMatmul node
maxnick 86e3126
[CPU] Introduced ConvertMoEMatMuls transformation
v-Golubev 34c5c50
ConvertBatchGatherMatmulToBatchGatherMatmulCompressed
v-Golubev 1a9fd5b
Gather Matmul initial impl
maxnick a88baea
1. Skip Slice in case of GPT-oss case
v-Golubev a7148cc
Floating point calculation working state
maxnick ebf6605
Make GPT-OSS test working
maxnick 55b5e98
Use keep_dims in the top_k normalization
maxnick db4eb6d
Make fp32 tests working
maxnick f7d654e
[TESTS] MoECompressedWeightsSubgraphTest class
v-Golubev 461df5a
Apply transformations ToDo
maxnick a6d5711
Adjust bf16 test threshold
maxnick e0916c8
Fix decompression support check
maxnick 4f5b60e
MoECompressedWeightsSubgraphTest::check_results fix
v-Golubev 0206e94
GatherMatmulShapeInfer: fixed warning
v-Golubev 50b378a
Move BatchGatherMatmulCompressed conversion to cpu specific transform…
v-Golubev 1bc3b14
BatchGatherMatmulCompressed fixes
v-Golubev f94425e
Added validation pass after BatchGatherMatmul conversion
v-Golubev 024facb
format+tidy
v-Golubev 3d0c58f
Fix Unsqueeze axis handling in ConvertMoEMatMuls
v-Golubev 37ea942
Fix scales and zp processing
maxnick d1e35d5
Add 3d FC related reorders for 4bit data types
maxnick d458b87
Increase bf16 tolerance in tests
maxnick b932f93
Merge remote-tracking branch 'origin/master' into cpu_moe_op_support
maxnick cfa6cf6
Process by expert keeping weights in cache
maxnick 7f17828
Enable weights decompression graph checks
maxnick 8ac2b2b
Clang tidy fix
maxnick 9a2d889
Fix clang format
maxnick 4f920ef
clang format fix
maxnick 0f6fc7a
Added check_results for MoESubgraphTest
v-Golubev 9d2a8b7
Refactored test builders to exactly match the real models
v-Golubev 92532f6
ConvertMoEMatMuls fix
v-Golubev 1ef951c
style & tidy fixes
v-Golubev f5b75dc
Prepare code to optimize prefill via gemm
maxnick 2671609
Use GEMM on prefill
maxnick 706bf0c
Optimize gather GEMM keeping data hot in cache
maxnick 04caa44
Enable bf16 decompression tests
maxnick 6b2a7ea
Add GatherMatmul to bf16 markup
maxnick cf5404b
Split prefill strategies for amx and avx
maxnick 9e848a0
BF16 support filtering in tests
maxnick 0824a49
Fix pure bf16 use case
maxnick 65bd473
Fix CC build
maxnick 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
22 changes: 22 additions & 0 deletions
22
...ommon/transformations/include/transformations/pattern_blocks/compressed_weights_block.hpp
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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (C) 2018-2025 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "openvino/pass/matcher_pass.hpp" | ||
| #include "openvino/pass/pattern/op/block.hpp" | ||
| #include "ov_ops/fully_connected.hpp" | ||
| #include "transformations_visibility.hpp" | ||
|
|
||
| namespace ov::pass::pattern::op { | ||
|
|
||
| class TRANSFORMATIONS_API CompressedWeightsBlock; | ||
|
|
||
| } // namespace ov::pass::pattern::op | ||
|
|
||
| class ov::pass::pattern::op::CompressedWeightsBlock : public ov::pass::pattern::op::Block { | ||
| public: | ||
| CompressedWeightsBlock(const std::vector<ov::element::Type>& supported_weights_types, | ||
| const std::set<size_t>& supported_weights_ranks); | ||
| }; |
234 changes: 112 additions & 122 deletions
234
src/common/transformations/src/transformations/op_conversions/convert_fc_to_compressed.cpp
Large diffs are not rendered by default.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
src/common/transformations/src/transformations/pattern_blocks/compressed_weights_block.cpp
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright (C) 2018-2025 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #include "transformations/pattern_blocks/compressed_weights_block.hpp" | ||
|
|
||
| #include <algorithm> | ||
| #include <memory> | ||
|
|
||
| #include "openvino/core/graph_util.hpp" | ||
| #include "openvino/core/rt_info.hpp" | ||
| #include "openvino/core/type/element_type.hpp" | ||
| #include "openvino/op/constant.hpp" | ||
| #include "openvino/op/convert.hpp" | ||
| #include "openvino/op/multiply.hpp" | ||
| #include "openvino/op/reshape.hpp" | ||
| #include "openvino/op/subtract.hpp" | ||
| #include "openvino/op/transpose.hpp" | ||
| #include "openvino/pass/pattern/op/optional.hpp" | ||
| #include "openvino/pass/pattern/op/or.hpp" | ||
| #include "openvino/pass/pattern/op/pattern.hpp" | ||
| #include "openvino/pass/pattern/op/wrap_type.hpp" | ||
| #include "ov_ops/fully_connected.hpp" | ||
| #include "ov_ops/fully_connected_compressed.hpp" | ||
| #include "transformations/utils/utils.hpp" | ||
|
|
||
| using namespace ov::pass::pattern; | ||
| ov::pass::pattern::op::CompressedWeightsBlock::CompressedWeightsBlock(const std::vector<ov::element::Type>& supported_weights_types, | ||
| const std::set<size_t>& supported_weights_ranks) | ||
| : Block({}, {}, "CompressedWeightsBlock") { | ||
| auto weights = wrap_type<ov::op::v0::Constant>(type_matches_any(supported_weights_types)); | ||
| auto convert = wrap_type<ov::op::v0::Convert>({weights}); | ||
|
|
||
| auto sub_const = wrap_type<ov::op::v0::Constant>(); | ||
| auto sub_convert_const = wrap_type<ov::op::v0::Convert>({sub_const}); | ||
| auto sub_with_convert = wrap_type<ov::op::v1::Subtract>({convert, sub_convert_const}); | ||
| auto sub_no_convert = wrap_type<ov::op::v1::Subtract>({convert, sub_const}); | ||
| auto subtract = sub_with_convert | sub_no_convert; | ||
|
|
||
| auto mul_const = wrap_type<ov::op::v0::Constant>(); | ||
| auto mul_convert_const = wrap_type<ov::op::v0::Convert>({mul_const}); | ||
| auto mul_scale = mul_const | mul_convert_const; | ||
|
|
||
| auto mul_with_sub = wrap_type<ov::op::v1::Multiply>({subtract, mul_scale}); | ||
| auto mul_no_sub = wrap_type<ov::op::v1::Multiply>({convert, mul_scale}); | ||
| auto mul = mul_with_sub | mul_no_sub; | ||
|
|
||
| auto reshape_predicate = [supported_weights_ranks](const ov::Output<ov::Node>& output) { | ||
| const auto& in_ps = output.get_node()->get_input_partial_shape(0); | ||
| const auto& out_ps = output.get_node()->get_output_partial_shape(0); | ||
| std::set<size_t> supported_weights_ranks_before_reshape; | ||
| for (auto r : supported_weights_ranks) { | ||
| supported_weights_ranks_before_reshape.insert(r + 1); | ||
| } | ||
| return in_ps.rank().is_static() && out_ps.rank().is_static() && | ||
| supported_weights_ranks_before_reshape.count(in_ps.size()) && | ||
| supported_weights_ranks.count(out_ps.size()); | ||
| }; | ||
| auto reshape_const = wrap_type<ov::op::v0::Constant>(); | ||
| auto reshape = wrap_type<ov::op::v1::Reshape>({mul, reshape_const}, reshape_predicate); | ||
|
|
||
| auto transpose_input = reshape | mul; | ||
| auto transpose_const = wrap_type<ov::op::v0::Constant>(); | ||
| auto transpose = wrap_type<ov::op::v1::Transpose>({transpose_input, transpose_const}); | ||
|
|
||
| auto weights_input = optional<ov::op::v0::Convert>({reshape | transpose | mul}); | ||
|
|
||
| // Block initialization | ||
| m_inputs = ov::OutputVector{weights}; | ||
| m_outputs = ov::OutputVector{weights_input}; | ||
| REGISTER_ANCHORS(this, | ||
| weights, | ||
| convert, | ||
| sub_const, | ||
| sub_with_convert, | ||
| sub_no_convert, | ||
| mul_const, | ||
| transpose, | ||
| transpose_const); | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The
GET_MACROnow includes_0parameter but this parameter is not actually used - it's only added to shift the argument positions. Consider adding a comment explaining this trick for future maintainers, as it's a non-obvious macro implementation detail.