vllm.model_executor.offloader ¶
Model parameter offloading infrastructure.
Modules:
| Name | Description |
|---|---|
base | Base classes for model parameter offloading. |
prefetch | Prefetch-based CPU offloading with async prefetching. |
prefetch_ops | Custom ops for prefetch offloader torch.compile + CUDA graph compatibility. |
uva | UVA-based CPU offloading using Unified Virtual Addressing. |
BaseOffloader ¶
Bases: ABC
Base class for model parameter offloading strategies.
Offloaders control how model parameters are stored and loaded during inference. Different strategies trade memory for compute/transfer time.
Source code in vllm/model_executor/offloader/base.py
join_after_forward ¶
post_init ¶
Called after model construction completes.
Offloaders can use this to: - Finalize parameter storage - Start initial prefetching - Allocate shared resources
sync_prev_onload ¶
wrap_modules abstractmethod ¶
Wrap modules with offloading logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modules_generator | Generator[Module, None, None] | Generator yielding modules to potentially offload. | required |
Returns:
| Type | Description |
|---|---|
list[Module] | List of modules, potentially with offloading hooks installed. |
Source code in vllm/model_executor/offloader/base.py
NoopOffloader ¶
Bases: BaseOffloader
No-op offloader that returns modules as-is without any offloading.
Source code in vllm/model_executor/offloader/base.py
wrap_modules ¶
PrefetchOffloader ¶
Bases: BaseOffloader
Prefetching-based offloader with group-based layer selection.
Groups layers and uses async H2D prefetch to hide transfer latency. Uses static buffers and stream synchronization for torch.compile and CUDA graph compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_size | int | Group every N layers together. | required |
num_in_group | int | Offload this many layers per group (last N of each group). | required |
prefetch_step | int | Number of layers to prefetch ahead. | required |
mode | str | Offload mode ("cpu" is currently supported). | 'cpu' |
Source code in vllm/model_executor/offloader/prefetch.py
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 173 174 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 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
_hook_module_forward ¶
Hook module's forward with torch.compile-compatible sync.
Source code in vllm/model_executor/offloader/prefetch.py
_start_prefetch ¶
_start_prefetch(layer_idx: int)
Called by custom op - start async copy to static buffer.
_wait_for_layer ¶
_wait_for_layer(layer_idx: int)
Called by custom op - wait for copy to complete.
Synchronization strategy: - During CUDA graph capture: use event-based wait (graph-compatible) - Outside capture (warmup/eager): use wait_stream (more robust)
During capture, we skip wait for pre-capture prefetches because: 1. sync_before_graph_capture() ensures pre-capture work is complete 2. We can't wait on pre-capture events during capture (isolation error)
Source code in vllm/model_executor/offloader/prefetch.py
join_after_forward ¶
Join copy_stream after model forward completes.
Call this after the model forward pass but before CUDA graph capture ends. This ensures copy_stream is rejoined for any prefetches started during the forward pass.
We join ALL layers that have _prefetch_in_capture=True, meaning their prefetch was started during capture but not yet waited on (joined). This handles both full and piecewise cudagraph modes correctly: - Full mode: joins layers 0..prefetch_step-1 (prefetched by last layers) - Piecewise mode: joins only layers prefetched by THIS subgraph's layers
Source code in vllm/model_executor/offloader/prefetch.py
post_init ¶
Allocate static buffer pool and start initial prefetches.
Note: Parameters have already been offloaded to CPU during wrap_modules() (in _CpuParamOffloader.init), so GPU memory is available for the static buffer pool.
Source code in vllm/model_executor/offloader/prefetch.py
sync_prev_onload ¶
Sync previous onload operations.
Ensures any H2D copies in flight on copy_stream complete before the compute stream continues. Call this before CUDA graph capture/replay or when synchronization is needed.
Source code in vllm/model_executor/offloader/prefetch.py
wrap_modules ¶
Wrap modules with prefetch offloading logic.
Source code in vllm/model_executor/offloader/prefetch.py
UVAOffloader ¶
Bases: BaseOffloader
Offloader using Unified Virtual Addressing (UVA) for zero-copy access.
This offloader moves parameters to pinned CPU memory and creates CUDA views using UVA. The GPU can then directly access the CPU memory without explicit transfers, at the cost of PCIe bandwidth (slower than GPU memory).
When UVA is disabled via env var, falls back to a functional_call-based approach that moves parameters on-demand.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cpu_offload_max_bytes | int | Maximum bytes to offload to CPU. | required |
cpu_offload_params | set[str] | None | Set of parameter name segments to selectively offload. If empty, all parameters are eligible up to the byte limit. | None |
Source code in vllm/model_executor/offloader/uva.py
21 22 23 24 25 26 27 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 | |
_maybe_offload_to_cpu ¶
Offload module parameters to CPU using UVA if budget allows.
Source code in vllm/model_executor/offloader/uva.py
wrap_modules ¶
Wrap modules with UVA offloading.
Source code in vllm/model_executor/offloader/uva.py
create_offloader ¶
create_offloader(
offload_config: OffloadConfig,
) -> BaseOffloader
Create an offloader based on the offload configuration.
Uses the explicit offload_backend selector. When set to "auto", selects prefetch if offload_group_size > 0, UVA if cpu_offload_gb > 0, otherwise noop.
Source code in vllm/model_executor/offloader/base.py
get_offloader ¶
get_offloader() -> BaseOffloader
set_offloader ¶
set_offloader(instance: BaseOffloader) -> None