vllm.v1.engine.async_llm
¶
Classes:
-
AsyncLLM–An asynchronous wrapper for the vLLM engine.
-
InputStreamError–Wrapper for errors from the input stream generator.
AsyncLLM
¶
Bases: EngineClient
An asynchronous wrapper for the vLLM engine.
Methods:
-
__init__–Create an AsyncLLM.
-
abort–Abort RequestId in OutputProcessor and EngineCore.
-
add_lora–Load a new LoRA adapter into the engine for future requests.
-
add_request–Add new request to the AsyncLLM.
-
check_admission–Reject the request if it would exceed queue limits.
-
check_health_generate–Check that every EngineCore can run the model.
-
collective_rpc–Perform a collective RPC call to the given path.
-
encode–Main function called by the API server to kick off a request
-
finish_weight_update–Finish the weight update and set its version if provided.
-
from_engine_args–Create an AsyncLLM from the EngineArgs.
-
generate–Main function called by the API server to kick off a request
-
get_weight_version–Return the latest committed weight version.
-
handle_fault–Send fault tolerance instruction to the engine.
-
init_weight_transfer_engine–Initialize weight transfer for RL training.
-
is_paused–Return whether the engine is currently paused.
-
list_loras–List all registered adapters.
-
notify_kv_transfer_request_rejected–Submit a pre-aborted request so the connector's request_finished
-
pause_generation–Pause generation to allow model weight updates.
-
pin_lora–Prevent an adapter from being evicted.
-
remove_lora–Remove an already loaded LoRA adapter.
-
resume_generation–Resume generation after
pause_generation. -
scale_elastic_ep–Scale the elastic EP data parallel size.
-
shutdown–Shutdown, cleaning up the background proc and IPC.
-
shutdown_weight_transfer_engine–Release the trainer connection without shutting down inference.
-
start_draft_weight_update–Start a new weight update targeting the speculative draft model.
-
start_weight_update–Start a new weight update.
-
update_weight_version–Set the weight version without updating weights.
-
update_weights–Batched weight update for RL training.
-
wait_for_requests_to_drain–Wait for all requests to be drained.
__init__(vllm_config, executor_class, log_stats, usage_context=UsageContext.ENGINE_CONTEXT, mm_registry=MULTIMODAL_REGISTRY, log_requests=True, start_engine_loop=True, stat_loggers=None, aggregate_engine_logging=False, client_addresses=None, client_count=1, client_index=0, profiler=None)
¶
Create an AsyncLLM.
Parameters:
-
(vllm_config¶VllmConfig) –global configuration.
-
(executor_class¶type[Executor]) –an Executor impl, e.g. MultiprocExecutor.
-
(log_stats¶bool) –Whether to log stats.
-
(usage_context¶UsageContext, default:ENGINE_CONTEXT) –Usage context of the LLM.
-
(mm_registry¶MultiModalRegistry, default:MULTIMODAL_REGISTRY) –Multi-modal registry.
-
(log_requests¶bool, default:True) –Whether to log requests.
-
(start_engine_loop¶bool, default:True) –Whether to start the engine loop.
-
(client_addresses¶dict[str, Any] | None, default:None) –ZMQ addresses of an externally launched engine, when not launching one in-process.
-
(client_count¶int, default:1) –Number of API-server clients sharing the engine.
-
(client_index¶int, default:0) –Index of this client within
client_count. -
(aggregate_engine_logging¶bool, default:False) –Whether to aggregate per-engine logs into a single stat logger.
-
(stat_loggers¶list[StatLoggerFactory] | None, default:None) –customized stat loggers for the engine. If not provided, default stat loggers will be used. PLEASE BE AWARE THAT STAT LOGGER IS NOT STABLE IN V1, AND ITS BASE CLASS INTERFACE MIGHT CHANGE.
-
(profiler¶TorchProfilerWrapper | None, default:None) –Torch profiler wrapper used to trace the frontend.
Returns:
-
None–None
_health_probe_task(engine_rank)
¶
Concurrent /health_generate callers share one in-flight probe per
engine.
_record_admission_rejection(reason)
¶
Increment the frontend admission rejection counter if logging is on.
_run_output_handler()
¶
Background loop: pulls from EngineCore and pushes to AsyncStreams.
abort(request_id, internal=False)
async
¶
Abort RequestId in OutputProcessor and EngineCore.
add_lora(lora_request)
async
¶
Load a new LoRA adapter into the engine for future requests.
add_request(request_id, prompt, params, arrival_time=None, lora_request=None, tokenization_kwargs=None, trace_headers=None, priority=0, data_parallel_rank=None, session_id=None, prompt_text=None, reasoning_ended=None, reasoning_parser_kwargs=None, kv_hints=None)
async
¶
Add new request to the AsyncLLM.
check_admission(n=1, request_id=None)
¶
Reject the request if it would exceed queue limits.
Both limits return HTTP 503 (Service Unavailable) so that load balancers and client SDKs retry on a different instance.
max_num_queued_reqs: approximate global cap on the number of unfinished requests (waiting + running). A request withn > 1counts asnslots.max_num_queued_tokens: TTFT QoS — cap on the total prompt tokens of requests still in prefill.
Note: get_num_queued_tokens uses prompt_len for all prefilling requests.
Chunked prefill progress and prefix-cache hits are not subtracted because the
scheduler's num_computed_tokens and num_cached_tokens are only
propagated to the API server after prefill completes. The overestimation is
conservative — earlier rejection, preserving TTFT targets.
Parameters:
-
(n¶int, default:1) –Number of sequences the request will occupy.
-
(request_id¶str | None, default:None) –Request id, used for logging only.
Raises:
-
EngineFaultedError–If the engine has faulted and is awaiting FT recovery.
-
QueueOverflowError–If
max_num_queued_reqswould be exceeded. -
MaxQueuedTokensError–If
max_num_queued_tokenswould be exceeded.
check_health_generate(timeout_s)
async
¶
Check that every EngineCore can run the model.
Each EngineCore reports whether it is sleeping or busy; an idle one runs a forward probe.
Parameters:
Raises:
-
EngineDeadError–If the EngineCore is dead.
-
EngineUnhealthyError–If the engine is not ready.
reasonanddetailsdescribe why.
collective_rpc(method, timeout=None, args=(), kwargs=None)
async
¶
Perform a collective RPC call to the given path.
encode(prompt, pooling_params, request_id, lora_request=None, trace_headers=None, priority=0, tokenization_kwargs=None, reasoning_ended=None)
async
¶
Main function called by the API server to kick off a request * 1) Making an AsyncStream corresponding to the Request. * 2) Processing the Input. * 3) Adding the Request to the EngineCore (separate process).
A separate output_handler loop runs in a background AsyncIO task, pulling outputs from EngineCore and putting them into the per-request AsyncStream.
The caller of generate() iterates the returned AsyncGenerator, returning the RequestOutput back to the caller.
finish_weight_update(weight_version=None)
async
¶
Finish the weight update and set its version if provided.
from_engine_args(engine_args, start_engine_loop=True, usage_context=UsageContext.ENGINE_CONTEXT, stat_loggers=None)
classmethod
¶
Create an AsyncLLM from the EngineArgs.
generate(prompt, sampling_params, request_id, *, prompt_text=None, lora_request=None, tokenization_kwargs=None, trace_headers=None, priority=0, data_parallel_rank=None, session_id=None, kv_hints=None, reasoning_ended=None, reasoning_parser_kwargs=None)
async
¶
Main function called by the API server to kick off a request * 1) Making an AsyncStream corresponding to the Request. * 2) Processing the Input. * 3) Adding the Request to the Detokenizer. * 4) Adding the Request to the EngineCore (separate process).
A separate output_handler loop runs in a background AsyncIO task, pulling outputs from EngineCore and putting them into the per-request AsyncStream.
The caller of generate() iterates the returned AsyncGenerator, returning the RequestOutput back to the caller.
Note
Passing a raw prompt string directly to this method is deprecated. Advanced power-users can manually bypass the raw-prompt fallback path using the Engine's underlying Renderer pipeline:
from vllm.inputs import parse_model_prompt parsed = parse_model_prompt(self.model_config, "Prompt text") params = self.renderer.default_cmpl_tok_params (engine_input,) = self.renderer.render_cmpl([parsed], params) gen = self.generate(engine_input, sampling_params, request_id)
get_weight_version()
async
¶
Return the latest committed weight version.
handle_fault(fault_tolerance_request)
async
¶
Send fault tolerance instruction to the engine.
init_weight_transfer_engine(request)
async
¶
Initialize weight transfer for RL training.
Parameters:
-
(request¶WeightTransferInitRequest) –Weight transfer initialization request with backend-specific info
is_paused()
async
¶
Return whether the engine is currently paused.
list_loras()
async
¶
List all registered adapters.
notify_kv_transfer_request_rejected(request_id, kv_transfer_params, *, data_parallel_rank=None)
async
¶
Submit a pre-aborted request so the connector's request_finished hook runs to free any pre-admission KV-transfer resources (e.g. NIXL prefill blocks pinned on the P node).
pause_generation(*, mode='abort', clear_cache=True)
async
¶
Pause generation to allow model weight updates.
Mode handling (abort / wait / keep) and cache clearing are done in
the engine, apart from the frontend multimodal processor cache. In
abort and wait mode, new requests are rejected
with RetryableRequestError from when the pause starts until
resume_generation; keep accepts and queues them.
Parameters:
-
(mode¶PauseMode, default:'abort') –How to handle in-flight requests: -
"abort": Abort all in-flight requests immediately (default). -"wait": Wait for in-flight requests to complete. -"keep": Freeze requests in queue; they resume onresume_generation. -
(clear_cache¶bool, default:True) –Whether to clear KV cache and prefix cache after draining. Set to
Falseto preserve cache for faster resume. Withmode="keep",clear_cache=Truepreempts the running requests, which are recomputed on resume, andclear_cache=Falseleaves them in place. Either way the multimodal processor cache is kept for the requests still queued.
pin_lora(lora_id)
async
¶
Prevent an adapter from being evicted.
remove_lora(lora_id)
async
¶
Remove an already loaded LoRA adapter.
resume_generation()
async
¶
Resume generation after pause_generation.
scale_elastic_ep(new_data_parallel_size, drain_timeout=300)
async
¶
Scale the elastic EP data parallel size.
shutdown(timeout=None)
¶
Shutdown, cleaning up the background proc and IPC.
shutdown_weight_transfer_engine()
async
¶
Release the trainer connection without shutting down inference.
start_draft_weight_update()
async
¶
Start a new weight update targeting the speculative draft model.
start_weight_update()
async
¶
Start a new weight update.
update_weight_version(new_version)
async
¶
Set the weight version without updating weights.
update_weights(request)
async
¶
Batched weight update for RL training.
Parameters:
-
(request¶WeightTransferUpdateRequest) –Weight update request with backend-specific update info
wait_for_requests_to_drain(drain_timeout=300)
async
¶
Wait for all requests to be drained.