Skip to content

Commit

Permalink
fix RMSProp one_dim_param_no_weight_decay
Browse files Browse the repository at this point in the history
  • Loading branch information
flytocc committed Apr 17, 2023
1 parent a283b51 commit d278df8
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions ppcls/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,26 +228,23 @@ def __init__(self,
def __call__(self, model_list):
# model_list is None in static graph
parameters = None
if len(self.no_weight_decay_name_list) > 0:
if model_list:
params_with_decay = []
params_without_decay = []
for m in model_list:
params = [p for n, p in m.named_parameters() \
if not any(nd in n for nd in self.no_weight_decay_name_list)]
params_with_decay.extend(params)
params = [p for n, p in m.named_parameters() \
if any(nd in n for nd in self.no_weight_decay_name_list) or (self.one_dim_param_no_weight_decay and len(p.shape) == 1)]
params_without_decay.extend(params)
for n, p in m.named_parameters():
if any(nd in n for nd in self.no_weight_decay_name_list) \
or (self.one_dim_param_no_weight_decay and len(p.shape) == 1):
params_without_decay.append(p)
else:
params_with_decay.append(p)
parameters = [{
"params": params_with_decay,
"weight_decay": self.weight_decay
}, {
"params": params_without_decay,
"weight_decay": 0.0
}]
else:
parameters = sum([m.parameters() for m in model_list],
[]) if model_list else None
opt = optim.RMSProp(
learning_rate=self.learning_rate,
momentum=self.momentum,
Expand Down

0 comments on commit d278df8

Please sign in to comment.