Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
b1b4c805
Commit
b1b4c805
authored
Dec 19, 2018
by
Shining Sun
Browse files
Inlude the distribution_utils file
parent
424c2045
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
4 deletions
+15
-4
official/utils/misc/distribution_utils.py
official/utils/misc/distribution_utils.py
+15
-4
No files found.
official/utils/misc/distribution_utils.py
View file @
b1b4c805
...
...
@@ -21,7 +21,8 @@ from __future__ import print_function
import
tensorflow
as
tf
def
get_distribution_strategy
(
num_gpus
,
all_reduce_alg
=
None
):
def
get_distribution_strategy
(
num_gpus
,
all_reduce_alg
=
None
,
use_one_device_strategy
):
"""Return a DistributionStrategy for running the model.
Args:
...
...
@@ -30,15 +31,25 @@ def get_distribution_strategy(num_gpus, all_reduce_alg=None):
See tf.contrib.distribute.AllReduceCrossDeviceOps for available
algorithms. If None, DistributionStrategy will choose based on device
topology.
use_one_device_strategy: Should only be set to Truen when num_gpus is 1.
If True, then use OneDeviceStrategy; otherwise, do not use any
distribution strategy.
Returns:
tf.contrib.distribute.DistibutionStrategy object.
"""
if
num_gpus
==
0
:
if
num_gpus
==
0
and
use_one_device_strategy
:
return
tf
.
contrib
.
distribute
.
OneDeviceStrategy
(
"device:CPU:0"
)
elif
num_gpus
==
1
:
elif
num_gpus
==
0
:
return
None
elif
num_gpus
==
1
and
use_one_device_strategy
:
return
tf
.
contrib
.
distribute
.
OneDeviceStrategy
(
"device:GPU:0"
)
else
:
elif
num_gpus
==
1
:
return
None
elif
use_one_device_strategy
:
rase
ValueError
(
"When %d GPUs are specified, use_one_device_strategy"
" flag cannot be set to True."
.
format
(
num_gpus
))
else
:
# num_gpus > 1 and not use_one_device_strategy
if
all_reduce_alg
:
return
tf
.
contrib
.
distribute
.
MirroredStrategy
(
num_gpus
=
num_gpus
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment