how autograph recognize variable read after write (raw) ,write after read(raw) and waw dependency

3 views
Skip to first unread message

刘振海

unread,
Jul 5, 2022, 3:39:32 AMJul 5
to devel...@tensorflow.org
I printed graph in tf.function. It seems that autograph did not insert control dependency between assign and read of the same variable.

below is my code

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)

Yu Feng

unread,
Jul 6, 2022, 12:25:29 PMJul 6
to 刘振海, devel...@tensorflow.org
Dear 刘振海,

The default graph you get from the tf_v1 API is not the complete graph.
The auto-control-dependency (not part of autograph) is run after the default graph is produced. If you check the graph of the concrete function of
`f`, the control dependency between variables Ops are inserted.

https://colab.research.google.com/gist/rainwoodman/e5eed5e8ab51874afebc2275efb1913c/acdvariablesliuzhenhai.ipynb

Best,

Yu

--
You received this message because you are subscribed to the Google Groups "TensorFlow Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to developers+...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/developers/CACYyuNcjC4mQ2hwCnG8qDU89ODUQVE7Zs%2BFc_8OAgNw7XJCemw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages