Run from a config file¶
A run that you repeat, such as the compression of every checkpoint of a sweep, is easier to review and to share when its options sit in a file. Every command that has options takes --config FILE, where FILE is JSON (.json), YAML (.yaml or .yml), or TOML (.toml). The options on the command line win over the file, and the file wins over the defaults.
Before you start¶
Start in an empty directory. Save make_checkpoint.py there and run it. Like the Tutorial: compress and restore a checkpoint, it needs the torch extra and safetensors. It writes checkpoint-1000/, which the examples use. Save the three files below next to it: config-compress.toml, config-verify.json, and config-bench.yaml.
$ python make_checkpoint.py
Write the file¶
The keys of a file are the long names of the options of the command, with underscores, and the names of its positional arguments. compress takes path, keep, threads, and base. A TOML file:
path = "checkpoint-1000"
keep = true
threads = 2
The same keys in JSON, for verify:
{
"path": "checkpoint-1000",
"threads": 2
}
And in YAML, for bench. A list of strings is how a file names candidates:
path: checkpoint-1000/model.safetensors
candidates: [raw/1, zstd/1]
repeats: 1
Reading YAML needs PyYAML, which the yaml extra installs: pip install ".[yaml]" from the clone. JSON and TOML need nothing more. Python 3.10 reads TOML with tomli, which Jabara installs for it.
See the settings, then run¶
--show-config prints the settings that the command would use, as JSON, and exits. It runs nothing, so it is safe to try on a new file:
$ jabara compress --config config-compress.toml --show-config
{
"command": "compress",
"config": "config-compress.toml",
"settings": {
"base": null,
"delta": null,
"dry_run": false,
"keep": true,
"path": "checkpoint-1000",
"recursive": false,
"threads": 2
}
}
Without it, the command runs as if you had written the options on the command line:
$ jabara compress --config config-compress.toml
checkpoint-1000/model.safetensors.jbr: ... -> ... bytes (...% of original)
checkpoint-1000/optimizer.pt.jbr: ... -> ... bytes (...% of original)
$ jabara verify --config config-verify.json
ok checkpoint-1000/model.safetensors.jbr
ok checkpoint-1000/optimizer.pt.jbr
$ jabara bench --config config-bench.yaml
... threads, best of 1, 1 warm-up, chunk ... bytes
raw/1 weight: ... bytes (...% of original), encode ... MB/s, decode ... MB/s, exact
zstd/1 weight: ... bytes (...% of original), encode ... MB/s, decode ... MB/s, exact
Override a value on the command line¶
An option on the command line replaces the same key of the file, wherever --config stands. Positional arguments fill from the left: a path on the command line replaces path, and the file supplies the ones that you leave out. One file can serve many runs:
$ jabara compress --config config-compress.toml --threads 4 --keep=false --show-config
{
"command": "compress",
"config": "config-compress.toml",
"settings": {
"base": null,
"delta": null,
"dry_run": false,
"keep": false,
"path": "checkpoint-1000",
"recursive": false,
"threads": 4
}
}
What a file may hold¶
The whole file is checked even where the command line replaces a value, so a bad value in the file is an error even then.
A key that the command does not have is a usage error, so a misspelled key never goes unnoticed.
configandshow_configare not keys.A value must have the type of its option: a string for a path, an integer for a count such as
threads,trueorfalsefor a switch such askeep, a list of strings forcandidates. A value of the wrong type, such asthreads = "2", or one that the option refuses, such asthreads = 0, is a usage error. So isnull.A suffix other than
.json,.yaml,.yml, and.toml, a file that does not parse, and a top level that is not a mapping are usage errors too.A usage error from a file prints one line,
jabara: <file>: <what is wrong>, names the key where there is one, runs nothing, and exits with status 2. A file that is missing or unreadable exits with status 1, as any missing input does. A YAML file without PyYAML exits with status 1 and says how to install it.Only
compress,decompress,ls,verify,export-weights,bench, andcodecstake--config.helpandmanhave no options to set.A file holds the options of one command. To run several commands, call
jabaraonce for each.YAML is read with
safe_load, so a file cannot build Python objects.