-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[BugFix] Handle num_cached_tokens/num_external_computed_tokens for different vllm version #8426
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
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
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 |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |
| from vllm.v1.request import Request, RequestStatus | ||
| from vllm.v1.structured_output import StructuredOutputManager | ||
|
|
||
| from vllm_ascend.utils import vllm_version_is | ||
|
|
||
|
|
||
| class BudgetRefiner: | ||
| """This budget refiner can make dynamic adjustment to the token budget | ||
|
|
@@ -488,9 +490,10 @@ def schedule(self) -> SchedulerOutput: | |
| token_budget -= num_new_tokens | ||
| request.status = RequestStatus.RUNNING | ||
| request.num_computed_tokens = num_computed_tokens | ||
| # Count the number of prefix cached tokens. | ||
| if request.num_cached_tokens < 0: | ||
| request.num_cached_tokens = num_computed_tokens | ||
| if vllm_version_is("0.19.0"): | ||
|
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. |
||
| # Count the number of prefix cached tokens. | ||
| if request.num_cached_tokens < 0: | ||
| request.num_cached_tokens = num_computed_tokens | ||
| # Encoder-related. | ||
| if encoder_inputs_to_schedule: | ||
| scheduled_encoder_inputs[request.request_id] = encoder_inputs_to_schedule | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ | |
| from vllm.v1.utils import record_function_or_nullcontext | ||
|
|
||
| from vllm_ascend.core.profiling_chunk_predictor import ProfilingChunkManager | ||
| from vllm_ascend.utils import vllm_version_is | ||
|
|
||
|
|
||
| class ProfilingChunkScheduler(Scheduler): | ||
|
|
@@ -482,13 +483,21 @@ def schedule(self) -> SchedulerOutput: # noqa: C901 | |
| step_skipped_waiting.prepend_request(request) | ||
| continue | ||
|
|
||
| request.num_external_computed_tokens = ext_tokens | ||
| if vllm_version_is("0.19.0"): | ||
|
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. |
||
| request.num_external_computed_tokens = ext_tokens | ||
| num_external_computed_tokens = ext_tokens | ||
|
|
||
| connector_prefix_cache_queries = request.num_tokens - num_new_local_computed_tokens | ||
| connector_prefix_cache_hits = num_external_computed_tokens | ||
|
|
||
| num_computed_tokens = num_new_local_computed_tokens + num_external_computed_tokens | ||
|
|
||
| if not vllm_version_is("0.19.0") and request.prefill_stats is not None: | ||
| request.prefill_stats.set( | ||
| num_prompt_tokens=request.num_prompt_tokens, | ||
| num_local_cached_tokens=num_new_local_computed_tokens, | ||
| num_external_cached_tokens=num_external_computed_tokens, | ||
| ) | ||
| assert num_computed_tokens <= request.num_tokens | ||
| else: | ||
| new_computed_blocks = self.kv_cache_manager.empty_kv_cache_blocks | ||
|
|
@@ -628,8 +637,9 @@ def schedule(self) -> SchedulerOutput: # noqa: C901 | |
| time_budget -= self.profiling_chunk_manager.predict_time(num_new_tokens, request.num_computed_tokens) | ||
| request.status = RequestStatus.RUNNING | ||
| request.num_computed_tokens = num_computed_tokens | ||
| if request.num_cached_tokens < 0: | ||
| request.num_cached_tokens = num_computed_tokens | ||
| if vllm_version_is("0.19.0"): | ||
| if request.num_cached_tokens < 0: | ||
| request.num_cached_tokens = num_computed_tokens | ||
| if encoder_inputs_to_schedule: | ||
| scheduled_encoder_inputs[request_id] = encoder_inputs_to_schedule | ||
| for i in encoder_inputs_to_schedule: | ||
|
|
||
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.
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
vllm_version_is("0.19.0")check uses exact equality (as defined invllm_ascend/utils.py). This logic will returnFalsefor any subsequent versions (e.g., 0.19.1, 0.20.0), causing the scheduler to revert to the legacyprefill_statspath. If the API changes introduced in 0.19.0 persist in later versions, this will lead to runtime errors. Consider using a version comparison (e.g.,>= 0.19.0) to ensure future compatibility.