forked from vllm-project/vllm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[V1] Support VLMs with fine-grained scheduling (vllm-project#9871)
Signed-off-by: Woosuk Kwon <[email protected]> Co-authored-by: Roger Wang <[email protected]>
- Loading branch information
Showing
12 changed files
with
542 additions
and
96 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
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
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,48 @@ | ||
from typing import Dict, List, Set, Tuple | ||
|
||
from vllm.v1.request import Request | ||
|
||
|
||
class EncoderCacheManager: | ||
|
||
def __init__(self, cache_size: int): | ||
self.cache_size = cache_size | ||
self.num_free_slots = cache_size | ||
# req_id -> cached input ids | ||
self.cached: Dict[str, Set[int]] = {} | ||
# List of [req_id, input_id] | ||
self.freed: List[Tuple[str, int]] = [] | ||
|
||
def has_cache(self, request: Request, input_id: int) -> bool: | ||
req_id = request.request_id | ||
return req_id in self.cached and input_id in self.cached[req_id] | ||
|
||
def can_allocate(self, request: Request, input_id: int) -> bool: | ||
num_tokens = request.get_num_encoder_tokens(input_id) | ||
return num_tokens <= self.num_free_slots | ||
|
||
def allocate(self, request: Request, input_id: int) -> None: | ||
req_id = request.request_id | ||
if req_id not in self.cached: | ||
self.cached[req_id] = set() | ||
self.cached[req_id].add(input_id) | ||
self.num_free_slots -= request.get_num_encoder_tokens(input_id) | ||
|
||
def get_cached_input_ids(self, request: Request) -> Set[int]: | ||
return self.cached.get(request.request_id, set()) | ||
|
||
def free(self, request: Request, input_id: int) -> None: | ||
req_id = request.request_id | ||
if req_id not in self.cached: | ||
return | ||
|
||
self.cached[req_id].discard(input_id) | ||
if len(self.cached[req_id]) == 0: | ||
del self.cached[req_id] | ||
self.num_free_slots += request.get_num_encoder_tokens(input_id) | ||
self.freed.append((req_id, input_id)) | ||
|
||
def get_freed_ids(self) -> List[Tuple[str, int]]: | ||
freed = self.freed | ||
self.freed = [] | ||
return freed |
Oops, something went wrong.