Skip to content
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

doc: graph: add document for sdpa with compressed key and value #2301

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wzt1997
Copy link
Contributor

@wzt1997 wzt1997 commented Dec 20, 2024

General

  1. Add document for SDPA with compressed Key and Value

@wzt1997 wzt1997 added the documentation A request to change/fix/improve the documentation. Codeowner: @oneapi-src/onednn-doc label Dec 20, 2024
@wzt1997 wzt1997 requested a review from TaoLv December 20, 2024 03:49
@wzt1997 wzt1997 self-assigned this Dec 20, 2024
@wzt1997 wzt1997 requested review from a team as code owners December 20, 2024 03:49
Copy link
Contributor

@mgouicem mgouicem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(open question) Do we want to have separate document for non-quantized and quantized patterns?
My understanding of existing SDPA page was that it would regroup different data-types given that it currently has a subsection for floating-point pattern.

doc/graph/sdpa_with_compressed_kv.md Outdated Show resolved Hide resolved
@TaoLv
Copy link
Contributor

TaoLv commented Dec 20, 2024

(open question) Do we want to have separate document for non-quantized and quantized patterns?

Thank you @mgouicem ! That's also my question. Initially when i added the floating-point section, i was thinking to include all these fp, int8 quantized, and only kv quantized patterns together in a single page. But with this PR, it seems there will be too much information. Maybe we need @ranukund 's input for which is a better format.

@wzt1997 wzt1997 force-pushed the zhitao/doc-compressed-sdpa branch from 51d1971 to 9c91ae9 Compare December 24, 2024 01:26
@wzt1997
Copy link
Contributor Author

wzt1997 commented Dec 24, 2024

Do we want to have separate document for non-quantized and quantized patterns?

Thanks for the question! From my perspective, I think it's better for us to put the quantized sdpa patterns in a separate document as it requires much more information compared with pure floating-point patterns, such as fpmath mode setting, group quantization and adding extra dynamic quantization ops.

It's also worth noting that this PR only includes the document for quantization sdpa patterns with compressed KV, but not the pure quantized sdpa. We may need to think about fusing them together in the future.

Copy link
Contributor

@TaoLv TaoLv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document folder has been changed on main branch. Please rebase the PR. Thanks.

doc/graph/sdpa_with_compressed_kv.md Outdated Show resolved Hide resolved
doc/graph/sdpa_with_compressed_kv.md Outdated Show resolved Hide resolved
doc/graph/sdpa_with_compressed_kv.md Outdated Show resolved Hide resolved
doc/graph/sdpa_with_compressed_kv.md Outdated Show resolved Hide resolved
| dt_fp | dt_fp | N/A | N/A | dt_int | dt_fp | u4,s4,u8,s8,s32 | dt_fp |

Notes:
- dt_fp can be either: f16, bf16 and f32.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the problem if we directly expand dt_fp as f32, bf16, f16 in the table above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we directly use f32, bf16, f16 in the table, it would result in an excessively lengthy table. Furthermore, it could lead users to misinterpret that these data types can be mixed, such as using f16 for Query with bf16 for Key scale. However, all sections involving dt_fp should utilize the same data type.

@wzt1997 wzt1997 force-pushed the zhitao/doc-compressed-sdpa branch from 9c91ae9 to 2f307af Compare December 24, 2024 05:34
@vpirogov
Copy link
Member

@ranukund, please help with the review.

@TaoLv TaoLv added the component:graph-api Codeowner: @oneapi-src/onednn-graph label Jan 3, 2025
Copy link
Contributor

@ranukund ranukund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a few comments, please incorporate as you see fit.


## Overview

The KV Cache mechanism was developed to improve the efficiency of models by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to spell out KV.


## Overview

The KV Cache mechanism was developed to improve the efficiency of models by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The KV Cache mechanism was developed to improve the efficiency of models by
The KV Cache mechanism is developed to improve the efficiency of models by

usage, and are subsequently de-quantized to wider floating point types such as
f16 and bf16 for computation.

It's worth noting that grouped quantization is required to improve model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It's worth noting that grouped quantization is required to improve model
Note that grouped quantization is required to improve the model

f16 and bf16 for computation.

It's worth noting that grouped quantization is required to improve model
accurarcy, especially for int4 data types. In this case, group size is needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
accurarcy, especially for int4 data types. In this case, group size is needed
accuracy, especially for int4 data types. In this case, group size is needed

as an attribute for quantization, which indicates the number of elements that
share the same scaling factor and zero-points in each quantization group.

The notations used in the document:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The notations used in the document:
The notations used in this topic are:

intermediate results of the dot products between Query and Key which takes
\f$O(S^2)\f$ memory. It may lead to Out-of-Memory error when computing long
sequence length input on platforms with limited memory.
2. The compressed SDPA patterns functionally support all input shapes meeting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
2. The compressed SDPA patterns functionally support all input shapes meeting
- The compressed SDPA patterns functionally support all input shapes meeting

sequence length input on platforms with limited memory.
2. The compressed SDPA patterns functionally support all input shapes meeting
the shape requirements of each operation in the graph.
3. CPU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
3. CPU
- CPU

- oneDNN does not provide optimized implementation on CPU currently. All
executions will be implemented with the primitive-based reference
computation.
4. GPU
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
4. GPU
- GPU

4. GPU
- Optimized implementation is available for 4D Q/K/V tensors with the shape
defined as (N, H, S, D) for Query, Key and Value, and (N, H, S, D/G) for
scales and zero-points( if available ).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
scales and zero-points( if available ).
scales and zero-points (if available).

computation data type on Intel Graphics Products with Intel(R) Xe Matrix
Extensions (Intel(R) XMX) support.
- If int4 zero-points are specified, optimized implementation will be only
avaibable when group size equals to 16.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
avaibable when group size equals to 16.
available when the group size equals 16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:graph-api Codeowner: @oneapi-src/onednn-graph documentation A request to change/fix/improve the documentation. Codeowner: @oneapi-src/onednn-doc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants