ag_save_model: Save an autograd module's state to disk
Description
Serializes the trainable parameters and persistent buffers of an
ag_sequential (or single ag_* layer) module as a portable
state dictionary of plain numeric matrices. This avoids serializing the live
module (environments + closures), which is brittle across ggmlR versions and
carries non-portable GPU pointers.
Usage
ag_save_model(model, path, model_fn = NULL)
Value
path, invisibly.
Arguments
model
An ag_sequential module or a single ag_* layer
exposing parameters().
path
File path to write (an RDS container).
model_fn
Optional zero-argument function that rebuilds the module
architecture (fresh, untrained). If supplied, it is stored in the container
so ag_load_model can rebuild without arguments. Must not
capture GPU tensors in its enclosing environment.
Details
Reconstruction requires the architecture. Either pass model_fn here so
it is stored in the file, or pass it later to ag_load_model.