Aliases:
tf.contrib.distribute.get_replica_contexttf.distribute.get_replica_context
tf.distribute.get_replica_context()
Defined in tensorflow/python/distribute/distribution_strategy_context.py.
Returns the current tf.distribute.ReplicaContext or None.
Returns None if in a cross-replica context.
Note that execution:
- starts in the default (single-replica) replica context (this function
will return the default
ReplicaContextobject); - switches to cross-replica context (in which case this will return
None) when entering awith tf.distribute.Strategy.scope():block; - switches to a (non-default) replica context inside
extended.call_for_each_replica(fn, ...); - if
fncallsget_replica_context().merge_call(merge_fn, ...), then insidemerge_fnyou are back in the cross-replica context (and again this function will returnNone).
Note that you can also go directly from step 1 to 4 to switch to a
cross-replica context for the default tf.distribute.Strategy. You may
also switch from the cross-replica context of 4 to a replica context by
calling extended.call_for_each_replica(), jumping back to step 3.
Most tf.distribute.Strategy methods may only be executed in
a cross-replica context, in a replica context you should use the
ReplicaContext API instead.
Returns:
The current ReplicaContext object when in a replica context scope,
else None.
Within a particular block, exactly one of these two things will be true:
get_replica_context()returns non-None, ortf.distribute.is_cross_replica_context()returns True.