-
Notifications
You must be signed in to change notification settings - Fork 28
Don't schedule prefill unless there is enough kv cache left to fulfil decode stage #5467
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
AleksKnezevic
wants to merge
3
commits into
main
Choose a base branch
from
aknezevic/prefill_schedule
base: main
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.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,8 @@ | |||||
| # SPDX-FileCopyrightText: Portions (c) 2025 Tenstorrent AI ULC | ||||||
|
|
||||||
| import contextlib | ||||||
| import os | ||||||
| import sys | ||||||
| from dataclasses import dataclass | ||||||
| from typing import TYPE_CHECKING, Optional, Union, cast | ||||||
|
|
||||||
|
|
@@ -62,6 +64,21 @@ class TTConfig: | |||||
| # above it, prefills batch as usual. 0 = off; needs min_num_seqs < max. | ||||||
| prefill_batch_threshold: int = 0 | ||||||
|
|
||||||
| # KV-cache high-watermark for *fresh* prefill admission, as a fraction of | ||||||
| # the block pool (tt-xla: large-context concurrency thrash). AscendScheduler | ||||||
| # stops admitting NEW prefills once doing so would leave less than this | ||||||
| # fraction of the pool free, reserving headroom for in-flight requests to | ||||||
| # finish decoding instead of evicting (preempting) them and re-prefilling. | ||||||
| # Continuation chunks of already-started prefills and decode are NOT gated | ||||||
| # (decode may use the pool to 100%). A forward-progress guard always admits | ||||||
| # at least one prefill when nothing is running, so a single large prompt is | ||||||
| # never starved. 0.0 = off (legacy 1% watermark for all prefills). | ||||||
| # Default 0.25 (reserve 25% free => stop admitting above ~75% usage). | ||||||
| # Override at runtime with env var TT_XLA_PREFILL_KV_WATERMARK_PERCENT (a | ||||||
| # percent, e.g. 25), which takes precedence over additional_config. | ||||||
| # Resolved/validated in TTPlatform.check_and_update_config. | ||||||
| prefill_kv_watermark: float = 0.25 | ||||||
|
|
||||||
| batch_size: int = 1 | ||||||
| enable_precompile_all: bool = True | ||||||
|
|
||||||
|
|
@@ -314,6 +331,23 @@ def check_and_update_config(cls, vllm_config: VllmConfig) -> None: | |||||
| raise ValueError( | ||||||
| "additional_config['prefill_batch_threshold'] must be >= 0." | ||||||
| ) | ||||||
|
|
||||||
| # Resolve prefill_kv_watermark to a concrete fraction the scheduler can | ||||||
| # read directly: default, then env override (percent), then validate. | ||||||
| # See TTConfig.prefill_kv_watermark. | ||||||
| if additional_config.get("prefill_kv_watermark") is None: | ||||||
| additional_config["prefill_kv_watermark"] = TTConfig.prefill_kv_watermark | ||||||
| env_wm = os.environ.get("TT_XLA_PREFILL_KV_WATERMARK_PERCENT") | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are mostly using env variable as
Suggested change
|
||||||
| if env_wm is not None: | ||||||
| additional_config["prefill_kv_watermark"] = float(env_wm) / 100.0 | ||||||
| wm = float(additional_config["prefill_kv_watermark"]) | ||||||
| if not (0.0 <= wm < 1.0): | ||||||
| raise ValueError( | ||||||
| "prefill_kv_watermark (TT_XLA_PREFILL_KV_WATERMARK_PERCENT / 100) " | ||||||
| f"must be in [0, 1); got {wm}." | ||||||
| ) | ||||||
| additional_config["prefill_kv_watermark"] = wm | ||||||
|
|
||||||
| vllm_config.additional_config = additional_config | ||||||
|
|
||||||
| # Stash cpu_sampling so validate_request() can read it without | ||||||
|
|
||||||
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
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.