I printed graph in tf.function. It seems that autograph did not insert control dependency between assign and read of the same variable.
import tensorflow as tf
import numpy as np
class F():
def __init__(self):
pass
@tf.function
def __call__(self, v1, v2):
c1 = tf.constant([[10, 10], [11., 1.]])
v1.assign_add(c1)
c2 = tf.constant([[1., 0.], [0., 1.]])
v2.assign_add(c2)
y = v1 + v2
print("PRINT: ", y)
# tf.print("TF-PRINT: ", y)
tf_v1 = tf._api.v2.compat.v1
g=tf_v1.get_default_graph()._as_graph_def()
print(g)
return y
v1 = tf.Variable([[12., 12.],[12., 12.]])
v2 = tf.Variable([[12., 12.],[12., 12.]])
f = F()
t = f(v, v2)
print("PRINT: ", t)