Uh oh!
There was an error while loading. Please reload this page.
TensorFlow type system refactoring - #139
Conversation
deansher
commented
Nov 3, 2020
I love the direction! I think you've created a package |
karllessard
commented
Nov 3, 2020
Oh, it looks like the whole generated source folder was missing, I've just pushed it back |
deansher
commented
Nov 3, 2020
Perhaps it would be worthwhile to carefully write down the intended semantics in the javadocs for a few cornerstone classes like // in class Output<T>public <UextendsTType> Output<U> expect(Class<U> tensorType) {
if (tensorType != type()) {
thrownewIllegalArgumentException(
"Cannot cast from output of " + type().getSimpleName() + " to output of type " + tensorType.getSimpleName());
}
return ((Output<U>) this);
}At compile time, would it be reasonable to have an Now suppose I have an We have a method whose implementation looks at it exactly that way, but whose javadoc does not: // in class TypeRegistry/** * Find a type registration from a type class * * @param typeClass class implementing {@link Tensor} * @return type registration * @throws IllegalArgumentException if the code matches no registered data type */publicstatic <TextendsTType> Type<T> find(Class<T> typeClass) {
Type<?> entry = TYPES_BY_CLASS.get(typeClass);
if (entry == null) {
thrownewIllegalArgumentException("Class \"" + typeClass.getName() + "\" is not a valid datatype class");
}
return (Type<T>)entry;
}The javadoc accurately describes Perhaps if we carefully write down the intended semantics in the javadocs for a few cornerstone classes like |
Hi @deansher , this PR is still a draft and the Javadoc is something I did not went through yet, as I wanted to collect more comments and have a common agreement that we want to move in that direction before completing it. So right now, please only look at it at a high-level. For example, I think what you mentioned about supporting |
deansher
commented
Nov 3, 2020
Yeah, I'm just poking around for interesting corner cases to see if I can spot any reasons that using a Java class as the runtime representation of a tensor type is going to go badly. |
91da1d2 to
4740bd4CompareCraigacp
commented
Jan 3, 2021
Is there anything left in this PR that hasn't landed in the others? As otherwise we should close this one. |
karllessard
commented
Jan 3, 2021
I think we are good to close it, yes |
This is another attempt to refactor and simplify the type system of TensorFlow Java, in reflection to what was previously discussed in the preview pull request #92 plus the ongoing discussion on #115 .
I think this new version supports most of the optimizations we were targeting and I plan to clean it up and, if possible, make smaller PR out of it for merging in our current snapshot, if everyone agrees with this approach. Breaking changes compared to the actual version (0.2.0) include:
org.tensorflow.typestensor.data()to convert a tensor handle to a data structure is no longer requiredDataTypehas been removed and theDataTypeproto, which is just an enum, is now used whenever neededTensorListandTensorMapthat also supports tensor type auto-casting (in progress)Here are a few before&after examples:
CC\ @deansher , @Craigacp