- layer->serializable layerprocedure
- serializable->layer alistprocedure
Convert a layer to and from the association list that is stored in the file.
Dense, convolutional, flatten and sequential layers can be saved. The AM-backed layers of nanograd-array-morphisms cannot.
(save-model model "model.ngrd") (define restored (load-model "model.ngrd"))
A checkpoint file holds one CBOR data item (RFC 8949), written with the cbor egg, after the CBOR self-describe tag. The item is an association list:
((format . nanograd-checkpoint) (version . 1) (model . <output of layer->serializable>))Tensor data are stored as RFC 8746 typed arrays (tag 85 for little-endian f32, tag 86 for little-endian f64), so they are read and written as single blocks of bytes and round-trip bit for bit. Other CBOR decoders can read the files; for example, Python's cbor2 package decodes a checkpoint, and numpy.frombuffer turns each typed array into an array.
Checkpoints written by nanograd 3.0 and earlier (CHICKEN 5, s11n format) cannot be read.