Skip to content

vllm.distributed.weight_transfer.nccl_common

Shared NCCL initialization helpers for weight transfer engines.

The dense (NCCLWeightTransferEngine) and sparse (SparseNCCLWeightTransferEngine) backends are independent engines that share only their process-group initialization. That common logic lives here so the sparse engine does not have to subclass the dense one.

Classes:

Functions:

NCCLRendezvous

Bases: Protocol

The TCP rendezvous fields used by trainer initialization helpers.

Structural so each backend can keep its own trainer init info next to its engine (dense NCCLTrainerInitInfo, SparseNCCLTrainerInitInfo) without this shared module importing either.

NCCLWeightTransferInitInfo dataclass

Bases: WeightTransferInitInfo

Worker-side initialization info for NCCL-based weight transfer backends.

Keyword-only (kw_only): adding the optional nccl_unique_id_b64 field means the rendezvous fields can no longer keep a fixed positional slot, so a stale positional call fails loudly instead of silently swapping arguments.

Provide exactly one rendezvous mode:

  • master_address + master_port -- TCPStore / StatelessProcessGroup rendezvous (requires torch on every rank, including the trainer), or
  • nccl_unique_id_b64 -- standard (RFC 4648, not URL-safe) base64 of the 128 raw bytes from ncclGetUniqueId, for torch-free trainers (e.g. JAX) that mint the unique id out of band and share it (over HTTP, etc.). Note a JAX peer must use base64.b64encode, not urlsafe_b64encode.

On the unique-id path all ranks must enter init concurrently (there is no store barrier), and every peer must honor the warm-up handshake: the worker's communicator issues a one-element all_reduce immediately after ncclCommInitRank (see PyNcclCommunicator.from_unique_id_bytes), so a foreign peer must issue a matching one-element all_reduce before any other collective or all ranks deadlock.

Attributes:

metadata = None class-attribute instance-attribute

(name, dtype name, shape) of every tensor the trainer sends; required with use_load_plan.

use_load_plan = False class-attribute instance-attribute

Dense backend only: write received tensors of the target model through a load plan built from metadata at the first weight update (see NCCLTrainerInitInfo.use_load_plan). The server must reload directly (the default with weight updates) and run without EPLB; init refuses otherwise.

_require_usable_communicator(comm)

A disabled communicator makes every broadcast a no-op (stale weights).

_worker_group_rank(rank_offset, parallel_config)

Return this worker's rank in a trainer-to-worker process group.

decode_nccl_unique_id(*, master_address, master_port, nccl_unique_id_b64, ctx)

Validate the rendezvous mode and decode a pre-shared unique id.

stateless_init_metadata_group(master_address, master_port, rank, world_size, *, listen_socket=None)

Create only the TCPStore group used for metadata agreement.

stateless_init_process_group(master_address, master_port, rank, world_size, device)

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.

trainer_init(init_info, rank=0)

Initialize NCCL process group for trainer-side weight transfer.

Uses the current CUDA device (torch.accelerator.current_device_index()).

Parameters:

  • init_info

    (NCCLRendezvous | dict) –

    Any object carrying the NCCLRendezvous fields (a trainer or worker NCCL init info), or a dict with keys: - master_address: str - master_port: int - world_size: int

  • rank

    (int, default: 0 ) –

    This trainer process's rank in the group. Trainer ranks occupy [0, num_trainer_ranks) and the workers start after them.

Returns:

uid_init_process_group(nccl_unique_id_bytes, rank, world_size, device)

Join the NCCL group from pre-shared ncclUniqueId bytes.

The torch-free rendezvous alternative to stateless_init_process_group: no TCPStore, and therefore no barrier -- every rank must enter concurrently.

worker_init_metadata_group(init_info, parallel_config)

Join the trainer-to-worker TCP metadata group without constructing NCCL.

worker_init_payload(init_info)

Serialize a worker init info for init_weight_transfer_engine, dropping the unset rendezvous field (the UID in TCP mode) so the wire payload carries only the mode actually in use. Shared by the dense and sparse trainer engines so the two cannot drift.

worker_init_process_group(init_info, parallel_config)

Create the trainer<->worker NCCL group on an inference worker.

Computes a unique rank for this worker across all data-parallel groups and joins the trainer via whichever rendezvous mode init_info carries.