-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Update config spec #24913
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
Merged
Update config spec #24913
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
a4d0675
Update config reference
natke f196fc2
Update provider list
natke 5283a99
Remove comment about C++
natke 6df2f8b
Remove incorrect anchors
natke cccfe7f
Fix some of the broken links
natke a3c2726
Update web build link
natke c4c8cc1
Remove broken architecture link
natke 84dc5dd
Merge branch 'gh-pages' into update-config-spec
natke a116e04
Fix Tensor RT build anchor
natke 7dec6e0
Update model type spec
natke 8afdf16
Expand min and max length definitions
natke a7c9ccf
Added past present share buffer explanation
natke d72c507
Address another round of review comments
natke 68e3b2c
Added examples for past present share buffer
natke 98bf9d6
Update docs/genai/howto/past-present-share-buffer.md
kunal-vaishnavi fb17885
Update docs/genai/howto/past-present-share-buffer.md
kunal-vaishnavi 21998b6
Update docs/genai/howto/past-present-share-buffer.md
kunal-vaishnavi 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| --- | ||
| title: Past present share buffer | ||
| description: How to configure the past present share buffer using the ONNX Runtime generate() API | ||
| has_children: false | ||
| parent: How to | ||
| grand_parent: Generate API (Preview) | ||
| nav_order: 6 | ||
| --- | ||
|
|
||
| # How to configure the past present share buffer | ||
|
|
||
| The past present share buffer is an optimization that can be used to save memory and processing time. | ||
|
|
||
| When the share buffer is used, the past and present KV cache buffers point to the same memory block. | ||
|
|
||
| When the share buffer is not used, the present KV cache buffers are re-allocated before every forward pass of the model, and copied to the past KV cache buffers. | ||
kunal-vaishnavi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| This is represented in the following diagram | ||
|
|
||
|  | ||
|
|
||
| The size of the KV cache is different depending on the value of the past present share buffer. | ||
kunal-vaishnavi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| ## Size of KV caches | ||
|
|
||
| ### When past_present_share_buffer is true | ||
|
|
||
| Size of past KV caches = size of present KV caches (bytes) | ||
|
|
||
| $batch\_size * num\_key\_value\_heads * max\_length * head\_size | ||
| $ | ||
|
|
||
| For example, for the [4-bit quantized Phi-4-mini-instruct](https://huggingface.co/microsoft/Phi-4-mini-instruct-onnx) model, with a batch size of 1 and a max length of 4k, the size of the cache is: $1 * 8 * 4096 * 128 = 4GB$ | ||
|
|
||
|
|
||
| Note that the size of the cache is largely determined the value of the max_length parameter. | ||
|
|
||
|
|
||
| ### When past_present_share_buffer is false | ||
|
|
||
| Size of past KV caches (bytes) = $batch\_size * num\_key\_value\_heads * past\_sequence\_length * head\_size$ | ||
|
|
||
| Size of present KV caches (bytes) = $batch\_size * num\_key\_value\_heads * (past\_sequence\_length + 1) * head\_size$ | ||
|
|
||
| For example, for the [4-bit quantized DeepSeek R1 Qwen 1.5B](https://huggingface.co/onnxruntime/DeepSeek-R1-Distill-ONNX) model, with a batch size of 1 and a past sequence length of 1k, the size of the past cache is: $1 * 2 * 1024 * 128 = 256M$ and the size of the present cache is: $1 * 2 * 1025 * 128 = 257M$ | ||
|
|
||
|
|
||
|
|
||
|
|
||
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.
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.