One of the unique things about Horovod is its ability to interleave communication and computation coupled with the ability to batch small allreduce operations, which results in improved performance. We call this batching feature Tensor Fusion.
Tensor Fusion works by attempting to combine all the tensors that are ready to be reduced at given moment of time into one reduction operation. The algorithm of Tensor Fusion is as follows:
- Determine which tensors are ready to be reduced. Select first few tensors that fit in
HOROVOD_FUSION_THRESHOLDbytes and have the same data type.
- Allocate fusion buffer of size
HOROVOD_FUSION_THRESHOLDif it was not allocated before. Default fusion buffer size is 64 MB.
- Copy data of selected tensors into the fusion buffer.
- Execute the allreduce operation on the fusion buffer.
- Copy data from the fusion buffer into the output tensors.
- Repeat until there are no more tensors to reduce in this cycle.
The fusion buffer size can be tweaked using the
HOROVOD_FUSION_THRESHOLD environment variable:
$ HOROVOD_FUSION_THRESHOLD=33554432 horovodrun -np 4 python train.py
HOROVOD_FUSION_THRESHOLD environment variable to zero disables Tensor Fusion:
$ HOROVOD_FUSION_THRESHOLD=0 horovodrun -np 4 python train.py
You can tweak time between cycles (defined in milliseconds) using the
HOROVOD_CYCLE_TIME environment variable:
$ HOROVOD_CYCLE_TIME=3.5 horovodrun -np 4 python train.py