Repository navigation
[Engine] Fit a 512K context: give the prompt loan back to the K/V, keep big chunks staged - #4433
Closed
xvcezrqpbxtpzblrt wants to merge 1 commit into
Closed
xvcezrqpbxtpzblrt wants to merge 1 commit into
xvcezrqpbxtpzblrt wants to merge 1 commit into
Conversation
…r new VRAM (#3998 follow-up)
Contributor
Author
|
Superseded by #4606, which carries this change with the rest of the 0.2.7 branch. Closing so the review has one place. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
A 512K context on a 16 GB card could not fit in one run. The prompt path borrows part of the expert cache as a staging buffer (the loan), and the K/V's ceiling stopped at the loan's first slot: the borrowed region was excluded from the cache for the whole run. When the K/V needed those slots, the engine asked the driver for new VRAM, and on a card that has none left the request ended with
and new VRAM, the cache being at its floor.Result (measured)
k8v4, 16 GB RTX 3080 Ti Laptop,
--max-context 524288, 510K prompt, 1.5 GiB reserve,--prefill 6144, staged chunks:K/V grownline has noand new VRAM)The loan shrinks from 6,144 to 4,608 tokens and the freed slots become K/V cells; nothing is requested from the driver. 128K on a cool card: 1463.5 tok/s (previous build 1514.5, within run-to-run heat).
What changed
kvg_ensure, at its floor and before any new VRAM: asks the prompt path to re-lay out in the largest chunk whose freed granules cover the K/V's need, then unmaps the tail into the cache (kvg_fit_loan).--prefill-stream-min N: chunks of N tokens or more stream every expert instead of staging the routed ones; an explicit value wins over the CPU share's own limit. Default behaviour is unchanged (the built-in 1,024 threshold).remainis 0), so their behaviour is the same as before.Validation
K/V grownwithoutand new VRAM).Limits
--kv-grow(the elastic K/V path).