コマンドライン¶
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
a file, a checkpoint directory, or with --recursive their parent [path] |
|
worker threads (default: up to 8) [positive integer] |
|
an archive of an earlier checkpoint, or its directory [path] |
|
take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false) |
|
keep the input files (also --keep=true or --keep=false) |
|
print what would be compressed, with its size on disk, and change nothing (also --dry-run=true or --dry-run=false) |
|
with --recursive: first or previous, the checkpoint each one is coded against |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
an archive, a checkpoint directory, or with --recursive their parent [path] |
|
worker threads (default: up to 8) [positive integer] |
|
an archive of an earlier checkpoint, or its directory [path] |
|
take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false) |
|
keep the input files (also --keep=true or --keep=false) |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
an archive or a directory, or with --recursive their parent [path] |
|
print JSON (also --json=true or --json=false) |
|
take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false) |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
an archive or a directory, or with --recursive their parent [path] |
|
worker threads (default: up to 8) [positive integer] |
|
the base archive of a delta archive, or its directory [path] |
|
take every checkpoint directory in PATH, one level down (also --recursive=true or --recursive=false) |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
[path] |
|
the safetensors file to write; must not exist [path] |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
an archive, a safetensors or torch file, or a directory [path] |
|
print the report as JSON (also --json=true or --json=false) |
|
the base tensors, a path of the same kinds [path] |
|
timed runs per codec [positive integer, default 3] |
|
worker threads (default: up to 8) [positive integer] |
|
the codecs to compare instead of the default ones [codec ids, comma-separated] |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
show everything about this codec |
|
show each codec's properties and references (also --long=true or --long=false) |
|
print JSON: a list of codecs, or one codec for an ID (also --json=true or --json=false) |
|
read options from a .json, .yaml, .yml, or .toml file [path] |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
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 |
|---|---|
|
print the short (-h) or the full help and exit |
|
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 は、コマンドを実行する前に引数リスト全体を解析して検査するので、拒否される引数リストやヘルプを求める引数リストでは、ファイルは変更されない。次の規則のうち、最初に一致したものが結果を決める。
位置を問わず、
-h、-H、--helpのいずれかをその綴りどおりに書くと、最初に指定したコマンドのヘルプを出力する。最初の引数がコマンドでなければ、概要を出力する。-hは短いヘルプを、-Hと--helpは完全なヘルプを出力する。終了ステータス 0 で終了し、何も実行しない。-hx、-hh、--help=xのような別の綴りは、使い方のエラーである。ほかの短いフラグは存在しない。--は、どこにあっても使い方のエラーである。-で始まるほかの引数は、すべてそのコマンドのフラグでなければならない。パスや値として扱われることはない。-で始まるパスは./-nameと書く。未知のフラグ、綴りの誤ったフラグ、フラグの接頭辞(--kee)、ほかのコマンドのフラグは、使い方のエラーである。ほかの引数は、すべて文字列である。Python のリテラルとしては読まれないので、
run#2、123、a,b、Trueはパスである。未設定の"$CKPT"を展開したときのような空のパスは、使い方のエラーである。位置引数の不足や過剰も、使い方のエラーである。--keep、--json、--recursive、--dry-runはスイッチである。--keep、--keep=true、--keep=falseは受け付け、--keep=0のようなほかの値は使い方のエラーである。スイッチは別の値を取らないので、--keep falseのfalseは、過剰な引数である。--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 |
コマンドが |
2 |
使い方のエラー。 |
それ以外の例外は捕捉されず、Python のトレースバックを出力してコマンドが終了する。