vllm.distributed.kv_transfer.kv_connector.v1.example_connector
¶
Classes:
Functions:
-
num_cached_tokens–Prompt prefix whose KV is stored or loaded.
ExampleConnector
¶
Bases: KVConnectorBase_V1
Methods:
-
build_connector_meta–Build the connector metadata for this step.
-
get_num_new_matched_tokens–Get number of new tokens that can be loaded from the
-
save_kv_layer–Start saving the KV cache of the layer from vLLM's paged buffer
-
start_load_kv–Start loading the KV cache from the connector buffer to vLLM's
-
update_state_after_alloc–Update KVConnector state after block allocation.
-
wait_for_layer_load–Blocking until the KV for a specific layer is loaded into vLLM's
_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:
-
(scheduler_output¶SchedulerOutput) –the scheduler output object.
get_num_new_matched_tokens(request, num_computed_tokens)
¶
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:
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.
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.