Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract tf.function decorator keyword arguments #144

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
39c7fb5
update
tatianacv Jan 31, 2023
f21e423
progress
tatianacv Jan 31, 2023
747d5c5
Progress
tatianacv Jan 31, 2023
8f8c0b1
Progress
tatianacv Jan 31, 2023
4ffa27a
Progress
tatianacv Jan 31, 2023
21a8004
Progress
tatianacv Jan 31, 2023
89e4dd0
Progress
tatianacv Feb 1, 2023
b6f4e9c
Progress
tatianacv Feb 1, 2023
b9c8107
adding more testing
tatianacv Feb 1, 2023
d6b110c
Fixing trailing whitespace of tests
tatianacv Feb 1, 2023
26fd8f1
Fix to test
tatianacv Feb 2, 2023
9a4cb62
adding other params
tatianacv Feb 2, 2023
d0d0875
Progress
tatianacv Feb 2, 2023
015965a
Modifying test resource
tatianacv Feb 2, 2023
6102351
Modifying test resource
tatianacv Feb 2, 2023
a62af55
Renaming variable
tatianacv Feb 5, 2023
f7a9373
Formatting
tatianacv Feb 5, 2023
c9ee308
Adding exceptions
tatianacv Feb 6, 2023
0ab5892
Add more info to exception
tatianacv Feb 6, 2023
db5147f
Adding new line to test resource
tatianacv Feb 6, 2023
b9bd9be
Restructuring exceptions
tatianacv Feb 6, 2023
9db5396
Adding new line to test resource
tatianacv Feb 6, 2023
ec84857
Fixing variable name
tatianacv Feb 6, 2023
74b4bc4
Progress
tatianacv Feb 7, 2023
e12fb16
Removing unnecessary else
tatianacv Feb 7, 2023
7aef65b
Progress
tatianacv Feb 8, 2023
9f49fea
Update
tatianacv Feb 8, 2023
279089b
Progress
tatianacv Feb 8, 2023
ef5d5bb
Progress
tatianacv Feb 8, 2023
64bd2b6
progress
tatianacv Feb 8, 2023
f53e997
Progress
tatianacv Feb 8, 2023
1df7219
Cleanup
tatianacv Feb 8, 2023
1b2ac89
making sure we are only checking literals
tatianacv Feb 10, 2023
c4184d4
Reorganization
tatianacv Feb 10, 2023
d2ae4c9
Renaming
tatianacv Feb 10, 2023
b48960d
Adding documentation
tatianacv Feb 10, 2023
1eb7274
Adding a test where there should be an exception
tatianacv Feb 10, 2023
9195db7
Formatting
tatianacv Feb 10, 2023
eba9736
Test
tatianacv Feb 10, 2023
dd82611
Revert "Test"
tatianacv Feb 10, 2023
df97664
Update
tatianacv Feb 10, 2023
54d78be
Adding new tests
tatianacv Feb 10, 2023
10cb16b
Removing unnecesary files, and adding new line
tatianacv Feb 10, 2023
303a117
Adding newline
tatianacv Feb 10, 2023
fc90f50
Update
tatianacv Feb 10, 2023
ecffbc5
Adding more tests
tatianacv Feb 14, 2023
3577a39
Trailing whitespace fix
tatianacv Feb 14, 2023
0c72e7d
Adding comments
tatianacv Feb 14, 2023
94733e6
Make sure we are dealing with TensorSpec (input_signature)
tatianacv Feb 14, 2023
41bfe8d
Revert "Make sure we are dealing with TensorSpec (input_signature)"
tatianacv Feb 15, 2023
9003639
Revert "Revert "Make sure we are dealing with TensorSpec (input_signa…
tatianacv Feb 24, 2023
6fd42b2
Fix build
tatianacv Feb 24, 2023
1682088
Adding comments
tatianacv Feb 27, 2023
02ef49b
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
tatianacv Mar 4, 2023
ece2522
Update
tatianacv Mar 6, 2023
93f4e9c
Restructuring
tatianacv Mar 9, 2023
af61fe5
Restructure
tatianacv Mar 9, 2023
247e1d6
Restructure
tatianacv Mar 9, 2023
9b764d9
Remove redundancy
tatianacv Mar 9, 2023
bc3ff06
Restructuring
tatianacv Mar 10, 2023
cb23e2f
Adding more information
tatianacv Mar 10, 2023
79d0ff3
update
tatianacv Mar 13, 2023
2c93c3f
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
tatianacv Mar 16, 2023
e690e4f
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
khatchad Mar 21, 2023
bc534a4
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
tatianacv Mar 21, 2023
9163368
Fixing asserts
tatianacv Mar 22, 2023
09d52cb
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
tatianacv Mar 22, 2023
d845f0a
Progress
tatianacv Mar 23, 2023
6a13a5e
progress
tatianacv Mar 23, 2023
4c79a5a
Progress
tatianacv Mar 23, 2023
720bba7
Merge branch '136-extract-tffunction-decorator-arguments' of https://…
tatianacv Mar 23, 2023
5d63094
Changing dtype
tatianacv Mar 23, 2023
0c345f0
fixing comments
tatianacv Mar 24, 2023
44b8b7b
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
khatchad Mar 28, 2023
c5b576b
Merge branch 'main' into 136-extract-tffunction-decorator-arguments
tatianacv Mar 31, 2023
f2238cf
Remove unnecessary comments, update comments, change tensorspecs shap…
tatianacv Mar 31, 2023
45bcfd2
Adding another test
tatianacv Mar 31, 2023
a8ddc42
remove file
tatianacv Mar 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package edu.cuny.hunter.hybridize.core.analysis;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* A representation of a tf.Tensorspec which describes a tf.Tensor
*/
public class TensorSpec {

public enum Dtype {
float16, float32, float64, int32, int64, uint8, uint16, uint32, uint64, int16, int8, complex64, complex128, string, bool, qint8,
quint8, qint16, quint16, qint32, bfloat16, half, resource, variant
}

/**
* Shape of the tensor being described by {@link TensorSpec}.
*/
private List<Integer> shape;

/**
* Type of the tensor being described by {@link TensorSpec}.
*/
private Dtype dtype;

public TensorSpec() {
// Initialize to empty list
this.shape = new ArrayList<>();
this.dtype = Dtype.float32;
}

public TensorSpec(List<Integer> s, Dtype d) {
this.shape = s;
this.dtype = d;
}

/**
* Shape of {@link TensorSpec}.
*
* @return List of dimensions (null if the shape is unspecified) of this {@link TensorSpec} shape.
*/
public List<Integer> getShape() {
return this.shape;
}

/**
* Dtype of {@link TensorSpec}.
*
* @return Dtype of this {@link TensorSpec} dtype.
*/
public Dtype getDType() {
return this.dtype;
}

/**
* Set shape of {@link TensorSpec}.
*/
public void setShape(List<Integer> s) {
this.shape = s;
}

/**
* Set dtype of {@link TensorSpec}.
*/
public void setDType(Dtype d) {
this.dtype = d;
}

@Override
public int hashCode() {
return Objects.hash(shape, dtype);
}

@Override
public boolean equals(Object tensorObject) {

if (tensorObject == this) {
return true;
}

if (!(tensorObject instanceof TensorSpec)) {
return false;
}

TensorSpec tensor = (TensorSpec) tensorObject;

return shape.equals(tensor.shape) && dtype.equals(tensor.dtype);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are hashCode and equals being overridden for this class? Are you comparing these or putting them into a Set (this is a question)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tensorflow as tf


@tf.function(input_signature=None)
def func(x):
return x


if __name__ == '__main__':
number = tf.constant([1.0, 1.0])
func(number)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(jit_compile=None)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(reduce_retracing=True)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(reduce_retracing=False)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_implements="google.matmul_low_rank_matrix")
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_implements="embedded_matmul")
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_implements=None)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_autograph_options=tf.autograph.experimental.Feature.EQUALITY_OPERATORS)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_autograph_options=tf.autograph.experimental.Feature.ALL)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_autograph_options=(tf.autograph.experimental.Feature.EQUALITY_OPERATORS, tf.autograph.experimental.Feature.BUILTIN_FUNCTIONS))
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_autograph_options=None)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),))
def func(x):
return x

if __name__ == '__main__':
number = tf.constant([1.0, 1.0])
func(number)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_follow_type_hints=True)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_follow_type_hints=False)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function(experimental_follow_type_hints=None)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import tensorflow as tf


@tf.function
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import tensorflow as tf


@tf.function(input_signature=(tf.TensorSpec(shape=[None], dtype=tf.float32),), autograph=False)
def func(x):
print('Tracing with', x)
return x


if __name__ == '__main__':
number = tf.constant([1.0, 1.0])
func(number)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import custom


@custom.decorator(input_signature=None)
def func(x):
print('Tracing with', x)
return x


if __name__ == '__main__':
func(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def decorator(input_signature=None):

def decorated(inner_function):

def wrapper(*args, **kwargs):
result = function(*args, **kwargs)
return result

return decorated

return decorator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import custom
import tensorflow as tf


@custom.decorator(input_signature=None)
@tf.function(autograph=False)
def func():
pass


if __name__ == '__main__':
func()
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
def decorator(input_signature=None):

def decorated(inner_function):

def wrapper(*args, **kwargs):
result = function(*args, **kwargs)
return result

return decorated

return decorator
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import tensorflow as tf


@tf.function(autograph=False)
@tf.function(jit_compile=True)
def func(x):
return x


if __name__ == '__main__':
func(tf.constant(1))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import tensorflow as tf

var = (tf.TensorSpec(shape=[None], dtype=tf.float32),)


@tf.function(input_signature=var)
def func(x):
return x


if __name__ == '__main__':
number = tf.constant([1.0, 1.0])
func(number)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tensorflow==2.9.3
Loading