Skip to content

vllm.model_executor.model_loader.reload

Layerwise weight reloading utilities for vLLM.

This module provides functionality to reload model weights layer-by-layer, which is useful for weight updates without full model reconstruction.

Limitations: 1. Composition with CPU offloading has not been implemented 2. Tied parameters will only reflect processing from one of the parent layers (for example, only processing from embed_tokens will have an effect) 3. This design assumes that the number of weights loaded from disk is the same as the number of weights created at model init time. This is not true for quant methods which (1) pad weights or (2) load qkv weights into the same parameter. Both of these cases are non-issues for today's quant methods, but future quantizations may cause reloading to fail

Modules:

  • bake –

    The load plan's bake: run load_weights once over TraceTensors, on

  • direct –

    Direct weight reload (VLLM_RELOAD_MODE=direct, or auto where it applies).

  • geometry –

    Integer geometry of the load plan: one traced copy_ as a box of the

  • inplace –
  • layerwise –
  • lifecycle –

    Begin and complete a checkpoint-format weight update in the reload mode

  • meta –
  • plan –

    Load plan: which part of each checkpoint tensor this rank needs, and where

  • sanitize –
  • trace –

    Tracing a model's weight loaders on zero-storage checkpoint tensors.

  • types –
  • utils –

Classes:

Functions:

LoadPlan dataclass

Methods:

  • get_boxes –

    Parts of the checkpoint tensor this rank needs; None: nothing.

  • get_dest –

    (part of a box, live tensor) pairs: copying each part, reshaped to

get_boxes(name)

Parts of the checkpoint tensor this rank needs; None: nothing.

For engines that send or read only those slices (sharded RDT, NCCL M2N follow-ups); an engine that receives full tensors calls load_planned instead.

get_dest(name)

(part of a box, live tensor) pairs: copying each part, reshaped to its tensor's shape, into that tensor is exactly what the loader would have written. None: fallback, send the full tensor through load_weights. Write only between start_reload and finish_reload; never read. A tensor may be in another dtype than the checkpoint tensor, so write it with copy_, not as raw bytes.

load_planned copies full tensors through it; an engine that sends only get_boxes copies its slices the same way.

check_plannable(model)

Refuse a configuration no load plan supports: a reload mode other than direct, EPLB, and online quantization (its loaders quantize what they load). Reads only configuration, so an engine can call it before start_reload changes the model. Direct reload's own refusals run in begin_direct_reload.

Raises:

finalize_layerwise_processing(model, model_config)

Apply processing to any layers which were not layerwise processed during loading. This includes attention layers and layers which have weight elements which are not loaded (due to padding).

This function should be applied after initialize_layerwise_reload is applied unwrap the layerwise weight loaders.

Parameters:

  • model

    (Module) –

    model to finalize processing for

  • model_config

    (ModelConfig) –

    config needed for applying processing to attention layers

finish_reload(model, model_config, device)

Complete the weight update start_reload began.

initialize_layerwise_reload(model, *, defer_processing=False)

Set up layerwise weight loading with deferred processing.

Must be called after record_metadata_for_reloading. This function: 1. Saves current kernel tensors for later copying 2. Restores layer parameters/buffers from metadata (on meta device) 3. Wraps weight loaders to defer processing until all weights are loaded

When all weights for a layer are loaded, the wrapped loaders will: 1. Materialize the layer onto the target device 2. Load all cached weights 3. Run quantization processing if applicable 4. Copy processed values back to original tensor storage

With defer_processing=True, only finalize_layerwise_reload triggers processing.

load_planned(model, plan, weights)

Load full checkpoint tensors as plan says: copy each direct name's boxes into its destinations, skip names this rank needs nothing of, and pass fallbacks to model.load_weights. Call between start_reload and finish_reload.

Copies are batched, so each tensor weights yields must stay unchanged until this call returns: do not reuse one buffer across items.

plan_loads(model, metadata)

Trace model.load_weights over the declared checkpoint tensors once and return where each lands on this rank.

Call between start_reload and finish_reload: the plan traces the real tensors in the layout begin_direct_reload applied. Incoming tensors are data-free traces, so nothing is loaded. Loaders' constant writes land, as on the load_weights path; so do writes into non-checkpoint GPU tensors fed by a read of a checkpoint tensor (a mirror), which are not restored: that name falls back and the update rewrites them. Module, parameter and buffer state a loader sets stays, as it would after load_weights.

Raises:

record_metadata_for_reloading(model)

Record layer metadata needed for later reloading.

Stores parameter and buffer metadata as meta tensors for restoration. Must be called before initialize_layerwise_reload.

start_reload(model)

Begin a weight update in the configured mode.

weight_update_active()

Whether a weight update is running, when one load_weights call may hold only part of the checkpoint. Process-wide, so a module nested in the model passed to start_reload sees it too.