Skip to contents

Round-trips a named list of numeric arrays through an RDS file and checks keys/shapes/values match exactly on reload.

Usage

morie_geron_save_load_pytorch(model, path, verify = TRUE)

Arguments

model

Named list of arrays (state dict), or an unnamed list (named param_0, param_1, ...).

path

Destination file (.rds); its directory must already exist.

verify

Reload and compare after writing.

Value

list with path, keys, shapes, n_params, bytes, loaded, exact, max_diff, estimate, n, method.

Examples

morie_geron_save_load_pytorch(model = c(1, 2, 3, 4, 5, 6, 7, 8), path = tempfile())
#> $path
#> [1] "/tmp/RtmpNbJQ2u/file2cd213e1d378.rds"
#> 
#> $keys
#> [1] "param_0" "param_1" "param_2" "param_3" "param_4" "param_5" "param_6"
#> [8] "param_7"
#> 
#> $shapes
#> $shapes$param_0
#> [1] 1
#> 
#> $shapes$param_1
#> [1] 1
#> 
#> $shapes$param_2
#> [1] 1
#> 
#> $shapes$param_3
#> [1] 1
#> 
#> $shapes$param_4
#> [1] 1
#> 
#> $shapes$param_5
#> [1] 1
#> 
#> $shapes$param_6
#> [1] 1
#> 
#> $shapes$param_7
#> [1] 1
#> 
#> 
#> $n_params
#> [1] 8
#> 
#> $bytes
#> [1] 133
#> 
#> $loaded
#> $loaded$param_0
#> [1] 1
#> 
#> $loaded$param_1
#> [1] 2
#> 
#> $loaded$param_2
#> [1] 3
#> 
#> $loaded$param_3
#> [1] 4
#> 
#> $loaded$param_4
#> [1] 5
#> 
#> $loaded$param_5
#> [1] 6
#> 
#> $loaded$param_6
#> [1] 7
#> 
#> $loaded$param_7
#> [1] 8
#> 
#> 
#> $exact
#> [1] TRUE
#> 
#> $max_diff
#> [1] 0
#> 
#> $estimate
#> [1] 8
#> 
#> $n
#> [1] 8
#> 
#> $method
#> [1] "state_dict serialised to RDS and reloaded, with key/shape and bit-exact value checks"
#>