-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Extract tf.function decorator keyword arguments #144
Conversation
There is no URL for each tf.function parameter. The most specific permalink would be https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/function#args |
Yeah? Like this one? https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/function#input_signature |
edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting there.
|
||
/** | ||
* Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. The values could be an optional | ||
* tuple or value of tf.autograph.experimental.Feature values or None. | ||
*/ | ||
private String experimentalAutographOptionsParamValue; | ||
private String experimentalAutographOptionsParam; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String
isn't a good type to represent these values. The docs even say, "this enumeration represents optional conversion options.". That's a hint at what Java (also in C++) type can be used here.
P.S. It's unfortunate that even the example there is using a decorator value from a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be an enumeration or tuple of enumerations (https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/function#experimental_autograph_options). How can this be represented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example:
https://github.com/tatianacv/Hybridize-Functions-Refactoring/blob/9163368a396e3108700da9aa211a27f0f1d47160/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments16/in/A.py#L1-L10
vs
https://github.com/tatianacv/Hybridize-Functions-Refactoring/blob/9163368a396e3108700da9aa211a27f0f1d47160/edu.cuny.hunter.hybridize.tests/resources/HybridizeFunction/testDecoratorArguments18/in/A.py#L1-L10
|
||
/** | ||
* Value of this {@link Function}'s {@link decoratorsType} parameter experimental_autograph_options. The values could be an optional | ||
* tuple or value of tf.autograph.experimental.Feature values or None. | ||
*/ | ||
private String experimentalAutographOptionsParamValue; | ||
private String experimentalAutographOptionsParam; | ||
|
||
/** | ||
* Value of this {@link Function}'s {@link decoratorsType} parameter experimental_implements. The value could be None or a name of a | ||
* "known" function this implements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an example value. This can be in HTML using <code>...</code>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
*/ | ||
private String inputSignatureParamValue; | ||
private ArrayList<TensorSpec> inputSignatureParam; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to specifically be an ArrayList
? Is it important that the list be contiguous in memory (this is not a question).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to List
edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java
Show resolved
Hide resolved
edu.cuny.hunter.hybridize.core/src/edu/cuny/hunter/hybridize/core/analysis/Function.java
Show resolved
Hide resolved
@@ -204,8 +207,13 @@ public HybridizationParameters(IProgressMonitor monitor) throws BadLocationExcep | |||
// Example of value: True, False, None | |||
if (keyword.value instanceof Name) { | |||
Name value = (Name) keyword.value; | |||
if (value.id == "True" || value.id == "False" || value.id == "None") // Checking only literals | |||
this.jitCompileParamValue = value.id; | |||
if (value.id == "True") // Checking only literals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per our conversations, we need to be able to tell when a literal value is not used. Thus, we need an exception thrown when a variable is used. Is that what is happening below (this is a question).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct
|
||
TensorSpec tensor = (TensorSpec) tensorObject; | ||
|
||
return shape.equals(tensor.shape) && dtype.equals(tensor.dtype); |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is overridden because, in our tests, I check am checking that the list of tensorspec that is generated is the same one as the one provided.
* True if the {@link TensorSpec} is using keyword arguments for the type. | ||
*/ | ||
private boolean dtypeKeyword; | ||
|
||
public TensorSpec() { | ||
this.shape = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there more useful representation for a shape than a String
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a List
* True if the {@link TensorSpec} is using keyword arguments for the type. | ||
*/ | ||
private boolean dtypeKeyword; | ||
|
||
public TensorSpec() { | ||
this.shape = ""; | ||
this.dtype = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with dtype
. Aren't dtype
s finite sets? Or, does it take any arbitrary type (this is a question).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -845,7 +846,7 @@ public void testDecoratorArguments() throws Exception { | |||
if (!args.hasFuncParam() && args.hasInputSignatureParam() & !args.hasAutoGraphParam() && !args.hasJitCompileParam() | |||
&& !args.hasReduceRetracingParam() && !args.hasExperimentalImplementsParam() && !args.hasExperimentalAutographOptParam() | |||
&& !args.hasExperimentalFollowTypeHintsParam()) | |||
assertEquals("None", args.getInputSignatureArg()); | |||
assertEquals(null, args.getInputSignatureArg()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
Thanks! I didn't know I could do that. I didn't see the option of getting the specific link on the site; I thought I couldn't. Thanks so letting me know. |
…github.com/tatianacv/Hybridize-Functions-Refactoring into 136-extract-tffunction-decorator-arguments
It's in the HTML. |
https://khatchad.commons.gc.cuny.edu/research/background/#link-6074 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Javadoc comments are outdated. Many of them say return String
but the methods don't return String
. Because of this reason, it doesn't make sense to to use types in the comments. The comments are used to explain what the code doesn't tell us. We can see from the method signature what the return type is. The javadoc should explain the concept of what is being returned.
@@ -38,10 +39,14 @@ | |||
*/ | |||
public class Function extends RefactorableProgramEntity { | |||
|
|||
public enum TfAutographExperimentalFeature { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need a javadoc comment here explaining what this is and a URL for more info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
@@ -38,10 +39,14 @@ | |||
*/ | |||
public class Function extends RefactorableProgramEntity { | |||
|
|||
public enum TfAutographExperimentalFeature { | |||
ALL, AUTO_CONTROL_DEPS, ASSERT_STATEMENTS, BUILTIN_FUNCTIONS, EQUALITY_OPERATORS, LISTS, NAME_SCOPES |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do each of these mean? What is the URL where we can find out more info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an URL in the javadoc
@@ -101,7 +107,7 @@ public class HybridizationParameters { | |||
* Value of this {@link Function}'s {@link decoratorsType} parameter input_signature. The value could be None, or a possibly nested | |||
* sequence of tf.TensorSpec objects specifying the shapes and dtypes of the Tensors that will be supplied to this function. | |||
*/ | |||
private ArrayList<TensorSpec> inputSignatureParam; | |||
private java.util.List<TensorSpec> inputSignatureParam; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Why not just
List
? - Why use
List
? Is ordering important? Can you have duplicates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We already have another import for
List
(org.python.pydev.parser.jython.ast.List
). Therefore, I had to specify whichList
it was by doingjava.util.List<TensorSpec>
. - Order is important, and we can have duplicates.
int count = 0; | ||
String tempString = ""; | ||
private java.util.List<Integer> processTupleOrListForShape(exprType[] exprTupleOrList) { | ||
java.util.List<Integer> shape = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Javadoc says it's returning a String. Is that still true?
- Why not just
List
? - I don't know how a list of integers represents tensor shape. Why a list? Doesn't a tensor shape just have two integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have another import for List (org.python.pydev.parser.jython.ast.List). Therefore, I had to specify which List it was by doing java.util.List. It is a list of dimensions (https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/TensorShape) which can be integers or None
.
A lot of problems here. The build is failing, and I'm unsure whether the data types make any sense. There also so many comments now that it is difficult to read the code, and the comments are getting out-of-sync with the code. Comments are needed for things the code doesn't tell us. |
Fixes #136 .
Commits
git diff
andgit status
to check my work carefully before committing.Expectations
Extract
tf.function
decorator keyword parameter values. We are obtaining the decorator’s argument literal values. We throw an exception when we find something we cannot process, like for example, non-literal values.Testing
git stash
to temporarily reset the working directory).I added tests for many possible values that could arise for each
tf.function
arguments. I used thetf.function
documentation to understand and make tests for different possible values. I also added test to make sure that for when we are not working with literals, we throw an exception.Final Checks