Skip to content

Use c10::variant-based enums for Reduction #27942

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

Closed
wants to merge 44 commits into from

Conversation

yf225
Copy link
Contributor

@yf225 yf225 commented Oct 14, 2019

Stack from ghstack:

Differential Revision: D18202857

Will Feng added 5 commits October 14, 2019 18:06
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
@@ -90,7 +92,7 @@ struct TORCH_API TripletMarginLossOptions {
/// E. Riba et al. Default: False
TORCH_ARG(bool, swap) = false;
/// Specifies the reduction to apply to the output. Default: Mean
TORCH_ARG(Reduction::Reduction, reduction) = Reduction::Mean;
TORCH_ARG(10::variant<enumtype::kNone, enumtype::kMean, enumtype::kSum>, reduction) = torch::kMean;
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry I was looking if a PR of mine was in the list and found this PR which kind of concerns what I was doing :P I think you are missing a c here (should be c10) and in previous declarations too!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CarMiranda Thanks a lot for the catch! I just fixed it. After this PR is merged, I will do a sweep to change all torch::nn layers that use Reduction to use the corresponding variant type. :D

Will Feng added 20 commits October 15, 2019 12:23
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
@yf225 yf225 mentioned this pull request Oct 21, 2019
…div / mse_loss / binary_cross_entropy"

Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
// ```
// Tensor some_functional(
// const Tensor& input,
// const SomeOptions& options = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This smells wrong to me. Why don't you just take it by value? It's a very small struct.

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 updated the comment here and will do a sweep to take Options by value in all functionals in a follow-up PR. Although it doesn't fix the problem that TORCH_OPTIONS_CTOR_VARIANT_ARG3/TORCH_OPTIONS_CTOR_VARIANT_ARG4 try to address though :(

return torch::l1_loss(
input,
target,
c10::visit(enumtype::_reduction_get_enum{}, options.reduction()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of manually typing out c10::visit everywhere, why not come up with a good API for doing this and call that instead? Especially since _reduction_get_enum is underscored...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I added torch::enumtype::reduction_get_enum() API for this purpose :D

@ezyang
Copy link
Contributor

ezyang commented Oct 22, 2019

Can you say more about what "fix F::kl_div / mse_loss / binary_cross_entropy" means?

…div / mse_loss / binary_cross_entropy"

Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Will Feng added 2 commits October 28, 2019 15:21
…div / mse_loss / binary_cross_entropy"

Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
…div / mse_loss / binary_cross_entropy"

Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
@yf225 yf225 changed the title Use c10::variant-based enums for Reduction, and fix F::kl_div / mse_loss / binary_cross_entropy Use c10::variant-based enums for Reduction Oct 28, 2019
Will Feng added 8 commits October 28, 2019 16:27
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
@yf225
Copy link
Contributor Author

yf225 commented Oct 28, 2019

Can you say more about what "fix F::kl_div / mse_loss / binary_cross_entropy" means?

The original logic in F::kl_div / mse_loss / binary_cross_entropy doesn't match that of Python version. I moved the changes to another PR since it is not strictly related to the Reduction enum changes.

@yf225 yf225 requested a review from ezyang October 28, 2019 21:15
Use c10::variant-based enums for Reduction

gh-metadata: pytorch pytorch 27942 gh/yf225/11/head
@facebook-github-bot
Copy link
Contributor

@yf225 merged this pull request in e33b4b6.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants