tf.config.experimental_run_functions_eagerly
Stay organized with collections
Save and categorize content based on your preferences.
Enables / disables eager execution of tf.function
s.
tf.config.experimental_run_functions_eagerly(
run_eagerly
)
Calling tf.config.experimental_run_functions_eagerly(True)
will make all
invocations of tf.function
run eagerly instead of running as a traced graph
function.
This can be useful for debugging or profiling. For example, let's say you
implemented a simple iterative sqrt function, and you want to collect the
intermediate values and plot the convergence. Appending the values to a list
in @tf.function
normally wouldn't work since it will just record the Tensors
being traced, not the values. Instead, you can do the following.
ys = []
@tf.function
def sqrt(x):
y = x / 2
d = y
for _ in range(10):
d /= 2
if y * y < x:
y += d
else:
y -= d
ys.append(y.numpy())
return y
tf.config.experimental_run_functions_eagerly(True)
sqrt(tf.constant(2.))
<tf.Tensor: shape=(), dtype=float32, numpy=1.4150391>
ys
[1.5, 1.25, 1.375, 1.4375, 1.40625, 1.421875, 1.4140625, 1.4179688, 1.4160156,
1.4150391]
tf.config.experimental_run_functions_eagerly(False)
Calling tf.config.experimental_run_functions_eagerly(False)
will undo this
behavior.
Args |
run_eagerly
|
Boolean. Whether to run functions eagerly.
|
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.
Last updated 2020-10-01 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 2020-10-01 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 2020-10-01 UTC."],[],[]]