tf.random.set_global_generator
Stay organized with collections
Save and categorize content based on your preferences.
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 puts restrictions on Variable creation thus one cannot freely
create a new random generator instance inside
tf.function
.
To call set_global_generator
inside tf.function
, the generator instance
must have already been created eagerly.
- tf.function captures the Variable during trace-compilation, thus a compiled
f.function will not be affected
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.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2023-10-06 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2023-10-06 UTC."],[],[]]