vllm.v1.worker.worker_base ¶
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.
Source code in vllm/v1/worker/worker_base.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
__init__ ¶
__init__(
vllm_config: VllmConfig,
local_rank: int,
rank: int,
distributed_init_method: str,
is_driver_worker: bool = False,
) -> None
Initialize common worker components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vllm_config | VllmConfig | Complete vLLM configuration | required |
local_rank | int | Local device index | required |
rank | int | Global rank in distributed setup | required |
distributed_init_method | str | Distributed initialization method | required |
is_driver_worker | bool | Whether this worker handles driver responsibilities | False |
Source code in vllm/v1/worker/worker_base.py
add_lora ¶
add_lora(lora_request: LoRARequest) -> bool
apply_model ¶
check_health ¶
compile_or_warm_up_model ¶
determine_num_available_blocks ¶
Determine the number of available blocks for the GPU KV cache and swappable CPU KV cache.
The implementation may run profiling or other heuristics to determine the size of caches.
Returns a tuple[num_gpu_blocks, num_cpu_blocks], where num_gpu_blocks are blocks that are "active" on the device and can be appended to. num_cpu_blocks refers to "swapped" blocks in CPU memory and cannot be appended to.
Source code in vllm/v1/worker/worker_base.py
execute_model ¶
execute_model(
execute_model_req: Optional[ExecuteModelRequest] = None,
) -> Optional[list[SamplerOutput]]
get_cache_block_size_bytes ¶
get_cache_block_size_bytes() -> int
Return the size of a single cache block, in bytes. Used in speculative decoding.
get_kv_cache_spec ¶
get_kv_cache_spec() -> dict[str, KVCacheSpec]
init_device ¶
Initialize device state, such as loading the model or other on-device memory allocations.
initialize_cache ¶
list_loras ¶
load_model ¶
pin_lora ¶
remove_lora ¶
shutdown ¶
start_worker_execution_loop ¶
Execute model loop in parallel worker.
You can stop the loop by executing a driver worker with an empty output. See stop_remote_worker_execution_loop
for more details.
Source code in vllm/v1/worker/worker_base.py
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
.
Source code in vllm/v1/worker/worker_base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
|
__getattr__ ¶
__init__ ¶
__init__(
vllm_config: VllmConfig, rpc_rank: int = 0
) -> 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.
Source code in vllm/v1/worker/worker_base.py
adjust_rank ¶
Adjust the rpc_rank based on the given mapping. It is only used during the initialization of the executor, to adjust the rpc_rank of workers after we create all workers.
Source code in vllm/v1/worker/worker_base.py
execute_method ¶
Source code in vllm/v1/worker/worker_base.py
init_device ¶
init_worker ¶
Here we inject some common logic before initializing the worker. Arguments are passed to the worker class constructor.