Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[jit] Respect order of Parameters in rnn.py#18198

Closed
driazati wants to merge 6 commits into
pytorch:masterfrom
driazati:fix
Closed

[jit] Respect order of Parameters in rnn.py#18198
driazati wants to merge 6 commits into
pytorch:masterfrom
driazati:fix

Conversation

@driazati
Copy link
Copy Markdown
Contributor

@driazati driazati commented Mar 19, 2019

Previously to get a list of parameters this code was just putting them in the reverse order in which they were defined, which is not always right. This PR allows parameter lists to define the order themselves. To do this parameter lists need to have a corresponding function that provides the names of the parameters.

@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Mar 19, 2019
Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Sorry what exactly was the issue previously and what is the new behavior?

Comment thread torch/csrc/jit/script/init.cpp Outdated
ConstantParameterList(std::shared_ptr<Module> module)
: module_(std::move(module)) {}
ConstantParameterList(std::shared_ptr<Module> module, py::list params)
: module_(std::move(module)), params_(std::move(params)) {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe convert & store the params to std::string here ? i imagine that's less overhead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It'd be more since it would duplicate the strings, the py::list is just a thin wrapper around a Python list with the same reference semantics

Comment thread torch/nn/modules/rnn.py Outdated
return self._flat_weights

def _get_flat_weights_names(self):
all_weights = [[weight for weight in weights] for weights in self._all_weights]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

imo the 4 weight(s) on one line is kidn of confusing

Comment thread torch/nn/modules/rnn.py Outdated

def _get_flat_weights_names(self):
all_weights = [[weight for weight in weights] for weights in self._all_weights]
return [p for layerparams in all_weights for p in layerparams]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ditto with the two layerparams / ps

davidriazati added 2 commits March 21, 2019 11:15
@driazati
Copy link
Copy Markdown
Contributor Author

driazati commented Apr 2, 2019

@eellison clarified reasons in PR message

@driazati driazati requested review from eellison and suo April 4, 2019 17:18
Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks good, a little hard to follow.

Comment thread torch/nn/modules/rnn.py
@_parameter_list
def get_flat_weights(self):
def _get_flat_weights_names(self):
return [weight for weights in self._all_weights for weight in weights]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do you mean rewriting? This is hard to read

Comment thread torch/_jit_internal.py
Comment thread torch/csrc/jit/script/init.cpp
Comment thread test/test_jit.py
Copy link
Copy Markdown
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.

@driazati has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
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.

@driazati has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Copy Markdown
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.

@driazati has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@driazati merged this pull request in f543563.

zhangguanheng66 pushed a commit to zhangguanheng66/pytorch that referenced this pull request May 6, 2019
Summary:
Previously to get a list of parameters this code was just putting them in the reverse order in which they were defined, which is not always right. This PR allows parameter lists to define the order themselves. To do this parameter lists need to have a corresponding function that provides the names of the parameters.
Pull Request resolved: pytorch#18198

Differential Revision: D14966270

Pulled By: driazati

fbshipit-source-id: 59331aa59408660069785906304b2088c19534b2
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Previously to get a list of parameters this code was just putting them in the reverse order in which they were defined, which is not always right. This PR allows parameter lists to define the order themselves. To do this parameter lists need to have a corresponding function that provides the names of the parameters.
Pull Request resolved: pytorch#18198

Differential Revision: D14966270

Pulled By: driazati

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

Labels

oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants