vllm.distributed.kv_transfer.kv_connector.v1.lmcache_connector
¶
Classes:
-
LMCacheConnectorV1– -
LMCacheKVEvents–Concrete implementation of KVConnectorKVEvents using KVEventAggregator.
LMCacheConnectorV1
¶
Bases: KVConnectorBase_V1
Methods:
-
build_connector_meta–Build the connector metadata for this step.
-
get_block_ids_with_load_errors–Get the set of block IDs that failed to load.
-
get_finished–Notifies worker-side connector ids of requests that have
-
get_kv_connector_kv_cache_events–Get the KV connector kv cache events collected during the last interval.
-
get_num_new_matched_tokens–Get number of new tokens that can be loaded from the
-
register_kv_caches–Initialize with the KV caches. Useful for pre-registering the
-
request_finished–Called when a request has finished, before its blocks are freed.
-
requires_piecewise_for_cudagraph–LMCache requires PIECEWISE CUDA graph mode when layerwise
-
save_kv_layer–Start saving the a layer of KV cache from vLLM's paged buffer
-
start_load_kv–Start loading the KV cache from the connector to vLLM's paged
-
take_events–Take the KV cache events from the connector.
-
update_connector_output–Update KVConnector state from worker-side connectors output.
-
update_state_after_alloc–Update KVConnector state after block allocation.
-
wait_for_layer_load–Block until the KV for a specific layer is loaded into vLLM's
-
wait_for_save–Block until all the save operations is done. This is called
build_connector_meta(scheduler_output)
¶
Build the connector metadata for this step.
This function should NOT modify fields in the scheduler_output. Also, calling this function will reset the state of the connector.
Parameters:
-
(scheduler_output¶SchedulerOutput) –the scheduler output object.
get_block_ids_with_load_errors()
¶
get_finished(finished_req_ids)
¶
Notifies worker-side connector ids of requests that have finished generating tokens.
Returns:
-
set[str] | None–ids of requests that have finished asynchronous transfer
-
set[str] | None–(requests that previously returned True from request_finished()),
-
tuple[set[str] | None, set[str] | None]–tuple of (sending/saving ids, recving/loading ids).
-
tuple[set[str] | None, set[str] | None]–The finished saves/sends req ids must belong to a set provided in a
-
tuple[set[str] | None, set[str] | None]–call to this method (this call or a prior one).
get_kv_connector_kv_cache_events()
¶
Get the KV connector kv cache events collected during the last interval.
get_num_new_matched_tokens(request, num_computed_tokens)
¶
register_kv_caches(kv_caches)
¶
request_finished(request, block_ids)
¶
Called when a request has finished, before its blocks are freed.
Returns:
-
bool–True if the request is being saved/sent asynchronously and blocks
-
dict[str, Any] | None–should not be freed until the request_id is returned from
-
tuple[bool, dict[str, Any] | None]–get_finished().
-
tuple[bool, dict[str, Any] | None]–Optional KVTransferParams to be included in the request outputs
-
tuple[bool, dict[str, Any] | None]–returned by the engine.
requires_piecewise_for_cudagraph(extra_config)
classmethod
¶
LMCache requires PIECEWISE CUDA graph mode when layerwise operations are enabled. The wait_for_layer_load and save_kv_layer methods perform actual async synchronization that cannot be captured in CUDA graphs.
save_kv_layer(layer_name, kv_layer, attn_metadata, **kwargs)
¶
Start saving the a layer of KV cache from vLLM's paged buffer to the connector. This is called from within attention layer to enable async copying during execution.
Parameters:
start_load_kv(forward_context, **kwargs)
¶
Start loading the KV cache from the connector to vLLM's paged KV buffer. This is called from the forward context before the forward pass to enable async loading during model execution.
Parameters:
-
(forward_context¶ForwardContext) –the forward context.
-
(**kwargs¶Any, default:{}) –additional arguments for the load operation
Note
The number of elements in kv_caches and layer_names should be the same.
take_events()
¶
Take the KV cache events from the connector.
Yields:
-
Iterable[KVCacheEvent]–New KV cache events since the last call.
update_connector_output(connector_output)
¶
Update KVConnector state from worker-side connectors output.
Parameters:
-
(connector_output¶KVConnectorOutput) –the worker-side connectors output.
update_state_after_alloc(request, blocks, num_external_tokens)
¶
Update KVConnector state after block allocation.
wait_for_layer_load(layer_name)
¶
wait_for_save()
¶
Block until all the save operations is done. This is called as the forward context exits to ensure that the async saving from save_kv_layer is complete before finishing the forward.
This prevents overwrites of paged KV buffer before saving done.
LMCacheKVEvents
¶
Bases: KVConnectorKVEvents
Concrete implementation of KVConnectorKVEvents using KVEventAggregator.
Methods:
-
aggregate–Aggregate KV events and retain only common events.
aggregate()
¶
Aggregate KV events and retain only common events.