From c64a142ceaef016020961a50aff8359cc76bde83 Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Tue, 23 May 2017 17:23:54 +0800 Subject: [PATCH] change the way of setting threshold --- paddle/parameter/FirstOrderOptimizer.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/paddle/parameter/FirstOrderOptimizer.cpp b/paddle/parameter/FirstOrderOptimizer.cpp index 826864b99..d82926016 100644 --- a/paddle/parameter/FirstOrderOptimizer.cpp +++ b/paddle/parameter/FirstOrderOptimizer.cpp @@ -310,18 +310,14 @@ void OptimizerWithGradientClipping::update(const VectorPtr vecs[], real threshold; std::string field; - // Get the minimum of local and global threshold - // as the real threshold for clipping - if (globalThreshold > 0.0f && localThreshold > 0.0f) { - threshold = - globalThreshold < localThreshold ? globalThreshold : localThreshold; - field = globalThreshold < localThreshold ? "global" : "local"; - } else if (globalThreshold > 0.0f) { - threshold = globalThreshold; - field = "global"; - } else { + // Use local gradient clipping threshold if it's enabled, + // otherwise using the global one. + if (localThreshold > 0.0f) { threshold = localThreshold; field = "local"; + } else { + threshold = globalThreshold; + field = "global"; } real maxAbsGrad = vecs[PARAMETER_GRADIENT]->getAbsMax(); -- GitLab