AdamOptimizer¶
-
class AdamOptimizer¶
Adam gradient-descent optimizer for a compute-graph loss function [1].
Wraps a loss
functioninto aRuntime, runs it forward and backward on each step, and applies the Adam update (beta1/beta2moment decay,epsfor numerical stability, optionalweight_decay) to itsrequires_gradContext globals.scheduleoptionally decays the learning rate overstep_countsteps;grad_clip_threshold, if non-zero, rescales the gradient norm before the update.References
[1] D. P. Kingma, J. Ba, “Adam: A method for stochastic optimization”, https://arxiv.org/abs/1412.6980
Public Types
Public Functions
-
AdamOptimizer(const Function &function, ContextPtr context, double learning_rate, LRSchedule schedule = LRSchedule::none, std::size_t step_count = 0, double beta1 = 0.9, double beta2 = 0.999, double eps = 1e-8, double grad_clip_threshold = 0.0, double weight_decay = 0.0)¶
- Parameters:
function – The loss function to minimize.
context – Context whose
requires_gradglobals are trained.learning_rate – Initial (or, without
schedule, constant) learning rate.schedule – Learning-rate decay over training.
step_count – Total number of steps, for
schedule.beta1 – First-moment decay rate.
beta2 – Second-moment decay rate.
eps – Numerical-stability constant.
grad_clip_threshold – Maximum gradient norm;
0disables clipping.weight_decay – L2 weight-decay coefficient.
-
TensorVec step(const TensorVec &inputs)¶
Run one training step on
inputsand apply the Adam update; returnsfunction’s outputs.
-
void replace_function(const Function &function)¶
Replace the loss function, keeping the optimizer state.
-
double learning_rate() const¶
The current, possibly
schedule-decayed, learning rate.
-
inline const TypeVec &input_types() const¶
Input types of the loss function.
-
inline ContextPtr context() const¶
The context being trained.
-
inline const std::vector<std::string> ¶m_names() const¶
Names of the trained globals, in the order they appear in parameters.