Repository navigation
Add support of drop_negatives for tf.unsorted_segment_sum - #13055
martinwicke merged 3 commits into
Conversation
|
Can one of the admins verify this patch? |
|
@yongtang, thanks for your PR! By analyzing the history of the files in this pull request, we identified @keveman, @tensorflower-gardener and @vrv to be potential reviewers. |
| bool drop_negatives = false; | ||
| OP_REQUIRES_OK(context, context->GetAttr("drop_negatives", &drop_negatives)); | ||
| if (drop_negatives) { | ||
| this->reduction_functor_ = &this->sum_with_drop_negatives_functor_; |
There was a problem hiding this comment.
Do we need this->? If not, please remove.
| }; | ||
|
|
||
| // Functor for UnsortedSegmentSumWithDropNegativesOp. | ||
| // 'output_rows': the number of output segments (unique segment ids in |
There was a problem hiding this comment.
Remove quotes unless they're there for consistency.
|
This will probably require an API review. At a high level, could we use |
22c3cb9 to
b415b8a
Compare
|
Thanks @drpngx for the review. I addressed some of the comments. For using However, I noticed that at the moment, the behavior of CPU and GPU is actually different. On CPU, negative indices will through out an error while on GPU negative indices will be ignored silently. In other words, on GPU the behavior of I am wondering if it make sense to just adjust the behavior on CPU so that negatives will be dropped? This will bring the behavior of GPU and CPU to the same without introducing another flag of Below is the output for GPU and CPU without this PR: Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> print tf.__version__
1.3.0
>>> with tf.device('/gpu:0'):
... v = tf.unsorted_segment_sum([1,2], [1, -1], 5)
KeyboardInterrupt
>>>
>>> import numpy as np
>>> with tf.device('/gpu:0'):
... v = tf.unsorted_segment_sum(np.asarray([1,2], dtype=np., [1, -1], 5)
KeyboardInterrupt
>>>
>>>
>>> with tf.device('/gpu:0'):
... v = tf.unsorted_segment_sum([1.0, 2.0], [1, -1], 5)
... tf.Session().run(v)
...
....
array([ 0., 1., 0., 0., 0.], dtype=float32)
>>> with tf.device('/cpu:0'):
... v = tf.unsorted_segment_sum([1.0, 2.0], [1, -1], 5)
... tf.Session().run(v)
...
2017-09-19 21:26:50.961788: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1055] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: Tesla K80, pci bus id: 0000:00:1e.0, compute capability: 3.7)
Traceback (most recent call last):
...
...
InvalidArgumentError (see above for traceback): segment_ids[1] = -1 is out of range [0, 5)
[[Node: UnsortedSegmentSum_1 = UnsortedSegmentSum[T=DT_FLOAT, Tindices=DT_INT32, _device="/job:localhost/replica:0/task:0/cpu:0"](UnsortedSegmentSum_1/data, UnsortedSegmentSum_1/segment_ids, UnsortedSegmentSum_1/num_segments)]]
>>> |
|
Requesting API review. To rephrase, see @yongtang comment: GPU and CPU behave differently, one dropping negatives and the other one doesn't. We can leave the behavior undefined until we use |
|
Since the behavior on GPU is I do not know whether we would still want the extra argument. Does anyone require |
This fix tries to address the issue raised in 478 by adding the support of `drop_negatives` for `tf.unsorted_segment_sum` so that it is possible to skip entries (when index = -1) This fix fixes 478. Signed-off-by: Yong Tang <[email protected]> Add test case for `drop_negatives` of `tf.unsorted_segment_sum` Signed-off-by: Yong Tang <[email protected]> Remove quote from comments. Signed-off-by: Yong Tang <[email protected]>
…matches. Signed-off-by: Yong Tang <[email protected]>
b415b8a to
c902776
Compare
|
Thanks @drpngx @martinwicke for the review. I updated the PR so that now negative indices will be dropped silently, bring in behaviors of GPU and CPU closer. I do notice another discrepancy between GPU and CPU. In GPU the bad index (> num_segments) are ignored as well while in CPU greater than num_segments will results in error. Not sure the best way to handle this situation. Any suggestions about that? |
|
Can you edit the docs in https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/ops/math_ops.cc#L1681 to point out the negative-dropping behavior? |
Signed-off-by: Yong Tang <[email protected]>
|
Thanks @martinwicke. The PR has been updated with the documentation added in |
|
Jenkins, test this please. |
|
I tried to produce locally for the python 3 failure |
|
Jenkins, test this please.
…On Sep 29, 2017 8:17 AM, "Yong Tang" ***@***.***> wrote:
I tried to produce locally for the python 3 failure
//tensorflow/contrib/learn:dnn_linear_combined_test but it works fine.
Maybe it is transient?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13055 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AT_SbTCvXSammRotSl5bmYQAqDYccMzJks5snQofgaJpZM4PYen7>
.
|
|
Approval for API review. |
|
Thanks all for the review. The Windows build failure is likely to be transient (didn't failure in the previous runs). I think a rerun might fix it. |
|
Jenkins, test this please. |
|
The |
|
Yes, but I still want to see it run. Jenkins, test this please. |
This fix tries to address the issue raised in #478 by adding the support of
drop_negativesfortf.unsorted_segment_sumso that it is possible to skip entries (when index = -1)This fix fixes #478.
Signed-off-by: Yong Tang [email protected]