Repository navigation
Add unsortedsegment(prod/min/max/sqrt_n/mean). - #15858
Conversation
|
Can one of the admins verify this patch? |
|
What
4 Oca 2018 23:09 tarihinde "Tensorflow Jenkins" <[email protected]>
yazdı:
… Can one of the admins verify this patch?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#15858 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APamuW3YLn30uY6xiS9OZ5o3sxjq4Coyks5tHS-SgaJpZM4RTgLn>
.
|
77df5e8 to
6963bb2
Compare
|
I rebased and updated the golden API, this should fix the test failures. |
|
Hey Phil Thanks for those updates needed them for some ray-tracing operations. In addition I also need the argmax/argmin operations. Could you direct me how I could add those operations. Cheers |
525f13b to
6195ce9
Compare
@ub216 Do you want to implement this as a native op or are you fine with a composition of native ops? For the composition you could take a look at the implementation of the gradient of unsorted_segment_max. I.e. something like this should work (untested): In any case, I think this is not the right thread to discuss this, if you're interested in implementing this as a cpp op I suggest to open a feature request issue to discuss it there ;) |
|
Apologies for crashing the thread. Will start a new thread for the cpp op and thanks for the composition of ops. |
|
@PhilJd Great work! Do you think it is possible to have an unsorted_segment_matmul op within your framework? |
|
@PhilJd you have to install Python 2.7 and run the api_compatibility test to add golden's with it, I believe. |
|
@PhilJd Sorry for the delay. I'll review this within the next couple of days. |
|
@rmlarsen @mehmetbasbug |
|
@PhilJd in the virtual environment you may need to rerun configure, rebuild and then run the commands. |
|
@PhilJd could you also please rebase to resolve the conflicts? |
6195ce9 to
eaa7643
Compare
|
@rmlarsen @gunan I'm a bit clueless regarding the build failures (see below). These tests build and run fine locally on two different machines (Ubuntu 16.04 and Arch Linux, python2/3, w. CUDA 9 and CUDNN 7, Pascal GPUs). Do the test servers run with cuda_arch < 600? This is handled separately, however, I didn't touch these lines. Cheers |
|
Okay, I was just too tired yesterday to remember that the complex specialization for atomicAdd relies on the double specialization. I switched the order, i.e. moved the complex specialization below the special case for double and cuda_arch < 600. Now compilation for cuda_arch 5.1 works. Sorry for the confusion! Could you trigger the tests again? Thanks! |
rmlarsen
left a comment
There was a problem hiding this comment.
Apart from a few nits, this PR looks excellent to me. Thanks a lot for this contribution!
| #include "tensorflow/core/framework/tensor.h" | ||
| #include "tensorflow/core/framework/tensor_shape.h" | ||
| #include "tensorflow/core/framework/tensor_types.h" | ||
| #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" |
There was a problem hiding this comment.
Nit: The Eigen include should usually go first. It doesn't strictly need to here, but many times we've seen bugs because somebody would would set Eigen-related macros after unknowingly including "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" through a transitively include.
| // reduction functors for the gpu | ||
| template <typename T> | ||
| struct SumOpGpu { | ||
| __device__ __forceinline__ void operator()(T* dest, const T& value) { |
There was a problem hiding this comment.
Prefer EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE to __device__ __forceinline__. Same everywhere.
|
@PhilJd would you consider adding support for fp16 (DT_HALF) and bfloat16 (DT_BFLOAT16)? Could be done as a followup PR. |
|
|
||
| template <typename T> | ||
| struct Lowest { | ||
| inline T operator()() const { return std::numeric_limits<T>::lowest(); } |
There was a problem hiding this comment.
Prefer Eigen::numext version instead - they have better support for 16-bit floating point types. Speaking of which, it would be awesome if this PR also supported those types for these new operations.
There was a problem hiding this comment.
It's in Eigen::NumTraits<T> - sorry that I mislead you in our internal chat, Erich :-)
See my comment.
rmlarsen
left a comment
There was a problem hiding this comment.
Apart from a few nits, this PR looks excellent to me. Thanks a lot for this contribution!
|
|
||
| template <typename T> | ||
| struct Lowest { | ||
| inline T operator()() const { return std::numeric_limits<T>::lowest(); } |
There was a problem hiding this comment.
If instead of using numeric_limits here, you used the equivalent functions from Eigen
Eigen::NumTraits<T>::highest() and Eigen::NumTraits<T>::lowest()
the code would handle DT_HALF and DT_BFLOAT16 correctly. See, e.g., https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/quantization_utils.h#L74
|
Thanks for the comments! |
This commit adds CPU/GPU implementations for prod/min/max ops and python implementations for mean/sqrt_n. Also, it adapts and unifies the corresponding tests of all unsorted reductions. Note: The new gradient of unsorted_segment_max fixes the crash occuring when negative indices on CPU are used.
…s the std::complex specialization of atomicAdd below the double specialization of atomicAdd for cuda_arch 600.
238dc3a to
e9dd60f
Compare
|
@PhilJd Thanks a lot for adding partial support for additional types! We can certainly leave complete support for bfloat16 for a future change. |
| a different number of elements. Therefore we consider three cases: | ||
| 1) A segment input contains no zeros and we can safely divide by the input | ||
| tensor. | ||
| 2) A segment contains exactly on zero. Then the gradient of each input of |
| 2) A segment contains exactly on zero. Then the gradient of each input of | ||
| the segment is zero except for the 0-input, there the gradient is | ||
| the product of the remaining segment entries. | ||
| 3) A segment contains at least two zeros. The gradient is zero for all |
There was a problem hiding this comment.
Very nice. Thanks for documenting the algorithm carefully.
|
I'll look into the test failures tomorrow morning! |
|
The GPU CC build should be fixed, the failure of the Android Demo App seems unrelated (tar exited with 1). I'm not sure why Ubuntu Python3 PIP failed, I can't reproduce it locally... |
|
@PhilJd Thanks again for a great contribution! |
This pull request
tf.unsorted_segment_min,tf.unsorted_segment_prodand atf.unsorted_segment_max.tf.unsorted_segment_meantf.unsorted_segment_sqrt_nAdd support of
drop_negativesfortf.unsorted_segment_sum#13055 introduced silent dropping of negative values on the cpu.However, the gradient of e.g. unsorted_segment_sum used tf.gather
and therefore failed for negative indices on cpu.
I tried to simplify the code and to remove code duplication,
addressing this todo.
(Also I once filed an issue to add these ops but only now had time to finish it ;).)
Some notes on this pull request:
tf.gather returns zero on GPU for negative indices and raises an exception on
CPU. To overcome this, the current implementation masks negative indices and
sets them to zero later. This is of course not as efficient as the original gather.
Would it make sense to use something like
if "gpu" in op.device.lower():to rundifferent functions, depending on the device?
Instead of having a native op for mean/sqrt_n I added them in python.
Making them native would require two additional template arguments
(a functor to process the counter), resulting in more complicated code with
probably only minor performance improvement, if at all. In my quick
benchmarks, the python ops are nearly as fast as unsorted_segment_sum. However,
they use more memory than a native op would, due to creating a tensor of ones.
(bincount doesn't work here as it doesn't support negative indices)
I simply copy-pasted some atomicOp code in
cuda_kernel_helper.hinstead ofwriting this more nicely as for a short period there was a completely different
version of this file online and I wanted to check back with you before
doing something more sophisticated. What's the status of this?
Additionally, I guess the function
AccumulateIntoinsegment_reduction_ops_gpu.cu.cccould be removed? CudaAtomicAdd has specializations for complex types in
cuda_kernel_helper.h
Cheers,
Phil