horovod

2025-12-10 0 380

Horovod

Horovod is a distributed deep learning training framework for TensorFlow, Keras, PyTorch, and Apache MXNet.
The goal of Horovod is to make distributed deep learning fast and easy to use.

Horovod is hosted by the LF AI & Data Foundation (LF AI & Data). If you are a company that is deeply
committed to using open source technologies in artificial intelligence, machine, and deep learning, and want to support
the communities of open source projects in these domains, consider joining the LF AI & Data Foundation. For details
about who\’s involved and how Horovod plays a role, read the Linux Foundation announcement.

Contents

  • Documentation
  • Why Horovod?
  • Install
  • Concepts
  • Supported frameworks
  • Usage
  • Running Horovod
  • Gloo
  • mpi4py
  • Inference
  • Tensor Fusion
  • Horovod Timeline
  • Automated Performance Tuning
  • Horovod Process Sets
  • Guides
  • Troubleshooting
  • Citation
  • Publications
  • References
  • Getting Involved

Documentation

  • Latest Release
  • master

Why Horovod?

The primary motivation for this project is to make it easy to take a single-GPU training script and successfully scale
it to train across many GPUs in parallel. This has two aspects:

  1. How much modification does one have to make to a program to make it distributed, and how easy is it to run it?
  2. How much faster would it run in distributed mode?

Internally at Uber we found the MPI model to be much more straightforward and require far less code changes than previous
solutions such as Distributed TensorFlow with parameter servers. Once a training script has been written for scale with
Horovod, it can run on a single-GPU, multiple-GPUs, or even multiple hosts without any further code changes.
See the Usage section for more details.

In addition to being easy to use, Horovod is fast. Below is a chart representing the benchmark that was done on 128
servers with 4 Pascal GPUs each connected by RoCE-capable 25 Gbit/s network:

Horovod achieves 90% scaling efficiency for both Inception V3 and ResNet-101, and 68% scaling efficiency for VGG-16.
See Benchmarks to find out how to reproduce these numbers.

While installing MPI and NCCL itself may seem like an extra hassle, it only needs to be done once by the team dealing
with infrastructure, while everyone else in the company who builds the models can enjoy the simplicity of training them at
scale.

Install

To install Horovod on Linux or macOS:

  1. Install CMake
  1. If you\’ve installed TensorFlow from PyPI, make sure that g++-5 or above is installed.
    Starting with TensorFlow 2.10 a C++17-compliant compiler like g++8 or above will be required.

    If you\’ve installed PyTorch from PyPI, make sure that g++-5 or above is installed.

    If you\’ve installed either package from Conda, make sure that the gxx_linux-64 Conda package is installed.

  1. Install the horovod pip package.

    To run on CPUs:

    $ pip install horovod

    To run on GPUs with NCCL:

    $ HOROVOD_GPU_OPERATIONS=NCCL pip install horovod

For more details on installing Horovod with GPU support, read Horovod on GPU.

For the full list of Horovod installation options, read the Installation Guide.

If you want to use MPI, read Horovod with MPI.

If you want to use Conda, read Building a Conda environment with GPU support for Horovod.

If you want to use Docker, read Horovod in Docker.

To compile Horovod from source, follow the instructions in the Contributor Guide.

Concepts

Horovod core principles are based on MPI concepts such as size, rank,
local rank, allreduce, allgather, broadcast, and alltoall. See this page
for more details.

Supported frameworks

See these pages for Horovod examples and best practices:

  • Horovod with TensorFlow
  • Horovod with XLA in Tensorflow
  • Horovod with Keras
  • Horovod with PyTorch
  • Horovod with MXNet

Usage

To use Horovod, make the following additions to your program:

  1. Run hvd.init() to initialize Horovod.
  1. Pin each GPU to a single process to avoid resource contention.

    With the typical setup of one GPU per process, set this to local rank. The first process on
    the server will be allocated the first GPU, the second process will be allocated the second GPU, and so forth.

  1. Scale the learning rate by the number of workers.

    Effective batch size in synchronous distributed training is scaled by the number of workers.
    An increase in learning rate compensates for the increased batch size.

  1. Wrap the optimizer in hvd.DistributedOptimizer.

    The distributed optimizer delegates gradient computation to the original optimizer, averages gradients using allreduce or allgather, and then applies those averaged gradients.

  1. Broadcast the initial variable states from rank 0 to all other processes.

    This is necessary to ensure consistent initialization of all workers when training is started with random weights or restored from a checkpoint.

  1. Modify your code to save checkpoints only on worker 0 to prevent other workers from corrupting them.

