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 that torch.save wrote 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 from torch.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 its argparse.Namespace, Lightning hyperparameters kept as an object), every storage gets the role other, the command prints one jabara: 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-zip refuses, and leaves as it is, a torch.save file in the legacy format from before PyTorch 1.6 and a zip whose members are compressed.

  • npy and npz: a NumPy array file, and a zip of them from np.savez (MLX's mx.savez writes the same). The header is read with ast.literal_eval, which runs no code. An array of a dtype that Jabara does not carry (big-endian, structured, Python objects) is kept as uint8 bytes with the role other; an array of Python objects is never unpickled. A Fortran-order array keeps its dtype and shape but gets the role other, because its bytes are in column order. An .npz from np.savez_compressed is 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 with struct alone. 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 as uint8 bytes with the role other. A file of metadata alone, with no tensor, is kept whole.

  • hdf5 and keras: an HDF5 file, such as a Keras 3 .weights.h5, and a Keras 3 .keras zip, which holds one. They need the hdf5 extra (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 under optimizer/ (Keras 3) and optimizer_weights/ (legacy Keras) get the role other.

  • In a checkpoint directory, compress takes only the file names that the formats list for a directory, so scheduler.pt, rng_state.pth, training_args.bin, and scheduler.bin stay as they are; .npy, .npz, .gguf, .h5, and .keras files 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 safetensors share jabara.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

gguf

supported

Keras 3 (save_weights), legacy Keras, h5py

*.weights.h5, *.h5, *.hdf5

hdf5

supported

Keras 3 (model.save)

*.keras

keras

supported

NumPy

*.npy

npy

supported

NumPy (np.savez), MLX (mx.savez)

*.npz

npz

supported

Hugging Face Transformers, Accelerate, PEFT, Diffusers, MLX

*.safetensors

safetensors

supported

Hugging Face Transformers

optimizer.pt, pytorch_model*.bin

torch-zip

supported

Accelerate

optimizer.bin, pytorch_model*.bin

torch-zip

supported

PyTorch Lightning

*.ckpt

torch-zip

supported

DeepSpeed

mp_rank_*_model_states.pt, *_optim_states.pt

torch-zip

supported

Megatron-LM (torch format)

model_optim_rng.pt

torch-zip

supported

PyTorch

*.pt, *.pth, *.bin, named on their own

torch-zip

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

gguf

jabara.formats.gguf.Gguf

18

142

hdf5

jabara.formats.hdf5.Hdf5

16

126

keras

jabara.formats.hdf5.Keras

21

126

npy

jabara.formats.npy.Npy

17

94

npz

jabara.formats.npy.Npz

23

94

safetensors

jabara.formats.safetensors.Safetensors

26

136

torch-zip

jabara.formats.torch_zip.TorchZip

48

260