| dp_train | R Documentation |
Runs synchronous data-parallel training:
make_model() is called n_gpu times to create one
independent model replica per GPU (each with its own parameters).
Each iteration: the current data item is forwarded through every
replica in parallel; gradients are computed via backward().
Gradients are averaged across all replicas (element-wise mean).
One optimizer step is taken on replica 0; updated weights are then broadcast to replicas 1 … N-1 so all replicas stay in sync.
dp_train(
make_model,
data,
loss_fn = NULL,
forward_fn = NULL,
target_fn = NULL,
n_gpu = NULL,
n_iter = 10L,
lr = 0.001,
max_norm = Inf,
verbose = 10L
)
make_model |
A zero-argument function that returns a model object with
at least |
data |
A list of training samples. Each element is passed directly to
|
loss_fn |
A function |
forward_fn |
Optional function |
target_fn |
Optional function |
n_gpu |
Number of GPU replicas (default: all available Vulkan devices, minimum 1). |
n_iter |
Number of training iterations (passes over |
lr |
Learning rate for Adam optimizer (default 1e-3). |
max_norm |
Gradient clipping threshold (default |
verbose |
Print loss every |
Because all replicas live in the same R process and ag_param uses
environment (reference) semantics, no IPC or NCCL is required — weight
synchronisation is a simple in-place copy.
A list with:
paramsNamed list of final parameters (from replica 0).
loss_historyNumeric vector of per-iteration mean loss.
modelReplica 0 model object.
make_model <- function() {
W <- ag_param(matrix(rnorm(4), 2, 2))
list(
forward = function(x) ag_matmul(W, x),
parameters = function() list(W = W)
)
}
data <- lapply(1:8, function(i) matrix(rnorm(2), 2, 1))
result <- dp_train(
make_model = make_model,
data = data,
loss_fn = function(out, tgt) ag_mse_loss(out, tgt),
target_fn = function(s) s,
n_gpu = 1L,
n_iter = 10L,
lr = 1e-3,
verbose = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.