Skip to content

Commit

Permalink
New API summaries (#134)
Browse files Browse the repository at this point in the history
- `tf.math.reduce_mean()`.
- `tf.GradientTape`
- `tf.GradientTape.gradient()`
  • Loading branch information
khatchad authored Jan 30, 2024
1 parent cea5223 commit 8f826d3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ public void testTf2()
testTf2("tf2_test_add5.py", "f", 1, 1, 2);
testTf2("tf2_test_add6.py", "f", 1, 1, 2);
testTf2("multigpu_training.py", "run_optimization", 2, 4, 2, 3);
testTf2("tf2_test_reduce_mean.py", "f", 1, 1, 2);
testTf2("tf2_test_reduce_mean.py", "g", 1, 1, 2);
testTf2("tf2_test_reduce_mean.py", "h", 1, 1, 2);
testTf2("tf2_test_gradient.py", "f", 1, 1, 2);
}

private void testTf2(
Expand Down
27 changes: 27 additions & 0 deletions com.ibm.wala.cast.python.ml/data/tensorflow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<putfield class="LRoot" field="run" fieldType="LRoot" ref="app" value="run" />
<new def="Estimator" class="Ltensorflow/estimator/Estimator" />
<putfield class="LRoot" field="Estimator" fieldType="LRoot" ref="estimator" value="Estimator" />
<new def="GradientTape" class="Ltensorflow/GradientTape" />
<putfield class="LRoot" field="GradientTape" fieldType="LRoot" ref="x" value="GradientTape" />
<new def="Dataset" class="Ltensorflow/data/Dataset" />
<putfield class="LRoot" field="Dataset" fieldType="LRoot" ref="data" value="Dataset" />
<new def="MirroredStrategy" class="Ltensorflow/distribute/MirroredStrategy" />
Expand Down Expand Up @@ -79,6 +81,9 @@
<new def="add" class="Ltensorflow/math/add" />
<putfield class="LRoot" field="add" fieldType="LRoot" ref="x" value="add" />
<putfield class="LRoot" field="add" fieldType="LRoot" ref="math" value="add" />
<new def="reduce_mean" class="Ltensorflow/math/reduce_mean" />
<putfield class="LRoot" field="reduce_mean" fieldType="LRoot" ref="x" value="reduce_mean" />
<putfield class="LRoot" field="reduce_mean" fieldType="LRoot" ref="math" value="reduce_mean" />
<new def="placeholder" class="Ltensorflow/functions/placeholder" />
<putfield class="LRoot" field="placeholder" fieldType="LRoot" ref="x" value="placeholder" />
<new def="examples" class="Lobject" />
Expand Down Expand Up @@ -280,6 +285,12 @@
<return value="xx" />
</method>
</class>
<class name="reduce_mean" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/reduce_mean -->
<method name="do" descriptor="()LRoot;" numArgs="5" paramNames="self input_tensor axis keepdims name">
<return value="input_tensor" />
</method>
</class>
</package>
<package name="tensorflow/functions">
<class name="AdamOptimizer" allocatable="true">
Expand Down Expand Up @@ -716,6 +727,22 @@
</method>
</class>
</package>
<package name="tensorflow">
<class name="GradientTape" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/GradientTape -->
<method name="do" descriptor="()LRoot;" numArgs="3" paramNames="self persistent watch_accessed_variables">
<new def="gradient" class="Ltensorflow/gradient" />
<putfield class="LRoot" field="gradient" fieldType="LRoot" ref="arg0" value="gradient" />
<return value="arg0" />
</method>
</class>
<class name="gradient" allocatable="true">
<!-- https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/GradientTape#gradient -->
<method name="do" descriptor="()LRoot;" numArgs="5" paramNames="self target sources output_gradients unconnected_gradients">
<return value="sources" />
</method>
</class>
</package>
<package name="tensorflow/data">
<class name="Dataset" allocatable="true">
<!-- "read_dataset" means that this function reads a tensor iterable. -->
Expand Down
14 changes: 14 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_gradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/GradientTape#gradient.

import tensorflow as tf


def f(a):
pass


x = tf.ragged.constant([[1.0, 2.0], [3.0]])
with tf.GradientTape() as g:
g.watch(x)
y = x * x
f(g.gradient(y, x))
22 changes: 22 additions & 0 deletions com.ibm.wala.cast.python.test/data/tf2_test_reduce_mean.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# From https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/math/reduce_mean#for_example
import tensorflow as tf


def f(a):
pass


def g(a):
pass


def h(a):
pass


x = tf.constant([[1.0, 1.0], [2.0, 2.0]])
f(tf.reduce_mean(x))

g(tf.reduce_mean(x, 0))

h(tf.reduce_mean(x, 1))

0 comments on commit 8f826d3

Please sign in to comment.