提交 f36ffbc4 编写于 作者: Y Yang Nie 提交者: Tingquan Gao

fix

上级 a69bc945
...@@ -112,16 +112,16 @@ class Momentum(object): ...@@ -112,16 +112,16 @@ class Momentum(object):
def __call__(self, model_list): def __call__(self, model_list):
# model_list is None in static graph # model_list is None in static graph
parameters = None parameters = None
if len(self.no_weight_decay_name_list) > 0: if model_list:
params_with_decay = [] params_with_decay = []
params_without_decay = [] params_without_decay = []
for m in model_list: for m in model_list:
params = [p for n, p in m.named_parameters() \ for n, p in m.named_parameters():
if not any(nd in n for nd in self.no_weight_decay_name_list)] if any(nd in n for nd in self.no_weight_decay_name_list) \
params_with_decay.extend(params) or (self.one_dim_param_no_weight_decay and len(p.shape) == 1):
params = [p for n, p in m.named_parameters() \ params_without_decay.append(p)
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)] else:
params_without_decay.extend(params) params_with_decay.append(p)
parameters = [{ parameters = [{
"params": params_with_decay, "params": params_with_decay,
"weight_decay": self.weight_decay "weight_decay": self.weight_decay
...@@ -129,9 +129,6 @@ class Momentum(object): ...@@ -129,9 +129,6 @@ class Momentum(object):
"params": params_without_decay, "params": params_without_decay,
"weight_decay": 0.0 "weight_decay": 0.0
}] }]
else:
parameters = sum([m.parameters() for m in model_list],
[]) if model_list else None
opt = optim.Momentum( opt = optim.Momentum(
learning_rate=self.learning_rate, learning_rate=self.learning_rate,
momentum=self.momentum, momentum=self.momentum,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册