distribute_utils_test.py 1.66 KB
Newer Older
Hongkun Yu's avatar
Hongkun Yu committed
1
# Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3
4
5
6
7
8
9
10
11
12
13
#
# Licensed 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.
Hongkun Yu's avatar
Hongkun Yu committed
14

15
16
""" Tests for distribution util functions."""

17
import tensorflow as tf
18

19
from official.common import distribute_utils
20
21
22
23


class GetDistributionStrategyTest(tf.test.TestCase):
  """Tests for get_distribution_strategy."""
Hongkun Yu's avatar
Hongkun Yu committed
24

25
  def test_one_device_strategy_cpu(self):
26
    ds = distribute_utils.get_distribution_strategy(num_gpus=0)
27
    self.assertEquals(ds.num_replicas_in_sync, 1)
28
29
    self.assertEquals(len(ds.extended.worker_devices), 1)
    self.assertIn('CPU', ds.extended.worker_devices[0])
30
31

  def test_one_device_strategy_gpu(self):
32
    ds = distribute_utils.get_distribution_strategy(num_gpus=1)
33
    self.assertEquals(ds.num_replicas_in_sync, 1)
34
35
    self.assertEquals(len(ds.extended.worker_devices), 1)
    self.assertIn('GPU', ds.extended.worker_devices[0])
36
37

  def test_mirrored_strategy(self):
38
    ds = distribute_utils.get_distribution_strategy(num_gpus=5)
39
    self.assertEquals(ds.num_replicas_in_sync, 5)
40
41
    self.assertEquals(len(ds.extended.worker_devices), 5)
    for device in ds.extended.worker_devices:
42
43
44
      self.assertIn('GPU', device)


Hongkun Yu's avatar
Hongkun Yu committed
45
if __name__ == '__main__':
46
  tf.test.main()