-
Notifications
You must be signed in to change notification settings - Fork 214
Native functions v2 #233
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
Native functions v2 #233
Conversation
@karllessard my main issue now is that there is that the native functions don't work with our Optionally, we can just not allow variables in ConcreteFunction, as the |
Another issue I need some guidance on: when loading a bundle, functions may call other functions that are part of the bundle (at least when loading the Python bundle). This doesn't work when the functions are extracted with |
After digging a bit more: the way we import things from Python (it might be the Python exporting, not sure if it's us), the native functions are called w/ placeholder inputs, and the imported MetaGraphSignatures use the wrappers. So the underlying functions are fine, and I can extract and use them, but that will differ slightly from the current export/import semantics (anything special in the call ops won't be included, I don't think there's that much?). Creating new functions from the wrappers causes the dependency issues. Update: I can get the underlying functions from the call ops, but some are double wrapped and I can't unwrap that. I can get them via the signature names instead, which works, but is rather fragile. |
I'm starting to think we shouldn't use ConcreteFunction for loading and instead have |
Alright, dependencies are working. Of note, it correctly supports defining a Also of note, we can not support ops with We could then use It would also be good to do statefulness disambiguation at the op level where possible, i.e. for |
Attaching a gradient function with a function does not appear to work, plus it causes issues with dependencies since it requires using the op name call style. |
The only issue remaining with this PR is initialization (variable exporting/importing). If we agree to delay that and rework initialization using |
b90db9d
to
4a124cc
Compare
Gradients are working with tensorflow/tensorflow#47774 |
4a124cc
to
f46f8c7
Compare
I also pushed op generation and the generated ops for ops that use functions. Eventually these should take a DeFun equivalent instead of ConcreteFunction (#238 (comment)), but they will work fine for now. Versions that take the function builder lambdas would be nice to have as well, and should be possible, but require more complicated codegen (and the new function API). |
Thanks @rnett ! Again, is it possible to break down this PR into smaller pieces? For instance, we can probably make the changes to |
Yeah, I can pull out those changes. It'll get smaller once #232 gets merged, too. |
b033ba9
to
34cec0b
Compare
Should be down to a reasonable size now. I just need to add the "function views" to SavedModelBundle if you're ok with handling things that way. |
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.
Hey @rnett , just dropping a few comments so far but I've just started to review it, I'll add more comments soon
tensorflow-core/tensorflow-core-api/src/gen/annotations/org/tensorflow/op/Ops.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/bazel/op_generator/op_specs.cc
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/EagerSession.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/ConcreteFunction.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/SavedModelBundle.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/SavedModelBundle.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Session.java
Outdated
Show resolved
Hide resolved
...ore/tensorflow-core-api/src/main/java/org/tensorflow/internal/c_api/AbstractTF_Function.java
Outdated
Show resolved
Hide resolved
...core/tensorflow-core-api/src/main/java/org/tensorflow/internal/c_api/presets/tensorflow.java
Outdated
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/op/NameScope.java
Outdated
Show resolved
Hide resolved
123adfc
to
971e6b1
Compare
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.
Looks good @rnett ! Any chance you can revert the reformatting from your PR though? Only if it's easy for you to do.
Any chance of merging #308 first/soon? That's what I would use to do this. |
I guess we can merge it with these changes until we are set for a solution for reformatting. Can you rebase your PR though, there is a conflict there. |
Also, could you merge #248 first (I'll rebase it in a moment)? Most of the changes are in here anyways, but it's the more up to date version. |
971e6b1
to
6ac9a43
Compare
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
6ac9a43
to
cecf71d
Compare
Alright @karllessard, should be good to go. |
Hey @rnett , sorry for reviving an old debate but I'm wondering if we could play with the naming again... I know we are still in alpha but could be great to preserve some backward compatibility between our releases. For that, I would suggest the following name changes:
It make sense to me but does it to you? Basically a "concrete function" just mean a function that is "typed" and "realized" in Python, which make more or less sense in Java. Hence I'd be comfortable keeping it with my proposal. wdyt? Doing this users won't need to do much when migrating from 0.3.1. Again, not a blocker, just a proposal. |
That makes sense to me. Since I'm going to be adding more functional stuff, what do you think about moving all the function types to a |
Do you think you can create a separate package without opening too many package-private methods? |
Ugh, apparently not, there's too much use in |
But even in eager mode, the function created ends up being a graph that is executed "eagerly", no? So because of that, I think I don't dislike |
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/SavedModelBundleTest.java
Show resolved
Hide resolved
tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/SavedModelBundleTest.java
Show resolved
Hide resolved
Signed-off-by: Ryan Nett <[email protected]>
Signed-off-by: Ryan Nett <[email protected]>
Awesome job @rnett , thanks! |
Replaces #211. Status is mostly the same, I still need to handle saving and gradients. It's also based on #232 instead of
master
, so the diff will get smaller once it's merged.Currently the only ops forbidden in the body of functions is
Placeholder
. This could lead to somewhat weird situations when creating a function from a graph where you have something like:where even though
e
depends onc
andd
andc
is not listed as an input, the function would work fine sincec
can be calculated without any inputs.