Checkpoint file formats¶
A format takes a checkpoint file apart into tensors and puts it back together. jabara compress and compress_file take a file in any supported format below, and jabara decompress writes it back byte for byte when the archive is lossless. The tables are generated from the format registry, jabara.formats, which also lists the formats that no entry takes and why.
safetensors: the JSON header is kept as text, and every tensor is compressed.torch-zip: any file thattorch.savewrote in its zip layout (PyTorch 1.6 and later). Each tensor storage is compressed, and the bytes around the storages (the pickle, the zip headers) are kept as one more tensor,(remainder). The pickle is never run: the dtype and size of each storage are read from its opcodes. Tensor names and roles come fromtorch.load(weights_only=True). When that refuses the file because it holds a class outside PyTorch's allow-list (a DeepSpeed ZeRO optimizer state, a Megatron-LM checkpoint with itsargparse.Namespace, Lightning hyperparameters kept as an object), every storage gets the roleother, the command prints onejabara:line on stderr, and the file is still compressed and restored byte for byte. A role-based assigner then chooses no lossy codec for it.torch-ziprefuses, and leaves as it is, atorch.savefile in the legacy format from before PyTorch 1.6 and a zip whose members are compressed.npyandnpz: a NumPy array file, and a zip of them fromnp.savez(MLX'smx.savezwrites the same). The header is read withast.literal_eval, which runs no code. An array of a dtype that Jabara does not carry (big-endian, structured, Python objects) is kept asuint8bytes with the roleother; an array of Python objects is never unpickled. A Fortran-order array keeps its dtype and shape but gets the roleother, because its bytes are in column order. An.npzfromnp.savez_compressedis refused, because deflating a member again gives the original bytes only with the same zlib build.gguf: a GGUF file, version 2 or 3, read withstructalone. The header and the metadata stay as they are. A tensor of a float or integer type keeps its dtype; a quantized tensor is kept asuint8bytes with the roleother. A file of metadata alone, with no tensor, is kept whole.hdf5andkeras: an HDF5 file, such as a Keras 3.weights.h5, and a Keras 3.keraszip, which holds one. They need thehdf5extra (h5py), which reports where each dataset sits in the file. A chunked, compressed, external, or virtual dataset is refused, because its bytes are not in one place. Datasets underoptimizer/(Keras 3) andoptimizer_weights/(legacy Keras) get the roleother.In a checkpoint directory,
compresstakes only the file names that the formats list for a directory, soscheduler.pt,rng_state.pth,training_args.bin, andscheduler.binstay as they are;.npy,.npz,.gguf,.h5, and.kerasfiles are taken only when named on their own, since a directory may hold such files as data. A file named on its own may have any name that a format's patterns match:*.safetensors,*.pt,*.pth,*.bin,*.ckpt,*.npy,*.npz,*.gguf,*.h5,*.hdf5,*.keras.To add a format, see Add a codec, an assigner, a state schema, or a file format. The second table gives the size of each entry: its class, and its whole module. All but
safetensorssharejabara.formats.splice, which cuts the tensors out and puts them back, and the zip formats share the reader of stored zip members.
Framework |
Files |
Format |
Status |
|---|---|---|---|
llama.cpp, and the tools that convert models for it |
*.gguf |
|
supported |
Keras 3 (save_weights), legacy Keras, h5py |
*.weights.h5, *.h5, *.hdf5 |
|
supported |
Keras 3 (model.save) |
*.keras |
|
supported |
NumPy |
*.npy |
|
supported |
NumPy (np.savez), MLX (mx.savez) |
*.npz |
|
supported |
Hugging Face Transformers, Accelerate, PEFT, Diffusers, MLX |
*.safetensors |
|
supported |
Hugging Face Transformers |
optimizer.pt, pytorch_model*.bin |
|
supported |
Accelerate |
optimizer.bin, pytorch_model*.bin |
|
supported |
PyTorch Lightning |
*.ckpt |
|
supported |
DeepSpeed |
mp_rank_*_model_states.pt, *_optim_states.pt |
|
supported |
Megatron-LM (torch format) |
model_optim_rng.pt |
|
supported |
PyTorch |
*.pt, *.pth, *.bin, named on their own |
|
supported |
TensorFlow (tf.train.Checkpoint) |
.index, .data--of- |
none |
not supported: the index is a table of protocol buffers that only TensorFlow's reader parses |
JAX: Orbax, TensorStore |
a directory of zarr or OCDBT files |
none |
not supported: each array is split into chunks, usually compressed, over many files |
PaddlePaddle |
*.pdparams, *.pdopt |
none |
not supported: a plain pickle, whose arrays are found only by running it |
MindSpore |
*.ckpt |
none |
not supported: protocol buffers of MindSpore's own schema |
ONNX |
*.onnx |
none |
not supported: a protocol buffer that holds the graph; its tensors need a protobuf parser |
Core ML |
*.mlmodel, *.mlpackage |
none |
not supported: a protocol buffer specification with its own weight file |
TensorRT |
*.engine, *.plan |
none |
not supported: an engine built for one GPU and TensorRT version, in a private layout |
PyTorch Distributed Checkpoint |
*.distcp, .metadata |
none |
not supported: one zip per tensor written back to back, and a .metadata file that only pickle.load reads |
NumPy (np.savez_compressed) |
*.npz with compressed members |
none |
not supported: deflating a member again gives the original bytes only with the same zlib build |
PyTorch before 1.6 |
*.pt, *.pth |
none |
not supported: a plain pickle, which Jabara does not run |
Format |
Class |
Class lines |
Module lines |
|---|---|---|---|
|
18 |
142 |
|
|
16 |
126 |
|
|
21 |
126 |
|
|
17 |
94 |
|
|
23 |
94 |
|
|
26 |
136 |
|
|
48 |
260 |