ag_load_state_dict: Load weights into an existing model

View source: R/ag_save.R

ag_load_state_dictR Documentation

Load weights into an existing model

Description

Writes a state from ag_state_dict (or the container of an ag_save_model file read with readRDS) into model in place. Device-resident weights are overwritten in their own buffers, so an optimizer built on the model stays valid and keeps its residency. Values are converted to the model's dtype on upload.

Usage

ag_load_state_dict(model, state, strict = TRUE)

Arguments

model

Target model (see ag_state_dict).

state

A state dict.

strict

TRUE (default): the parameter and buffer names must match exactly. FALSE: names present on only one side are skipped (partial loading, transfer learning); names present on both sides are still shape-checked, always.

Details

Everything is checked before anything is written: an error leaves the model untouched.

Value

model, invisibly.


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.