From eb9ae55849df62aa9d7629aa7db3be8c92ad85df Mon Sep 17 00:00:00 2001 From: Yiqun Liu Date: Wed, 25 Nov 2020 21:11:00 +0800 Subject: [PATCH] Optimize the performance of piecewise_decay. (#29077) --- .../fluid/layers/learning_rate_scheduler.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/python/paddle/fluid/layers/learning_rate_scheduler.py b/python/paddle/fluid/layers/learning_rate_scheduler.py index 26f08a2356..68d69dd312 100644 --- a/python/paddle/fluid/layers/learning_rate_scheduler.py +++ b/python/paddle/fluid/layers/learning_rate_scheduler.py @@ -425,16 +425,18 @@ Applies piecewise decay to the initial learning rate. dtype='float32', value=float(boundaries[i]), force_cpu=True) - value_var = tensor.fill_constant( - shape=[1], dtype='float32', value=float(values[i])) with switch.case(global_step < boundary_val): - tensor.assign(value_var, lr) - last_value_var = tensor.fill_constant( - shape=[1], - dtype='float32', - value=float(values[len(values) - 1])) + tensor.fill_constant( + shape=[1], + dtype="float32", + value=float(values[i]), + out=lr) with switch.default(): - tensor.assign(last_value_var, lr) + tensor.fill_constant( + shape=[1], + dtype="float32", + value=float(values[len(values) - 1]), + out=lr) return lr -- GitLab