返回 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。