apeforest commented on a change in pull request #14286: Add examples of running MXNet with Horovod URL: https://github.com/apache/incubator-mxnet/pull/14286#discussion_r263638882
########## File path: example/distributed_training-horovod/README.md ########## @@ -0,0 +1,207 @@ +<!--- Licensed to the Apache Software Foundation (ASF) under one --> +<!--- or more contributor license agreements. See the NOTICE file --> +<!--- distributed with this work for additional information --> +<!--- regarding copyright ownership. The ASF licenses this file --> +<!--- to you under the Apache License, Version 2.0 (the --> +<!--- "License"); you may not use this file except in compliance --> +<!--- with the License. You may obtain a copy of the License at --> + +<!--- http://www.apache.org/licenses/LICENSE-2.0 --> + +<!--- Unless required by applicable law or agreed to in writing, --> +<!--- software distributed under the License is distributed on an --> +<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY --> +<!--- KIND, either express or implied. See the License for the --> +<!--- specific language governing permissions and limitations --> +<!--- under the License. --> + +# MXNet + Horovod +[Horovod](https://github.com/horovod/horovod) is a distributed training framework that demonstrates +excellent scaling efficiency for dense models running on a large number of nodes. It currently +supports mainstream deep learning frameworks such as MXNet, TensorFlow, Keras, and PyTorch. +It is created at Uber and currently hosted by the [Linux Foundation Deep Learning](https://lfdl.io)(LF DL). + +MXNet is recently supported in Horovod 0.16.0 [release](https://eng.uber.com/horovod-pyspark-apache-mxnet-support/). + +## What's New? +Compared with the standard distributed training script in MXNet which uses parameter server to +distribute and aggregate parameters, Horovod uses ring allreduce algorithm to communicate parameters +between workers. There is no dedicated server and the communication data size +between workers does not depend on the number of workers. Therefore, it scales well in the case where +there are a large number of workers and network bandwidth becomes bottleneck. + +# Install + +To install Horovod: + +1. Install [Open MPI](https://www.open-mpi.org/) or another MPI implementation. + +Steps to install Open MPI are listed [here](https://www.open-mpi.org/faq/?category=building#easy-build). + +**Note**: Open MPI 3.1.3 has an issue that may cause hangs. It is recommended +to downgrade to Open MPI 3.1.2 or upgrade to Open MPI 4.0.0. + +2. Install the `horovod` pip package. + +```bash +$ pip install horovod +``` + +This basic installation is good for laptops and for getting to know Horovod. +If you're installing Horovod on a server with GPUs, read the [Horovod on GPU](https://github.com/horovod/horovod/blob/master/docs/gpus.md) page. +If you want to use Docker, read the [Horovod in Docker](https://github.com/horovod/horovod/blob/master/docs/docker.md) page. + +**Note**: we recommend users to build MXNet from source when running on a Linux OS with GCC version 5.X and above. +The MXNet shared library distributed through MXNet pip package is currently built using GCC 4.8.4. If we build and install Horovod +on a Linux OS with GCC 5.X+ with MXNet pip package, we will hit segmentation fault due to std::function definition change from +GCC [4.X](https://github.com/gcc-mirror/gcc/blob/gcc-4_8_4-release/libstdc++-v3/include/std/functional#L2069) to +GCC [5.X](https://github.com/gcc-mirror/gcc/blob/gcc-5_4_0-release/libstdc++-v3/include/std/functional#L1854). + +# Usage + +To run MXNet with Horovod, make the following additions to your training script: + +1. Run `hvd.init()`. + +2. Pin a server GPU to the context using `context = mx.gpu(hvd.local_rank())`. + With the typical setup of one GPU per process, this can be set to *local rank*. In that case, the first process on + the server will be allocated the first GPU, second process will be allocated the second GPU and so forth. + +3. Scale the learning rate by 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. + +4. Wrap 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. + +5. Add `hvd.broadcast_parameters` to broadcast 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. + +# Example + +Here we provide the building blocks to train a model using MXNet with Horovod. +The full examples are in [MINST](mxnet_mnist.py) and [ImageNet](mxnet_imagenet_resnet50.py). Review comment: Added one for gluon and one for module in separate files. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services