Skip to content

vllm.model_executor.offloader

Model parameter offloading infrastructure.

Modules:

  • 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.

Classes:

  • BaseOffloader –

    Base class for model parameter offloading strategies.

  • NoopOffloader –

    No-op offloader that returns modules as-is without any offloading.

  • PrefetchOffloader –

    Prefetching-based offloader with group-based layer selection.

  • UVAOffloader –

    Offloader using Unified Virtual Addressing (UVA) for zero-copy access.

Functions:

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.

Methods:

Attributes:

supports_tower_offload = False class-attribute instance-attribute

Whether wrap_modules also accepts modules routed by SupportsMultiModal._mark_tower_model, outside the make_layers call.

Offloaders whose wrap_modules may only be called on the decoder layer stack (e.g. PrefetchOffloader, which schedules prefetches over a circular layer stack) must keep this False.

_start_prefetch(layer_idx)

Start layer prefetch. Override in subclasses.

_wait_for_layer(layer_idx)

Wait for layer prefetch. Override in subclasses.

join_after_forward()

Join streams after forward. Override in subclasses.

post_init()

Called after model construction completes.

Offloaders can use this to: - Finalize parameter storage - Start initial prefetching - Allocate shared resources

sync_prev_onload()

Sync previous onload operations. Override in subclasses.

wrap_modules(modules_generator, prefix='') abstractmethod

Wrap modules with offloading logic.

Parameters:

  • modules_generator

    (Generator[Module, None, None]) –

    Generator yielding modules to potentially offload.

  • prefix

    (str, default: '' ) –

    Name prefix prepended to parameter names before matching them against the offloading parameter set. Used when the modules are not the full model, so that name segments stay fully qualified (e.g. visual for a tower module).

Returns:

  • list[Module] –

    List of modules, potentially with offloading hooks installed.

NoopOffloader

Bases: BaseOffloader

No-op offloader that returns modules as-is without any offloading.

Methods:

wrap_modules(modules_generator, prefix='')

Return modules unchanged.

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:

  • group_size

    (int) –

    Group every N layers together.

  • num_in_group

    (int) –

    Offload this many layers per group (last N of each group).

  • prefetch_step

    (int) –

    Number of layers to prefetch ahead.

  • mode

    (str, default: 'cpu' ) –

    Offload mode ("cpu" is currently supported).

Methods:

_hook_module_forward(index, module)

Hook module's forward with torch.compile-compatible sync.

_start_prefetch(layer_idx)

Called by custom op - start async copy to static buffer.

_wait_for_layer(layer_idx)

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)

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

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.

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.

wrap_modules(modules_generator, prefix='')

Wrap modules with prefetch offloading logic.

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:

  • cpu_offload_max_bytes

    (int) –

    Maximum bytes to offload to CPU.

  • cpu_offload_params

    (set[str] | None, default: None ) –

    Set of parameter name segments to selectively offload. If empty, all parameters are eligible up to the byte limit.

Methods:

  • targets –

    Whether cpu_offload_params selects the parameter param_name.

  • wrap_modules –

    Wrap modules with UVA offloading.

_maybe_offload_to_cpu(module, prefix='')

Offload module parameters to CPU using UVA if budget allows.

targets(param_name)

Whether cpu_offload_params selects the parameter param_name.

wrap_modules(modules_generator, prefix='')

Wrap modules with UVA offloading.

create_offloader(offload_config)

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.

get_offloader()

Get the global offloader instance.

set_offloader(instance)

Set or reset the global offloader instance.

should_pin_memory()

Check if pinned memory should be used for weight offloading.

Combines the platform capability check with the user override env var. On unified-memory systems (e.g. GH200) pinned memory eats into GPU memory, so users can disable it via VLLM_WEIGHT_OFFLOADING_DISABLE_PIN_MEMORY.