Example using TensorFlow v1 (see the examples directory for full training examples):

import tensorflow as tf
import horovod.tensorflow as hvd


# Initialize Horovod
hvd.init()

# Pin GPU to be used to process local rank (one GPU per process)
config = tf.ConfigProto()
config.gpu_options.visible_device_list = str(hvd.local_rank())

# Build model...
loss = ...
opt = tf.train.AdagradOptimizer(0.01 * hvd.size())

# Add Horovod Distributed Optimizer
opt = hvd.DistributedOptimizer(opt)

# Add hook to broadcast variables from rank 0 to all other processes during
# initialization.
hooks = [hvd.BroadcastGlobalVariablesHook(0)]

# Make training operation
train_op = opt.minimize(loss)

# Save checkpoints only on worker 0 to prevent other workers from corrupting them.
checkpoint_dir = \'/tmp/train_logs\' if hvd.rank() == 0 else None

# The MonitoredTrainingSession takes care of session initialization,
# restoring from a checkpoint, saving to a checkpoint, and closing when done
# or an error occurs.
with tf.train.MonitoredTrainingSession(checkpoint_dir=checkpoint_dir,
                                       config=config,
                                       hooks=hooks) as mon_sess:
  while not mon_sess.should_stop():
    # Perform synchronous training.
    mon_sess.run(train_op)

Running Horovod

The example commands below show how to run distributed training.
See Run Horovod for more details, including RoCE/InfiniBand tweaks and tips for dealing with hangs.

  1. To run on a machine with 4 GPUs:

    $ horovodrun -np 4 -H localhost:4 python train.py
  2. To run on 4 machines with 4 GPUs each:

    $ horovodrun -np 16 -H server1:4,server2:4,server3:4,server4:4 python train.py
  3. To run using Open MPI without the horovodrun wrapper, see Running Horovod with Open MPI.

  4. To run in Docker, see Horovod in Docker.

  5. To run on Kubernetes, see Helm Chart, Kubeflow MPI Operator, FfDL, and Polyaxon.

  6. To run on Spark, see Horovod on Spark.

  7. To run on Ray, see Horovod on Ray.

  8. To run in Singularity, see Singularity.

  9. To run in a LSF HPC cluster (e.g. Summit), see LSF.

  10. To run on Hadoop Yarn, see TonY.

Gloo

Gloo is an open source collective communications library developed by Facebook.

Gloo comes included with Horovod, and allows users to run Horovod without requiring MPI to be installed.

For environments that have support both MPI and Gloo, you can choose to use Gloo at runtime by passing the --gloo argument to horovodrun:

$ horovodrun --gloo -np 2 python train.py

mpi4py

Horovod supports mixing and matching Horovod collectives with other MPI libraries, such as mpi4py,
provided that the MPI was built with multi-threading support.

You can check for MPI multi-threading support by querying the hvd.mpi_threads_supported() function.

import horovod.tensorflow as hvd

# Initialize Horovod
hvd.init()

# Verify that MPI multi-threading is supported.
assert hvd.mpi_threads_supported()

from mpi4py import MPI
assert hvd.size() == MPI.COMM_WORLD.Get_size()

You can also initialize Horovod with an mpi4py sub-communicator, in which case each sub-communicator
will run an independent Horovod training.

from mpi4py import MPI
import horovod.tensorflow as hvd

# Split COMM_WORLD into subcommunicators
subcomm = MPI.COMM_WORLD.Split(color=MPI.COMM_WORLD.rank % 2,
                               key=MPI.COMM_WORLD.rank)

# Initialize Horovod
hvd.init(comm=subcomm)

print(\'COMM_WORLD rank: %d, Horovod rank: %d\' % (MPI.COMM_WORLD.rank, hvd.rank()))

Inference

Learn how to optimize your model for inference and remove Horovod operations from the graph here.

Tensor Fusion

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.

See here for full details and tweaking instructions.

Horovod Timeline

Horovod has the ability to record the timeline of its activity, called Horovod Timeline.

Use Horovod timeline to analyze Horovod performance.
See here for full details and usage instructions.

Automated Performance Tuning

Selecting the right values to efficiently make use of Tensor Fusion and other advanced Horovod features can involve
a good amount of trial and error. We provide a system to automate this performance optimization process called
autotuning, which you can enable with a single command line argument to horovodrun.

See here for full details and usage instructions.

Horovod Process Sets

Horovod allows you to concurrently run distinct collective operations in different groups of processes taking part in
one distributed training. Set up hvd.process_set objects to make use of this capability.

See Process Sets for detailed instructions.

Guides

  1. Run distributed training in Microsoft Azure using Batch AI and Horovod.
  2. Distributed model training using Horovod.

Send us links to any user guides you want to publish on this site

Troubleshooting

See Troubleshooting and submit a ticket
if you can\’t find an answer.

Citation

Please cite Horovod in your publications if it helps your research:

@article{sergeev2018horovod,
  Author = {Alexander Sergeev and Mike Del Balso},
  Journal = {arXiv preprint arXiv:1802.05799},
  Title = {Horovod: fast and easy distributed deep learning in {TensorFlow}},
  Year = {2018}
}

Publications

1. Sergeev, A., Del Balso, M. (2017) Meet Horovod: Uber’s Open Source Distributed Deep Learning Framework for TensorFlow.
Retrieved from https://eng.**u*ber.com/horovod/

2. Sergeev, A. (2017) Horovod – Distributed TensorFlow Made Easy. Retrieved from
https://www.slide**sh*are.net/AlexanderSergeev4/horovod-distributed-tensorflow-made-easy

3. Sergeev, A., Del Balso, M. (2018) Horovod: fast and easy distributed deep learning in TensorFlow. Retrieved from
arXiv:1802.05799

References

The Horovod source code was based off the Baidu tensorflow-allreduce
repository written by Andrew Gibiansky and Joel Hestness. Their original work is described in the article
Bringing HPC Techniques to Deep Learning.

Getting Involved

  • Community Slack for collaboration and discussion
  • Horovod Announce for updates on the project
  • Horovod Technical-Discuss for public discussion
  • Horovod Security to report security vulnerabilities

下载源码

通过命令行克隆项目:

git clone https://github.com/horovod/horovod.git

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

申明:本文由第三方发布,内容仅代表作者观点,与本网站无关。对本文以及其中全部或者部分内容的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。本网发布或转载文章出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,也不代表本网对其真实性负责。

左子网 编程相关 horovod https://www.zuozi.net/33371.html

常见问题
  • 1、自动:拍下后,点击(下载)链接即可下载;2、手动:拍下后,联系卖家发放即可或者联系官方找开发者发货。
查看详情
  • 1、源码默认交易周期:手动发货商品为1-3天,并且用户付款金额将会进入平台担保直到交易完成或者3-7天即可发放,如遇纠纷无限期延长收款金额直至纠纷解决或者退款!;
查看详情
  • 1、描述:源码描述(含标题)与实际源码不一致的(例:货不对板); 2、演示:有演示站时,与实际源码小于95%一致的(但描述中有”不保证完全一样、有变化的可能性”类似显著声明的除外); 3、发货:不发货可无理由退款; 4、安装:免费提供安装服务的源码但卖家不履行的; 5、收费:价格虚标,额外收取其他费用的(但描述中有显著声明或双方交易前有商定的除外); 6、其他:如质量方面的硬性常规问题BUG等。 注:经核实符合上述任一,均支持退款,但卖家予以积极解决问题则除外。
查看详情
  • 1、左子会对双方交易的过程及交易商品的快照进行永久存档,以确保交易的真实、有效、安全! 2、左子无法对如“永久包更新”、“永久技术支持”等类似交易之后的商家承诺做担保,请买家自行鉴别; 3、在源码同时有网站演示与图片演示,且站演与图演不一致时,默认按图演作为纠纷评判依据(特别声明或有商定除外); 4、在没有”无任何正当退款依据”的前提下,商品写有”一旦售出,概不支持退款”等类似的声明,视为无效声明; 5、在未拍下前,双方在QQ上所商定的交易内容,亦可成为纠纷评判依据(商定与描述冲突时,商定为准); 6、因聊天记录可作为纠纷评判依据,故双方联系时,只与对方在左子上所留的QQ、手机号沟通,以防对方不承认自我承诺。 7、虽然交易产生纠纷的几率很小,但一定要保留如聊天记录、手机短信等这样的重要信息,以防产生纠纷时便于左子介入快速处理。
查看详情

相关文章

猜你喜欢
发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务