Skip to content

Conversation

@yf225
Copy link
Contributor

@yf225 yf225 commented Oct 14, 2019

Stack from ghstack:

Differential Revision: D18009044

Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Will Feng added 14 commits October 14, 2019 18:06
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
@yf225 yf225 requested review from ezyang and removed request for ebetica and goldsborough October 17, 2019 15:42
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
} else if (nonlinearity == torch::nn::init::Nonlinearity::LeakyReLU) {
} else if (c10::get_if<enumtype::kLeakyReLU>(&nonlinearity)) {
return std::sqrt(2.0 / (1 + pow(param, 2))); // NOLINT
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. If we ever add a new variant to the enum, will we then get an error saying we didn't handle all cases yet? If not, we should add a fallthrough case here...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah we should have a fallthrough case here - I will do it as part of the work for torch::nn::init::calculate_gain parity.

LeakyReLU
};

// This enum class is deprecated and will be removed in 1.5.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I wonder if we can statically warn in these cases... does C10_DEPRECATED work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that adding C10_DEPRECATED prevents the enum class from being used in some CI configs such as pytorch_macos_10_13_py3_test, hence breaking BC-support. For now I'll keep the comment instead.


#define COMPUTE_NONLINEARITY_ENUM(name) /* NOLINT(cppcoreguidelines-macro-usage) */ \
case Nonlinearity::name: \
TORCH_WARN( \
Copy link
Contributor

Choose a reason for hiding this comment

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

TORCH_WARN_ONCE?

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 do want people to move to the new enum style sooner than later, because the old style will be deprecated soon :D I think it's probably okay for the warning to be a bit more annoying here, since moving to the new style is minimal effort.

Will Feng added 3 commits October 18, 2019 02:05
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
Use c10::variant-based enums for Nonlinearity and FanMode

gh-metadata: pytorch pytorch 27933 gh/yf225/10/head
@facebook-github-bot
Copy link
Contributor

@yf225 merged this pull request in eb4bb00.

@facebook-github-bot facebook-github-bot deleted the gh/yf225/10/head branch October 28, 2019 22:22
thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary: Pull Request resolved: pytorch#27933

Test Plan: Imported from OSS

Differential Revision: D18009044

Pulled By: yf225

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants