| optimizer_adam | R Documentation |
Create an Adam optimizer
optimizer_adam(
params,
lr = 0.001,
beta1 = 0.9,
beta2 = 0.999,
eps = 1e-08,
accumulate_steps = 1L,
average = TRUE
)
params |
List of ag_param tensors, named or not (names are used only for display). The same tensor listed twice is kept once, with a warning. |
lr |
Learning rate (default 1e-3) |
beta1 |
First moment decay (default 0.9) |
beta2 |
Second moment decay (default 0.999) |
eps |
Stability constant (default 1e-8) |
accumulate_steps |
Number of |
average |
When accumulating, divide the accumulated gradient by
|
An optimizer environment with step(grads), zero_grad(),
state() and load_state(state). state() returns a
versioned list (moments as host double matrices, t,
accum_count); load_state() checks the type, parameter
count, names (when both sides have them) and shapes before writing
anything, restores t and accum_count, and does NOT restore
hyperparameters (it warns when they differ). Exact continuation holds on
the same device and dtype; CPU <-> GPU in f32 continues within float
tolerance; across f16 and f32 it cannot be exact. Only read saved states
you trust (readRDS).
On the GPU the step always runs in F32, whatever ag_dtype
is: the moments are F32, the gradient is converted to F32 before it is
squared, and a weight held in f16 has an F32 master copy that the step
updates and then copies into the f16 weight, so updates smaller than the
f16 spacing still accumulate. state() includes these master
weights, and load_state() installs them as the parameter values;
load the optimizer state after the model's own weights.
w <- ag_param(matrix(runif(4), 2, 2))
opt <- optimizer_adam(list(w = w), lr = 1e-3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.