Skip to content

Conversation

@nuka137
Copy link
Contributor

@nuka137 nuka137 commented Oct 12, 2019

Add torch::nn::LPPool1d module and functional support for the C++ API.

Related Issue: #25883

Reviewer: @yf225

Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

Thanks so much for the awesome work @nuka137! I left some minor comments.

};

/// `LPPoolOptions` specialized for 1-D lppool.
using LPPool1dOptions = LPPoolOptions<1>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should add template struct LPPoolOptions<1>; in torch/csrc/api/src/nn/options/pooling.cpp, similar to the other pooling options.

Copy link
Contributor Author

@nuka137 nuka137 Oct 14, 2019

Choose a reason for hiding this comment

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

Added template struct LPPoolOptions<1> to torch/csrc/api/src/nn/options/pooling.cpp.

template <size_t D, typename Derived>
void LPPoolImpl<D, Derived>::pretty_print(std::ostream& stream) const {
stream << std::boolalpha
<< "torch::nn::LPPool" << D << "d("
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be awesome to print norm_type as well, to match the Python version even better :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added norm_type to print.

avg_pool_options.stride(stride);
out = avg_pool1d(input.pow(norm_type), avg_pool_options);

return ((torch::sign(out) * torch::relu(torch::abs(out))) * (*kernel_size)[0]).pow(1. / norm_type);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that it might be easier to maintain Python version parity if we write this function in the following way:

Tensor out = avg_pool1d(
  input.pow(options.norm_type()),
  AvgPool1dOptions(options.kernel_size()).stride(options.stride()).padding(0).ceil_mode(options.ceil_mode()));

return (torch::sign(out) * relu(torch::abs(out))).mul((*kernel_size)[0]).pow(1. / norm_type);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it

template <size_t D>
struct LPPoolOptions {
LPPoolOptions(ExpandingArray<D> kernel_size)
: kernel_size_(kernel_size), stride_(kernel_size) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe norm_type is a non-optional argument for the LPPool1d constructor in Python version, and we should take it in LPPoolOptions's constructor as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I added norm_type as a non-optional argument.

LPPoolOptions(ExpandingArray<D> kernel_size)
: kernel_size_(kernel_size), stride_(kernel_size) {}

TORCH_ARG(float, norm_type) = 1.0f;
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe norm_type doesn't have a default value in Python version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed default value.

@yf225
Copy link
Contributor

yf225 commented Oct 14, 2019

@pytorchbot rebase this please

@nuka137
Copy link
Contributor Author

nuka137 commented Oct 14, 2019

@yf225

Thank you.
I fixed all issues you mentioned. Please review again.

Copy link
Contributor

@yf225 yf225 left a comment

Choose a reason for hiding this comment

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

@nuka137 Thanks so much for the awesome work! :D

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@yf225 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@yf225 merged this pull request in 9ea42f8.

facebook-github-bot pushed a commit that referenced this pull request Oct 28, 2019
Summary:
Add torch::nn::LPPool2d module and functional support for the C++ API.

Related Issue: #25883 #27800

Reviewer: yf225
Pull Request resolved: #28492

Differential Revision: D18109401

Pulled By: yf225

fbshipit-source-id: 5cedecb895d9d44c2167cdb3f6f758f3426b3497
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary:
Add torch::nn::LPPool1d module and functional support for the C++ API.

Related Issue: pytorch#25883

Reviewer: yf225
Pull Request resolved: pytorch#27800

Differential Revision: D18045040

Pulled By: yf225

fbshipit-source-id: e61fefe9efec3423f7a93dd1e946f3e380122927
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: cpp Related to C++ API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants