Skip to content

vllm.distributed.ec_transfer.ec_connector.base

ECConnectorBase Class for Distributed Encoder Cache & P2P Encoder cache communication in V1

The class provides the following primitives

Scheduler-side: runs in the scheduler, binds metadata, which is used by the worker-side to load/save Encoder cache. check_caches_exist() - Check whether Encoder cache of requests exist update_state_after_alloc() - update ECConnector state after allocate. This will decide to load the cache or not request_finished() - called when a request is finished, free the cache with the requests

Worker-side: runs in each worker, loads/saves Encoder Cache to/from the Connector based on the metadata. start_load_ec() - starts loading all ECs (maybe async) wait_for_save() - blocks until all saves are done

get_finished() - called with ids of finished requests, returns
    ids of requests that have completed async sending/recving.
build_connector_worker_meta() - builds metadata to be sent
    back to the scheduler-side connector

Classes:

ECConnectorBase

Bases: ABC

Methods:

_get_connector_metadata()

Get the connector metadata.

This function should only be called inside the connector.

Returns:

bind_connector_metadata(connector_metadata)

Set the connector metadata from the scheduler.

This function should be called by the model runner every time before the model execution. The metadata will be used for runtime EC cache loading.

Parameters:

  • connector_metadata

    (dict) –

    the connector metadata.

bind_encoder_cache_query(query)

Provide a read-only query for each input's cached embedding count.

build_connector_meta(scheduler_output) abstractmethod

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:

build_connector_worker_meta()

Build the ECConnector worker metadata for this engine step.

Returns:

build_ec_connector_stats(data=None) classmethod

ECConnectorStats resolution method. This method allows dynamically registered connectors to return their own ECConnectorStats object, which can implement custom aggregation logic on the data dict.

build_prom_metrics(vllm_config, metric_types, labelnames, per_engine_labelvalues) classmethod

Create an ECConnectorPromMetrics subclass which should register per-connector Prometheus metrics and implement observe() to expose connector transfer stats via Prometheus.

clear_connector_metadata()

Clear the connector metadata.

This function should be called by the model runner every time after the model execution.

ensure_cache_available(request, num_computed_tokens)

Ensure encoder cache items are available for the given request. May initiate asynchronous transfers for items not yet local.

Parameters:

  • request

    (Request) –

    the request whose multimodal features to check.

  • num_computed_tokens

    (int) –

    tokens already covered by cached KV blocks.

Returns:

  • bool –

    True if all items are ready or no transfer is needed.

  • bool –

    False if any items are still in transit (request should be deferred).

get_ec_connector_stats()

Get the EC connector stats collected during the last interval.

Callable on either a worker-side or scheduler-side connector instance: the worker-side instance reports stats gathered during cache save/load, while the scheduler-side instance reports stats gathered during scheduling decisions.

get_finished(finished_req_ids)

Notifies worker-side connector ids of requests that have finished generating tokens on the worker. The scheduler process (via the Executors) will use this output to track which workers are done.

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).

has_cache_item(identifier) abstractmethod

Check if a single encoder cache exists.

Parameters:

  • identifier

    (str) –

    the identifier of the media.

Returns:

  • bool –

    A bool where value is True if cache exist for

  • bool –

    the media

has_pending_push_work()

Return True if the connector has push-mode work that requires the engine main loop to keep stepping (e.g. for EPD, Producer has push work when Xfer is in progress - Consumer is reading it). This mirrors exactly the KV Connector's has_pending_push_work().

Connectors that don't implement push-based EC transfer should leave this as False.

on_new_request(request)

Notify the connector after a new request is queued.

register_caches(ec_caches)

Initialize with the EC caches.

Parameters:

request_finished(request)

Called when a request has finished, before its encoder cache is freed.

Returns:

  • bool –

    True if the request is being saved/sent asynchronously and cached

  • dict[str, Any] | None –

    should not be freed until the request_id is returned from

  • tuple[bool, dict[str, Any] | None] –

    get_finished().

requires_encoder_cache_readmission(request, input_id)

Whether an evicted runner hit needs another admission check.

reset()

Invalidate connector-side encoder cache bookkeeping.

Called from Scheduler.reset_encoder_cache after the EncoderCacheManager is cleared, and from the worker reset_encoder_cache path after the local encoder cache is cleared. The default is a no-op; connectors that mirror local cache residency must drop that state so a later request cannot skip a necessary Load or Encode.

save_caches(encoder_cache, mm_hash, **kwargs) abstractmethod

Save the encoder cache to the connector.

This method saves the encoder cache from the worker's local storage to shared storage or another external connector.

Parameters:

  • encoder_cache

    (dict[str, Tensor]) –

    A dictionary mapping multimodal data hashes (mm_hash) to encoder cache tensors.

  • mm_hash

    (str) –

    The hash of the multimodal data whose cache is being saved.

  • kwargs

    (dict, default: {} ) –

    Additional keyword arguments for the connector.

shutdown()

Shutdown the connector. This is called when the process is shutting down to ensure that all the async operations are completed and the connector is cleaned up properly.

start_load_caches(encoder_cache, **kwargs) abstractmethod

Start loading the cache from the connector into vLLM's encoder cache.

This method loads the encoder cache based on metadata provided by the scheduler. It is called before gather_mm_embeddings for the EC Connector. For EC, the encoder_cache and mm_hash are stored in kwargs.

Parameters:

  • encoder_cache

    (dict[str, Tensor]) –

    A dictionary mapping multimodal data hashes (mm_hash) to encoder cache tensors.

  • kwargs

    (dict, default: {} ) –

    Additional keyword arguments for the connector.

start_save_caches(**kwargs)

Prepare this step's outbound pushes before the model runs.

start_worker_services()

Start Worker-side services once the model is resident.

take_events()

Take the encoder cache events collected since the last call.

Returns:

take_unavailable_requests()

Request IDs whose encoder inputs the connector can no longer obtain.

The Scheduler fails these; re-issuing the request re-runs the encode.

update_connector_output(connector_output)

Update ECConnector state from worker-side connectors output.

Parameters:

  • connector_output

    (ECConnectorOutput) –

    the worker-side connectors output.

update_state_after_alloc(request, index) abstractmethod

Update ECConnector state to decide allocate cache for requests.

Parameters:

  • request

    (Request) –

    the request object.

  • index

    (int) –

    index of the encoder cache entry being allocated.

update_state_after_free(request, index)

Notify the connector that an encoder cache entry was released.

ECConnectorMetadata

Bases: ABC

Abstract Metadata used to communicate between the Scheduler ECConnector and Worker ECConnector.

ECConnectorWorkerMetadata

Bases: ABC

Abstract Metadata used to communicate back Worker ECConnector -> Scheduler ECConnector.

Each worker can output its own metadata. For a single engine step, all metadata objects returned by workers will be aggregated using the aggregate method below, before being passed to the Scheduler ECConnector.

Methods:

  • aggregate –

    Aggregate metadata with another ECConnectorWorkerMetadata object.

aggregate(other) abstractmethod

Aggregate metadata with another ECConnectorWorkerMetadata object.