チェックポイントのファイル形式¶
形式は、チェックポイントのファイルをテンソルに分解し、元のファイルに組み立て直す。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。hdf5extra(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 |
|
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 |