Skip to content

vllm.distributed.kv_transfer.kv_connector.v1.flexkv_connector

Classes:

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(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:

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)

Get the number of new tokens that can be loaded from the external KV cache beyond num_computed_tokens.

Parameters:

  • request

    (Request) –

    the request object.

  • num_computed_tokens

    (int) –

    the number of locally computed tokens for this request.

Returns:

  • int –

    Tuple of (num_external_tokens, is_ready) where

  • bool –

    num_external_tokens is the number of additional tokens that

  • tuple[int, bool] –

    can be loaded from the external KV cache.

register_kv_caches(kv_caches)

Initialize with the KV caches. Useful for pre-registering the KV caches in the KVConnector (e.g. for NIXL).

Parameters:

  • kv_caches

    (dict[str, Tensor]) –

    dictionary of layer names to kv cache tensors.

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:

  • layer_name

    (str) –

    the name of the layer (unused).

  • kv_layer

    (Tensor) –

    the paged KV buffer (unused).

  • attn_metadata

    (AttentionMetadata) –

    the attention metadata (unused).

  • **kwargs

    (Any, default: {} ) –

    additional arguments (unused).

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:

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)

No-op for FlexKV (currently).

FlexKV manages all KV transfers on the scheduler side. This hook is retained for KVConnectorBase_V1 API compatibility.

Parameters:

  • layer_name

    (str) –

    the name of the layer (unused).

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.