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_weightsonce overTraceTensors, on -
direct–Direct weight reload (
VLLM_RELOAD_MODE=direct). -
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– -
torchao_decorator– -
trace–Tracing a model's weight loaders on zero-storage checkpoint tensors.
-
utils–
Classes:
-
LoadPlan–
Functions:
-
check_plannable–Refuse a configuration no load plan supports: a reload mode other than
-
finalize_layerwise_processing–Apply processing to any layers which were not layerwise processed during loading.
-
finish_reload–Complete the weight update
start_reloadbegan. -
initialize_layerwise_reload–Set up layerwise weight loading with deferred processing.
-
load_planned–Load full checkpoint tensors as
plansays: copy each direct name's -
plan_loads–Trace
model.load_weightsover the declared checkpoint tensors once -
record_metadata_for_reloading–Record layer metadata needed for later reloading.
-
start_reload–Begin a weight update in the configured mode.
-
support_quantized_model_reload_from_hp_weights–Decorator for
load_weightsmethod for AutoWeightsLoader.load_weights to support
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
Source code in vllm/model_executor/model_loader/reload/plan.py
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.
Source code in vllm/model_executor/model_loader/reload/plan.py
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.
load_planned copies full tensors through it; an engine that sends
only get_boxes copies its slices the same way.
Source code in vllm/model_executor/model_loader/reload/plan.py
check_plannable(model)
¶
Refuse a configuration no load plan supports: a reload mode other than
direct, and EPLB. 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:
-
RuntimeError–the configuration cannot be planned.
Source code in vllm/model_executor/model_loader/reload/plan.py
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
Source code in vllm/model_executor/model_loader/reload/layerwise.py
finish_reload(model, model_config, device)
¶
Complete the weight update start_reload began.
Source code in vllm/model_executor/model_loader/reload/lifecycle.py
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.
Source code in vllm/model_executor/model_loader/reload/layerwise.py
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.
Source code in vllm/model_executor/model_loader/reload/plan.py
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:
-
ValueError–a name is declared twice.
-
RuntimeError–the model cannot be planned.
Source code in vllm/model_executor/model_loader/reload/plan.py
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.
Source code in vllm/model_executor/model_loader/reload/layerwise.py
start_reload(model)
¶
Begin a weight update in the configured mode.
support_quantized_model_reload_from_hp_weights(original_load_weights)
¶
Decorator for load_weights method for AutoWeightsLoader.load_weights to support
reloading high precision (bfloat16/float16/float32) weight for an already quantized
model, this involves restoring the weights to a high precision weights and
then online quantize the weights.
Only applies to torchao quantized models. Assumes that all model weights are loaded within a single weights iterator (cannot perform batched updates)