Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

support setattr for some specified paramter of ParameterDict #9323

Closed
wants to merge 1 commit into from
Closed

support setattr for some specified paramter of ParameterDict #9323

wants to merge 1 commit into from

Conversation

tornadomeet
Copy link
Contributor

@tornadomeet tornadomeet commented Jan 5, 2018

Description

Somewhat similar with fixed_param_names in mx.mod.Module(), which can set attr of some specified paramter.

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Comments

selected_param_names may be not a good parameter name, better name is welcome.

@piiswrong
Copy link
Contributor

this can be done with a simple two line loop by the user. I don't think its worth adding an argument

@tornadomeet
Copy link
Contributor Author

tornadomeet commented Jan 6, 2018

@piiswrong if we only set one attr, then we need some code like this(not concise):

all_params = net.collect_params()
fixed_params = [###]
for k, v in all_params.items():
    if k in all_params.keys():
       setattr(v, 'grad_req', 'null')

but, if we need set others attrs in the same project, such as change lr_mult, wd_mult, we need this code again, of course we can write a function to do this, but in that case why not just support this function in gluon api for better experience.

@tornadomeet tornadomeet changed the title support setattr of some specified paramter of ParameterDict support setattr for some specified paramter of ParameterDict Jan 6, 2018
if selected_param_names == "all":
selected_param_names = self.keys()
elif isinstance(selected_param_names, str):
selected_param_names = [selected_param_names]
Copy link
Member

Choose a reason for hiding this comment

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

"all" can be a valid parameter name.

Copy link
Contributor Author

@tornadomeet tornadomeet Jan 7, 2018

Choose a reason for hiding this comment

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

agree, '"all" is bad here.

@szha
Copy link
Member

szha commented Jan 7, 2018

I agree with Eric that this option probably isn't worth adding. This option is hidden and the semantic meaning isn't that straightforward, and it only saves 4 lines at best.

Another option is to add selection functionality to collect_params, such as by name regex or name list.

@tornadomeet
Copy link
Contributor Author

tornadomeet commented Jan 7, 2018

@szha how about add select_params() for class Block? so that we can do like this:

net.select_params(net.collect_params(), ['conv1_weigh', 'conv1_bias'].setattr('gred_req', 'null')

if that's fine, i'll add it.

@szha
Copy link
Member

szha commented Jan 7, 2018

I think selecting params is not the concern of a block, but that of the block's param dict. Since collect_params is already the interface for getting parameters, having selection/filtering functionality there feels natural.

@tornadomeet
Copy link
Contributor Author

do you mean add regex or name-list as a parameter of collect_params()?

@szha
Copy link
Member

szha commented Jan 7, 2018

Yes

@tornadomeet
Copy link
Contributor Author

ok, got it, i'll try.

@tornadomeet tornadomeet closed this Jan 7, 2018
@tornadomeet tornadomeet deleted the open branch January 7, 2018 08:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants