vllm.distributed.kv_transfer.kv_connector.v1.lmcache_integration
¶
Modules:
Classes:
LMCacheMPSchedulerAdapter
¶
Methods:
-
__init__–Args:
-
check_lookup_result–Check the result of a previously submitted lookup request.
-
cleanup_lookup_result–Clean up lookup future for a finished request to prevent memory leak.
-
end_session–Notify LMCache server to remove the session for a finished request.
-
maybe_submit_lookup_request–Submit a new lookup request to LMCache if there is no ongoing request.
-
num_blocks_per_chunk–Returns:
Attributes:
-
tp_size(int) –The tensor parallel size.
-
worker_id(int) –The worker id.
-
world_size(int) –The world size.
tp_size
property
¶
The tensor parallel size.
worker_id
property
¶
The worker id.
world_size
property
¶
The world size.
__init__(server_url, context, model_name, vllm_block_size, parallel_strategy)
¶
Args: server_url: The server URL for the LMCache message queue context: The ZMQ context
model_name: The model name used for LMCache keys
vllm_block_size: The block size used in vLLM
parallel_strategy:
The parallel strategy, which includes use_mla,
world_size, worker_id and so on
_create_hash_key(chunk_hash, request_id=None)
¶
Create a hash-mode IPC cache engine key.
_create_key(token_ids, start=0, end=0, request_id=None)
¶
Convert token IDs to an IPC cache engine key.
check_lookup_result(request_id)
¶
Check the result of a previously submitted lookup request.
Parameters:
Returns:
cleanup_lookup_result(request_id)
¶
end_session(request_id)
¶
maybe_submit_lookup_request(request_id, block_hashes=None, token_ids=None)
¶
Submit a new lookup request to LMCache if there is no ongoing request.
Supports both token-based and hash-based vLLM: - token_ids: token IDs (token-based vLLM) -> single token-mode key - block_hashes: block hashes (hash-based vLLM) -> strided hash-mode keys
Exactly one of block_hashes or token_ids must be provided.
Parameters:
-
(request_id¶str) –The ID of the lookup request. The same ID indicates it's from the same request
-
(block_hashes¶list[bytes] | None, default:None) –Block hashes to lookup from LMCache (hash mode)
-
(token_ids¶list[int] | None, default:None) –Token IDs to lookup from LMCache (token mode)
Returns:
-
None–None
Notes
This function will have a side-effect: submitting a look up request to
LMCache, which will essentially 'lock' the KV cache chunks in the LMCache
for later retrieve operations.
In the meantime, this function will record the lookup request, and the
status of the look up request can be checked by check_lookup_result.
num_blocks_per_chunk()
¶
Returns: The number of vllm blocks in a LMCache data chunk
LMCacheMPWorkerAdapter
¶
Methods:
-
batched_submit_retrieve_requests–Submit a batched retrieve request to LMCache.
-
batched_submit_store_requests–Submit a batched store request to LMCache.
-
get_finished–Check and get the finished store and retrieve requests.
-
num_blocks_per_chunk–Returns:
-
register_kv_caches–Register the kv caches with LMCache server.
-
shutdown–Shutdown the LMCache MP worker adapter.
-
submit_retrieve_request–Submit a KV cache retrieve request to LMCache.
-
submit_store_request–Submit a KV cache store request to LMCache.
Attributes:
-
is_first_rank_of_pp_group(bool) –Is the first rank of the pipeline parallel group.
-
use_mla(bool) –Whether to use MLA.
-
worker_id(int) –The worker id.
-
world_size(int) –The world size.
is_first_rank_of_pp_group
property
¶
Is the first rank of the pipeline parallel group.
use_mla
property
¶
Whether to use MLA.
worker_id
property
¶
The worker id.
world_size
property
¶
The world size.
_create_hash_key(chunk_hash, request_id=None)
¶
Create a hash-mode IPC cache engine key.
_create_key(token_ids, start=0, end=0, request_id=None)
¶
Convert token IDs to an IPC cache engine key.
_update_and_get_finished_store()
¶
Converge the internal states about finished stores and returns the 'safe finished store request ids' back
batched_submit_retrieve_requests(request_ids, ops, event)
¶
Submit a batched retrieve request to LMCache.
Parameters:
batched_submit_store_requests(request_ids, ops, event)
¶
Submit a batched store request to LMCache.
Parameters:
get_finished(finished_req_ids_from_engine)
¶
Check and get the finished store and retrieve requests.
Parameters:
-
(finished_req_ids_from_engine¶set[str]) –the set of request ids that are reported as finished from the vLLM engine side.
Returns:
-
set[str] | None–A tuple of two sets:
-
set[str] | None–- The first set contains the finished store request ids. The returned
store request ids MUST be seen before in the
finished_req_ids_from_engine.
- The first set contains the finished store request ids. The returned
store request ids MUST be seen before in the
-
tuple[set[str] | None, set[str] | None]–- The second set contains the finished retrieve request ids.
Notes
When enabling async scheduling in vLLM, the same request ID may appear
multiple times in finished_req_ids_from_engine. The adapter should
take care of deduplicating the request IDs and only return the request
IDs that have not been returned before.
num_blocks_per_chunk()
¶
Returns: The number of vllm blocks in a LMCache data chunk
register_kv_caches(kv_caches)
¶
shutdown()
¶
Shutdown the LMCache MP worker adapter.
submit_retrieve_request(request_id, op, event)
¶
submit_store_request(request_id, op, event)
¶
LoadStoreOp
dataclass
¶
Attributes:
-
block_hashes(list[bytes] | None) –Block hashes for the load/store operation (hash mode)
-
block_ids(list[int]) –Block ids for the load/store operation
-
end(int) –End token index (token mode only)
-
start(int) –Start token index (token mode only)
-
token_ids(list[int] | None) –Token IDs for the load/store operation (token mode)
block_hashes = None
class-attribute
instance-attribute
¶
Block hashes for the load/store operation (hash mode)
block_ids
instance-attribute
¶
Block ids for the load/store operation
end = 0
class-attribute
instance-attribute
¶
End token index (token mode only)
start = 0
class-attribute
instance-attribute
¶
Start token index (token mode only)
token_ids = None
class-attribute
instance-attribute
¶
Token IDs for the load/store operation (token mode)
ParallelStrategy
dataclass
¶
Attributes:
-
actual_worker_id(int) –The actual worker id of the sub-process.
-
actual_world_size(int) –The actual world size.
-
kv_worker_id(int) –The kv worker id of the sub-process, kv_worker_id may not be equal to the
-
kv_world_size(int) –The kv world size, kv_world_size may not be equal to the actual_world_size,
-
pp_size(int) –The pipeline parallel size.
-
tp_size(int) –The tensor parallel size.
-
use_mla(bool) –Whether to use the MLA.
actual_worker_id
instance-attribute
¶
The actual worker id of the sub-process.
actual_world_size
instance-attribute
¶
The actual world size.
kv_worker_id
instance-attribute
¶
The kv worker id of the sub-process, kv_worker_id may not be equal to the
actual_worker_id, in the case of mla, it will 'exclude' the effect of TP,
the value is calculated by extract_world_size_and_kv_rank in
lmcache_mp_connector.py.
kv_world_size
instance-attribute
¶
The kv world size, kv_world_size may not be equal to the actual_world_size,
in the case of mla, it will 'exclude' the effect of TP, the value is
calculated by extract_world_size_and_kv_rank in lmcache_mp_connector.py.
pp_size
instance-attribute
¶
The pipeline parallel size.
tp_size
instance-attribute
¶
The tensor parallel size.
use_mla
instance-attribute
¶
Whether to use the MLA.