Expand description
Distributed groups and collective operations, as MLX’s mx.distributed.
A Group is a set of processes with a rank and a size. Collectives (all_sum,
all_max, all_min, all_gather, sum_scatter, send, recv) are lazy array
operations over a group: they run when their result is evaluated, compose with grad,
vmap and compile as MLX defines, and run on the CPU over the arrays’ shared memory.
On a GPU stream they run on the group’s worker thread once the GPU work producing their
inputs completes, and the GPU work reading their outputs is committed once they are done,
so neither the evaluating thread nor the GPU waits for the network. Without a configured group, the default group
has size 1 and every collective is the identity, so single-process code runs unchanged.
The transport is a Communicator; nuvec-distributed provides MLX’s TCP ring and
JACCL backends and installs one as the default group.
Structs§
- Group
- A group of processes (MLX’s
Group): cheap to clone.
Enums§
- AllReduce
- The reduction of
Communicator::all_reduce. - Collective
Op - A collective operation’s kind, with its parameters (
Primitive::Collective).
Traits§
- Communicator
- The transport of a
Group: every rank of the group calls the same operations in the same order. Buffers are row-contiguous elements; a failure names the peer.
Functions§
- all_
gather - Every rank’s
xconcatenated along the first axis in rank order (a scalar gathers to a vector), as MLX’sall_gather. - all_max
- The element-wise maximum of
xover the ranks ofgroup(MLX’sall_max). - all_min
- The element-wise minimum of
xover the ranks ofgroup(MLX’sall_min). - all_sum
- The element-wise sum of
xover the ranks ofgroup(the default group ifNone), as MLX’sall_sum: every rank gets the same bits. - default_
group - The default group: the one set by
set_default_group, else this process alone. - recv
- An array of
shapeanddtypereceived from ranksrcofgroup, as MLX’srecv. A sender’s other dtype or shape is an error when it is evaluated. - recv_
like recvofx’s shape and dtype (MLX’srecv_like).- send
- Sends
xto rankdstofgroupwhen the result (which isx) is evaluated, as MLX’ssend. MLX’s ring backend sends to its neighbours only. - set_
default_ group - Makes
groupthe default group of the collectives (whatnuvec-distributed’sinitdoes). - sum_
gradients xunchanged, whose gradient is summed overgroup(MLX’ssum_gradients): the input of a layer whose output is sharded across the group, so each rank’s gradient covers every rank’s slice of the output.- sum_
scatter - Rank
rgets the sum overgroupof every rank’s rowsr·k..(r+1)·kofx, whose first axis issize·k, as MLX’ssum_scatter(the reduce-scatter half of an all-reduce). A group of size 1 returnsx.