Distributed replicated training. Each worker process builds the same model on one or more GPUs. Gradients across GPUs are averaged within the worker, and get synchronously applied to the global copy of variables located on PS. Then each worker copy the latest variables from PS b
| 133 | |
| 134 | |
| 135 | class DistributedReplicatedBuilder(DataParallelBuilder, DistributedBuilderBase): |
| 136 | """ |
| 137 | Distributed replicated training. |
| 138 | Each worker process builds the same model on one or more GPUs. |
| 139 | Gradients across GPUs are averaged within the worker, |
| 140 | and get synchronously applied to the global copy of variables located on PS. |
| 141 | Then each worker copy the latest variables from PS back to local. |
| 142 | |
| 143 | It is an equivalent of ``--variable_update=distributed_replicated`` in |
| 144 | `tensorflow/benchmarks <https://github.com/tensorflow/benchmarks>`_. |
| 145 | Note that the performance of this trainer is still not satisfactory, |
| 146 | and TensorFlow team is not actively maintaining distributed training features. |
| 147 | Check :class:`HorovodTrainer` and |
| 148 | `ResNet-Horovod <https://github.com/tensorpack/benchmarks/tree/master/ResNet-Horovod>`_ |
| 149 | for better distributed training support. |
| 150 | |
| 151 | Note: |
| 152 | 1. Gradients are not averaged across workers, but applied to PS variables |
| 153 | directly (either with or without locking depending on the optimizer). |
| 154 | 2. Some details about collections: all variables created inside tower |
| 155 | will become local variables, |
| 156 | and a clone will be made in global variables for all trainable/model variables. |
| 157 | |
| 158 | Example: |
| 159 | |
| 160 | .. code-block:: python |
| 161 | |
| 162 | # Create the server object like this: |
| 163 | hosts = ['host1.com', 'host2.com'] |
| 164 | cluster_spec = tf.train.ClusterSpec({ |
| 165 | 'ps': [h + ':2222' for h in hosts], |
| 166 | 'worker': [h + ':2223' for h in hosts] |
| 167 | }) |
| 168 | server = tf.train.Server( |
| 169 | cluster_spec, job_name=args.job, task_index=args.task, |
| 170 | config=get_default_sess_config()) |
| 171 | # initialize trainer with this server object |
| 172 | |
| 173 | .. code-block:: none |
| 174 | |
| 175 | # Start training like this: |
| 176 | (host1)$ ./train.py --job worker --task 0 |
| 177 | (host1)$ CUDA_VISIBLE_DEVICES= ./train.py --job ps --task 0 |
| 178 | (host2)$ ./train.py --job worker --task 1 |
| 179 | (host2)$ CUDA_VISIBLE_DEVICES= ./train.py --job ps --task 1 |
| 180 | """ |
| 181 | |
| 182 | def __init__(self, towers, server): |
| 183 | """ |
| 184 | Args: |
| 185 | towers (list[int]): list of GPU ids. |
| 186 | server (tf.train.Server): the server with ps and workers. |
| 187 | job_name must be 'worker'. |
| 188 | """ |
| 189 | DataParallelBuilder.__init__(self, towers) |
| 190 | DistributedBuilderBase.__init__(self, server) |
| 191 | |
| 192 | self.is_chief = (self.task_index == 0) |
no outgoing calls
no test coverage detected
searching dependent graphs…