Replaces the global generator with another Generator object.
tf.random.set_global_generator(
generator
)
This function replaces the global generator with the provided generator object. A random number generator utilizes a tf.Variable object to store its state. The user shall be aware of caveats how set_global_generator interacts with tf.function:
tf.function. To call set_global_generator inside tf.function, the generator instance must have already been created eagerly.set_global_generator as demonstrated by random_test.py/RandomTest.testResetGlobalGeneratorBadWithDefun .For most use cases, avoid calling set_global_generator after program initialization, and prefer to reset the state of the existing global generator instead, such as,
rng = tf.random.get_global_generator() rng.reset_from_seed(30)
| Args | |
|---|---|
generator | the new Generator object. |
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/random/set_global_generator