-
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
Tensor roll op implementation #14953
Conversation
Half migrated to tf.manip
Added compile script
fix namespace error
Fixed thread pooling issue that was due to a bad cost_per_unit parameter Also improved readability
DoRollV2 copies memory in groups instead of element by element. Not thoroughly tested yet. Polished DoRollV2 algorithm
Roll op GPU bug fix GPU bug fix Roll op GPU bug fix Roll op GPU fix Roll GPU test BUILD update
Fully remove roll op GPU code Remove compile_cpu.sh
Migrated to tf.manip Roll op registered Roll op uses InlinedVector Small improvements
Can one of the admins verify this patch? |
@yzhwang Thanks for the review! Just added the changes! |
@yzhwang Could you please take another look? |
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.
Thanks for the change! Both code and tests LGTM, just had some minor nits, all should be easy fix. Also please resolve on conflict in the BUILD file before you merge in the code.
@@ -0,0 +1,237 @@ | |||
# array_ops |
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.
Note that this file has been deleted with this commit, please do a sync:
d6326d7#diff-c35db0b1af76a093b0c04498d159994a
op { | ||
graph_op_name: "Roll" | ||
in_arg { | ||
name: "shift" |
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.
Please specify that the number of dimensions for both shift and axis.
tensorflow/core/kernels/roll_op.cc
Outdated
@@ -0,0 +1,334 @@ | |||
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. |
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.
2018?
tensorflow/core/kernels/roll_op.cc
Outdated
// offset = shift[j] + ... other offsets | ||
// offset - dim_range[j] = -threshold[j] + ... other offsets | ||
// thus we undo our previous offset as well as add a new offset of | ||
// -threshold[j] in one opperation |
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.
opperation->operation
@@ -0,0 +1,481 @@ | |||
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved. |
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.
2018
test::ExpectTensorEqual<string>(expected, *GetOutput(0)); | ||
} | ||
|
||
TEST_F(RollOpTest, DuplicateShifts_TwoD32) { |
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.
Consider switching duplicate to multi since you are testing combining multiple shifts on one axis.
EXPECT_TRUE(StringPiece(s.ToString()).contains("is out of range")) << s; | ||
} | ||
|
||
static Graph* RollGraph(const TensorShape& shape, int isd) { |
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.
What is isd here?
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'll add some comments to clarify. This also stands for inner shift dimension. Basically I shift the isd and all outer dimensions. When I benchmark with a 2-D tensor if isd=0 then since dimension 1 is on the inside of dimension 0, dimension 1 will not be shifted and dimension 0 will. If isd=1 then both dimension 1 and 0 get shifted. This allows me to compare performance between just shifting the outer dimension and shifting all dimensions.
tensorflow/core/ops/manip_ops.cc
Outdated
@@ -0,0 +1,67 @@ | |||
/* Copyright 2016 The TensorFlow Authors. All Rights Reserved. |
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.
2018 :-)
@@ -0,0 +1,126 @@ | |||
# Copyright 2015 The TensorFlow Authors. All Rights Reserved. |
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.
2018 :-)
Thanks for the review! Just added the last changes! |
Roll op: fixed BUILD file Roll op: api docs update
- updates goldens and fixes api compatibility issue - fixes python op test issue for windows - fixes makefile issues
@rmlarsen I think I fixed the failures. Can we run the checks again? |
Windows CMake checks were failing because numpy was on an older version that did not support np.roll on multiple shifts that was use to check the correctness of tf.manip.roll. manip_ops_test.py now checks for numpy version 1.12.0 before testing multiple shifts, otherwise it'll just test single shift roll.
@asimshankar thanks. Sorry I missed that you had already done an API review on this! |
Closes #10761
Added a tf.manip.roll op that works similarly to numpy's np.roll. This was a feature requested in #10761 and was marked as contributions welcome.
Usage:
Rolls the elements of a tensor by the offsets of
shift
along the dimensionsof
axis
. Elements that roll passed the last position will wrap aroundto the first.
For example:
shift:
shift[i]
specifies the number of places by which elements are shiftedalong the dimension specified by
axis[i]
. Negative shifts will roll theelements in the opposite direction.
axis:
axis[i]
specifies the dimension that the shiftshift[i]
should occur.if the same axis is referenced more than once, the total shift for that axis
will be the sum of all the shifts that belong to that axis.
output: Has the same shape and size as the input. The elements are shifted by
the offsets of
shift
along the dimensions ofaxis
.Unit tests:
Benchmarks:
I had made a pull request for this before but accidentally closed it