Saving & loading
StateDict, NXM1 format, and checkpoint limitations.
01StateDict snapshots#
state_dict clones parameter data and buffers. Keys are hierarchical, such as 0.weight or norm.running_mean. Gradients, optimizer, RNG, training mode, and architecture are not saved. Construct the same architecture first.
save_state_dict(model.state_dict(), "model.nxm");auto state=load_state_dict_file("model.nxm");model.load_state_dict(state); // strict=truemodel.eval();02Strict loading#
load_state_dict(state,strict=true) rejects missing/extra keys. strict=false tolerates them; shapes of matching keys still must agree. Values copy into existing parameters.
03NXM1 layout#
NXM1 magic + uint32 entry count. Each entry: uint32 name length, name bytes, uint32 rank, uint64 dimensions, raw float32. Uses host byte order without endian conversion.
04Validation limits#
Reader checks magic, rank≤8, and truncation, without quotas on total size, name length, or entry count. Intended for controlled checkpoint exchange. Add bounded validation before accepting untrusted uploads.