ag_load_model: Load an autograd module from a saved state

View source: R/ag_save.R

ag_load_modelR Documentation

Load an autograd module from a saved state

Description

Reconstructs an ag_* module saved with ag_save_model. The architecture is rebuilt by calling model_fn (either the one passed here, or the one stored inside the container at save time), and the saved parameter and buffer values are copied back by name.

Usage

ag_load_model(path, model_fn = NULL, device = NULL)

Arguments

path

File path written by ag_save_model.

model_fn

Optional zero-argument rebuild function. Required if no model_fn was stored at save time. If both are present, this argument takes precedence.

device

Optional device for the rebuilt module ("cpu" or "gpu"). If NULL (default), the current ag_device() is used by the rebuild.

Value

The reconstructed module with restored weights, in eval mode.

See Also

ag_save_model

Examples


build <- function() ag_sequential(ag_linear(4L, 8L), ag_linear(8L, 3L))
f <- tempfile(fileext = ".rds")
ag_save_model(build(), f, model_fn = build)
model <- ag_load_model(f)


ggmlR documentation built on July 14, 2026, 1:08 a.m.