Skip to content

Conversation

@yf225
Copy link
Contributor

@yf225 yf225 commented Dec 9, 2019

Currently, both Conv{1,2,3}dOptions and ConvTranspose{1,2,3}dOptions are aliases of the ConvOptions<{1,2,3}> class, which causes confusion because the ConvOptions class has parameters such as transposed that shouldn't be exposed to the end user. (This has caused issues such as #30931.) This PR makes the following improvements:

  1. Rename the original torch::nn::ConvOptions<N> class to torch::nn::detail::ConvNdOptions<N> class, to signify that it's an implementation detail and should not be used publicly.
  2. Create new classes torch::nn::ConvOptions<N> and torch::nn::ConvTransposeOptions<N>, which have parameters that exactly match the constructor of torch.nn.Conv{1,2,3}d and torch.nn.ConvTranspose{1,2,3}d in Python API.

This PR is BC-breaking in the following way:

  • Conv{1,2,3}dOptions no longer has the transposed argument. Users should migrate their code to use ConvTranspose{1,2,3}d layers instead, if they have transposed originally set to true in Conv{1,2,3}dOptions. Note that ConvTranspose{1,2,3}d cannot be used in a Sequential module because Sequential module doesn't support modules with forward method that can take optional arguments. Users should create their own wrapper for ConvTranspose{1,2,3}d and have its forward method just accept a tensor, if they want to use it in a Sequential module.
    For example:
struct ConvTranspose2dWrapperImpl : public torch::nn::ConvTranspose2dImpl {
  using torch::nn::ConvTranspose2dImpl::ConvTranspose2dImpl;

  torch::Tensor forward(const torch::Tensor& input) {
    return torch::nn::ConvTranspose2dImpl::forward(input, c10::nullopt);
  }
};

TORCH_MODULE(ConvTranspose2dWrapper);

torch::nn::Sequential sequential(
  ConvTranspose2dWrapper(torch::nn::ConvTranspose2dOptions(3, 3, 4));

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 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

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 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@yf225 yf225 added the module: cpp Related to C++ API label Dec 12, 2019
yf225 pushed a commit that referenced this pull request Dec 12, 2019
…lasses (#31005)

Summary:
Currently, both `Conv{1,2,3}dOptions` and `ConvTranspose{1,2,3}dOptions` are aliases of the `ConvOptions<{1,2,3}>` class, which causes confusion because the `ConvOptions` class has parameters such as `transposed` that shouldn't be exposed to the end user. (This has caused issues such as #30931.) This PR makes the following improvements:
1. Rename the original `torch::nn::ConvOptions<N>` class to `torch::nn::detail::ConvNdOptions<N>` class, to signify that it's an implementation detail and should not be used publicly.
2. Create new classes `torch::nn::ConvOptions<N>` and `torch::nn::ConvTransposeOptions<N>`, which have parameters that exactly match the constructor of `torch.nn.Conv{1,2,3}d` and `torch.nn.ConvTranspose{1,2,3}d` in Python API.
Pull Request resolved: #31005

Differential Revision: D18898048

Pulled By: yf225

fbshipit-source-id: 7663d646304c8cb004ca7f4aa4e70d3612c7bc75
@yf225 yf225 added the module: bc-breaking Related to a BC-breaking change label Dec 12, 2019
yf225 pushed a commit that referenced this pull request Dec 12, 2019
…lasses (#31005)

Summary:
Currently, both `Conv{1,2,3}dOptions` and `ConvTranspose{1,2,3}dOptions` are aliases of the `ConvOptions<{1,2,3}>` class, which causes confusion because the `ConvOptions` class has parameters such as `transposed` that shouldn't be exposed to the end user. (This has caused issues such as #30931.) This PR makes the following improvements:
1. Rename the original `torch::nn::ConvOptions<N>` class to `torch::nn::detail::ConvNdOptions<N>` class, to signify that it's an implementation detail and should not be used publicly.
2. Create new classes `torch::nn::ConvOptions<N>` and `torch::nn::ConvTransposeOptions<N>`, which have parameters that exactly match the constructor of `torch.nn.Conv{1,2,3}d` and `torch.nn.ConvTranspose{1,2,3}d` in Python API.
Pull Request resolved: #31005

Differential Revision: D18898048

Pulled By: yf225

fbshipit-source-id: 7663d646304c8cb004ca7f4aa4e70d3612c7bc75
@facebook-github-bot
Copy link
Contributor

@yf225 merged this pull request in 49a5841.

facebook-github-bot pushed a commit that referenced this pull request Jan 15, 2020
…ow to use them in a Sequential module (#32223)

Summary:
Following changes in #31005.
Pull Request resolved: #32223

Differential Revision: D19415328

Pulled By: yf225

fbshipit-source-id: f6f74f10ba3b5cc7e1a92f8b02ea4c9747018ae8
wuhuikx pushed a commit to wuhuikx/pytorch that referenced this pull request Jan 30, 2020
…lasses (pytorch#31005)

Summary:
Currently, both `Conv{1,2,3}dOptions` and `ConvTranspose{1,2,3}dOptions` are aliases of the `ConvOptions<{1,2,3}>` class, which causes confusion because the `ConvOptions` class has parameters such as `transposed` that shouldn't be exposed to the end user. (This has caused issues such as pytorch#30931.) This PR makes the following improvements:
1. Rename the original `torch::nn::ConvOptions<N>` class to `torch::nn::detail::ConvNdOptions<N>` class, to signify that it's an implementation detail and should not be used publicly.
2. Create new classes `torch::nn::ConvOptions<N>` and `torch::nn::ConvTransposeOptions<N>`, which have parameters that exactly match the constructor of `torch.nn.Conv{1,2,3}d` and `torch.nn.ConvTranspose{1,2,3}d` in Python API.
Pull Request resolved: pytorch#31005

Differential Revision: D18898048

Pulled By: yf225

fbshipit-source-id: 7663d646304c8cb004ca7f4aa4e70d3612c7bc75
wuhuikx pushed a commit to wuhuikx/pytorch that referenced this pull request Jan 30, 2020
…ow to use them in a Sequential module (pytorch#32223)

Summary:
Following changes in pytorch#31005.
Pull Request resolved: pytorch#32223

Differential Revision: D19415328

Pulled By: yf225

fbshipit-source-id: f6f74f10ba3b5cc7e1a92f8b02ea4c9747018ae8
ttumiel pushed a commit to ttumiel/pytorch that referenced this pull request Mar 4, 2020
…ow to use them in a Sequential module (pytorch#32223)

Summary:
Following changes in pytorch#31005.
Pull Request resolved: pytorch#32223

Differential Revision: D19415328

Pulled By: yf225

fbshipit-source-id: f6f74f10ba3b5cc7e1a92f8b02ea4c9747018ae8
@facebook-github-bot facebook-github-bot deleted the fix_conv_options branch July 13, 2020 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: bc-breaking Related to a BC-breaking change module: cpp Related to C++ API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants