vllm.v1.worker.worker_base
¶
Classes:
-
CompilationTimes– -
WorkerBase–Worker interface that allows vLLM to cleanly separate implementations for
-
WorkerWrapperBase–This class represents one process in an executor/engine. It is responsible
CompilationTimes
¶
Bases: NamedTuple
Attributes:
-
num_kv_blocks(int | None) –KV cache blocks that fit in the memory measured after warmup, reported
num_kv_blocks = None
class-attribute
instance-attribute
¶
KV cache blocks that fit in the memory measured after warmup, reported by workers with an extensible KV cache.
WorkerBase
¶
Worker interface that allows vLLM to cleanly separate implementations for different hardware. Also abstracts control plane communication, e.g., to communicate request metadata to other workers.
Methods:
-
__init__–Initialize common worker components.
-
apply_model–Apply a function on the model inside this worker.
-
check_health–Basic health check (override for device-specific checks).
-
compile_or_warm_up_model–Prepare model for execution through compilation/warmup.
-
execute_model–If this method returns None, sample_tokens should be called immediately after
-
extend_kv_cache–Commit the final size of an extensible KV cache.
-
extensible_kv_cache_unsupported_reason–Why this worker cannot back an extensible KV cache, or None.
-
get_kv_cache_layer_configs–Get specifications for KV cache implementation.
-
get_model_inspection–Return a transformers-style hierarchical view of the model.
-
get_supported_kv_cache_layouts–Layout names every attention backend supports, most preferred first.
-
has_incomplete_weight_update–Whether a weight update started and has not finished successfully,
-
init_device–Initialize device state, such as loading the model or other on-device
-
load_model–Load model onto target device.
-
next_kv_transfer_poll_time–When
poll_kv_transfers()is next due between RPCs -
notify_kv_cache_ready–Finish startup device work before notifying the worker connector.
-
poll_kv_transfers–Collect finished KV transfers for the next model output.
-
probe_forward–Readiness probe for
/health_generate: run a dummy forward pass and -
sample_tokens–Should be called immediately after execute_model iff it returned None.
-
set_kv_cache_layout–Assign the KV cache layout and CP interleave size resolved by the core.
-
set_mamba_block_size–Assign the Mamba block size resolved by the core.
-
shutdown–Clean up resources held by the worker.
-
supports_draft_weight_updates–Whether this worker can update its configured speculative model.
-
synchronize_device–Block until in-flight device work completes; backends outside
Attributes:
-
vocab_size(int) –Get vocabulary size from model configuration.
vocab_size
property
¶
Get vocabulary size from model configuration.
__init__(vllm_config, local_rank, rank, distributed_init_method, is_driver_worker=False)
¶
Initialize common worker components.
Parameters:
-
(vllm_config¶VllmConfig) –Complete vLLM configuration
-
(local_rank¶int) –Local device index
-
(rank¶int) –Global rank in distributed setup
-
(distributed_init_method¶str) –Distributed initialization method
-
(is_driver_worker¶bool, default:False) –Whether this worker handles driver responsibilities
apply_model(fn)
¶
Apply a function on the model inside this worker.
check_health()
¶
Basic health check (override for device-specific checks).
compile_or_warm_up_model()
¶
Prepare model for execution through compilation/warmup.
Returns:
-
CompilationTimes–Compilation times (language_model, encoder) in seconds, and the
-
CompilationTimes–measured KV cache size for an extensible KV cache.
execute_model(scheduler_output)
¶
If this method returns None, sample_tokens should be called immediately after to obtain the ModelRunnerOutput.
Note that this design may be changed in future if/when structured outputs parallelism is re-architected.
extend_kv_cache(num_blocks)
¶
Commit the final size of an extensible KV cache.
extensible_kv_cache_unsupported_reason()
¶
Why this worker cannot back an extensible KV cache, or None.
get_kv_cache_layer_configs()
¶
Get specifications for KV cache implementation.
get_model_inspection()
¶
Return a transformers-style hierarchical view of the model.
get_supported_kv_cache_layouts()
¶
Layout names every attention backend supports, most preferred first.
has_incomplete_weight_update()
¶
Whether a weight update started and has not finished successfully, so the model weights may be incomplete.
init_device()
¶
Initialize device state, such as loading the model or other on-device memory allocations.
load_model(*, load_dummy_weights=False)
¶
Load model onto target device.
next_kv_transfer_poll_time()
¶
When poll_kv_transfers() is next due between RPCs
(time.monotonic()), or None if it isn't needed.
notify_kv_cache_ready()
¶
Finish startup device work before notifying the worker connector.
poll_kv_transfers()
¶
Collect finished KV transfers for the next model output.
probe_forward()
¶
Readiness probe for /health_generate: run a dummy forward pass and
wait for it to complete on the device.
Returns:
sample_tokens(grammar_output)
¶
Should be called immediately after execute_model iff it returned None.
set_kv_cache_layout(kv_cache_layout, cp_kv_cache_interleave_size)
¶
Assign the KV cache layout and CP interleave size resolved by the core.
set_mamba_block_size(mamba_block_size)
¶
Assign the Mamba block size resolved by the core.
shutdown()
¶
Clean up resources held by the worker.
supports_draft_weight_updates()
¶
Whether this worker can update its configured speculative model.
synchronize_device()
¶
Block until in-flight device work completes; backends outside
torch.accelerator must override with their own wait.
WorkerWrapperBase
¶
This class represents one process in an executor/engine. It is responsible
for lazily initializing the worker and handling the worker's lifecycle.
We first instantiate the WorkerWrapper, which remembers the worker module
and class name. Then, when we call update_environment_variables, and the
real initialization happens in init_worker.
Methods:
-
__init__–Initialize the worker wrapper with the given vllm_config and rpc_rank.
-
init_worker–Here we inject some common logic before initializing the worker.
__init__(rpc_rank=0, global_rank=None)
¶
Initialize the worker wrapper with the given vllm_config and rpc_rank. Note: rpc_rank is the rank of the worker in the executor. In most cases, it is also the rank of the worker in the distributed group. However, when multiple executors work together, they can be different. e.g. in the case of SPMD-style offline inference with TP=2, users can launch 2 engines/executors, each with only 1 worker. All workers have rpc_rank=0, but they have different ranks in the TP group.
init_worker(all_kwargs)
¶
Here we inject some common logic before initializing the worker. Arguments are passed to the worker class constructor.