🤖 AI/ML

Horovod

Horovod

A distributed deep learning framework. Developed by Uber, multi-GPU training.

📖 Detailed Explanation

Horovod is an open-source distributed deep learning framework developed by Uber. It is compatible with several deep learning frameworks, including TensorFlow, PyTorch, MXNet, and Keras, and makes it easy to implement multi-GPU and multi-node training.

The name comes from the traditional Russian circle dance "khorovod (Khorovod)," in which all participants cooperate on an equal footing, which matches the philosophy of distributed training. It was first released in 2017 and is currently managed by the LF AI & Data Foundation.

The core of Horovod is the Ring-AllReduce algorithm. Compared with the traditional Parameter Server approach, it has fewer network bottlenecks and scales nearly linearly with the number of GPUs. It can achieve scaling efficiency of over 90% on 256 GPUs.

In practice, Horovod has the advantage that existing single-GPU training code can be converted to distributed training by adding just a few lines. It runs easily with the horovodrun command and supports high-speed communication between NVIDIA GPUs through the NCCL backend.

💻 Code Example

import torch
import horovod.torch as hvd

# Horovod를 사용한 PyTorch 분산 학습
def train_distributed():
    # 1. Horovod 초기화
    hvd.init()

    # 2. GPU 할당 (각 프로세스에 하나씩)
    torch.cuda.set_device(hvd.local_rank())

    # 3. 모델 생성 및 GPU 이동
    model = YourModel().cuda()

    # 4. Optimizer 생성 및 Horovod로 래핑
    optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
    optimizer = hvd.DistributedOptimizer(
        optimizer,
        named_parameters=model.named_parameters()
    )

    # 5. 초기 상태 브로드캐스트 (모든 워커 동기화)
    hvd.broadcast_parameters(model.state_dict(), root_rank=0)
    hvd.broadcast_optimizer_state(optimizer, root_rank=0)

    # 6. 학습 루프
    for epoch in range(10):
        for batch in train_loader:
            optimizer.zero_grad()
            loss = model(batch)
            loss.backward()
            optimizer.step()

        # rank 0에서만 로그 출력
        if hvd.rank() == 0:
            print(f"Epoch {epoch}, Loss: {loss.item():.4f}")

# 실행: horovodrun -np 4 -H localhost:4 python train.py
# (-np: 프로세스 수, -H: 호스트 설정)

🗣️ Say It Like This in Practice

In an ML Infrastructure Meeting

"A training job that takes 3 days on a single GPU can be cut to half a day by distributing it across 8 GPUs with Horovod. The code changes take only about 10 lines, and you can run it right away with horovodrun."

In a technical interview

"The reason Horovod's Ring-AllReduce is more efficient than the Parameter Server is that it has no communication bottleneck. With a PS, the central server becomes the bottleneck, but in a Ring, each node sends only to its neighbor, so the total communication volume is independent of the number of GPUs."

In a performance optimization discussion

"If GPU utilization is low in Horovod training, a data loading bottleneck is likely. Try increasing num_workers in the DataLoader and adjusting prefetch_factor. The NCCL communication itself is very fast."

Take a mock interview on this topic → WIA SOOM AI Interview · Start for free

⚠️ Common Mistakes & Cautions

1
Batch Size Adjustment Required

In distributed training, the effective batch size grows by a factor equal to the number of GPUs. Adjust the learning rate accordingly, or apply learning rate warmup.

2
Environment Setup Complexity

In multi-node environments, initial setup, such as SSH keys, network settings, and NCCL environment variables, is tricky. Standardize the environment with Docker or Kubernetes.

3
Consider Newer Alternatives

PyTorch DDP and DeepSpeed are under more active development. For new projects, consider these alternatives alongside Horovod.

🔗 Related Terms

📚 Learn More