vllm.distributed.weight_transfer.m2n_engine
¶
Inference-side weight transfer engine built on NCCL M2N (nccl_m2n).
The trainer and the inference workers share one NCCL communicator: trainer ranks
occupy [0, T), workers [T, T + N). Each parameter is moved with a single
nccl.m2n.reshard, which redistributes it from the trainer's layout (FSDP / EP
/ arbitrary DTensor sharding) to the inference layout — so the trainer sends its
local shards and never all-gathers a full tensor, which is what the broadcast
NCCL backend forces it to do.
When an incoming checkpoint parameter maps directly to a live vLLM parameter,
M2N reshards into that worker's local model storage. Parameters whose names or
layouts cannot be resolved receive a full tensor and fall back to
load_weights, preserving the existing backend's loading behavior.
Both meshes participate in every reshard, in the same order, so this backend has
the same concurrency shape as the broadcast NCCL backend: the worker must be
inside receive_weights while the trainer is sending. Driving that from the
trainer is the trainer engine's job.
Classes:
-
M2NWeightTransferEngine–Inference-side engine: receives each parameter with one reshard.
-
M2NWeightTransferInitInfo–Worker-side init info: the rendezvous plus the full transfer plan.
-
M2NWeightTransferUpdateInfo–Per-round update info: which parameters this chunk carries, in order.
M2NWeightTransferEngine
¶
Bases: WeightTransferEngine[M2NWeightTransferInitInfo, M2NWeightTransferUpdateInfo]
Inference-side engine: receives each parameter with one reshard.
Resolvable parameters are resharded from the trainer layout directly into
each worker's live local model storage. Unresolvable parameters receive a
full tensor and use load_weights. In both cases, the trainer sends its
local shards without materializing a full tensor.
Methods:
-
finish_weight_update–Finalize layerwise reloading when the plan uses fallback entries.
-
init_transfer_engine–Join the trainer's communicator and rebuild the transfer plan.
-
receive_weights–Receive each requested parameter using its initialization-time plan.
-
shutdown–Finish pending GPU work and release M2N communication state.
-
start_weight_update–Set up layerwise reloading, but only if some parameter needs it.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
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 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
_reshard(comm, stream, src_meta, dst_placements, dst_buffer)
¶
Reshard one parameter from its trainer layout into a worker buffer.
dst_placements describes the buffer's logical placement over the
worker mesh; dst_buffer is this rank's physical storage.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
finish_weight_update()
¶
Finalize layerwise reloading when the plan uses fallback entries.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
init_transfer_engine(init_info)
¶
Join the trainer's communicator and rebuild the transfer plan.
Every precondition (dtype, tensor rank, divisibility) is checked here so a bad plan fails the init RPC instead of hanging the first collective.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
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 316 317 318 319 320 321 322 323 324 325 326 327 | |
receive_weights(update_info)
¶
Receive each requested parameter using its initialization-time plan.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
shutdown()
¶
Finish pending GPU work and release M2N communication state.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
start_weight_update()
¶
Set up layerwise reloading, but only if some parameter needs it.
Directly-resharded parameters are written in place and never go through
load_weights, so a plan with no fallback entries has nothing to
reload.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
M2NWeightTransferInitInfo
dataclass
¶
Bases: WeightTransferInitInfo
Worker-side init info: the rendezvous plus the full transfer plan.
Layouts are static for the whole run, so they ride the one-time init handshake and the per-round update info stays a list of names. Everything is plain JSON so the HTTP control plane carries it unchanged.
Attributes:
-
dst_mesh_dims(list[int]) –The inference mesh, starting at
rank_offset. Declared rather than -
rank_offset(int) –First worker rank, i.e. the number of trainer ranks.
-
src_mesh_dims(list[int]) –The trainer's mesh, shared by every parameter (
start_rankis 0: the -
src_placements(list[list[int] | None]) –Per parameter, relative to
src_mesh_dims;Nonemeans replicated. -
world_size(int) –Trainer ranks + all inference workers.
Source code in vllm/distributed/weight_transfer/m2n_engine.py
dst_mesh_dims
instance-attribute
¶
The inference mesh, starting at rank_offset. Declared rather than
derived so both sides describe the destination identically.
rank_offset
instance-attribute
¶
First worker rank, i.e. the number of trainer ranks.
src_mesh_dims
instance-attribute
¶
The trainer's mesh, shared by every parameter (start_rank is 0: the
trainer occupies the front of the communicator).
src_placements
instance-attribute
¶
Per parameter, relative to src_mesh_dims; None means replicated.
world_size
instance-attribute
¶
Trainer ranks + all inference workers.
M2NWeightTransferUpdateInfo
dataclass
¶
Bases: WeightTransferUpdateInfo
Per-round update info: which parameters this chunk carries, in order.
Shapes, dtypes and layouts were fixed at init, so a round only needs to say what is coming and in what order — both sides must issue their reshards in exactly that order.