一个类包装分发函数所需的信息。
用法
tf.distribute.experimental.ValueContext(
replica_id_in_sync_group=0, num_replicas_in_sync=1
)
参数
-
replica_id_in_sync_group
当前的replica_id,应该是 [0,num_replicas_in_sync
) 中的 int。 -
num_replicas_in_sync
同步的副本数。
属性
-
num_replicas_in_sync
返回同步的计算副本数。 -
replica_id_in_sync_group
返回副本 ID。
这是一个上下文类,它传递给strategy.experimental_distribute_values_from_function
中的value_fn
,并包含有关计算副本的信息。 num_replicas_in_sync
和replica_id
可用于自定义每个副本的值。
示例用法:
- 直接构建。
def value_fn(context):
return context.replica_id_in_sync_group/context.num_replicas_in_sync
context = tf.distribute.experimental.ValueContext(
replica_id_in_sync_group=2, num_replicas_in_sync=4)
per_replica_value = value_fn(context)
per_replica_value
0.5
- 由
experimental_distribute_values_from_function
传入。
strategy = tf.distribute.MirroredStrategy(["GPU:0", "GPU:1"])
def value_fn(value_context):
return value_context.num_replicas_in_sync
distributed_values = (
strategy.experimental_distribute_values_from_function(
value_fn))
local_result = strategy.experimental_local_results(distributed_values)
local_result
(2, 2)
相关用法
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.gather用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy用法及代码示例
- Python tf.distribute.experimental.rpc.Server.create用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.distribute.experimental.partitioners.Partitioner.__call__用法及代码示例
- Python tf.distribute.experimental.TPUStrategy.experimental_distribute_values_from_function用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.run用法及代码示例
- Python tf.distribute.experimental.partitioners.MaxSizePartitioner.__call__用法及代码示例
- Python tf.distribute.experimental.partitioners.FixedShardsPartitioner用法及代码示例
- Python tf.distribute.experimental.TPUStrategy.experimental_distribute_dataset用法及代码示例
- Python tf.distribute.experimental.ParameterServerStrategy.gather用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.scope用法及代码示例
- Python tf.distribute.experimental.TPUStrategy用法及代码示例
- Python tf.distribute.experimental.MultiWorkerMirroredStrategy.reduce用法及代码示例
- Python tf.distribute.experimental.partitioners.MinSizePartitioner用法及代码示例
- Python tf.distribute.experimental.ParameterServerStrategy.experimental_distribute_values_from_function用法及代码示例
- Python tf.distribute.experimental.CentralStorageStrategy.experimental_distribute_values_from_function用法及代码示例
- Python tf.distribute.experimental.CentralStorageStrategy用法及代码示例
- Python tf.distribute.experimental.coordinator.ClusterCoordinator.fetch用法及代码示例
- Python tf.distribute.experimental.ParameterServerStrategy.experimental_distribute_dataset用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.distribute.experimental.ValueContext。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。