vllm.distributed.weight_transfer ¶
Weight transfer engines for syncing model weights from trainers to inference workers.
Modules:
| Name | Description |
|---|---|
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_common | Shared NCCL initialization helpers for weight transfer engines. |
nccl_engine | NCCL-based (dense) weight transfer engine. |
packed_tensor | Packed tensor utilities for efficient weight transfer. |
sparse_nccl_engine | Sparse NCCL weight transfer engine. |
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, RDMA[TODO]) to be plugged in.
Each engine owns its full weight-update lifecycle: start_weight_update, update_weights, and finish_weight_update. Layerwise reloading (used by checkpoint-format engines) is opted into per engine by running it inside start_weight_update/finish_weight_update. Engines that apply weights in place (e.g. sparse patches) leave those methods as no-ops.
Session lifecycle state (whether an update is active) is tracked by the worker, not the engine, so subclasses do not need to chain to super() in their lifecycle methods.
Subclasses should define
init_info_cls: Type of backend-specific initialization info update_info_cls: Type of backend-specific update info
Source code in vllm/distributed/weight_transfer/base.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 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 242 243 | |
__init__ ¶
__init__(
config: WeightTransferConfig,
vllm_config: VllmConfig,
device: device,
model: Module,
) -> None
Initialize the weight transfer engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | WeightTransferConfig | The configuration for the weight transfer engine | required |
vllm_config | VllmConfig | The full vLLM config (provides parallel/model config and is used to set the current config when running layerwise reload) | required |
device | device | The device this worker's model lives on | required |
model | Module | The local model instance which will receive the weights | required |
Source code in vllm/distributed/weight_transfer/base.py
finish_weight_update abstractmethod ¶
Finalize the current weight update.
Checkpoint-format engines finalize layerwise reloading here; engines that apply weights in place leave this as a no-op. Must not chain to super().
Source code in vllm/distributed/weight_transfer/base.py
init_transfer_engine abstractmethod ¶
Initialize the weight transfer mechanism. This is called once at the beginning of training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_info | TInitInfo | Backend-specific initialization info | required |
Source code in vllm/distributed/weight_transfer/base.py
parse_init_info ¶
Construct typed init info from dict with validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_dict | dict[str, Any] | Dictionary containing backend-specific initialization parameters | required |
Returns:
| Type | Description |
|---|---|
TInitInfo | Typed backend-specific init info dataclass |
Raises:
| Type | Description |
|---|---|
ValueError | If init_dict is invalid for this backend |
Source code in vllm/distributed/weight_transfer/base.py
parse_update_info ¶
Construct typed update info from dict with validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_dict | dict[str, Any] | Dictionary containing backend-specific update parameters | required |
Returns:
| Type | Description |
|---|---|
TUpdateInfo | Typed backend-specific update info dataclass |
Raises:
| Type | Description |
|---|---|
ValueError | If update_dict is invalid for this backend |
Source code in vllm/distributed/weight_transfer/base.py
receive_weights abstractmethod ¶
Receive weights from the trainer and load them into the model.
Implementations should load weights incrementally (one or a few at a time) into self.model to avoid OOM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_info | TUpdateInfo | Backend-specific update info containing parameter metadata and any backend-specific data | required |
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.
start_weight_update abstractmethod ¶
Prepare the engine for a new weight update.
Checkpoint-format engines initialize layerwise reloading here; engines that apply weights in place leave this as a no-op. Must not chain to super().
Source code in vllm/distributed/weight_transfer/base.py
trainer_send_weights 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:
| Name | Type | Description | Default |
|---|---|---|---|
iterator | Iterator[Any] | Iterator of backend-specific items to send. Dense engines iterate (name, tensor) tuples; sparse engines iterate patch objects. Tensors should be on the appropriate device. | required |
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. | required |
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
update_weights ¶
Receive one weight update chunk and load it into the model.
This is stateless orchestration: parse the backend-specific update info, receive the weights, then synchronize so the new weights are visible to the next forward pass. Session-lifecycle bookkeeping is handled by the worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_info | dict[str, Any] | Dictionary containing backend-specific update info | required |
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
Source code in vllm/distributed/weight_transfer/factory.py
create_engine classmethod ¶
create_engine(
config: WeightTransferConfig,
vllm_config: VllmConfig,
device: device,
model: Module,
) -> WeightTransferEngine
Create a weight transfer engine instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | WeightTransferConfig | Weight transfer configuration containing the backend name | required |
vllm_config | VllmConfig | The full vLLM config (provides parallel/model config) | required |
device | device | The device this worker's model lives on | required |
model | Module | The local model instance which will receive the weights | required |
Returns:
| Type | Description |
|---|---|
WeightTransferEngine | An initialized weight transfer engine instance |
Raises:
| Type | Description |
|---|---|
ValueError | If the backend is not registered |
Source code in vllm/distributed/weight_transfer/factory.py
register_engine classmethod ¶
register_engine(
name: str,
module_path_or_cls: str | type[WeightTransferEngine],
class_name: str | None = None,
) -> None
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 | Type | Description | Default |
|---|---|---|---|
name | str | The name to register the engine under (e.g., "nccl") | required |
module_path_or_cls | str | type[WeightTransferEngine] | Either a module path string for lazy loading, or the engine class directly | required |
class_name | str | None | Name of the engine class (required if module_path is string) | None |
Raises:
| Type | Description |
|---|---|
ValueError | If an engine with the same name is already registered |