Skip to main content

distributed.all_reduce

distributed.all_reduce(stat, /, group=None)

Combine a statistic across the ranks of group.

Every rank gathers all statistics and folds them with + in rank order, so all ranks hold the same result: the statistic of one process over all their data, for any monoid. The rank’s own statistic enters as it is and keeps its autograd graph; the others arrive as detached copies on the same devices as the matching leaves here. A leaf this rank lacks (for example the data-fit term of a rank that saw no batches) goes to the device of the first local leaf off the CPU, or stays on the CPU.

Batch generators come from each rank’s own example count and its rank, so a sampled method on several ranks draws differently from one process over the same data.

Parameters

Name Type Description Default
stat T This rank’s statistic. required
group Any The process group. None means the default group. None

Returns

Name Type Description
T The statistic over all ranks. Without a process group, stat unchanged.