Skip to content
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

Conv Shift Operator #4591

Merged
merged 6 commits into from
Oct 10, 2017
Merged

Conv Shift Operator #4591

merged 6 commits into from
Oct 10, 2017

Conversation

mkliegl
Copy link
Contributor

@mkliegl mkliegl commented Oct 4, 2017

This closes #4574 .

This is an unoptimized Eigen-based port of the existing code:

Examples of possible future optimizations include:

  • For M >> log N or N >> log M, it could make sense to use FFT to do circular convolution.
  • Instead of a loop over the batch dimension on the outside, it could be faster to do a batchwise operation inside the loop like out.col(i) = x.col(index) * y.col(j). This would make the most sense if we either had column-major storage order or if the batch dimension were last rather than first.

I would probably leave such optimizations to the future when we can profile an actual use case and see whether the improvements are worth it.

@dzhwinter Would you mind taking a look? This is my first PR to this repo - your feedback would be much appreciated!

@mkliegl mkliegl requested a review from dzhwinter October 4, 2017 18:04
@mkliegl
Copy link
Contributor Author

mkliegl commented Oct 4, 2017

I think this code does not work for GPU - I will try to fix that. For an overall review, it may be better to wait until that is done. (That said, this code will probably stay about the same for CPU, so I would appreciate feedback on that any time.)

Copy link
Contributor

@dzhwinter dzhwinter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great Job! Thanks for the detailed comments! There is only some pieces of code need to be fixed. :)

namespace paddle {
namespace operators {

using Tensor = framework::Tensor;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use using in the header file violate the google style, see the detail in Namespace

Do not use Namespace aliases at namespace scope in header files except in explicitly marked internal-only namespaces, because anything imported into a namespace in a header file becomes part of the public API exported by that file.

By the way, I think

using framework::Tensor;

is enough here.

Some old operators have a wrong guide, sorry for that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just see this comment by chance.

The Google style says:

Do not use Namespace aliases at namespace scope in header files

I think:

using Tensor = framework::Tensor

this usage does not violate the above Google style because it is just a type alias, not a namespace alias. But, I admit that using type alias in such a large scope is not a good thing, so you are right...

size_t y_width = y_dims[1];
size_t y_half_width = (y_width - 1) / 2;

// The below trades code duplication for efficiency (keeping the if
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!
An if condition inside a three-fold for loop will cost a lot of time.

Markus Kliegl added 5 commits October 10, 2017 00:23
Limitations:
- both gradient outputs must be specified and are always computed
- explicit for loops => could be optimized in various ways
  (e.g., different memory layout)
fix case when not all output gradients desired
@mkliegl
Copy link
Contributor Author

mkliegl commented Oct 10, 2017

@dzhwinter @lcy-seso

Thank you for the feedback! I moved the using code you mentioned into the *.cc file and wrote an initial GPU implementation. I also cleaned the code up a little bit. The code is not optimized much but passes the tests. I think it is ready to be merged.

@lcy-seso
Copy link
Contributor

This PR LGTM, quite clean and well commented~

Copy link
Contributor

@lcy-seso lcy-seso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@mkliegl mkliegl merged commit a281b38 into PaddlePaddle:develop Oct 10, 2017
@mkliegl mkliegl deleted the conv_shift branch October 10, 2017 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conv Shift Operator.
4 participants