[Perf] Avoid some more unnecessary GPU<->CPU syncs (#51458)
Signed-off-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
@@ -20,6 +20,7 @@ from vllm.distributed.kv_transfer.kv_connector.factory import KVConnectorFactory
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.attention_layer_base import AttentionLayerBase
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.torch_utils import async_tensor_h2d
|
||||
from vllm.v1.attention.backend import AttentionBackend
|
||||
from vllm.v1.outputs import KVConnectorOutput, ModelRunnerOutput
|
||||
|
||||
@@ -179,9 +180,13 @@ def _make_src_and_dst_indices(
|
||||
src_device: torch.device | str,
|
||||
dst_device: torch.device | str,
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
src_indices = torch.tensor(src_block_ids, device=src_device, dtype=torch.int64)
|
||||
dst_indices = torch.tensor(dst_block_ids, device=dst_device, dtype=torch.int64)
|
||||
return src_indices, dst_indices
|
||||
def _to(block_ids: list[int], device: torch.device | str) -> torch.Tensor:
|
||||
device = torch.device(device) if isinstance(device, str) else device
|
||||
if device.type == "cpu":
|
||||
return torch.tensor(block_ids, dtype=torch.int64, device=device)
|
||||
return async_tensor_h2d(block_ids, dtype=torch.int64, device=device)
|
||||
|
||||
return _to(src_block_ids, src_device), _to(dst_block_ids, dst_device)
|
||||
|
||||
|
||||
def copy_kv_blocks(
|
||||
|
||||
Reference in New Issue
Block a user