vllm.distributed.kv_transfer.kv_connector.v1.flexkv_connector
¶
Classes:
-
FlexKVConnectorV1–KV Connector that offloads KV cache to FlexKV.
FlexKVConnectorV1
¶
Bases: KVConnectorBase_V1
KV Connector that offloads KV cache to FlexKV.
FlexKV is a distributed KV Store and multi-level cache management system designed for ultra-large-scale LLM inference. It supports offloading KV cache to CPU memory, SSD, and remote storage.
Installation
See https://github.com/taco-project/FlexKV for installation instructions. Quick start::
git clone git@github.com:taco-project/FlexKV.git
cd FlexKV && bash build.sh
Configuration
Pass kv_connector="FlexKVConnectorV1" via --kv-transfer-config::
--kv-transfer-config \
'{"kv_connector":"FlexKVConnectorV1","kv_role":"kv_both"}'
Methods:
-
build_connector_meta–Build the connector metadata for this step.
-
get_block_ids_with_load_errors–Get the block ids that have failed to load.
-
get_finished–Notify worker-side connector of requests that have finished
-
get_kv_connector_stats–Get the KV connector stats collected during the last interval.
-
get_num_new_matched_tokens–Get the 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.
-
save_kv_layer–No-op for FlexKV (currently).
-
start_load_kv–No-op for FlexKV (currently).
-
take_events–Collect buffered KV cache events.
-
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–No-op for FlexKV (currently).
-
wait_for_save–No-op for FlexKV (currently).
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 the block ids that have failed to load.
get_finished(finished_req_ids)
¶
Notify worker-side connector of requests that have finished generating tokens.
Returns:
-
set[str] | None–Tuple of (sending/saving ids, recving/loading ids) for requests
-
set[str] | None–that have finished asynchronous transfer. The finished saves/sends
-
tuple[set[str] | None, set[str] | None]–req ids must belong to a set provided in a call to this method
-
tuple[set[str] | None, set[str] | None]–(this call or a prior one).
get_kv_connector_stats()
¶
Get the KV connector stats 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–Tuple of (async_save, kv_transfer_params) where async_save is
-
dict[str, Any] | None–True if the request is being saved/sent asynchronously and blocks
-
tuple[bool, dict[str, Any] | None]–should not be freed until the request_id is returned from
-
tuple[bool, dict[str, Any] | None]–get_finished. kv_transfer_params is an optional dict of -
tuple[bool, dict[str, Any] | None]–KVTransferParams to be included in the request outputs.
save_kv_layer(layer_name, kv_layer, attn_metadata, **kwargs)
¶
No-op for FlexKV (currently).
FlexKV offloads KV cache asynchronously from the scheduler side
after a request finishes (see request_finished). It does not
intercept individual layer tensors during the forward pass.
This hook is retained to satisfy KVConnectorBase_V1 and as an
extension point for future per-layer async offload support.
Parameters:
start_load_kv(forward_context, **kwargs)
¶
No-op for FlexKV (currently).
FlexKV manages all KV transfers on the scheduler side via
build_connector_meta (which calls launch_tasks) and
update_connector_output (which polls query_finished_task).
KV blocks are transferred directly between the FlexKV server and
vLLM's GPU memory without worker-side intervention during the
forward pass — similar to how NIXL operates.
These worker-side hooks are kept (rather than omitted) to satisfy
the KVConnectorBase_V1 interface contract and to serve as
extension points for a future worker-side layer-pipelining path.
Parameters:
-
(forward_context¶ForwardContext) –the forward context.
-
(**kwargs¶Any, default:{}) –additional arguments (unused).
take_events()
¶
Collect buffered KV cache events.
Returns:
-
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()
¶
No-op for FlexKV (currently).
KV offload tasks are tracked asynchronously by the scheduler
connector via request_finished / query_finished_task.
There is no pending worker-side save to wait for at
forward-context exit.
Retained to satisfy KVConnectorBase_V1 and as an extension
point for future worker-side save-completion signalling.