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

[C++ API] Fix clip_grad_norm_ / clip_grad_value_ to take input by value instead of by non-const ref #30216

Closed
wants to merge 4 commits into from

Conversation

yf225
Copy link
Contributor

@yf225 yf225 commented Nov 21, 2019

The original design of torch::nn::utils::clip_grad_norm_ / clip_grad_value_ takes input by non-const reference, which prevents users from passing rvalue reference as input into the functions. This PR changes the functions to take input by value, which 1. fixes the problem, 2. matches the Python version's semantics, 3. adheres to the C++ API convention that if a function modifies its input in-place, it should take that input by value.

@yf225 yf225 requested review from pbelevich and removed request for ebetica and goldsborough November 21, 2019 03:44
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 merged module: cpp Related to C++ API labels Nov 22, 2019
@facebook-github-bot facebook-github-bot deleted the cpp_fix_nn_utils_input_type branch July 13, 2020 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: cpp Related to C++ API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants