Burn Pack
The burnpack binary serialization format for the Burn deep learning framework
burn-pack reads and writes the burnpack container format. It is tensor-library-agnostic and
dependency-light: it depends only on burn-std (for DType
/ Bytes), serde, and a CBOR codec — it knows the on-disk format but has no notion of Burn
modules. Tensor data is Bytes-native and read lazily from files (256-byte aligned for
zero-copy mmap and efficient GPU transfers), and the reader is hardened against malformed input.
If you just want to save and load Burn models, use the higher-level
burn-core record API or
burn-store (which adds PyTorch/SafeTensors interop).
Reach for burn-pack directly only to produce or consume the raw format.
Usage
use ;
let raw: = .iter.flat_map.collect;
let tensor = new;
let packed = new.into_bytes.unwrap;
let reader = from_bytes.unwrap;
assert_eq!;
Use Writer::write_to_file / Reader::from_file for disk I/O (the default std feature; disable
it for no-std targets). write_to_file replaces the destination in place, so a save that fails
partway leaves it truncated. write_to_file_atomic instead builds the container beside the
destination and renames it into place once complete, so the old file survives a failed save; that
is what deferred tensors want, since their bytes are produced mid-write. See the API docs for how
far each guarantee reaches.
Writing models larger than memory
A tensor's bytes need not exist yet. Tensor::deferred describes one by its length plus a provider
that yields the data on demand, so the writer can lay out the whole container before any I/O and
then draw the bytes one tensor at a time, dropping each before asking for the next:
let tensor = deferred;
Paired with write_to_file, peak host memory is bounded by the largest single tensor rather than
by the whole model. burn-store collects a module's parameters directly as these, so saving a
Module gets it for free.
See the docs for the format layout and the full API.
License
This project is dual-licensed under MIT and Apache-2.0.