View source: R/ag_memory_budget.R
| ag_estimate_training_memory | R Documentation |
Adds up the four things that are alive at the same time during training on
the autograd (ag_*) path: the weights, their gradients, the
optimizer's per-parameter state, and the activations held by the tape until
zero_grad() clears it.
ag_estimate_training_memory(
shapes,
batch_size = 32L,
optimizer = c("adam", "sgd", "sgd_plain"),
activation_frac = 0.01,
quiet = FALSE
)
shapes |
List of parameter shapes, each a numeric vector of dimensions
(e.g. |
batch_size |
Batch size the activations are sized for. Activations scale with it; weights and optimizer state do not. |
optimizer |
One of |
activation_frac |
Activations as a fraction of the weight bytes, per
unit of batch. The default 0.01 reproduces the measured tape composition
for a dense stack ( |
quiet |
Suppress the printed report and return the figures only. Note
that the double-vs-f32 caveat is part of that report, so a caller passing
|
Everything is counted at 8 bytes per scalar, because that is what the path
actually uses: gradients are accumulated by R closures in double, and
optimizer moments are R matrices. ag_dtype affects only
forward tensors uploaded into a ggml buffer and does not reach either. An
estimate made in f32 would be half the real figure, so the returned list
carries a note saying so.
Invisibly, a list of byte counts: params, weights,
gradients, optimizer, activations, total, plus
bytes_per_scalar and note. Printed as a report.
ag_tape_memory measures a real tape instead of
estimating one; ggml_estimate_memory sizes a single tensor in
a ggml buffer, where dtype does apply.
# a 3-layer MLP, 512 wide, trained with Adam at batch 64
ag_estimate_training_memory(
shapes = list(c(512, 512), c(512, 512), c(512, 512)),
batch_size = 64)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.