[Core][Optimization] change python dict to pytorch tensor (#4607)

This commit is contained in:
youkaichao
2024-05-06 21:30:27 -07:00
committed by GitHub
parent a98187cf72
commit 63575bc2e1
19 changed files with 77 additions and 81 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ class CacheEngine:
self.attn_backend.swap_blocks(self.gpu_cache[i], self.cpu_cache[i],
src_to_dst)
def copy(self, src_to_dsts: Dict[int, List[int]]) -> None:
def copy(self, src_to_dsts: torch.Tensor) -> None:
self.attn_backend.copy_blocks(self.gpu_cache, src_to_dsts)
@staticmethod
+5 -2
View File
@@ -248,9 +248,9 @@ class CPUWorker(LoraNotSupportedWorkerBase):
def cache_copy(
self,
blocks_to_copy: Dict[int, List[int]],
blocks_to_copy: torch.Tensor,
) -> None:
if blocks_to_copy:
if blocks_to_copy.numel() > 0:
self.cache_engine.copy(blocks_to_copy)
@torch.inference_mode()
@@ -269,6 +269,9 @@ class CPUWorker(LoraNotSupportedWorkerBase):
num_seq_groups: int = len(seq_group_metadata_list)
assert execute_model_req is not None
blocks_to_copy = execute_model_req.blocks_to_copy
blocks_to_copy = torch.tensor(execute_model_req.blocks_to_copy,
device="cpu",
dtype=torch.int64).view(-1, 2)
assert len(execute_model_req.blocks_to_swap_in) == 0
assert len(execute_model_req.blocks_to_swap_out) == 0
data: Dict[str, Any] = {
+5 -3
View File
@@ -197,7 +197,7 @@ class Worker(WorkerBase):
self,
blocks_to_swap_in: Dict[int, int],
blocks_to_swap_out: Dict[int, int],
blocks_to_copy: Dict[int, List[int]],
blocks_to_copy: torch.Tensor,
) -> None:
# Issue cache operations.
# TODO(woosuk): Profile swapping overhead and optimize if needed.
@@ -205,7 +205,7 @@ class Worker(WorkerBase):
self.cache_engine.swap_in(blocks_to_swap_in)
if blocks_to_swap_out:
self.cache_engine.swap_out(blocks_to_swap_out)
if blocks_to_copy:
if blocks_to_copy.numel() > 0:
self.cache_engine.copy(blocks_to_copy)
@torch.inference_mode()
@@ -225,7 +225,9 @@ class Worker(WorkerBase):
num_seq_groups = len(seq_group_metadata_list)
blocks_to_swap_in = execute_model_req.blocks_to_swap_in
blocks_to_swap_out = execute_model_req.blocks_to_swap_out
blocks_to_copy = execute_model_req.blocks_to_copy
blocks_to_copy = torch.tensor(execute_model_req.blocks_to_copy,
device=self.device,
dtype=torch.int64).view(-1, 2)
data: Dict[str, Any] = {
"num_seq_groups": num_seq_groups,
"blocks_to_swap_in": blocks_to_swap_in,