コマンドライン

jabara コマンドは、チェックポイントの圧縮、復元、一覧表示、検証、比較を行う。PATH は、チェックポイントのファイルまたはディレクトリである。下のコマンドごとの節は、引数パーサから生成している。

コマンド

jabara compress

jabara compress [-h] [--threads N] [--base BASE] [--recursive] [--keep] [--dry-run] [--delta MODE] [--config FILE] [--show-config] PATH

Compress a checkpoint file, or the files it recognises in a checkpoint directory.

With --base BASE (an archive of an earlier checkpoint, or the directory of one), float tensors are stored as differences from the tensors of the same name in it. With --recursive, PATH holds several checkpoint directories (checkpoint-100, checkpoint-200, ...): each is compressed in turn as a directory is, the first failure stops the run, --delta first codes every checkpoint but the first against the first, and --delta previous codes each against the one before it, a chain that restores in order. --dry-run lists what would be compressed and changes nothing.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

PATH

a file, a checkpoint directory, or with --recursive their parent [path]

--threads N

worker threads (default: up to 8) [positive integer]

--base BASE

an archive of an earlier checkpoint, or its directory [path]

--recursive

take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false)

--keep

keep the input files (also --keep=true or --keep=false)

--dry-run

print what would be compressed, with its size on disk, and change nothing (also --dry-run=true or --dry-run=false)

--delta MODE

with --recursive: first or previous, the checkpoint each one is coded against

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara decompress

jabara decompress [-h] [--threads N] [--base BASE] [--recursive] [--keep] [--config FILE] [--show-config] PATH

Restore the original file from an archive, or every archive in a directory.

An archive written with --base needs the same --base BASE here. With --recursive, PATH holds several checkpoint directories: each is restored in turn as a directory is, dependants of another checkpoint's archives first, and the first failure stops the run. Without --keep, a checkpoint whose archives a sibling checkpoint still needs as its base is not restored before that sibling.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

PATH

an archive, a checkpoint directory, or with --recursive their parent [path]

--threads N

worker threads (default: up to 8) [positive integer]

--base BASE

an archive of an earlier checkpoint, or its directory [path]

--recursive

take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false)

--keep

keep the input files (also --keep=true or --keep=false)

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara ls

jabara ls [-h] [--json] [--recursive] [--config FILE] [--show-config] PATH

List the tensors of an archive, or of every archive in a directory. A directory without one is an error.

With --recursive, PATH holds several checkpoint directories, and the archives of each are listed.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

PATH

an archive or a directory, or with --recursive their parent [path]

--json

print JSON (also --json=true or --json=false)

--recursive

take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false)

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara verify

jabara verify [-h] [--threads N] [--base BASE] [--recursive] [--config FILE] [--show-config] PATH

Decode every chunk of an archive, or of every archive in a directory, and check its checksum.

A directory without an archive is an error. A delta archive needs --base BASE, as for decompress. With --recursive, PATH holds several checkpoint directories: every archive of each is checked, a delta archive against the archives of the other checkpoints that it names, and a failure does not stop the others.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

PATH

an archive or a directory, or with --recursive their parent [path]

--threads N

worker threads (default: up to 8) [positive integer]

--base BASE

the base archive of a delta archive, or its directory [path]

--recursive

take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false)

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara export-weights

jabara export-weights [-h] [--config FILE] [--show-config] ARCHIVE OUT

Write the weight tensors of ARCHIVE as a safetensors file.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

ARCHIVE

[path]

OUT

the safetensors file to write; must not exist [path]

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara bench

jabara bench [-h] [--json] [--base BASE] [--repeats N] [--threads N] [--candidates a,b,c] [--config FILE] [--show-config] PATH

Compare codecs in memory on the tensors of PATH: an archive, a safetensors or torch file, or a directory.

Default candidates are the lossless codecs that need no base; with --base (a path of the same kinds) the delta codecs join them. --candidates a,b,c names codecs instead, lossy ones included. It takes no --recursive: it holds every tensor in memory, and a parent of several checkpoints would multiply that.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

PATH

an archive, a safetensors or torch file, or a directory [path]

--json

print the report as JSON (also --json=true or --json=false)

--base BASE

the base tensors, a path of the same kinds [path]

--repeats N

timed runs per codec [positive integer, default 3]

--threads N

worker threads (default: up to 8) [positive integer]

--candidates a,b,c

the codecs to compare instead of the default ones [codec ids, comma-separated]

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara codecs

jabara codecs [-h] [--long] [--json] [--config FILE] [--show-config] [ID]

List the registered codecs: their ids, or with --long, --json or an ID what each is and builds on.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

ID

show everything about this codec

--long

show each codec's properties and references (also --long=true or --long=false)

--json

print JSON: a list of codecs, or one codec for an ID (also --json=true or --json=false)

--config FILE

read options from a .json, .yaml, .yml, or .toml file [path]

--show-config

print the settings to be used, as JSON, and exit

jabara help

jabara help [-h] [COMMAND]

Print the full help of jabara or of a command.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

COMMAND

a command; jabara itself without it [command name]

jabara man

jabara man [-h] [COMMAND]

Show the manual page of jabara or of a command.

Argument

Description

-h, -H, --help

print the short (-h) or the full help and exit

COMMAND

a command; jabara itself without it [command name]

ファイルとディレクトリ

  • ファイルに対する compress が対象にするのは *.safetensors、*.pt、*.pth、*.bin、*.ckpt、*.npy、*.npz、*.gguf、*.h5、*.hdf5、*.keras で、隣に <name>.jbr を書く。ディレクトリに対しては、名前が *.safetensors、optimizer.pt、optimizer.bin、pytorch_model*.bin、*.ckpt、mp_rank_*_model_states.pt、*_optim_states.pt、model_optim_rng.pt の通常のファイルを、再帰せずに対象にし、ほかのファイルには触れない。これらのファイルを書くフレームワークは チェックポイントのファイル形式 にある。アーカイブが可逆なら、decompress は各ファイルをバイト単位で同一に書き戻す。model-00001-of-00002.safetensors のように分割したモデルのファイルは、それぞれ一つのアーカイブになり、model.safetensors.index.json はそのまま残る。どれもないディレクトリはエラーになる。

  • ファイルに対する decompress が対象にするのは *.jbr で、接尾辞を除いた名前で書き出す。既存のファイルへの上書きは拒否する。ディレクトリに対しては、すべての *.jbr ファイルを復元する。

  • compress と decompress は、何かを変更する前に、隣に自身のアーカイブがあるファイル(model.safetensors と model.safetensors.jbr)を拒否する。先にどちらか一方を削除すること。

  • ディレクトリに対する compress と decompress は、すべてが成功するか、何も変わらないかのどちらかである。まずすべての出力を書いて検証し、--keep を渡さない限り、そのあとで入力を削除する。一つのファイルでも失敗すると、書き出した出力を削除し、入力はすべて元の場所に残る。

  • ls と verify は、アーカイブまたはディレクトリを受け取る。ディレクトリに対しては *.jbr ファイルを読み、アーカイブがないディレクトリはエラーになる。

  • compress、decompress、verify では、--base が以前のチェックポイントのアーカイブか、そのチェックポイントのディレクトリを指す。PATH がファイルでもディレクトリでも使える。ディレクトリを指定すると、各テンソルはそのどれかのアーカイブにある同じ名前のテンソルとの差分になり、そのディレクトリにはアーカイブのないチェックポイントのファイルがあってはならない。compress --base で書いたアーカイブには、decompress と verify でも、そのベースのアーカイブを含む --base が必要である。bench では、--base は bench が読める任意の種類のパスである。

  • export-weights は、役割が weight のテンソルを safetensors ファイルに書き出す。

    • safetensors ファイルのアーカイブでは、すべてのテンソルがこの役割を持ち、出力は元のファイルとバイト単位で同一になる。

    • それ以外のアーカイブでは、出力には役割が weight のテンソルが入り、残りは含まれない。save_state と WeightsSchema で作ったアーカイブには、そのようなテンソルしかない。

    • compress は、torch のファイルのテンソルに、パスからオプティマイザの役割を付けるので、モデルの state_dict のテンソルには役割 other が付く。export-weights はそのアーカイブを拒否し、jabara: model.pt.jbr: no tensors with role 'weight' を出力して終了ステータス 1 で終了する。optimizer.pt のアーカイブも同じである。

    • OUT は存在してはならない。

    • export-weights はベースを受け取らないので、差分アーカイブは読めない。

  • bench は、アーカイブ、compress が対象にするファイル、ディレクトリのどれかを読む。ディレクトリでは、compress が対象にするファイルと *.jbr ファイルを読み、各テンソルの名前の前にファイル名と / を付ける。アーカイブは、復元先のファイルの名前で数えるので、圧縮したディレクトリと圧縮していないディレクトリで、テンソル名は同じになる。ファイルとそのアーカイブが並んでいるディレクトリはエラーになる。bench は差分アーカイブを読めない。

チェックポイントの親ディレクトリ

compress、decompress、verify、ls は --recursive を受け取る。このとき PATH は、Hugging Face の Trainer の output_dir のような親ディレクトリで、コマンドはその中のチェックポイントを一つずつ順に処理する。

  • チェックポイントのディレクトリとは、compress がディレクトリで対象にする通常のファイルか、*.jbr アーカイブを直接に持つディレクトリである。チェックポイントは、そのようなディレクトリである直下のサブディレクトリを、名前の自然順(checkpoint-200 が checkpoint-1000 より前)に並べたもので、PATH 自身がそのようなディレクトリなら最後に加わる。best のような名前は checkpoint-* より前に並び、--delta ではそれが最初のチェックポイントになるので、順序は --dry-run で確認すること。たどるのは一階層だけで、それより深くは入らず、隠しディレクトリとディレクトリへのシンボリックリンクは飛ばす。チェックポイントのファイルでないものには触れない。Python では jabara.files.checkpoint_dirs(path) が同じ一覧を返す。

  • --recursive がないとき、自分で処理するファイルを持たない PATH は、これまでどおりエラーである。メッセージには、見つけたチェックポイントのディレクトリの名前と、--recursive を使う案内が入る。

  • compress と decompress は、チェックポイントを一つずつ、それぞれすべて成功するか何も変わらないかのどちらかで処理し、最初の失敗で止まる。それより前のチェックポイントは完了したままなので、実行しながらディスク容量が空く。失敗したものと、それ以降のものは元のままである。コマンドは終了ステータス 1 で終了し、jabara: <checkpoint>: <error>; stopped there: <k> checkpoints done or skipped before it, this one and <n> after it left as they were の一行を出力する。何かを変更する前に、どのチェックポイントでも、隣に自身のアーカイブがあるファイルを拒否する。

  • やることがないチェックポイントは <dir>: skipped, already compressed(decompress では already decompressed)を出力し、エラーにはならない。止まったあとは、同じコマンドをもう一度実行する。

  • compress --dry-run はどの PATH でも使える。同じ拒否を行ったあと、テンソルを読まず、何も変更せずに、圧縮する対象とそのディスク上のサイズを出力する。

  • compress --recursive --delta first は、上の順序の最初のチェックポイントを完全なアーカイブとして圧縮する。すでに完全なアーカイブだけを持つなら、そのまま使う。それ以外のすべてのチェックポイントは、PATH 自身も含めて、ディレクトリに対する --base と同じように、その最初のものとの差分にする。最初のチェックポイントに差分アーカイブがあると拒否する。compress --recursive --delta previous は、最初のもの以外のすべてのチェックポイントを、上の順序で一つ前のチェックポイントとの差分にするので、アーカイブは連鎖になる。先に圧縮したチェックポイントはそのままにするので、後からの実行は、新しいチェックポイントを最後のものとの差分にする。復元は連鎖をたどる。位置 k のチェックポイントは、テンソルごとに k 個のアーカイブを復号し、アーカイブを一つ失うと、それ以降のすべてのチェックポイントを失う。どのチェックポイントがいつ必要になるか分からないときは first を、多くはめったに読まず、ディスクが制約のときは previous を使う(ハウツーガイドに測定値がある)。--delta には --recursive が必要で、--base とは併用できない。--recursive も --base と併用できない。いずれも使い方のエラーである。

  • decompress --recursive と verify --recursive は、差分アーカイブのベースを、他のチェックポイントのアーカイブの中から、記録されたファイル名とインデックスの CRC-32 で見つける。decompress --recursive は、差分アーカイブを持つチェックポイントを、それが必要とするチェックポイントより先に復元するので、連鎖では最後のチェックポイントが最初になる。先にすべてのベースを連鎖の先まで確認するので、どのチェックポイントにもないベースがあれば、何も復元せずに止まる。アーカイブ自身のベースより先にある連鎖の途中のものが欠けているときは、メッセージが二つのアーカイブを挙げる。<archive>: <owner>: base <name> (index crc <c>) is missing or changed

  • --keep なしの、チェックポイントのディレクトリまたは一つのアーカイブに対する decompress は、削除するアーカイブをベースにした差分アーカイブを隣のチェックポイントが持ち、そのアーカイブのコピー(インデックスの CRC-32 が同じもの)が隣に残らないとき、何も変更せずに拒否される。先にそちらを復元するか、--keep を渡す。decompress --recursive も、PATH 自身について同じ確認を行う。PATH の隣にあるものは、親ディレクトリのチェックポイントではないからである。ベースが親ディレクトリの外にある差分アーカイブがあると、decompress --recursive は止まる。そのチェックポイントだけを --base を付けて復元すること。

  • --delta で圧縮した親ディレクトリのチェックポイントは、後のものが圧縮されている間、削除も移動もしないこと。jabara.hf.attach(trainer, delta="first") は first と同じ配置を書き、Trainer が古いチェックポイントを回転させるときも最初のチェックポイントを残す。

  • bench は --recursive を受け取らない。すべてのテンソルをメモリに載せるので、親ディレクトリではその量が増える。

