You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Java][Feature] Generating operation methods used to build a graph #7149
Is anyone already working on that feature? If not, I'm tempted to try it. I was thinking of generating a builder hierarchy that allows to optionally set an argument after adding an operation. For example
GraphBuider
.matMul(a, b)
.withTransposeB(true)
.softmax(logits)
...
and the GraphBuilder classes would be generated at build time by Bazel and would make use of the already existing OperationBuilder. Since I'm new to Tensorflow, please tell me if that doesn't make any sense to you
Thanks
(p.s. as suggested by @drpngx, I've started this discussion as a seperate issue to avoid continuing the #5 saga)
Having generated code for ops in Java is indeed a next step for the Java API, but we haven't gotten around to it, or figuring out what an appropriate API would be.
We'd be happy to hear any suggestions/proposals you may have. As for the suggestion above, I don't think we want to put all operations as methods in a single GraphBuilder class for a few reasons such as (a) Per-op attribute handling seems a bit tricky, (b) What about custom operations defined by other external libraries (e.g. as per the Adding a new op HOWTO).
We can take inspiration from the generated C++ API (see the label_image example and the Go API, but it does require more thought.
I agree that exposing operations in their own particular object would create a richer API than declaring everything into a single builder class, I'll also get my mind into it.
Now, without insisting, I'll clarify how my suggestion would have handled point a), maybe some of those ideas can morph into something else:
The generated builder class implements each operations by returning a specialized builder that inherits this same class (e.g. GraphBuilder.matMul() returns a MatMulGraphBuilder that inherits GraphBuilder).
The specialized builder exposes all other operations directly from its superclass (for going on with graph building) + methods for setting optional attributes of the current operation, prefixed by "with" (e.g. withTransposeA() and withTransposeB()).
The specialized builder is responsible of building the current operation, using internally an OperationBuilder.
Invoking another operation on a specialized builder will therefore end the construction of the current operation and return another specialized builder for building the new operation.
Anyone curious to see how a static API for building a graph may look like, I've pushed a little POC to my repo (this commit) that minimally fulfill the requirements of the LabelImage example.
This POC focuses on the following point:
Group operations into related topics, like the C++ client does, by generating a static API per /tensorflow/core/ops/* library (e.g. ImageOps, ArrayOps, ...)
Allow optional parametrization using operation-specific methods encapsulated in their own classes (e.g. the DecodeJpeg interface)
Keep the simplicity and elegance of the solution from the previous version of LabelImage while allowing more flexibility to support all cases (e.g. multi-output operations, etc). The following lists supported technics to connect nodes together.
@karllessard and I (with guidance from @asimshankar) have consolidated ideas on this thread into a proposal for the API. We'd love to hear your feedback, so please continue to add comments on this issue.
We'd also like to help move things forward via code contributions, and Karl and I plan to start some related PRs. Please let us know if you're interested/working on something related, so we can jointly work to bring Java bindings for Tensorflow operators.
What is the current status of this issue? Is someone working on it and is it supposed to be resolved soon or is it a goal which lies far in the future?
It is still ongoing and actively being committed but it takes some time, there is a lot of code and iterations involved. Pull request #14094 is related to this story and is currently being reviewed by @asimshankar .
Reacted by Benjamin Wilhelm, Christian Tzolov and up-to-you
Activity
drpngx commentedon Jan 30, 2017
Thanks @karllessard! @asimshankar should know if that's in the plans or if it would be a welcome contribution.
asimshankar commentedon Jan 30, 2017
Having generated code for ops in Java is indeed a next step for the Java API, but we haven't gotten around to it, or figuring out what an appropriate API would be.
We'd be happy to hear any suggestions/proposals you may have. As for the suggestion above, I don't think we want to put all operations as methods in a single
GraphBuilderclass for a few reasons such as (a) Per-op attribute handling seems a bit tricky, (b) What about custom operations defined by other external libraries (e.g. as per the Adding a new op HOWTO).We can take inspiration from the generated C++ API (see the label_image example and the Go API, but it does require more thought.
karllessard commentedon Jan 31, 2017
I agree that exposing operations in their own particular object would create a richer API than declaring everything into a single builder class, I'll also get my mind into it.
Now, without insisting, I'll clarify how my suggestion would have handled point a), maybe some of those ideas can morph into something else:
The generated builder class implements each operations by returning a specialized builder that inherits this same class (e.g. GraphBuilder.matMul() returns a MatMulGraphBuilder that inherits GraphBuilder).
The specialized builder exposes all other operations directly from its superclass (for going on with graph building) + methods for setting optional attributes of the current operation, prefixed by "with" (e.g. withTransposeA() and withTransposeB()).
The specialized builder is responsible of building the current operation, using internally an OperationBuilder.
Invoking another operation on a specialized builder will therefore end the construction of the current operation and return another specialized builder for building the new operation.
karllessard commentedon Feb 6, 2017
Anyone curious to see how a static API for building a graph may look like, I've pushed a little POC to my repo (this commit) that minimally fulfill the requirements of the LabelImage example.
This POC focuses on the following point:
Group operations into related topics, like the C++ client does, by generating a static API per /tensorflow/core/ops/* library (e.g. ImageOps, ArrayOps, ...)
Allow optional parametrization using operation-specific methods encapsulated in their own classes (e.g. the DecodeJpeg interface)
Keep the simplicity and elegance of the solution from the previous version of LabelImage while allowing more flexibility to support all cases (e.g. multi-output operations, etc). The following lists supported technics to connect nodes together.
a) Functionally
b) By node references
c) By node lookups
Technics b) and c) allows us to access output value other than the default (0) one for multi-output operations. For example:
Any comments are more than welcomed
Merged commit includes the following changes:
Squashed commit of the following:
kbsriram commentedon May 23, 2017
@karllessard and I (with guidance from @asimshankar) have consolidated ideas on this thread into a proposal for the API. We'd love to hear your feedback, so please continue to add comments on this issue.
We'd also like to help move things forward via code contributions, and Karl and I plan to start some related PRs. Please let us know if you're interested/working on something related, so we can jointly work to bring Java bindings for Tensorflow operators.
Initial scope implementation.
Initial scope implementation.
Initial scope implementation.
Initial scope implementation.
7 remaining items
Add the Constant operator class
Add the Constant operator class
Add the Constant operator class (#11559)
Merge changes from github.
Skeleton code for annotation processor.
Skeleton code for annotation processor.
Skeleton code for annotation processor.
Skeleton code for annotation processor.
Skeleton code for annotation processor.
Skeleton code for annotation processor. (#12828)
HedgehogCode commentedon Dec 12, 2017
What is the current status of this issue? Is someone working on it and is it supposed to be resolved soon or is it a goal which lies far in the future?
karllessard commentedon Dec 12, 2017
It is still ongoing and actively being committed but it takes some time, there is a lot of code and iterations involved. Pull request #14094 is related to this story and is currently being reviewed by @asimshankar .
wt-huang commentedon Nov 8, 2018
Closing as this is resolved
Initial scope implementation.