-
-
Notifications
You must be signed in to change notification settings - Fork 17.7k
[P/D][Feature] Support kv_transfer_params for parallel sampling (n>1) #38900
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
base: main
Are you sure you want to change the base?
Changes from all commits
d4c20ef
0836848
b7482d8
cc9a763
f4a096f
2eddc95
6e53cde
eae6076
16d9bde
003d3ee
2327dfe
dd58080
a221751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -107,7 +107,7 @@ class ChatCompletionResponse(OpenAIBaseModel): | |
| # vLLM-specific fields that are not in OpenAI spec | ||
| prompt_logprobs: list[dict[int, Logprob] | None] | None = None | ||
| prompt_token_ids: list[int] | None = None | ||
| kv_transfer_params: dict[str, Any] | None = Field( | ||
| kv_transfer_params: dict[str, Any] | list[dict[str, Any]] | None = Field( | ||
|
Member
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. nit: we could also comment here when we expect a list |
||
| default=None, description="KVTransfer parameters." | ||
| ) | ||
|
|
||
|
|
@@ -332,7 +332,7 @@ class ChatCompletionRequest(OpenAIBaseModel): | |
| ), | ||
| ) | ||
|
|
||
| kv_transfer_params: dict[str, Any] | None = Field( | ||
| kv_transfer_params: dict[str, Any] | list[dict[str, Any]] | None = Field( | ||
| default=None, | ||
| description="KVTransfer parameters used for disaggregated serving.", | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ class CompletionOutput: | |
| to stop, None if the completion finished for some other reason | ||
| including encountering the EOS token. | ||
| lora_request: The LoRA request that was used to generate the output. | ||
| kv_transfer_params: The params for remote K/V transfer. | ||
| """ | ||
|
|
||
| index: int | ||
|
|
@@ -46,6 +47,7 @@ class CompletionOutput: | |
| finish_reason: str | None = None | ||
| stop_reason: int | str | None = None | ||
| lora_request: LoRARequest | None = None | ||
| kv_transfer_params: dict[str, Any] | None = None | ||
|
|
||
| def finished(self) -> bool: | ||
| return self.finish_reason is not None | ||
|
|
@@ -59,7 +61,8 @@ def __repr__(self) -> str: | |
| f"cumulative_logprob={self.cumulative_logprob}, " | ||
| f"logprobs={self.logprobs}, " | ||
| f"finish_reason={self.finish_reason}, " | ||
| f"stop_reason={self.stop_reason})" | ||
| f"stop_reason={self.stop_reason}, " | ||
| f"kv_transfer_params={self.kv_transfer_params})" | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -103,7 +106,6 @@ class RequestOutput: | |
| encoder_prompt_token_ids: The token IDs of the encoder prompt. | ||
| None if decoder-only. | ||
| num_cached_tokens: The number of tokens with prefix cache hit. | ||
| kv_transfer_params: The params for remote K/V transfer. | ||
| """ | ||
|
|
||
| def __init__( | ||
|
|
@@ -119,8 +121,6 @@ def __init__( | |
| encoder_prompt: str | None = None, | ||
| encoder_prompt_token_ids: list[int] | None = None, | ||
| num_cached_tokens: int | None = None, | ||
| *, | ||
| kv_transfer_params: dict[str, Any] | None = None, | ||
| # Forward compatibility, code that uses args added in new release can | ||
| # still run with older versions of vLLM without breaking. | ||
| **kwargs: Any, | ||
|
|
@@ -140,14 +140,27 @@ def __init__( | |
| self.encoder_prompt = encoder_prompt | ||
| self.encoder_prompt_token_ids = encoder_prompt_token_ids | ||
| self.num_cached_tokens = num_cached_tokens | ||
| self.kv_transfer_params = kv_transfer_params | ||
|
|
||
| @property | ||
| def kv_transfer_params(self) -> dict[str, Any] | list[dict[str, Any]] | None: | ||
|
Collaborator
Author
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.
@njhill I’ve also taken this case into consideration. I’ve added some backward-compatible handling here, and you can see that the constructor supports So whether it’s initialization or accessing the |
||
| params_list = [ | ||
| o.kv_transfer_params for o in self.outputs if o.kv_transfer_params | ||
| ] | ||
| if len(params_list) == 1: | ||
| # keep backward compatibility for the common case where there is | ||
| # only one output and its kv_transfer_params is a dict | ||
| return params_list[0] | ||
| if len(params_list) > 1: | ||
| # for the case where there are multiple outputs, we return a list of | ||
| # kv_transfer_params dicts. This is for parallel sampling (n > 1) | ||
| # where each child request may have different kv_transfer_params. | ||
| return params_list | ||
| return None | ||
|
|
||
| def add(self, next_output: "RequestOutput", aggregate: bool) -> None: | ||
| """Merge subsequent RequestOutput into this one""" | ||
|
|
||
| self.finished |= next_output.finished | ||
| self.kv_transfer_params = next_output.kv_transfer_params | ||
|
|
||
| for next_completion in next_output.outputs: | ||
| for i, completion in enumerate(self.outputs): | ||
| if completion.index == next_completion.index: | ||
|
|
@@ -165,6 +178,9 @@ def add(self, next_output: "RequestOutput", aggregate: bool) -> None: | |
| ) | ||
| completion.finish_reason = next_completion.finish_reason | ||
| completion.stop_reason = next_completion.stop_reason | ||
| completion.kv_transfer_params = ( | ||
| next_completion.kv_transfer_params | ||
| ) | ||
| else: | ||
| # Replace the output with the new one | ||
| self.outputs[i] = next_completion | ||
|
|
@@ -184,7 +200,8 @@ def __repr__(self) -> str: | |
| f"finished={self.finished}, " | ||
| f"metrics={self.metrics}, " | ||
| f"lora_request={self.lora_request}, " | ||
| f"num_cached_tokens={self.num_cached_tokens})" | ||
| f"num_cached_tokens={self.num_cached_tokens}, " | ||
| f"kv_transfer_params={self.kv_transfer_params})" | ||
| ) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.