one-machine 策略將所有變量放在單個設備上。
繼承自:Strategy
用法
tf.compat.v1.distribute.experimental.CentralStorageStrategy(
compute_devices=None, parameter_device=None
)
屬性
-
cluster_resolver
返回與此策略關聯的集群解析器。一般來說,當使用multi-worker
tf.distribute
策略如tf.distribute.experimental.MultiWorkerMirroredStrategy
或tf.distribute.TPUStrategy()
時,有一個tf.distribute.cluster_resolver.ClusterResolver
與所使用的策略相關聯,並且這樣的實例由該屬性返回。打算擁有關聯
tf.distribute.cluster_resolver.ClusterResolver
的策略必須設置相關屬性,或覆蓋此屬性;否則,默認返回None
。這些策略還應提供有關此屬性返回的內容的信息。Single-worker 策略通常沒有
tf.distribute.cluster_resolver.ClusterResolver
,在這些情況下,此屬性將返回None
。當用戶需要訪問集群規範、任務類型或任務 ID 等信息時,
tf.distribute.cluster_resolver.ClusterResolver
可能很有用。例如,os.environ['TF_CONFIG'] = json.dumps({ 'cluster':{ 'worker':["localhost:12345", "localhost:23456"], 'ps':["localhost:34567"] }, 'task':{'type':'worker', 'index':0} }) # This implicitly uses TF_CONFIG for the cluster and current task info. strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy() ... if strategy.cluster_resolver.task_type == 'worker': # Perform something that's only applicable on workers. Since we set this # as a worker above, this block will run on this particular instance. elif strategy.cluster_resolver.task_type == 'ps': # Perform something that's only applicable on parameter servers. Since we # set this as a worker above, this block will not run on this particular # instance.
有關詳細信息,請參閱
tf.distribute.cluster_resolver.ClusterResolver
的 API 文檔字符串。 -
extended
tf.distribute.StrategyExtended
與其他方法。 -
num_replicas_in_sync
返回聚合梯度的副本數。
變量分配給本地 CPU 或唯一的 GPU。如果有多個 GPU,計算操作(變量更新操作除外)將在所有 GPU 上複製。
例如:
strategy = tf.distribute.experimental.CentralStorageStrategy()
# Create a dataset
ds = tf.data.Dataset.range(5).batch(2)
# Distribute that dataset
dist_dataset = strategy.experimental_distribute_dataset(ds)
with strategy.scope():
@tf.function
def train_step(val):
return val + 1
# Iterate over the distributed dataset
for x in dist_dataset:
# process dataset elements
strategy.run(train_step, args=(x,))
相關用法
- Python tf.compat.v1.distribute.experimental.CentralStorageStrategy.make_input_fn_iterator用法及代碼示例
- Python tf.compat.v1.distribute.experimental.CentralStorageStrategy.run用法及代碼示例
- Python tf.compat.v1.distribute.experimental.CentralStorageStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.CentralStorageStrategy.reduce用法及代碼示例
- Python tf.compat.v1.distribute.experimental.CentralStorageStrategy.experimental_make_numpy_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.CentralStorageStrategy.scope用法及代碼示例
- Python tf.compat.v1.distribute.experimental.TPUStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.TPUStrategy.experimental_make_numpy_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.MultiWorkerMirroredStrategy.reduce用法及代碼示例
- Python tf.compat.v1.distribute.experimental.MultiWorkerMirroredStrategy.experimental_make_numpy_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.TPUStrategy.scope用法及代碼示例
- Python tf.compat.v1.distribute.experimental.ParameterServerStrategy.experimental_make_numpy_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.TPUStrategy用法及代碼示例
- Python tf.compat.v1.distribute.experimental.TPUStrategy.reduce用法及代碼示例
- Python tf.compat.v1.distribute.experimental.MultiWorkerMirroredStrategy用法及代碼示例
- Python tf.compat.v1.distribute.experimental.MultiWorkerMirroredStrategy.run用法及代碼示例
- Python tf.compat.v1.distribute.experimental.MultiWorkerMirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.ParameterServerStrategy.experimental_distribute_dataset用法及代碼示例
- Python tf.compat.v1.distribute.experimental.MultiWorkerMirroredStrategy.scope用法及代碼示例
- Python tf.compat.v1.distribute.experimental.TPUStrategy.run用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.distribute.experimental.CentralStorageStrategy。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。