出力

サイズはファイルのサイズではなくテンソルのバイト数である。<raw> はテンソルのバイト数、<stored> は符号化したチャンクのバイト数を数える。パーセントは 100 * stored / raw を小数第 1 位まで表したもので、raw が 0 のときは empty になる。

  • compress は、アーカイブごとに一行を出力する。<path>: <raw> -> <stored> bytes (<p>% of original)。

  • decompress は、復元した各ファイルのパスを出力する。

  • --recursive を付けた compress と decompress は、チェックポイントごとに通常の行を出力し、続けて <dir>: <n> archives, <raw> -> <stored> bytes (<p>% of original) を出力する。最後に total: <k> checkpoints, <s> skipped, <raw> -> <stored> bytes (<p>% of original) を出力する。<k> は見つけたチェックポイントすべて、<s> は飛ばしたものの数である。decompress のサイズは、復元する前にアーカイブから取る。

  • compress --dry-run は、ファイルごとに <path>: would compress, <n> bytes on disk を出力し、最後の行は total: <n> files, <size> bytes on disk である。--recursive では、チェックポイントごとに <dir>: <n> files, <size> bytes on disk も出力し(--delta では末尾に , delta against <base> が付く)、最後の行は total: <k> checkpoints, <s> skipped, <n> files, <size> bytes on disk になる。

  • ls は、アーカイブごとに一行、<path>: <n> tensors, <raw> -> <stored> bytes (<p>% of original) を出力し、続けてテンソルごとに一行、名前、dtype、形状、役割、コーデック、サイズを出力する。ls --json は、キー path と tensors を持つオブジェクトの JSON リストを、--recursive でも出力する。

  • verify は、アーカイブごとに ok <path> を出力する。verify --recursive は、すべてのアーカイブを検査し、最初の失敗では止まらない。失敗したアーカイブには FAILED <path>: <reason> を出力し(たとえば base <name> (index crc <c>) is missing or changed)、jabara: <m> of <n> archives failed のあと、終了ステータス 1 で終了する。

  • export-weights は何も出力しない。

  • codecs は、コーデックの ID を一行に一つずつ出力する。codecs --long、codecs ID、codecs --json については 組み込みコーデック を参照。

  • bench は、まずヘッダの行 <n> threads, best of <repeats>, <w> warm-up, chunk <size> bytes を出力し、続けて候補と役割の組ごとに一行を出力する。この行には、サイズ、符号化と復号のスループット(MB/s、1 秒あたり 10^6 バイト)、exact または NOT EXACT が入る。スループットは、元のバイト数を、計測した実行のうち最小の時間で割った値である。一回の実行が計測するのは、メモリ上でのコーデックによるチャンクの符号化または復号だけで、ファイルの読み書きは含まない。計測しない <w> 回のラウンドを最初に実行する。どのラウンドでも、各候補が順に一度ずつ符号化と復号を行い、計測するラウンドでは、候補の順序を一回おきに逆にする。計測する符号化と復号の直前には、スレッドプールのスレッドと呼び出し元のスレッドが、計測せずに 0.1 秒間ビジーループを実行する。復号まで行った非可逆な行には max_abs_err=<value> が付く。復号が失敗したときは、復号のスループットの代わりに decode failed (<message>) と表示される。差分の候補が一部のテンソルでフォールバックしたときは、行の末尾が、テンソルが一つなら , 1 tensor used the fallback、複数なら , <n> tensors used the fallback になる。NOT EXACT の行があっても、終了ステータスは 0 である。bench --json は、JSON スキーマ で説明しているレポートを出力する。

引数の解析規則

