vllm.distributed.weight_transfer.base ¶
Base class for weight transfer engines.
Classes:
-
SparseWeightPatch–A sparse in-place patch for one existing parameter.
-
WeightTransferEngine–Base class for weight transfer engines that handle transport of model weights
-
WeightTransferInitInfo–Base class for backend-specific initialization info.
-
WeightTransferInitRequest–API-level weight transfer initialization request.
-
WeightTransferUpdateInfo–Base class for backend-specific weight update info.
-
WeightTransferUpdateRequest–API-level weight update request.
SparseWeightPatch dataclass ¶
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
WeightTransferInitInfo dataclass ¶
WeightTransferInitRequest dataclass ¶
WeightTransferUpdateInfo dataclass ¶
Bases: ABC
Base class for backend-specific weight update info.
Attributes:
-
num_updates_list(list[int] | None) –Number of sparse entries to receive for each parameter in
names. -
update_kind(Literal['dense', 'sparse_flat']) –Weight update format.