vllm.distributed.weight_transfer ¶
Weight transfer engines for syncing model weights from trainers to inference workers.
Modules:
-
base–Base class for weight transfer engines.
-
factory–Factory for weight transfer engines with lazy loading.
-
ipc_engine–IPC-based weight transfer engine using CUDA IPC for communication.
-
nccl_engine–NCCL-based weight transfer engine.
-
packed_tensor–Packed tensor utilities for efficient weight transfer.
Classes:
-
WeightTransferEngine–Base class for weight transfer engines that handle transport of model weights
-
WeightTransferEngineFactory–Factory for creating weight transfer engines with lazy loading.
WeightTransferEngine ¶
Bases: ABC, Generic[TInitInfo, TUpdateInfo]
Base class for weight transfer engines that handle transport of model weights from a trainer to inference workers.
This abstraction separates weight transfer transport logic from the worker implementation, allowing different backends (NCCL, CUDA IPC[TODO], RDMA[TODO]) to be plugged in.
Subclasses should define
init_info_cls: Type of backend-specific initialization info update_info_cls: Type of backend-specific update info
Methods:
-
__init__–Initialize the weight transfer engine.
-
init_transfer_engine–Initialize the weight transfer mechanism.
-
parse_init_info–Construct typed init info from dict with validation.
-
parse_update_info–Construct typed update info from dict with validation.
-
receive_sparse_weights–Receive sparse weight patches from the trainer.
-
receive_weights–Receive weights from the trainer and load them incrementally.
-
shutdown–Shutdown the weight transfer engine.
-
trainer_send_sparse_weights–Send sparse weight patches from trainer to inference workers.
-
trainer_send_weights–Send weights from trainer to inference workers.
Source code in vllm/distributed/weight_transfer/base.py
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 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 | |
__init__(config, parallel_config, model) ¶
Initialize the weight transfer engine.
Parameters:
-
(config¶WeightTransferConfig) –The configuration for the weight transfer engine
-
(parallel_config¶ParallelConfig) –The configuration for the parallel setup
-
(model¶Module) –The local model instance which will receive the weights
Source code in vllm/distributed/weight_transfer/base.py
init_transfer_engine(init_info) abstractmethod ¶
Initialize the weight transfer mechanism. This is called once at the beginning of training.
Parameters:
-
(init_info¶TInitInfo) –Backend-specific initialization info
Source code in vllm/distributed/weight_transfer/base.py
parse_init_info(init_dict) ¶
Construct typed init info from dict with validation.
Parameters:
Returns:
-
TInitInfo–Typed backend-specific init info dataclass
Raises:
-
ValueError–If init_dict is invalid for this backend
Source code in vllm/distributed/weight_transfer/base.py
parse_update_info(update_dict) ¶
Construct typed update info from dict with validation.
Parameters:
Returns:
-
TUpdateInfo–Typed backend-specific update info dataclass
Raises:
-
ValueError–If update_dict is invalid for this backend
Source code in vllm/distributed/weight_transfer/base.py
receive_sparse_weights(update_info, apply_patches) ¶
Receive sparse weight patches from the trainer.
Source code in vllm/distributed/weight_transfer/base.py
receive_weights(update_info, load_weights) abstractmethod ¶
Receive weights from the trainer and load them incrementally.
Parameters:
-
(update_info¶TUpdateInfo) –Backend-specific update info containing parameter metadata and any backend-specific data
-
(load_weights¶Callable[[list[tuple[str, Tensor]]], None]) –Callable that loads weights into the model. Called incrementally for each weight to avoid OOM.
Source code in vllm/distributed/weight_transfer/base.py
shutdown() abstractmethod ¶
Shutdown the weight transfer engine. This should be called when the worker is shutting down.
trainer_send_sparse_weights(_iterator, _trainer_args) staticmethod ¶
Send sparse weight patches from trainer to inference workers.
Source code in vllm/distributed/weight_transfer/base.py
trainer_send_weights(iterator, trainer_args) abstractmethod staticmethod ¶
Send weights from trainer to inference workers.
This is a static method that can be called from the trainer process to send weights to all inference workers.
Parameters:
-
(iterator¶Iterator[tuple[str, Tensor]]) –Iterator of model parameters. Returns (name, tensor) tuples. The tensors should be on the appropriate device for the backend.
-
(trainer_args¶dict[str, Any] | Any) –Dictionary containing backend-specific arguments needed to send weights. The structure depends on the backend: - NCCL: Contains 'group', 'src', 'packed', etc. - IPC: Contains 'mode' ('http' or 'ray'), 'llm_handle' (for Ray), 'url' (for HTTP), etc.
Example
param_iter = ((n, p) for n, p in model.named_parameters()) engine.trainer_send_weights(param_iter, trainer_args)
Source code in vllm/distributed/weight_transfer/base.py
WeightTransferEngineFactory ¶
Factory for creating weight transfer engines with lazy loading.
This factory implements a registry pattern that supports: - Lazy loading: Engine modules are only imported when actually needed - Extensibility: Custom engines can be registered at runtime - Centralized registration: All built-in engines registered in one place
Methods:
-
create_engine–Create a weight transfer engine instance.
-
register_engine–Register an engine with lazy-loading or direct class reference.
Source code in vllm/distributed/weight_transfer/factory.py
create_engine(config, parallel_config, model) classmethod ¶
Create a weight transfer engine instance.
Parameters:
-
(config¶WeightTransferConfig) –Weight transfer configuration containing the backend name
-
(parallel_config¶ParallelConfig) –Parallel configuration for the engine
-
(model¶Module) –The local model instance which will receive the weights
Returns:
-
WeightTransferEngine–An initialized weight transfer engine instance
Raises:
-
ValueError–If the backend is not registered
Source code in vllm/distributed/weight_transfer/factory.py
register_engine(name, module_path_or_cls, class_name=None) classmethod ¶
Register an engine with lazy-loading or direct class reference.
Supports two calling conventions: 1. Lazy loading: register_engine(name, module_path, class_name) 2. Direct class: register_engine(name, engine_cls)
Parameters:
-
(name¶str) –The name to register the engine under (e.g., "nccl")
-
(module_path_or_cls¶str | type[WeightTransferEngine]) –Either a module path string for lazy loading, or the engine class directly
-
(class_name¶str | None, default:None) –Name of the engine class (required if module_path is string)
Raises:
-
ValueError–If an engine with the same name is already registered