-
Notifications
You must be signed in to change notification settings - Fork 6.8k
support setattr for some specified paramter of ParameterDict #9323
Conversation
this can be done with a simple two line loop by the user. I don't think its worth adding an argument |
@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 |
if selected_param_names == "all": | ||
selected_param_names = self.keys() | ||
elif isinstance(selected_param_names, str): | ||
selected_param_names = [selected_param_names] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 |
@szha how about add net.select_params(net.collect_params(), ['conv1_weigh', 'conv1_bias'].setattr('gred_req', 'null') if that's fine, i'll add it. |
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. |
do you mean add regex or name-list as a parameter of |
Yes |
ok, got it, i'll try. |
Description
Somewhat similar with
fixed_param_names
inmx.mod.Module()
, which can set attr of some specified paramter.Checklist
Essentials
make lint
)Comments
selected_param_names
may be not a good parameter name, better name is welcome.