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
There is currently no Optimizer in the C++ API compared as the ones that we can find in the Python API.
It means, when using only the C++ API that we have to manually collect the gradients and apply them.
Don't you think it should be a convenient add? Retrieving the gradients and applying them is kind of hard and error prone. If yes, I could work on it and create an Optimizer + GradientDescentOptimizer in the C++ API.
Yes, the C++ (and other language) APIs lack many of the higher level Python conveniences right now.
(Side note: The gradient registry for all operations in C++ is not as comprehensive as Python, so there is work to be done there - for details see the link that @drpngx pointed to).
The TensorFlow team doesn't have the cycles to pursue this ourselves right now, but if you'd like to give it a shot we'd be happy to discuss any interfaces/design that you propose.
In python the Optimizer class provides a minimize method that calls compute_gradient and apply_gradient. compute_gradient adds the gradient ops to the graph, apply_gradient adds the apply ops to the graph and return an operation that applies the gradients.
The mains files are:
optimizer.py
gradient_descent.py
gradients_impl.py
In C++ some gradient operations are implemented. There is also a SymbolicGradientBuilder that applies the gradient operations to the graph. The missing part is the applying of the gradients.
The steps would be:
Create the Optimizer and GradientDescentOptimizer class
Use the SymbolicGradientBuilder in the ComputeGradient method
Add apply operations to the graph and return an operation in the ApplyGradient method
Hi @theflofly ! Your steps sounds reasonable in general. I would like to work on that but need guidance to start. Please contact if you are still interested in.
Hi @AhmetCanSolak, I am working on it and I made good progress even if it is not as easy as it sounds.
I don't see a way to split the task unfortunately. Especially at this point. Once the optimizer part is added, there will be plenty of work. Namely adding all the Optimizers (adam, adagrad, momentum, etc.). If you want I can ping you at this time and we'll share the work.
In the meantime, there is always the gradient operations that need to be ported.
Great. It is better idea to ping me when sharing tasks possible. Meanwhile I better check again the contribution guidelines since I have not contributed to TF yet.
Hello, this is a message to keep you updated. I think that I have a working version, I'll soon share the code. I still have a TODO list of minor things to do.
@GedisJ For now I am working on migrating the gradients from Python to C++ because one Operation without gradient in the graph means an untrainable network.
Because the node ApplyAdam already exists I think that adding Adam is not that hard. I'll take a look and keep you updated.
@theflofly this is true about gradients, I had to add some simple gradient operations myself, before they were introduced in 1.4 release.
regarding Adam the main thing I guess is adding slots implementation to base Optimizer from what I've seen in Python code, because in C++ this seems to be missing too.
The sad news is that someone from Google hasn't worked on a design.
The good news is that we've gotten better in terms of establishing a process so that design changes can be made without constantly waiting on someone at Google to drive it!
If there is interest in pushing this, then it would be great for the person interested to drive the TensorFlow RFC process, which involves writing a design proposal as a first step. This will allow the community and maintainers to see the full picture and make sure it's headed in the right direction, instead of having the design evolve through a series of one-off PRs.
I personally feel the ideal outcome would be that we'd have a path so that individual optimizer classes implemented in Python can be migrated to C++ so that the Python class becomes a trivial wrapper over the functionality exposed by the C API instead of having to duplicate logic in two languages. The work earlier this year to get the Python graph building libraries to be wrappers over the C API for graph construction should make this much easier than it would have been last year.
So, long story short: No plan/roadmap available yet, but contributions are welcome to make them! :)
@theflofly : I would have loved to have been, but I've since moved to other projects (and am no longer involved with TensorFlow on a daily basis) and am thus not a good person for this at the moment.
@ewilderj / @karmel should be able to find an appropriate sponsor.
Thanks @theflofly for keeping on us about this. If you put together an RFC for review, I can help as the sponsor to find appropriate reviewers, etc. (CC @alextp , @skye who might be good reviewers here)
Hi @theflofly , How is work doing? We also need the GradientDescentOptimizer in our project, but I didn't find it in the TF 2.0, hope your work merge into the TF.
Activity
drpngx commentedon May 11, 2017
I would recommend working with us to define the interface and design that looks like gradients. That would be a nice contribution!
Ideally, we would have a check that things don't go out of sync with python.
asimshankar commentedon May 11, 2017
Yes, the C++ (and other language) APIs lack many of the higher level Python conveniences right now.
(Side note: The gradient registry for all operations in C++ is not as comprehensive as Python, so there is work to be done there - for details see the link that @drpngx pointed to).
The TensorFlow team doesn't have the cycles to pursue this ourselves right now, but if you'd like to give it a shot we'd be happy to discuss any interfaces/design that you propose.
FYI @suharshs @skye @josh11b
theflofly commentedon May 11, 2017
Ok. I'll see how I can do things and I'll make proposals here. I'll surely contribute to the C++ gradients as you pointed it out.
theflofly commentedon May 24, 2017
My observations until now.
In python the Optimizer class provides a minimize method that calls compute_gradient and apply_gradient. compute_gradient adds the gradient ops to the graph, apply_gradient adds the apply ops to the graph and return an operation that applies the gradients.
The mains files are:
In C++ some gradient operations are implemented. There is also a SymbolicGradientBuilder that applies the gradient operations to the graph. The missing part is the applying of the gradients.
The steps would be:
What do you think?
AhmetCanSolak commentedon Jun 22, 2017
Hi @theflofly ! Your steps sounds reasonable in general. I would like to work on that but need guidance to start. Please contact if you are still interested in.
theflofly commentedon Jun 22, 2017
Hi @AhmetCanSolak, I am working on it and I made good progress even if it is not as easy as it sounds.
I don't see a way to split the task unfortunately. Especially at this point. Once the optimizer part is added, there will be plenty of work. Namely adding all the Optimizers (adam, adagrad, momentum, etc.). If you want I can ping you at this time and we'll share the work.
In the meantime, there is always the gradient operations that need to be ported.
AhmetCanSolak commentedon Jun 22, 2017
Great. It is better idea to ping me when sharing tasks possible. Meanwhile I better check again the contribution guidelines since I have not contributed to TF yet.
Moriadry-zz commentedon Jun 25, 2017
@theflofly Do you have any ideas about bringing automatic differentiation (gradients) to C++ API?
also, If any help needed, you can ping me:)
theflofly commentedon Jun 25, 2017
@moriadry AD is already here.
Will add the gradient operations to the graph. You can find more example here. https://github.com/tensorflow/tensorflow/blob/master/tensorflow/cc/framework/gradients_test.cc
The goal of this issue is mainly about the update part. If you want to add some gradients you can follow these guidelines.
Does this answer?
Moriadry-zz commentedon Jun 26, 2017
@theflofly ok, your answer looks like making sense, I will try to figure that out. thank you!
theflofly commentedon Jul 6, 2017
Hello, this is a message to keep you updated. I think that I have a working version, I'll soon share the code. I still have a TODO list of minor things to do.
12 remaining items
theflofly commentedon Dec 4, 2017
@GedisJ For now I am working on migrating the gradients from Python to C++ because one Operation without gradient in the graph means an untrainable network.
Because the node
ApplyAdamalready exists I think that adding Adam is not that hard. I'll take a look and keep you updated.gedas256 commentedon Dec 4, 2017
@theflofly this is true about gradients, I had to add some simple gradient operations myself, before they were introduced in 1.4 release.
regarding Adam the main thing I guess is adding slots implementation to base Optimizer from what I've seen in Python code, because in C++ this seems to be missing too.
epignatelli commentedon Dec 2, 2018
Reviving this old thread in connection with #11377.
Is there any plan / road map publicly available to keep track and contribute to this?
theflofly commentedon Dec 8, 2018
I would also be interested.
The work I began to do was in the end discarded and I never heard back from someone at Google about working on a design...
asimshankar commentedon Dec 11, 2018
Thanks for reviving this thread.
The sad news is that someone from Google hasn't worked on a design.
The good news is that we've gotten better in terms of establishing a process so that design changes can be made without constantly waiting on someone at Google to drive it!
If there is interest in pushing this, then it would be great for the person interested to drive the TensorFlow RFC process, which involves writing a design proposal as a first step. This will allow the community and maintainers to see the full picture and make sure it's headed in the right direction, instead of having the design evolve through a series of one-off PRs.
I personally feel the ideal outcome would be that we'd have a path so that individual optimizer classes implemented in Python can be migrated to C++ so that the Python class becomes a trivial wrapper over the functionality exposed by the C API instead of having to duplicate logic in two languages. The work earlier this year to get the Python graph building libraries to be wrappers over the C API for graph construction should make this much easier than it would have been last year.
So, long story short: No plan/roadmap available yet, but contributions are welcome to make them! :)
FYI @ewilderj
theflofly commentedon Feb 20, 2019
Thanks for your answer @asimshankar, in the case of a RFC process do you accept being the RFC sponsor?
ewilderj commentedon Feb 20, 2019
cc @karmel
asimshankar commentedon Feb 20, 2019
@theflofly : I would have loved to have been, but I've since moved to other projects (and am no longer involved with TensorFlow on a daily basis) and am thus not a good person for this at the moment.
@ewilderj / @karmel should be able to find an appropriate sponsor.
karmel commentedon Feb 21, 2019
Thanks @theflofly for keeping on us about this. If you put together an RFC for review, I can help as the sponsor to find appropriate reviewers, etc. (CC @alextp , @skye who might be good reviewers here)
theflofly commentedon Feb 25, 2019
Thanks @asimshankar, @karmel.
I will work on something then, but bear with me I am quite busy at the moment.
cj741 commentedon Dec 4, 2019
Hi @theflofly , How is work doing? We also need the GradientDescentOptimizer in our project, but I didn't find it in the TF 2.0, hope your work merge into the TF.
github-actions commentedon Mar 28, 2023
This issue is stale because it has been open for 180 days with no activity. It will be closed if no further activity occurs. Thank you.
github-actions commentedon Mar 29, 2024
This issue was closed because it has been inactive for 1 year.