vllm.distributed.weight_transfer.nccl_engine ¶
NCCL-based weight transfer engine.
NCCLWeightTransferEngine ¶
Bases: WeightTransferEngine[NCCLWeightTransferInitInfo, NCCLWeightTransferUpdateInfo]
Weight transfer engine using NCCL for communication between trainer and workers.
This implementation uses NCCL broadcast operations to transfer weights from the trainer (rank 0) to all inference workers in a process group.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
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 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
__init__ ¶
__init__(
config: WeightTransferConfig,
parallel_config: ParallelConfig,
) -> None
Initialize the NCCL weight transfer engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | WeightTransferConfig | The configuration for the weight transfer engine | required |
parallel_config | ParallelConfig | The configuration for the parallel setup | required |
Source code in vllm/distributed/weight_transfer/nccl_engine.py
_stateless_init_process_group staticmethod ¶
vLLM provides StatelessProcessGroup to create a process group without considering the global process group in torch.distributed. It is recommended to create StatelessProcessGroup, and then initialize the data-plane communication (NCCL) between external (train processes) and vLLM workers.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
init_transfer_engine ¶
init_transfer_engine(
init_info: NCCLWeightTransferInitInfo,
) -> None
Initialize NCCL process group with the trainer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_info | NCCLWeightTransferInitInfo | NCCL initialization info containing master address, port, rank offset, and world size | required |
Source code in vllm/distributed/weight_transfer/nccl_engine.py
receive_weights ¶
receive_weights(
update_info: NCCLWeightTransferUpdateInfo,
load_weights: Callable[
[list[tuple[str, Tensor]]], None
],
) -> None
Receive weights from trainer via NCCL broadcast and load them incrementally.
If update_info.packed is True, uses packed tensor broadcasting for efficient transfer of multiple weights in batches. Otherwise, uses simple one-by-one broadcasting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
update_info | NCCLWeightTransferUpdateInfo | NCCL update info containing parameter names, dtypes, shapes, and packed flag | required |
load_weights | Callable[[list[tuple[str, Tensor]]], None] | Callable that loads weights into the model. Called incrementally for each batch of weights to avoid OOM. | required |
Source code in vllm/distributed/weight_transfer/nccl_engine.py
trainer_init staticmethod ¶
trainer_init(
init_info: NCCLWeightTransferInitInfo | dict,
) -> PyNcclCommunicator
Initialize NCCL process group for trainer-side weight transfer.
The trainer is always rank 0 in the process group. Uses the current CUDA device (torch.cuda.current_device()).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
init_info | NCCLWeightTransferInitInfo | dict | Either an NCCLWeightTransferInitInfo object or a dict with keys: - master_address: str - master_port: int - world_size: int | required |
Returns:
| Type | Description |
|---|---|
PyNcclCommunicator | PyNcclCommunicator for weight transfer. |
Example
from vllm.distributed.weight_transfer.nccl_engine import ( ... NCCLWeightTransferEngine, ... ) group = NCCLWeightTransferEngine.trainer_init( ... dict( ... master_address=master_address, ... master_port=master_port, ... world_size=world_size, ... ), ... )
Source code in vllm/distributed/weight_transfer/nccl_engine.py
trainer_send_weights staticmethod ¶
trainer_send_weights(
iterator: Iterator[tuple[str, Tensor]],
group: Any,
src: int = 0,
post_iter_func: Callable[[tuple[str, Tensor]], Tensor]
| None = None,
packed: bool = False,
stream: Stream | None = None,
packed_buffer_size_bytes: int = DEFAULT_PACKED_BUFFER_SIZE_BYTES,
packed_num_buffers: int = DEFAULT_PACKED_NUM_BUFFERS,
) -> None
Broadcast weights from trainer to vLLM workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iterator | Iterator[tuple[str, Tensor]] | Iterator of model parameters. Returns (name, tensor) tuples | required |
group | Any | Process group (PyNcclCommunicator) | required |
src | int | Source rank (default 0, trainer is typically rank 0) | 0 |
post_iter_func | Callable[[tuple[str, Tensor]], Tensor] | None | Optional function to apply to each (name, tensor) pair before broadcasting. If None, extracts just the tensor. | None |
packed | bool | Whether to use packed tensor broadcasting for efficiency. When True, multiple tensors are batched together before broadcasting to reduce NCCL communication overhead. | False |
stream | Stream | None | CUDA stream to use for broadcasting if packed is False. If packed is True, new streams will be created for each buffer. | None |
packed_buffer_size_bytes | int | Size in bytes for each packed tensor buffer. Must match the value used in NCCLWeightTransferUpdateInfo. | DEFAULT_PACKED_BUFFER_SIZE_BYTES |
packed_num_buffers | int | Number of buffers for double/triple buffering. Must match the value used in NCCLWeightTransferUpdateInfo. | DEFAULT_PACKED_NUM_BUFFERS |
Example
from vllm.distributed.weight_transfer.nccl_engine import ( ... NCCLWeightTransferEngine, ... ) param_iter = ((n, p) for n, p in model.named_parameters()) NCCLWeightTransferEngine.trainer_send_weights( ... param_iter, group, packed=True ... )
Source code in vllm/distributed/weight_transfer/nccl_engine.py
NCCLWeightTransferInitInfo dataclass ¶
Bases: WeightTransferInitInfo
Initialization info for NCCL weight transfer backend.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
NCCLWeightTransferUpdateInfo dataclass ¶
Bases: WeightTransferUpdateInfo
Update info for NCCL weight transfer backend.
Source code in vllm/distributed/weight_transfer/nccl_engine.py
packed class-attribute instance-attribute ¶
packed: bool = False
Whether to use packed tensor broadcasting for efficiency. When True, multiple tensors are batched together before broadcasting to reduce NCCL communication overhead.
packed_buffer_size_bytes class-attribute instance-attribute ¶
packed_buffer_size_bytes: int = (
DEFAULT_PACKED_BUFFER_SIZE_BYTES
)
Size in bytes for each packed tensor buffer. Default is 1GB. Both producer and consumer must use the same value.
packed_num_buffers class-attribute instance-attribute ¶
packed_num_buffers: int = DEFAULT_PACKED_NUM_BUFFERS
Number of buffers for double/triple buffering during packed transfer. Both producer and consumer must use the same value.
__post_init__ ¶
Validate that all lists have the same length.