Class TensorParallelGroup
java.lang.Object
smile.llm.parallel.TensorParallelGroup
- All Implemented Interfaces:
AutoCloseable
Single-process tensor-parallel group: one
ParallelState and CUDA
device per TP rank, plus NCCL (or peer-copy fallback) collectives.
When NCCL is available, each rank calls allReduceSumInPlace(int, Tensor) on its
own tensor without a host barrier gather. The communicator is retained for
future pipeline-parallel send/recv on the same process group.
-
Constructor Summary
ConstructorsConstructorDescriptionTensorParallelGroup(ParallelConfig config) Creates a TP group for the given mesh configuration.TensorParallelGroup(ParallelConfig localConfig, int worldSize, int rankOffset, byte[] uniqueId) A group whose ranks span several processes (and nodes): this process owns the world ranksrankOffset .. rankOffset + localConfig.tpSize() - 1, one per device oflocalConfig, and joins the NCCL communicator identified byuniqueId(the same 128 bytes in every process, fromNative.ncclUniqueId()). -
Method Summary
Modifier and TypeMethodDescriptionvoidallReduceSumInPlace(int tpRank, Tensor local) In-place sum all-reduce.voidBroadcastslocals[root]to every other slot.voidclose()config()Returns the process-mesh configuration.device(int tpRank) Returns the CUDA device for a TP rank.booleanhasNccl()Returns whether NCCL backs collectives for this group.booleanisClosed()Returns whetherclose()has been called.mesh()Returns the device mesh for this group.intReturns the world rank of this process's first local rank.state(int tpRank) Returns the parallel state for a TP rank.inttpSize()Returns the tensor-parallel size.intReturns the ranks of the whole communicator (equalstpSize()unless it spans processes).
-
Constructor Details
-
TensorParallelGroup
Creates a TP group for the given mesh configuration.- Parameters:
config- process-mesh configuration (ppSizemust be 1 in phase 1).
-
TensorParallelGroup
public TensorParallelGroup(ParallelConfig localConfig, int worldSize, int rankOffset, byte[] uniqueId) A group whose ranks span several processes (and nodes): this process owns the world ranksrankOffset .. rankOffset + localConfig.tpSize() - 1, one per device oflocalConfig, and joins the NCCL communicator identified byuniqueId(the same 128 bytes in every process, fromNative.ncclUniqueId()). Construction returns once every rank of the world has joined, so all processes must construct their groups concurrently.allReduceSumInPlace(int, Tensor)takes WORLD ranks.- Parameters:
localConfig- the devices of this process (one rank each).worldSize- ranks of the whole communicator.rankOffset- world rank of this process's first rank.uniqueId- the shared NCCL unique id.
-
-
Method Details
-
worldSize
-
rankOffset
public int rankOffset()Returns the world rank of this process's first local rank.- Returns:
- world rank of this process's first local rank.
-
config
-
mesh
-
tpSize
public int tpSize()Returns the tensor-parallel size.- Returns:
- TP size.
-
hasNccl
public boolean hasNccl()Returns whether NCCL backs collectives for this group.- Returns:
truewhen an NCCL communicator was created.
-
state
Returns the parallel state for a TP rank.- Parameters:
tpRank- tensor-parallel rank.- Returns:
- per-rank state.
-
device
Returns the CUDA device for a TP rank.- Parameters:
tpRank- tensor-parallel rank.- Returns:
- device for that rank.
-
allReduceSumInPlace
In-place sum all-reduce. Every TP rank's worker thread must call this with its local tensor (same shape/dtype). No-op whentpSize == 1.- Parameters:
tpRank- calling rank.local- local tensor to reduce in place.
-
broadcast
Broadcastslocals[root]to every other slot. Caller must supply the full array (one tensor per rank) from a single coordinating thread, or use per-rank buffers that are already filled.- Parameters:
locals- one tensor per TP rank.root- source rank whose tensor is copied to the others.
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
isClosed
-