parameter_optimizer.h 1.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#ifndef PADDLE_PARAMETER_OPTIMIZER_H_
#define PADDLE_PARAMETER_OPTIMIZER_H_

#include <glog/logging.h>
#include <functional>
#include <string>
#include "OptimizerConfig.pb.h"
#include "Tensor.h"
#include "lr_policy.h"

namespace paddle {
namespace optimizer {

class ParameterOptimizer {
public:
  /**
   * @brief  update hook for algorithm need to traverse parameter more than
   * once.
   */
20
  // use config for pack trainig state
21 22
  ParameterOptimizer(const OptimizerConfig &config) : config_(config){};

23 24 25
  ParameterOptimizer(BaseLr *lr) : lr_policy(lr), num_sample_passed(0) {}
  virtual ~ParameterOptimizer() { delete parameter_; };

26
  static ParameterOptimizer *create(const ::std::string &config_proto);
27
  virtual void update(const Tensor *gradient) = 0;
D
dzhwinter 已提交
28 29
  virtual real *get_weight() const;
  virtual void set_weight(Tensor *parameter);
30

31
public:
32
  OptimizerConfig config_;
D
dzhwinter 已提交
33
  Tensor *parameter_;
34 35 36 37 38 39 40 41 42 43

  // learning rate policy
  BaseLr *lr_policy;
  uint64_t num_sample_passed;
};

}  // namespace optimizer
}  // namespace paddle

#endif