チェックポイントのファイル形式

形式は、チェックポイントのファイルをテンソルに分解し、元のファイルに組み立て直す。jabara compress と compress_file は下の対応しているどの形式のファイルも受け取り、アーカイブが可逆なら、jabara decompress はそれをバイト単位で同一に書き戻す。表は、形式のレジストリ jabara.formats から生成していて、どのエントリも受け取らない形式とその理由も挙げる。

  • safetensors:JSON のヘッダはテキストとして保持し、すべてのテンソルを圧縮する。

  • torch-zip:torch.save が zip の形式(PyTorch 1.6 以降)で書いたファイルなら何でも受け取る。テンソルのストレージをそれぞれ圧縮し、ストレージのまわりのバイト列(pickle と zip のヘッダ)は、もう一つのテンソル (remainder) として保持する。pickle は実行しない。各ストレージの dtype と大きさは、pickle のオペコードから読む。テンソルの名前と役割は torch.load(weights_only=True) から得る。ファイルが PyTorch の許可リストにないクラスを持つため、これが拒否するとき(DeepSpeed の ZeRO のオプティマイザ状態、argparse.Namespace を持つ Megatron-LM のチェックポイント、オブジェクトとして保存した Lightning のハイパーパラメータ)は、すべてのストレージの役割が other になり、コマンドは標準エラー出力に jabara: で始まる行を一つ出力する。それでもファイルは圧縮され、バイト単位で同一に復元される。役割で選ぶ Assigner は、このファイルに非可逆なコーデックを選ばない。

  • torch-zip は、PyTorch 1.6 より前の旧形式の torch.save のファイルと、メンバーが圧縮された zip を拒否し、そのまま残す。

  • npy と npz:NumPy の配列のファイルと、np.savez が書くその zip(MLX の mx.savez も同じものを書く)。ヘッダは、コードを実行しない ast.literal_eval で読む。Jabara が扱わない dtype(ビッグエンディアン、構造体、Python オブジェクト)の配列は、役割 other の uint8 のバイト列として保持し、Python オブジェクトの配列を unpickle することはない。Fortran 順の配列は、dtype と形状を保つが、バイト列が列の順に並ぶので役割は other になる。np.savez_compressed の .npz は拒否する。メンバーをもう一度 deflate して元のバイト列になるのは、同じ zlib のビルドを使うときだけだからである。

  • gguf:バージョン 2 または 3 の GGUF ファイルで、struct だけで読む。ヘッダとメタデータはそのまま残す。浮動小数点数型と整数型のテンソルは dtype を保ち、量子化されたテンソルは役割 other の uint8 のバイト列として保持する。テンソルがなくメタデータだけのファイルは、全体をそのまま保持する。

  • hdf5 と keras:Keras 3 の .weights.h5 のような HDF5 ファイルと、それを含む Keras 3 の .keras の zip。hdf5 extra(h5py)が必要で、h5py が各データセットのファイル内の位置を示す。チャンク化、圧縮、外部、仮想のデータセットは、バイト列が一か所にないので拒否する。optimizer/(Keras 3)と optimizer_weights/(旧 Keras)の下のデータセットの役割は other になる。

  • チェックポイントのディレクトリでは、compress は各形式がディレクトリ用に挙げるファイル名だけを取るので、scheduler.pt、rng_state.pth、training_args.bin、scheduler.bin はそのまま残る。.npy、.npz、.gguf、.h5、.keras のファイルは、ディレクトリがデータとして持つこともあるので、単独で指定したときだけ取る。単独で指定したファイルは、形式のパターンに合う名前なら何でもよい。*.safetensors、*.pt、*.pth、*.bin、*.ckpt、*.npy、*.npz、*.gguf、*.h5、*.hdf5、*.keras である。

  • 形式を追加するには、コーデック、Assigner、状態スキーマ、ファイル形式を追加する を参照。二つ目の表は、各形式のクラスとモジュール全体の大きさである。safetensors 以外はテンソルを切り出して戻す jabara.formats.splice を共有し、zip の形式は、格納されたまま(stored)の zip のメンバーを読む部分を共有する。

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