Skip to content

vllm.distributed.kv_transfer.kv_connector.v1.example_connector

Classes:

Functions:

ExampleConnector

Bases: KVConnectorBase_V1

Methods:

_found_match_for_request(request)

Check if the cache is hit for the request.

_generate_filename_debug(layer_name, token_ids, mm_hashes)

Generate a file name based on the layer name and the hash of the bytes of the input ids.

_generate_foldername_debug(token_ids, mm_hashes, create_folder=False)

Generate a folder name based on the hash of the bytes of the input ids.

build_connector_meta(scheduler_output)

Build the connector metadata for this step.

This function should NOT modify any fields in the scheduler_output. Also, calling this function will reset the state of the connector.

Parameters:

get_num_new_matched_tokens(request, num_computed_tokens)

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

Parameters:

  • request

    (Request) –

    the request object.

  • num_computed_tokens

    (int) –

    the number of locally computed tokens for this request

Returns:

  • int | None –

    the number of tokens that can be loaded from the

  • bool –

    external KV cache beyond what is already computed.

save_kv_layer(layer_name, kv_layer, attn_metadata, **kwargs)

Start saving the KV cache of the layer from vLLM's paged buffer to the connector.

Parameters:

  • layer_name

    (str) –

    the name of the layer.

  • kv_layer

    (Tensor) –

    the paged KV buffer of the current layer in vLLM.

  • attn_metadata

    (AttentionMetadata) –

    the attention metadata.

  • **kwargs

    (Any, default: {} ) –

    additional arguments for the save operation.

start_load_kv(forward_context, **kwargs)

Start loading the KV cache from the connector buffer to vLLM's paged KV buffer.

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.

update_state_after_alloc(request, blocks, num_external_tokens)

Update KVConnector state after block allocation.

If blocks were allocated, add to _requests_need_load, such that we load the KVs in the next forward pass.

wait_for_layer_load(layer_name)

Blocking until the KV for a specific layer is loaded into vLLM's paged buffer.

This interface will be useful for layer-by-layer pipelining.

Parameters:

  • layer_name

    (str) –

    the name of that layer

num_cached_tokens(num_prompt_tokens, block_size, num_hash_lookahead_tokens, is_store)

Prompt prefix whose KV is stored or loaded.

Its key adds the next num_hash_lookahead_tokens, which the draft KV of the prefix depends on. A load prompt is the cached prompt plus one generated token, so that token is left out.