-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Chendi Xue <[email protected]>
- Loading branch information
Showing
6 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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,62 @@ | ||
from typing import List, Optional | ||
|
||
import torch | ||
|
||
from vllm.logger import init_logger | ||
from vllm.model_executor.layers.sampler import SamplerOutput | ||
from vllm.sequence import IntermediateTensors | ||
from vllm.worker.hpu_model_runner import HPUModelRunner as ModelRunnerBaseCls | ||
from vllm.worker.hpu_model_runner import ModelInputForHPUWithSamplingMetadata | ||
|
||
logger = init_logger(__name__) | ||
|
||
# A flag to enable debug prints for the updated input tensors | ||
# before each step. | ||
debug_advance_input = False | ||
# A flag to allow GPU advance step for draft model runner. | ||
# Set to False for debugging. | ||
allow_gpu_advance_step = True | ||
|
||
|
||
class HPUTP1DraftModelRunner(ModelRunnerBaseCls): | ||
"""Specialized model runner for speculative decoding draft model. | ||
Since the draft model always execute k forward passes consecutively to | ||
generate k speculative tokens in a single speculative decoding step, | ||
we could get rid of most CPU-GPU synchronization and data transfer | ||
overheads by keeping model input and output tensors on GPU all the time. | ||
TODOs: | ||
1. Support TP > 1 (this requires some designs because we do not expect | ||
any broadcasting inside execute_model). | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
if kwargs.get("return_hidden_states"): | ||
raise ValueError( | ||
"return_hidden_states is not supported for TP1DraftModelRunner." | ||
) | ||
|
||
super().__init__(*args, **kwargs) | ||
|
||
self.indices_of_seq_with_bonus_tokens = None | ||
|
||
@torch.inference_mode() | ||
def execute_model( | ||
self, | ||
model_input: ModelInputForHPUWithSamplingMetadata, | ||
kv_caches: List[torch.Tensor], | ||
previous_hidden_states: Optional[torch.Tensor] = None, | ||
intermediate_tensors: Optional[IntermediateTensors] = None, | ||
num_steps: int = 1, | ||
) -> Optional[List[SamplerOutput]]: | ||
if previous_hidden_states is not None: | ||
_, block_size = model_input.input_tokens.shape | ||
previous_hidden_states = previous_hidden_states.expand( | ||
block_size, -1).unsqueeze(0) | ||
return super().execute_model( | ||
model_input=model_input, | ||
kv_caches=kv_caches, | ||
previous_hidden_states=previous_hidden_states, | ||
intermediate_tensors=intermediate_tensors, | ||
num_steps=num_steps, | ||
) |
This file contains 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 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 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