jabara は、コマンドを実行する前に引数リスト全体を解析して検査するので、拒否される引数リストやヘルプを求める引数リストでは、ファイルは変更されない。次の規則のうち、最初に一致したものが結果を決める。

  1. 位置を問わず、-h、-H、--help のいずれかをその綴りどおりに書くと、最初に指定したコマンドのヘルプを出力する。最初の引数がコマンドでなければ、概要を出力する。-h は短いヘルプを、-H と --help は完全なヘルプを出力する。終了ステータス 0 で終了し、何も実行しない。-hx、-hh、--help=x のような別の綴りは、使い方のエラーである。ほかの短いフラグは存在しない。

  2. -- は、どこにあっても使い方のエラーである。

  3. - で始まるほかの引数は、すべてそのコマンドのフラグでなければならない。パスや値として扱われることはない。- で始まるパスは ./-name と書く。未知のフラグ、綴りの誤ったフラグ、フラグの接頭辞(--kee)、ほかのコマンドのフラグは、使い方のエラーである。

  4. ほかの引数は、すべて文字列である。Python のリテラルとしては読まれないので、run#2、123、a,b、True はパスである。未設定の "$CKPT" を展開したときのような空のパスは、使い方のエラーである。位置引数の不足や過剰も、使い方のエラーである。

  5. --keep、--json、--recursive、--dry-run はスイッチである。--keep、--keep=true、--keep=false は受け付け、--keep=0 のようなほかの値は使い方のエラーである。スイッチは別の値を取らないので、--keep false の false は、過剰な引数である。

  6. --threads と --repeats は、ASCII の数字による正の整数を、--threads 2 や --threads=2 の形で取る。--candidates は、コーデックの ID を一つ、または複数をコンマで区切って取る。同じフラグを二回指定すると、最後の値が使われる。

設定ファイル

compress、decompress、ls、verify、export-weights、bench、codecs は --config FILE を受け取る。ファイルは、マッピングを書いた .json、.yaml、.yml、.toml のファイルである。それぞれの例は設定ファイルから実行するにある。

  • キーは、コマンド自身のオプションと引数の宛先である。長いオプション名(ハイフンの代わりにアンダースコアを使う。base、keep、threads、candidates)と、位置引数の名前(path、archive、out)がキーになる。上の生成されたセクションにキーの一覧がある。あとのバージョンで追加されたオプションは、ほかに変更しなくてもキーになる。

  • 優先順位は、コマンドライン、ファイル、デフォルトの順である。コマンドラインの位置引数は、ファイルの同じ引数を置き換え、左から埋まる。

  • 値の型はコマンドラインと同じである。パスは文字列、個数は整数、スイッチは true か false、candidates は文字列のリストである。値はそれぞれのオプションの検査を通るので、threads = 0 は --threads 0 と同じように失敗する。コマンドにないキー、別の型の値、null、一覧にない拡張子、解釈できないテキスト、マッピングでないトップレベルは、使い方のエラーになる。config と show_config はキーではない。

  • ファイルが原因の使い方のエラーは、jabara: <file>: key '<key>': <reason> か jabara: <file>: <reason> の一行を出力し、終了ステータス 2 で終了する。読めないファイルは終了ステータス 1 で終了する。PyYAML がないときの YAML ファイルも終了ステータス 1 で終了し、jabara[yaml] をインストールするよう伝える。

  • --show-config は、{"command": ..., "config": ..., "settings": {...}} を JSON で出力し、終了ステータス 0 で終了する。設定にはコマンドのすべてのキーが入る。何も実行しない。

  • YAML は PyYAML の safe_load で読む。TOML は tomllib で、Python 3.10 では tomli で読む。

ヘルプとマニュアルページ

jabara help COMMAND は、jabara COMMAND --help と同じ内容を出力する。引数なしの jabara は、短い概要を標準エラー出力に出力し、使い方のエラーとして終了ステータス 2 で終了する。

パッケージは、jabara と各コマンドのマニュアルページ(jabara-compress(1) など)を、環境の share/man/man1 にインストールする。環境の bin ディレクトリが PATH にあれば、man jabara で表示できる。有効にした仮想環境や、pipx install でインストールした場合がこれにあたる。uv tool install は、マニュアルページをリンクしない。jabara man COMMAND は、どの環境でも同じページを表示する。標準出力が端末でなければ、ページの roff ソースを出力する。

終了ステータス

ステータス

条件

0

コマンドが成功した、またはヘルプを出力した。

1

コマンドが JabaraError、OSError、ValueError を発生させた。jabara は jabara: <message> の一行を標準エラー出力に出力する。

2

使い方のエラー。jabara は使い方の行とエラーの一行を標準エラー出力に出力し、コマンドは実行しない。設定ファイルが不正なときは、使い方の行は出さず、jabara: <file>: <message> の一行を出力する。

それ以外の例外は捕捉されず、Python のトレースバックを出力してコマンドが終了する。