From fb12491836c68f6eabed5437f78d9e6c274588e7 Mon Sep 17 00:00:00 2001 From: xiaoda99 Date: Sun, 18 Nov 2018 16:16:21 +0800 Subject: [PATCH] Fix ineffective no_decay bug --- examples/run_classifier.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/run_classifier.py b/examples/run_classifier.py index 75692ef39e1d7f..204d2d6a7beaa3 100644 --- a/examples/run_classifier.py +++ b/examples/run_classifier.py @@ -503,8 +503,8 @@ def main(): param_optimizer = list(model.named_parameters()) no_decay = ['bias', 'gamma', 'beta'] optimizer_grouped_parameters = [ - {'params': [p for n, p in param_optimizer if n not in no_decay], 'weight_decay_rate': 0.01}, - {'params': [p for n, p in param_optimizer if n in no_decay], 'weight_decay_rate': 0.0} + {'params': [p for n, p in param_optimizer if not any(nd in n for nd in no_decay)], 'weight_decay_rate': 0.01}, + {'params': [p for n, p in param_optimizer if any(nd in n for nd in no_decay)], 'weight_decay_rate': 0.0} ] optimizer = BertAdam(optimizer_grouped_parameters, lr=args.learning_rate,