From 4aaac74e6f5e7b029af19ba2b7317e1fbc17e318 Mon Sep 17 00:00:00 2001 From: Parichay Kapoor Date: Thu, 9 Dec 2021 20:52:48 +0900 Subject: [PATCH] [optimizer] prepare for learning rate scheduler Move declaration and definition of learning rate related properties out to common properties from optimizer_impl class. Signed-off-by: Parichay Kapoor --- nntrainer/layers/common_properties.h | 31 ++++++++++++++++++++++++++++ nntrainer/optimizers/optimizer_impl.cpp | 6 ++++-- nntrainer/optimizers/optimizer_impl.h | 36 +++------------------------------ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/nntrainer/layers/common_properties.h b/nntrainer/layers/common_properties.h index e67c5c3..7bef681 100644 --- a/nntrainer/layers/common_properties.h +++ b/nntrainer/layers/common_properties.h @@ -1109,6 +1109,37 @@ public: using prop_tag = float_prop_tag; /**< property type */ }; +/** + * @brief Learning Rate props + * + */ +class LearningRate : public Property { +public: + static constexpr const char *key = + "learning_rate"; /**< unique key to access */ + using prop_tag = float_prop_tag; /**< property type */ +}; + +/** + * @brief Decay rate property + * + */ +class DecayRate : public Property { +public: + static constexpr const char *key = "decay_rate"; /**< unique key to access */ + using prop_tag = float_prop_tag; /**< property type */ +}; + +/** + * @brief decay steps property + * + */ +class DecaySteps : public PositiveIntegerProperty { +public: + static constexpr const char *key = "decay_steps"; /**< unique key to access */ + using prop_tag = uint_prop_tag; /**< property type */ +}; + } // namespace props } // namespace nntrainer diff --git a/nntrainer/optimizers/optimizer_impl.cpp b/nntrainer/optimizers/optimizer_impl.cpp index 305c983..93dd62c 100644 --- a/nntrainer/optimizers/optimizer_impl.cpp +++ b/nntrainer/optimizers/optimizer_impl.cpp @@ -12,10 +12,11 @@ * */ +#include #include #include -#include +#include #include #include #include @@ -25,7 +26,8 @@ namespace nntrainer { OptimizerImpl::OptimizerImpl() : - optimizer_impl_props(PropsLR(), PropsDecayRate(), PropsDecaySteps()) {} + optimizer_impl_props(props::LearningRate(), props::DecayRate(), + props::DecaySteps()) {} void OptimizerImpl::setProperty(const std::vector &values) { auto left = loadProperties(values, optimizer_impl_props); diff --git a/nntrainer/optimizers/optimizer_impl.h b/nntrainer/optimizers/optimizer_impl.h index 81cc996..22c6870 100644 --- a/nntrainer/optimizers/optimizer_impl.h +++ b/nntrainer/optimizers/optimizer_impl.h @@ -18,43 +18,12 @@ #include -#include +#include #include namespace nntrainer { /** - * @brief Learning Rate props - * - */ -class PropsLR : public Property { -public: - static constexpr const char *key = - "learning_rate"; /**< unique key to access */ - using prop_tag = float_prop_tag; /**< property type */ -}; - -/** - * @brief Decay rate property - * - */ -class PropsDecayRate : public Property { -public: - static constexpr const char *key = "decay_rate"; /**< unique key to access */ - using prop_tag = float_prop_tag; /**< property type */ -}; - -/** - * @brief decay steps property - * - */ -class PropsDecaySteps : public PositiveIntegerProperty { -public: - static constexpr const char *key = "decay_steps"; /**< unique key to access */ - using prop_tag = uint_prop_tag; /**< property type */ -}; - -/** * @class Optimizer Base class for optimizers * @brief Basic implementation class for nntrainer supported optimizers */ @@ -120,7 +89,8 @@ public: } protected: - std::tuple optimizer_impl_props; + std::tuple + optimizer_impl_props; }; } /* namespace nntrainer */ -- 2.7.4