-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Add integer data types to IsTrainable for use with custom gradients #25386
Comments
This is a cool use case, but unfortunately I think is too large a project to take on at this time. I think this would be a difficult feature to fully implement, because we'd have to make sure that every integer operation has a proper gradient function defined. Gradient functions are currently written with the assumption that we don't need to handle integers (e.g. we always return None for the indices param of a gather op). The result of this is, without careful auditing and/or testing, many gradients() calls over integers would silently return None or even the wrong answer. This is a big enough feature that we'd probably want close collaboration with someone on the TF team. If there's enough demand in the future it might be worth the effort, but for now I don't think we can properly deliver on this. cc @alextp @ebrevdo @martinwicke -- maybe I'm missing something that makes this more tractable? |
I agree with @skye . It might be easier for you to bypass TF's gradient code entirely if you want to go this route, since our ops have gradients which don't behave well at all with integers. |
@skye to understand the problem better and out of curiosity, would you mind pointing to a place where the assumption on returning None is used? |
Here's one I happen to run into recently: https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/array_grad.py#L410 |
I have this need for integer tensor and their gradients too ... it’s disappointing nothing seems to be happening with this, I think this will restrict future innovation in some interesting areas |
Hi @mohantym, thanks for the response. It's nice to see that the error is no longer being thrown, but unfortunately I don't think that suffices to consider this issue solved. In particular, the check that forces a jump out of the backprop logic seems to be the same, just moved to a new location here. Thus it's still not possible for integer-typed tensors to have non-None gradients, even when defined explicitly with a FWIW, I think my understanding of TF's goals & aims has evolved. I would not be surprised if this feature were considered a non-goal for the project. It's a relatively niche request. Anyway, I think Jax might be a bit better fit for something so experimental. |
@jvmncs ! |
Hi, Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base. The Tensorflow team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TensorFlow version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate. Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow space. |
System information
Describe the feature and the current behavior/state.
Currently, there are a limited number of DTypes usable with autograd (see
IsTrainable
and_IsBackpropagatable
below)tensorflow/tensorflow/python/ops/gradients_impl.py
Line 300 in 6631cd5
In particular, nodes with integer tensors automatically generate gradients of None, which breaks any call to
tf.gradients
. This is a reasonable assumption for usual practices in machine learning, however this prevents one from creating their own autograd system usingtf.custom_gradient
. I'd contend that, as a general purpose automatic differentiation library, TF should enable experimenting with such uses of its autograd system. This would be particularly useful when intending to perform automatic differentiation over rings or finite fields, which are often represented in computers as sets of consecutive integers (i.e.Z_p
).Will this change the current api? How?
This change shouldn't affect any standard usage of TensorFlow -- all autograd on floats will be unchanged. The only change will occur when calling autograd on graphs that compute integer arithmetic and similar.
Currently, performing
tf.gradients
on graphs with integer tensors will raise an unhandled error:Returns:
See #783 (comment) for other cases in which Ops can generate a
None
gradient.After implementing this feature, we'd return the following:
Who will benefit with this feature?
Anyone who wants to perform automatic differentiation on integer data types, as would be the case when operating in integer rings or finite fields.
Any Other info.
This request is motivated by the
tf-encrypted
project.The text was updated successfully, but these errors were encountered: