-
Notifications
You must be signed in to change notification settings - Fork 536
Gradient tests which were dependant only on cached_session #1173
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
Gradient tests which were dependant only on cached_session #1173
Conversation
var y = tf.identity(x); | ||
var dy_indices = tf.placeholder(TF_DataType.TF_INT32); | ||
var dy_values = tf.placeholder(TF_DataType.TF_FLOAT); | ||
Tensor dy = new IndexedSlices(dy_values, dy_indices); |
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.
@Wanglongzhi2001 this one fails because IndexedSlices
has null
shape. Should I create an issue?
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.
After comparing the implementations of TensorFlow and TensorFlow.NET, it seems that TensorFlow.NET just simpley does not throw error when dense_shape is null.
https://github.com/tensorflow/tensorflow/blob/704c1918a05574215d0499a74905f9a43fab01d5/tensorflow/python/framework/indexed_slices.py#L435-L438
I'm sorry that I'm not very familiar with tf1, is it correct to use IndexSlice in your example? Or users need to manually pass in the dense_shape parameter? After all, in most case in tensorflow, dense_shape is manually passed in.
https://github.com/tensorflow/tensorflow/blob/704c1918a05574215d0499a74905f9a43fab01d5/tensorflow/python/client/session_test.py#L884-L920
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.
I just ported an existing test from TensorFlow. You may that this code was commented before.
The problem is in conversion from IndexedSlices
to Tensor
. Python TensorFlow doesn't have any restrictions on gradients interface and it looks like it converts IndexedSlices
internally in a different way. I'm trying to run Python TensorFlow tests now to compare, but it is not easy to configure them for the first time.
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.
This is what's really going on here:
IndexedSlices
actually is a CompositeTensor
.
If we go to _GradientsHelper
we'll find out that it shoud be able to convert CompositeTensor
to Tensor
by its own rules.
https://github.com/tensorflow/tensorflow/blob/8fcc1b465a354c2277dc84b7503443013c693541/tensorflow/python/ops/gradients_util.py#L535
In other words gradients
conditionally should support the following signature:
public (Tensor | CompositeTensor)[] gradients((Tensor | CompositeTensor)[] ys,
(Tensor | CompositeTensor)[] xs,
(Tensor | CompositeTensor)[] grad_ys = null,
...);
Where (Tensor | CompositeTensor)
is an abstract union type.
However, it is not implemented yet.
if (src_graph == null) |
The code is just skipped.
So, I just commented and marked the test as "TODO".
I can also leave a comment in
gradients
if necessary.
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.
I'm agree with you. And it seems that the implementation of CompositeTensor is a relatively big feature. So it may not be implemented in the near future. Anyway, really thank you for your contribution. ^_^
|
||
var a = functionOf(Array.Empty<Tensor>(), 3); |
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.
@Wanglongzhi2001 this one fails because created Tensor
s have null
in their op
field. Should I create an issue?
// tf.Graph().as_default(); | ||
// var x = tf.constant(1.0, shape: new long[] { 2, 2 }); | ||
// var y = tf.constant(3.0, shape: new long[] { 3, 1 }); | ||
// var grads = tf.gradients(new[] { y }, new[] { x }, unconnected_gradients: "zero"); |
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.
@Wanglongzhi2001 there's no unconnected_gradients
parameter here yet.
LGTM @Oceania2018 |
testAggregationMethodAccumulateN
testAggregationMethodAddN
testAggregationMethodTree
testSingletonIndexedSlices - broken
testDependentYs
testPartialDerivatives
testStopGradients - broken