[bias] Bias updation missing for sgd
authorParichay Kapoor <pk.kapoor@samsung.com>
Wed, 24 Jun 2020 02:57:49 +0000 (11:57 +0900)
committerParichay Kapoor <pk.kapoor@samsung.com>
Wed, 24 Jun 2020 06:36:09 +0000 (15:36 +0900)
Bias updatation fixed for sgd where it only happened when bias was initialized with 0
For adam, bias updataion was happening twice

Signed-off-by: Parichay Kapoor <pk.kapoor@samsung.com>
nntrainer/include/optimizer.h
nntrainer/src/optimizer.cpp

index 76fb1f0..2b470d9 100644 (file)
@@ -160,10 +160,9 @@ public:
    * @param[in/out] Weight Weight Tensor
    * @param[in/out] Bias Bias Tensor
    * @param[in] iteration nth epoch number
-   * @param[in] init_zero bool it is true if bias sets zero.
    */
   void calculate(const Tensor &djdw, const Tensor &djdb, Tensor &weight,
-                 Tensor &bias, int iteration, bool init_zero);
+                 Tensor &bias, int iteration);
 
   /**
    * @brief     Property Enumeration
index dbb355f..34e8c26 100644 (file)
@@ -78,8 +78,7 @@ int Optimizer::initialize(TensorDim d, bool set_tensor) {
 }
 
 void Optimizer::calculate(const Tensor &djdw, const Tensor &djdb,
-                          Tensor &weight, Tensor &bias, int iteration,
-                          bool init_zero) {
+    Tensor &weight, Tensor &bias, int iteration) {
   Tensor djdwAvg, djdbAvg;
   float ll = popt.learning_rate;
   if (popt.decay_steps != -1) {
@@ -92,6 +91,7 @@ void Optimizer::calculate(const Tensor &djdw, const Tensor &djdb,
   switch (type) {
   case OptType::sgd:
     weight.add_i(djdwAvg, -ll);
+    bias.add_i(djdbAvg, -ll);
     break;
   case OptType::adam: {
     std::function<float(float)> sqrtEps = [&](float f) {
@@ -124,10 +124,6 @@ void Optimizer::calculate(const Tensor &djdw, const Tensor &djdb,
   default:
     break;
   }
-
-  if (init_zero) {
-    bias.add_i(djdbAvg, -ll);
-  }
 }
 
 int Optimizer::setProperty(std::vector<std::string> values) {