Caffe2 - C++ API
A deep learning, cross platform ML framework
learning_rate_op.cc
1 
17 #include "caffe2/sgd/learning_rate_op.h"
18 
19 namespace caffe2 {
20 REGISTER_CPU_OPERATOR(LearningRate, LearningRateOp<float, CPUContext>);
21 
22 OPERATOR_SCHEMA(LearningRate)
23  .NumInputs(1)
24  .NumOutputs(1)
25  .SetDoc(R"DOC(
26 Learning rate is a decreasing function of time. With low learning rates the
27 improvements will be linear. With high learning rates they will start to look
28 more exponential. Learning rate is controlled by the following arguments:
29 
30 
31 Required:
32  `iterations`
33  `base_lr`: base learning rate
34  `policy`: this controls how the learning rate is applied, options are:
35  `fixed`
36  `step`: uses `stepsize`, `gamma`
37  `exp`: uses `gamma`
38  `inv`: uses `gamma`, `power`
39  `linearWarmup`: uses `start_multiplier`, `num_iter`
40  `constantWarmup`: uses `multiplier`, `num_iter`
41  `alter`: uses `active_first`, `active_period`, `inactive_period`
42  `hill`: uses those in both `linearWarmup` and `inv`, plus `end_multiplier`
43 
44 
45 Optional:
46  `stepsize`: defaults to 0
47  `gamma`: defaults to 0
48  `power`: defaults to 0
49  `num_iter`: defaults to 0
50  `start_multiplier`: defaults to 0
51  `multiplier`: defaults to 0.5
52 
53 
54 Usage:
55  train_net.LearningRate(*iterations*, "*label*", base_lr=*float*,
56  policy="policy_name", stepsize=*int*, gamma=*float*)
57 
58 
59 Example usage:
60  train_net.LearningRate(200, "LR", base_lr=-0.1,
61  policy="step", stepsize=20, gamma=0.9)
62 )DOC")
63  .Arg("base_lr", "(float, required) base learning rate")
64  .Arg("policy", "(float, default 1.0) strategy for gamma enforcement")
65  .Arg("power", "(float, default 1.0) used only for inv policy type")
66  .Arg("gamma", "(float, default 1.0) momentum of change")
67  .Arg("stepsize", "(float, default 1.0) sampling rate on iterations")
68  .Arg("active_first", "(boolean, default True) in alter policy")
69  .Arg("active_period", "(int64_t, required) in alter policy")
70  .Arg("inactive_period", "(int64_t, required) in alter policy")
71  .Arg(
72  "max_iter",
73  "(int, default -1) maximum iterations in this training run")
74  .Arg(
75  "num_iter",
76  "(int, default 0) number of iterations over which to warmup lr")
77  .Arg(
78  "start_multiplier",
79  "(float, default 0) starting multiplier for learning rate")
80  .Arg(
81  "end_multiplier",
82  "(float, default 0) end multiplier for learning rate")
83  .Arg(
84  "multiplier",
85  "(float, default 0.5) constant multiplier for learning rate")
86  .Input(0, "input", "description needed")
87  .Output(0, "output", "description needed")
88  .DeviceInferenceFunction([](const OperatorDef& def) {
89  return std::make_pair(
90  std::vector<DeviceOption>{DeviceOption()},
91  std::vector<DeviceOption>{def.device_option()});
92  });
93 
94 NO_GRADIENT(LearningRate);
95 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.