vllm.model_executor.model_loader
¶
Modules:
-
base_loader– -
checkpoint_weight_patch–Apply dense or sparse weight updates in checkpoint coordinates.
-
default_loader– -
dummy_loader– -
ep_weight_filter–Filter out non-local expert weights during loading to avoid redundant I/O.
-
modelexpress_loader– -
reload–Layerwise weight reloading utilities for vLLM.
-
runai_streamer_loader– -
sharded_state_loader– -
tensorizer– -
tensorizer_loader– -
utils–Utilities for selecting and loading models.
-
weight_cache– -
weight_checksum–Per-parameter weight digests and reset, for verifying weight updates.
-
weight_tying–Reconcile word embedding tying with what the checkpoint actually contains.
-
weight_utils–Utilities for downloading and initializing model weights.
Classes:
-
BaseModelLoader–Base class for model loaders.
-
DefaultModelLoader–Model loader that can load different file types from disk.
-
DummyModelLoader–Model loader that will set model weights to random values.
-
IpcModelLoader–Zero-copy loads a model using the weight cache daemon's sharing backend.
-
ModelExpressModelLoader–Thin vLLM loader wrapper for ModelExpress.
-
RunaiModelStreamerLoader–Model loader that can load safetensors
-
ShardedStateLoader–Model loader that directly loads each worker's model state dict, which
-
TensorizerLoader–Model loader using CoreWeave's tensorizer library.
Functions:
-
bind_model_loader–Record
loaderas the loader that loadedmodel. -
get_model_loader–Get a model loader based on the load format.
-
get_model_loader_cls–Get the model loader class for the load format.
-
register_model_loader–Register a customized vllm model loader.
BaseModelLoader
¶
Bases: ABC
Base class for model loaders.
Methods:
-
create_model–Create a model with the given configurations.
-
download_model–Download a model so that it can be immediately loaded.
-
get_all_weights–Iterate over all weights by checkpoint name, for filtered
-
get_external_weight_memory–Get weights memory from external process;
-
load_model–Load a model with the given configurations.
-
load_weights–Load weights into a model. This standalone API allows
-
on_sleep–Called before
Worker.sleep(level)frees the GPU memory holding -
on_wake_up–Called after
Worker.wake_up(tags)returns. -
reload_model–Reload
model's weights in place from this loader's source.
create_model(vllm_config, model_config, prefix='')
¶
Create a model with the given configurations.
download_model(model_config)
abstractmethod
¶
Download a model so that it can be immediately loaded.
get_all_weights(model_config, model)
¶
Iterate over all weights by checkpoint name, for filtered partial reloads (e.g. FT expert reload after scale_down).
get_external_weight_memory(vllm_config)
¶
Get weights memory from external process; 0 when the weights are not external.
load_model(vllm_config, model_config, prefix='')
¶
Load a model with the given configurations.
load_weights(model, model_config)
abstractmethod
¶
Load weights into a model. This standalone API allows inplace weights loading for an already-initialized model
on_sleep(level)
¶
Called before Worker.sleep(level) frees the GPU memory holding
the weights of the model this loader loaded.
No-op by default. Override to release or pause any external state that depends on that memory remaining valid before it becomes invalid.
on_wake_up(tags)
¶
Called after Worker.wake_up(tags) returns.
No-op by default. Override to resume whatever on_sleep paused.
tags is the same argument wake_up was called with; the weights
are woken only when it is None or includes "weights". Once woken
after a level-1 sleep, the weights are valid here. After a level-2
sleep they are not: they only become valid once the reload_model
call that follows has completed.
reload_model(vllm_config, model_config, model, *, is_checkpoint_format=True)
¶
Reload model's weights in place from this loader's source.
Used by reload_weights() when no weights are provided. After a
level-2 sleep this is the point where weights become valid again.
The default streams get_all_weights() through the generic in-place
reload. Loaders that write final weights into the model themselves
override it; the instance that loaded model is then reused, so
state it keeps across on_sleep/on_wake_up sees the reload.
DefaultModelLoader
¶
Bases: BaseModelLoader
Model loader that can load different file types from disk.
Classes:
-
Source–A source for weights.
Source
dataclass
¶
A source for weights.
Attributes:
-
allow_patterns_overrides(list[str] | None) –If defined, weights will load exclusively using these patterns.
-
fall_back_to_pt(bool) –Whether .pt weights can be used.
-
is_unused_weight(Callable[[str], bool] | None) –If defined, safetensors shards holding only weights whose checkpoint
-
model_or_path(str) –The model ID or path.
-
prefix(str) –A prefix to prepend to all weights.
-
revision(str | None) –The optional model revision.
-
subfolder(str | None) –The subfolder inside the model repo.
allow_patterns_overrides = None
class-attribute
instance-attribute
¶
If defined, weights will load exclusively using these patterns.
fall_back_to_pt = True
class-attribute
instance-attribute
¶
Whether .pt weights can be used.
is_unused_weight = None
class-attribute
instance-attribute
¶
If defined, safetensors shards holding only weights whose checkpoint name (before prefix) it accepts are not read.
model_or_path
instance-attribute
¶
The model ID or path.
prefix = ''
class-attribute
instance-attribute
¶
A prefix to prepend to all weights.
revision
instance-attribute
¶
The optional model revision.
subfolder = None
class-attribute
instance-attribute
¶
The subfolder inside the model repo.
_get_weights_iterator(source)
¶
Get an iterator for the model weights based on the load format.
_init_ep_weight_filter(model, model_config)
¶
Compute local expert ids for EP weight filtering.
When expert parallelism is active, each rank only needs a subset of expert weights. By computing the set upfront we can skip non-local expert tensors before reading them from disk.
_init_mm_encoder_only_weight_filter(model, model_config)
¶
Skip pure language-model safetensors shards under --mm-encoder-only.
_prepare_weights(model_name_or_path, subfolder, revision, fall_back_to_pt, allow_patterns_overrides)
¶
Prepare weights for the model.
If the model is not local, it will be downloaded.
DummyModelLoader
¶
Bases: BaseModelLoader
Model loader that will set model weights to random values.
_process_online_quant_layer(layer, info)
¶
Materialize, apply dummy weights, and run quantization processing.
IpcModelLoader
¶
Bases: BaseModelLoader
Zero-copy loads a model using the weight cache daemon's sharing backend.
The model is initialized on the meta device and receives the daemon's post-processed tensors. Post-load hooks can recreate process-local state such as accelerator views over shared pinned CPU weights.
Extra config keys (via --model-loader-extra-config):
- socket_path: explicit daemon socket path. Defaults to a per-GPU path derived from the physical GPU uuid and the cache role (target/draft).
- socket_dir: directory containing the daemon sockets.
- fallback: fall back to disk loading when fetching state fails because the daemon is unavailable or the fingerprints mismatch (default: True).
- connect_timeout_s: socket connect timeout (default: 5.0).
- state_timeout_s: timeout for the weight-transfer request (default: 300.0).
The weights live in externally held backend allocations, so sleep mode (CuMemAllocator weight offloading) must not be used with this loader. If the daemon exits, the CUDA driver keeps the mapped weights alive until the engine exits, so the engine keeps serving; the loader watches the daemon and warns since a restarted daemon then holds a second copy of the weights on the GPU.
_rebuild_storages(state)
¶
Rebuild manifest tensors from one imported buffer per storage.
_watch_daemon()
¶
Watch for the exit of the daemon serving the zero-copy weights.
The daemon holds the watch connection open for its lifetime, so the connection closes exactly when that daemon instance exits; a daemon restarted on the same socket does not mask the loss.
_with_startup_wait(op)
¶
Retry op until the daemon answers or the state timeout elapses; the daemon may still be loading the model when the engine starts.
ModelExpressModelLoader
¶
RunaiModelStreamerLoader
¶
Bases: BaseModelLoader
Model loader that can load safetensors files from local FS, S3, GCS, or Azure Blob Storage.
Methods:
-
download_model–Download model if necessary.
-
load_weights–Load weights into a model.
_get_weights_iterator(model_or_path, revision, is_unused_weight=None)
¶
Get an iterator for the model weights based on the load format.
_prepare_weights(model_name_or_path, revision)
¶
Prepare weights for the model.
If the model is not local, it will be downloaded.
download_model(model_config)
¶
Download model if necessary.
load_weights(model, model_config)
¶
Load weights into a model.
ShardedStateLoader
¶
Bases: BaseModelLoader
Model loader that directly loads each worker's model state dict, which
enables a fast load path for large tensor-parallel/pipeline-parallel models
where each worker only needs to read its own shard rather than the entire
checkpoint. See examples/features/sharded_state/save_sharded_state_offline.py
for creating a sharded checkpoint.
_filter_subtensors(tensors)
staticmethod
¶
Filter out all tensors that share the same memory or a subset of the memory of another tensor.
TensorizerLoader
¶
Bases: BaseModelLoader
Model loader using CoreWeave's tensorizer library.
Methods:
-
load_weights–Load serialized model weights with tensorizer.
load_weights(model, model_config)
¶
Load serialized model weights with tensorizer.
Expects a vLLM-tensorized model. See the examples/features/tensorize_vllm_model.py example script for serializing vLLM models.
bind_model_loader(model, loader)
¶
Record loader as the loader that loaded model.
get_model_loader(load_config)
¶
Get a model loader based on the load format.
get_model_loader_cls(load_config)
¶
Get the model loader class for the load format.
register_model_loader(load_format)
¶
Register a customized vllm model loader.
When a load format is not supported by vllm, you can register a customized model loader to support it.
Parameters:
Examples:
>>> from vllm.config.load import LoadConfig
>>> from vllm.model_executor.model_loader import (
... get_model_loader,
... register_model_loader,
... )
>>> from vllm.model_executor.model_loader.base_loader import BaseModelLoader
>>>
>>> @register_model_loader("my_loader")
... class MyModelLoader(BaseModelLoader):
... def download_model(self):
... pass
...
... def load_weights(self):
... pass
>>>
>>> load_config = LoadConfig(load_format="my_loader")
>>> type(get_model_loader(load_config))
<class 'MyModelLoader'>