返回 device function
以在为副本构建 Graph 时使用。
用法
tf.compat.v1.train.replica_device_setter(
ps_tasks=0, ps_device='/job:ps',
worker_device='/job:worker', merge_devices=True, cluster=None,
ps_ops=None, ps_strategy=None
)
参数
-
ps_tasks
ps
作业中的任务数。如果提供了cluster
,则忽略。 -
ps_device
String 。ps
作业的设备。如果为空,则不使用ps
作业。默认为ps
。 -
worker_device
String 。worker
作业的设备。如果为空,则不使用worker
作业。 -
merge_devices
Boolean
。如果True
,如果设备约束完全未设置,则合并或仅设置设备。合并设备规范而不是覆盖它们。 -
cluster
ClusterDef
原型或ClusterSpec
。 -
ps_ops
表示需要放置在ps
设备上的Operation
类型的字符串列表。如果None
,默认为STANDARD_PS_OPS
。 -
ps_strategy
为每个 psOperation
(即与ps_ops
匹配)调用的可调用对象,它采用Operation
并返回要使用的 ps 任务索引。如果None
,则默认为跨所有ps
设备的 round-robin 策略。
返回
-
传递给
tf.device()
的函数。
抛出
-
如果
cluster
不是字典或ClusterDef
协议缓冲区,或者如果提供了ps_strategy
但不是可调用的,则类型错误。
with tf.device(device_function):
语句中使用设备函数在构造它们时自动将设备分配给 Operation
对象,首先从 inner-most 上下文添加设备约束,向外工作。合并行为将约束添加到尚未由更内部上下文设置的字段。目前的字段是(作业、任务、cpu/gpu)。
如果 cluster
是 None
,并且 ps_tasks
是 0,则返回的函数是 no-op。否则,ps_tasks
的值是从 cluster
派生的。
默认情况下,ps任务上只放置Variable ops,放置策略为round-robin覆盖所有ps任务。自定义 ps_strategy
可用于进行更智能的放置,例如 tf.contrib.training.GreedyLoadBalancingStrategy
。
例如,
# To build a cluster with two ps jobs on hosts ps0 and ps1, and 3 worker
# jobs on hosts worker0, worker1 and worker2.
cluster_spec = {
"ps":["ps0:2222", "ps1:2222"],
"worker":["worker0:2222", "worker1:2222", "worker2:2222"]}
with
tf.compat.v1.device(tf.compat.v1.train.replica_device_setter(cluster=cluster_spec)):
# Build your graph
v1 = tf.Variable(...) # assigned to /job:ps/task:0
v2 = tf.Variable(...) # assigned to /job:ps/task:1
v3 = tf.Variable(...) # assigned to /job:ps/task:0
# Run compute
相关用法
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代码示例
- Python tf.compat.v1.train.get_or_create_global_step用法及代码示例
- Python tf.compat.v1.train.cosine_decay_restarts用法及代码示例
- Python tf.compat.v1.train.Optimizer用法及代码示例
- Python tf.compat.v1.train.AdagradOptimizer.compute_gradients用法及代码示例
- Python tf.compat.v1.train.init_from_checkpoint用法及代码示例
- Python tf.compat.v1.train.Checkpoint用法及代码示例
- Python tf.compat.v1.train.Supervisor.managed_session用法及代码示例
- Python tf.compat.v1.train.Checkpoint.restore用法及代码示例
- Python tf.compat.v1.train.global_step用法及代码示例
- Python tf.compat.v1.train.MonitoredSession.run_step_fn用法及代码示例
- Python tf.compat.v1.train.RMSPropOptimizer.compute_gradients用法及代码示例
- Python tf.compat.v1.train.exponential_decay用法及代码示例
- Python tf.compat.v1.train.natural_exp_decay用法及代码示例
- Python tf.compat.v1.train.MomentumOptimizer用法及代码示例
- Python tf.compat.v1.train.RMSPropOptimizer用法及代码示例
- Python tf.compat.v1.train.get_global_step用法及代码示例
- Python tf.compat.v1.train.GradientDescentOptimizer.compute_gradients用法及代码示例
- Python tf.compat.v1.train.linear_cosine_decay用法及代码示例
- Python tf.compat.v1.train.Supervisor用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.train.replica_device_setter。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。