You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# From https://www.tensorflow.org/guide/function#all_outputs_of_a_tffunction_must_be_return_valuesimporttensorflowastffromnose.toolsimportassert_raises@tf.functiondefleaky_function(a):
globalxx=a+1# Bad - leaks local tensorreturnx# Good - uses local tensorcorrect_a=leaky_function(tf.constant(1))
print(correct_a.numpy()) # Good - value obtained from function's returnstry:
x.numpy() # Bad - tensor leaked from inside the function, cannot be used hereexceptAttributeErrorasexpected:
print(expected)
defcaptures_leaked_tensor(b):
b+=x# Bad - `x` is leaked from `leaky_function`returnbwithassert_raises(TypeError):
captures_leaked_tensor(tf.constant(2))
Here, capture_leaked_tensor() doesn't explicitly have Python side-effects, but it reads from a global variable that was written to by a function that does have Python side-effects. Thus, captures_leaked_tensor should not be converted to hybrid.
Expected Behavior
The function capture_leaked_tensor() should not be hybridized.
If capture_leaked_tensor() is already hybrid, we should warn.
The text was updated successfully, but these errors were encountered:
Consider the following code:
Here,
capture_leaked_tensor()
doesn't explicitly have Python side-effects, but it reads from a global variable that was written to by a function that does have Python side-effects. Thus,captures_leaked_tensor
should not be converted to hybrid.Expected Behavior
capture_leaked_tensor()
should not be hybridized.capture_leaked_tensor()
is already hybrid, we should warn.The text was updated successfully, but these errors were encountered: