vllm.v1.engine.core
¶
Classes:
-
DPEngineCoreProc–ZMQ-wrapper for running EngineCore in background process
-
DPMoEEngineCoreActor–Used for MoE model data parallel cases.
-
EngineCore–Inner loop of vLLM's Engine.
-
EngineCoreActor–Used for non-MoE and/or non-DP cases.
-
EngineCoreActorMixin–Ray actor for running EngineCore in a data parallel context.
-
EngineCoreProc–ZMQ-wrapper for running EngineCore in background process.
DPEngineCoreProc
¶
Bases: EngineCoreProc
ZMQ-wrapper for running EngineCore in background process in a data parallel context.
Methods:
-
barrier–Blocking barrier on the DP process group (test-only utility).
-
run_busy_loop–Core busy loop of the EngineCore for data parallel case.
_eep_send_engine_core_notification(notification_type)
¶
Send notifications to EngineCoreClient, which can then forward the notifications to other engine core processes. It is used for: 1) In scale down: removing core engines to notify EngineCoreClient so EngineCoreClient can release their ray placement groups; 2) Both scale up/down: to notify EngineCoreClient that existing core engines have already switched to the new parallel setup.
_pause_complete()
¶
Two-phase DP-aware pause.
Phase 1: Set local pause state and pending_pause flag. If the
engines are idle, kick-start them by setting engines_running to
True so ranks enter the stepping loop and reach the all-reduce
consensus checkpoint in _has_global_unfinished_reqs.
Phase 2 (in _has_global_unfinished_reqs): Once the all-reduce
confirms that all ranks have pending_pause set, collectively
stop stepping and set ignore_start_dp_wave so that stale
START_DP_WAVE messages cannot re-wake any engine.
_probe_forward()
¶
Liveness only: the reply proves the busy loop is not wedged.
A dummy batch here would run outside the DP wave and could deadlock against a peer's wave collectives.
barrier()
¶
Blocking barrier on the DP process group (test-only utility).
run_busy_loop()
¶
Core busy loop of the EngineCore for data parallel case.
DPMoEEngineCoreActor
¶
EngineCore
¶
Inner loop of vLLM's Engine.
Methods:
-
abort_requests–Abort requests from the scheduler.
-
add_request–Add request to the scheduler.
-
get_kv_cache_group_metadata–Return serializable KV cache metadata for external event consumers
-
get_weight_version–Return the latest committed weight version.
-
is_inference_ready–Whether the engine can accept and process new requests: it is not
-
is_scheduler_paused–Return whether the scheduler is in any pause state.
-
is_sleeping–Check if engine is sleeping at any level.
-
log_error_detail–Execute the model and log detailed info on failure.
-
pause_scheduler–Pause generation; behavior depends on mode.
-
preprocess_add_request–Preprocess the request.
-
release_kv_cache_memory–Discard KV cache physical memory. Requires a completed pause
-
reset_encoder_cache–Reset the encoder cache to invalidate all cached encoder outputs.
-
resume_scheduler–Resume the scheduler and flush any requests queued while paused.
-
sleep–Put the engine to sleep at the specified level.
-
step–Schedule, execute, and make output.
-
step_with_batch_queue–Schedule and execute batches with the batch queue.
-
wake_up–Wake up the engine from sleep.
_handle_inputs_while_waiting(future, stop_on_add=False)
¶
Handle inputs until the output is ready. Returns True if stop_on_add
and a request was added first.
_set_kv_cache_reclaimable(reclaimable)
¶
Tell the workers whether their extensible KV cache holds nothing to keep, as from a pause that cleared it until the resume, so that a weight reload may borrow its memory.
_should_throttle_prefills()
¶
Whether to defer prefills this step, to run them every Nth step. Overridden by the DP engine core to align across ranks.
_untimed_iteration_details(scheduler_output)
¶
Details of a finished iteration that the output worker does not time.
_wait_for_new_request(batch_queue)
¶
PP, with a free batch slot: wait on the oldest batch, but return True as soon as a request is added, to schedule it into the slot.
_wait_for_output(future)
¶
Wait for a step's model output, meanwhile handling inputs if possible.
abort_requests(request_ids)
¶
Abort requests from the scheduler.
add_request(request, request_wave=0)
¶
Add request to the scheduler.
request_wave: indicate which wave of requests this is expected to
belong to in DP case
get_kv_cache_group_metadata()
¶
Return serializable KV cache metadata for external event consumers (e.g., Dynamo). This function has no call sites within vLLM but needs to be kept.
get_weight_version()
¶
Return the latest committed weight version.
is_inference_ready()
¶
Whether the engine can accept and process new requests: it is not paused (including for a checkpoint) or asleep, and no weight update has left the weights incomplete.
is_scheduler_paused()
¶
Return whether the scheduler is in any pause state.
is_sleeping()
¶
Check if engine is sleeping at any level.
log_error_detail(scheduler_output)
¶
Execute the model and log detailed info on failure.
pause_scheduler(mode='abort', clear_cache=True, reset_connector=True, reset_mm_cache=True)
¶
Pause generation; behavior depends on mode.
All pause modes queue new adds -- "abort" and "keep" skip step(); "wait" allows step() so in-flight requests can drain.
abort: Set PAUSED_NEW, abort all requests, wait for abort outputs to be sent (when running with output_queue), optionally clear caches, then complete the returned Future.wait: Set PAUSED_NEW (queue adds, keep stepping); when drained, optionally clear caches, then complete the returned Future.keep: Set PAUSED_ALL; return a Future that completes when the output queue is empty.
reset_connector and reset_mm_cache decide whether clearing caches
also resets the KV connector's cache and the multimodal processor cache.
preprocess_add_request(request)
¶
Preprocess the request.
This function could be directly used in input processing thread to allow request initialization running in parallel with Model forward
release_kv_cache_memory(reset_connector=True)
¶
Discard KV cache physical memory. Requires a completed pause
and all executor memory to be resident. Kept requests are recomputed
after wake-up. reset_connector is as for sleep.
reset_encoder_cache()
¶
Reset the encoder cache to invalidate all cached encoder outputs.
This should be called when model weights are updated to ensure stale vision embeddings computed with old weights are not reused. Clears both the scheduler's cache manager and the GPU model runner's cache.
resume_scheduler()
¶
Resume the scheduler and flush any requests queued while paused.
sleep(level=1, mode='abort', reset_connector=True)
¶
Put the engine to sleep at the specified level.
Parameters:
-
(level¶int, default:1) –Sleep level. - Level 0: Pause scheduling only. Requests are still accepted but not processed. No GPU memory changes. - Level 1: Offload model weights to CPU, discard KV cache. - Level 2: Discard model parameters and KV cache.
-
(mode¶PauseMode, default:'abort') –Pause mode - how to deal with any existing requests, see documentation of pause_scheduler method.
-
(reset_connector¶bool, default:True) –Also reset the KV connector's cache; see
LLM.sleep.
step()
¶
Schedule, execute, and make output.
Returns tuple of outputs and a flag indicating whether the model was executed.
step_with_batch_queue()
¶
Schedule and execute batches with the batch queue. Note that if nothing to output in this step, None is returned.
The execution flow is as follows: 1. Try to schedule a new batch if the batch queue is not full. If a new batch is scheduled, directly return an empty engine core output. In other words, fulfilling the batch queue has a higher priority than getting model outputs. 2. If there is no new scheduled batch, meaning that the batch queue is full or no other requests can be scheduled, we block until the first batch in the job queue is finished. 3. Update the scheduler from the output.
EngineCoreActor
¶
EngineCoreActorMixin
¶
Ray actor for running EngineCore in a data parallel context.
Methods:
-
run–Run the engine core busy loop.
-
wait_for_init–Wait until the engine core is initialized.
_perform_handshakes(handshake_address, identity, local_client, vllm_config, client_handshake_address)
¶
For Ray, we don't need to actually perform handshake. All addresses information is known before the actor creation. Therefore, we simply yield these addresses.
run()
¶
Run the engine core busy loop.
wait_for_init()
¶
Wait until the engine core is initialized.
This is just an empty method. When ray.get() on this method (or any other method of the actor) returns, it is guaranteed that actor creation (i.e., init) is complete.
EngineCoreProc
¶
Bases: EngineCore
ZMQ-wrapper for running EngineCore in background process.
Methods:
-
check_health_generate–Health check served by the busy loop between steps.
-
checkpoint_prepare–Drain with
mode, then release the KV cache and what a process -
checkpoint_restore–Bring back what preparing released, wake the KV cache and resume
-
has_work–Returns true if the engine should be stepped.
-
is_running–Returns true if shutdown has not been requested.
-
pause_generation–pause_schedulerfor a user pause: "abort" and "wait" also reject -
pause_scheduler–Pause generation; behavior depends on mode.
-
process_input_sockets–Input socket IO thread.
-
process_output_sockets–Output socket IO thread.
-
run_busy_loop–Core busy loop of the EngineCore.
-
run_engine_core–Launch EngineCore busy loop in background process.
_config_hash()
¶
hash_config() of the initialized config, the hash part of a
frontend's system_fingerprint. Like the frontend, never fail startup
over the fingerprint.
_convert_msgspec_args(method, args)
staticmethod
¶
If a provided arg type doesn't match corresponding target method arg type, try converting to msgspec object.
_handle_client_request(request_type, request)
¶
Dispatch request from client.
_handle_inputs_while_waiting(future, stop_on_add=False)
¶
Handle new requests and aborts while waiting for a step's output.
_handle_mm_cache_miss(request, err)
¶
Return a retryable response for a P0/P1 cache-drift miss.
Surfaces every drifted hash via EngineCoreOutput.mm_cache_miss_hashes so
the frontend drops them from its sender cache and the client resends with
data (see MultiModalCacheMissError). Logged at warning, not exception,
because it is expected and self-healing.
_handle_request_preproc_error(request)
¶
Log and return a request-scoped error response for exceptions raised from the add request preprocessing in the input socket processing thread.
_pause_complete()
¶
Returns True if the pause has fully completed and the caller can
return None synchronously; False if the pause is still pending
and the caller should register an idle-state callback to finish it.
_perform_handshakes(handshake_address, identity, local_client, vllm_config, client_handshake_address)
¶
Perform startup handshakes.
For DP=1 or offline mode, this is with the colocated front-end process.
For DP>1 with internal load-balancing this is with the shared front-end process which may reside on a different node.
For DP>1 with external or hybrid load-balancing, two handshakes are performed: - With the rank 0 front-end process which retrieves the DP Coordinator ZMQ addresses and DP process group address. - With the colocated front-end process which retrieves the client input/output socket addresses. with the exception of the rank 0 and colocated engines themselves which don't require the second handshake.
Here, "front-end" process can mean the process containing the engine core client (which is the API server process in the case the API server is not scaled out), OR the launcher process running the run_multi_api_server() function in serve.py.
_process_engine_step()
¶
Called only when there are unfinished local requests.
_process_input_queue()
¶
Exits when an engine step needs to be performed.
_send_engine_dead()
¶
Send EngineDead status to the EngineCoreClient.
_send_msg_tracking_payload(socket, buffers)
staticmethod
¶
Send buffers as a zero-copy multipart message, returning a tracker
for the first frame.
Used instead of Socket.send_multipart() because we reuse the buffer
passed to MsgpackEncoder.encode_into(): send_multipart() returns a
tracker for the last frame only.
check_health_generate()
¶
Health check served by the busy loop between steps.
A busy engine adds no GPU work; an idle one runs the forward probe.
checkpoint_prepare(mode='wait')
¶
Drain with mode, then release the KV cache and what a process
checkpoint must not contain, such as communicator state. The state
becomes PREPARED once the drain completes. Repeating is a no-op.
Returns:
-
str | None–Why the engine cannot prepare, with nothing changed, or None.
checkpoint_restore()
¶
Bring back what preparing released, wake the KV cache and resume scheduling. Repeating is a no-op.
has_work()
¶
Returns true if the engine should be stepped.
is_running()
¶
Returns true if shutdown has not been requested.
pause_generation(mode='abort', clear_cache=True)
¶
pause_scheduler for a user pause: "abort" and "wait" also reject
new requests with a retryable error until resume, rather than queue
them. Other pauses (e.g. sleep) leave this policy unchanged.
"keep" also keeps the multimodal processor cache, which the requests it
keeps may still read and which does not depend on the weights.
clear_cache still clears the prefix and encoder caches.
pause_scheduler(mode='abort', clear_cache=True, reset_connector=True, reset_mm_cache=True)
¶
Pause generation; behavior depends on mode.
All pause modes queue new adds -- "abort" and "keep" skip step(); "wait" allows step() so in-flight requests can drain.
abort: Set PAUSED_NEW, abort all requests, wait for abort outputs to be sent (when running with output_queue), optionally clear caches, then complete the returned Future.wait: Set PAUSED_NEW (queue adds, keep stepping); when drained, optionally clear caches, then complete the returned Future.keep: Set PAUSED_ALL; return a Future that completes when the output queue is empty.
process_input_sockets(input_addresses, coord_input_address, identity, ready_event)
¶
Input socket IO thread.
process_output_sockets(output_paths, coord_output_path, engine_index)
¶
Output socket IO thread.
run_busy_loop()
¶
Core busy loop of the EngineCore.
run_engine_core(*args, dp_rank=0, local_dp_rank=0, **kwargs)
staticmethod
¶
Launch EngineCore busy loop in background process.