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– -
ECConnectorMetadata–Abstract Metadata used to communicate between the
-
ECConnectorWorkerMetadata–Abstract Metadata used to communicate back
ECConnectorBase
¶
Bases: ABC
Methods:
-
bind_connector_metadata–Set the connector metadata from the scheduler.
-
bind_encoder_cache_query–Provide a read-only query for each input's cached embedding count.
-
build_connector_meta–Build the connector metadata for this step.
-
build_connector_worker_meta–Build the ECConnector worker metadata for this engine step.
-
build_ec_connector_stats–ECConnectorStats resolution method. This method allows dynamically
-
build_prom_metrics–Create an ECConnectorPromMetrics subclass which should register
-
clear_connector_metadata–Clear the connector metadata.
-
ensure_cache_available–Ensure encoder cache items are available for the given request.
-
get_ec_connector_stats–Get the EC connector stats collected during the last interval.
-
get_finished–Notifies worker-side connector ids of requests that have
-
has_cache_item–Check if a single encoder cache exists.
-
has_pending_push_work–Return True if the connector has push-mode work that requires
-
on_new_request–Notify the connector after a new request is queued.
-
register_caches–Initialize with the EC caches.
-
request_finished–Called when a request has finished, before its encoder cache is freed.
-
requires_encoder_cache_readmission–Whether an evicted runner hit needs another admission check.
-
reset–Invalidate connector-side encoder cache bookkeeping.
-
save_caches–Save the encoder cache to the connector.
-
shutdown–Shutdown the connector. This is called when the process
-
start_load_caches–Start loading the cache from the connector into vLLM's encoder cache.
-
start_save_caches–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.
-
take_unavailable_requests–Request IDs whose encoder inputs the connector can no longer obtain.
-
update_connector_output–Update ECConnector state from worker-side connectors output.
-
update_state_after_alloc–Update ECConnector state to decide allocate cache for requests.
-
update_state_after_free–Notify the connector that an encoder cache entry was released.
_get_connector_metadata()
¶
Get the connector metadata.
This function should only be called inside the connector.
Returns:
-
ConnectorMetadata(ECConnectorMetadata) –the connector metadata.
bind_connector_metadata(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:
-
(scheduler_output¶SchedulerOutput) –the scheduler output object.
build_connector_worker_meta()
¶
Build the ECConnector worker metadata for this engine step.
Returns:
-
ECConnectorWorkerMetadata(ECConnectorWorkerMetadata | None) –the worker metadata.
-
ECConnectorWorkerMetadata | None–None if no worker metadata is available.
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)
¶
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
¶
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)
¶
request_finished(request)
¶
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:
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:
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:
-
Iterable[ECCacheEvent]–New encoder cache events. Connectors that do not publish events
-
Iterable[ECCacheEvent]–return nothing.
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_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
ECConnectorWorkerMetadataobject.
aggregate(other)
abstractmethod
¶
Aggregate metadata with another ECConnectorWorkerMetadata object.