| optimizer_sgd | R Documentation |
Create an SGD optimizer
optimizer_sgd(
params,
lr = 0.01,
momentum = 0,
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 0.01) |
momentum |
Momentum factor (default 0) |
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).
w <- ag_param(matrix(runif(4), 2, 2))
opt <- optimizer_sgd(list(w = w), lr = 0.01)
# accumulate 4 micro-batches per update
opt4 <- optimizer_sgd(list(w = w), lr = 0.01, accumulate_steps = 4L)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.