-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[CPU]PageAttn with 4bit-quantization #27992
Merged
dmitry-gorokhov
merged 36 commits into
openvinotoolkit:master
from
zhangYiIntel:yi3/4bit-cache
Jan 8, 2025
+1,413
−411
Merged
Changes from 26 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
15fcdb8
[CPU]separate precisions of kv cache
zhangYiIntel 82f843a
[CPU]use element as template args
zhangYiIntel a754404
[CPU]make quantize grouped
zhangYiIntel 2aba224
[CPU]make u8 kernel grouped
zhangYiIntel fc435f6
[CPU]U4 Group size support with reference
zhangYiIntel d080e2a
[CPU]AVX512 support for u4 kernel
zhangYiIntel 78ef4dd
[CPU]Support S4 quantization
zhangYiIntel 3e821ea
[CPU]use AVX512 to quant s4
zhangYiIntel 80b093f
[CPU]4-bit quantization with avx2
zhangYiIntel 13a496e
fix build on elder compiler
zhangYiIntel 92e6cb3
[CPU]fix fp32 inference
zhangYiIntel 91ebc09
[CPU]set group size via hint
zhangYiIntel 685f263
[CPU]fix code style
zhangYiIntel e56639a
[CPU]fix property test
zhangYiIntel a34ce8b
[CPU]add cache precision check
zhangYiIntel 8548773
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel fe6c311
[CPU]fix code style of config.cpp
zhangYiIntel 522215a
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel 8faadd8
[CPU]pre calculate count
zhangYiIntel b4b0f0d
[CPU]Use ov::element as template args
zhangYiIntel 5c838f7
[CPU]remove redundant marco
zhangYiIntel c98cec9
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel f03e23c
apply review comments
zhangYiIntel 99d5c4d
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel dddb4d9
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel c362399
[CPU]apply review comments
zhangYiIntel 28bcf7b
[CPU]remove useless code of s4
zhangYiIntel 94522a2
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel 56245d0
[CPU]Unify u8/u4 dequant kernel with template arg
zhangYiIntel 84f03a3
[CPU]Define key/value cache prec/group_size priority
zhangYiIntel e0b437e
[CPU]fix prec order & check group_size
zhangYiIntel 79df402
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel f196535
Merge branch 'master' into yi3/4bit-cache
zhangYiIntel 0515410
[CPU]fix sdpa test
zhangYiIntel 7a412f7
[CPU]fix group_size in sdpa
zhangYiIntel 594b392
[CPU]Change default group_size
zhangYiIntel 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 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 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 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 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 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 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 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.
We need to align positioning regarding these options.
We already have high-level hint for KV-cache: ov::hint::kv_cache_precision. These new options are rather fine tuning options. So I would propose the following:
ov::hint::kv_cache_precision
should remain major (including positioning to the user) option for KV-Cache quantization control.ov::hint::kv_cache_precision
(like other hints) should impact values of lower level options:ov::hint::key_cache_precision
/ov::hint::value_cache_precision
/ov::hint::key_cache_group_size
/ov::hint::value_cache_group_size
. E.g.ov::hint::kv_cache_precision == u4
will result in(u8/u4/32/32)
config for lower options.cc'ed @AlexKoff88 @vladimir-paramuzov @sshlyapn @p-durandin
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.
I think it looks good. Just to clarify:
ov::hint::kv_cache_precision
for coarse control of KV-cache quantization parameters by default. I would deprecate it at some point (not sure what is the best time).ov::hint::key_cache_precision
,ov::hint::value_cache_precision
,ov::hint::key_cache_group_size
,ov::hint::value_cache_group_size
are for fine-grained control of KV-cache quantization and they have higher priority overov::hint::kv_cache_precision
if defined.ov::hint::key_cache_group_size
,ov::hint::value_cache_group_size
should have reasonable defaults, e.g. 32 or 64 what fits the best for runtime.rt_info/runtime_options
subsection of the IR.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.
@dmitry-gorokhov If not use hint namespace, do we have a better namespace for this ?
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.
@zhangYiIntel just
ov::key_cache_precision
.You can use
ov::num_streams
as an example - this is low level property which is affected by high-level hints likeov::hint::performance_mode
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.
@AlexKoff88 @dmitry-gorokhov Regarding to the default
group_size
, since thehidden_state
must be divided bygroup_size
, if the we set it to 32/64, then what should we do ifhidden_state
is not divisible by 32/64, should we fallbackgroup_size
tohidden_state
or just throw a exception ?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.
Given this is not the hint it should throw an exception, in case user sets invalid value.
If no user input is provided for these properties, then default value should be properly adjusted.
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.
Another leftover here is that if we set default
group_size
to 32/64 other thanhidden_state
, then OpenVINO.GenAI has to update accordingly, otherwise the U8 KV cache quantization is broken.CC: @ilya-lavrenov
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.
Why? I bet GenAI doesn't set any specific value for
group_size
, which means no user input for these properties. So as I mentionedgroup_size
default value should be properly asjusted on CPU plugin side.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.
For CB implementation we need to duplicate all this logic related to KV cache as it's maintained outside of plugin.
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.
The problem here with GenAI is that the
ContinousBatchingPipeline
allocates the memory for `PageAttention``s key/value cache, it must know the group_size in advacnde to allocate correct memory size for both cache + scale/zp at https://github.com/openvinotoolkit/openvino.genai/blob/09a542608b560959edb96e628915a1d6bd780c26/src/cpp/src/cache_manager.hpp#L57The cache shape is defined at https://github.com/openvinotoolkit/openvino.genai/blob/09a542608b560959edb96e628915a1d6bd780c26/src/cpp/src/device_config.hpp#L120
The
m_head_size
defined is defined as following, which only considers 1 group per hidden_statesTherefore
ContinousBatchingPipeline
is broken with group_num greater than 1