W3cubDocs

/TensorFlow 2.3

tf.distribute.experimental_set_strategy

View source on GitHub

Set a tf.distribute.Strategy as current without with strategy.scope().

tf.distribute.experimental_set_strategy(strategy1)
f()
tf.distribute.experimental_set_strategy(strategy2)
g()
tf.distribute.experimental_set_strategy(None)
h()

is equivalent to:

with strategy1.scope():
  f()
with strategy2.scope():
  g()
h()

In general, you should use the with strategy.scope(): API, but this alternative may be convenient in notebooks where you would have to put each cell in a with strategy.scope(): block.

Note: This should only be called outside of any TensorFlow scope to avoid improper nesting.
Args
strategy A tf.distribute.Strategy object or None.
Raises
RuntimeError If called inside a with strategy.scope():.

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/distribute/experimental_set_strategy