Restore many files at once¶
jabara decompress on a directory restores its archives one after another. With --jobs N it restores N of them at the same time. That is faster for a directory of many files, and it costs memory in proportion to N. The default is --jobs 1, which restores one archive at a time as before. This guide shows the option, what it keeps and what it costs, and one measurement. It assumes that you know jabara compress and jabara decompress (see the Tutorial: compress and restore a checkpoint).
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. Then compress the checkpoint:
$ python make_checkpoint.py
$ jabara compress checkpoint-1000
checkpoint-1000/model.safetensors.jbr: ... -> ... bytes (...% of original)
checkpoint-1000/optimizer.pt.jbr: ... -> ... bytes (...% of original)
Restore two archives at once¶
$ jabara decompress checkpoint-1000 --jobs 2
checkpoint-1000/model.safetensors
checkpoint-1000/optimizer.pt
The output, the restored files, and the exit status are the same as for --jobs 1, and the paths are printed in name order. --jobs is a key of a configuration file too (jobs: 2, see Run from a config file), and a value below 1 is a usage error (exit status 2). The Python side is decompress_dir(path, jobs=2), where a value below 1 raises ValueError. On a single archive the option has no effect, and with --recursive the checkpoint directories are still restored one after another, each with N archives at a time.
What stays the same¶
All or nothing. Archives are deleted (unless
--keep) only after every file is restored and checked. When one fails, no archive is deleted and the files this call wrote are removed. Archives that have not started when a failure is seen are skipped, and the running ones finish first, so nothing is written after the cleanup.The error you get. It is the error of the first failing archive in name order, which is the one
--jobs 1reports, even when a later archive fails sooner in time.Delta archives. Restoring reads the base archives, never a restored file, and the archives stay until every file is restored, so no archive waits for another and
--delta firstand--delta previousneed no extra care. Split archives count as one archive each.
What it costs¶
Each archive that restores at the same time holds its decoded tensors and the file it is writing. The peak memory grows with N, by up to about the size of one file for each archive that you add to the run: --jobs 8 on a directory of 64 MiB files needs up to about eight files' worth of room (the table below peaked lower). Choose N from the memory you can spare, not from the number of files. A value above the number of archives is the number of archives.
--threads stays the budget of the whole command. Each archive gets THREADS / N of them, and at least one, so about THREADS threads decode at once however large N is. With --jobs above --threads, each archive still gets one thread, so N threads work.
A measurement¶
This is an illustrative measurement on one laptop, not Jabara's benchmark. Setup: Apple M1 Max with 10 cores and 64 GiB, macOS, Python 3.13, --threads 8. Each directory holds archives made by jabara compress from synthetic safetensors files of four equal tensors, with values from a normal distribution with standard deviation 0.02, as float32 or as bfloat16 (the upper 16 bits of the float32 value). Each cell is the median of three runs of jabara decompress DIR --keep --threads 8 --jobs N, each in a fresh process, with the archives already in the file cache from an untimed run, and the restored files deleted between runs. The time is that of the whole command and includes about 0.2 s of start-up. The peak memory is the maximum resident set size of the process that /usr/bin/time -l reports. The machine did nothing else.
Directory |
|
Time, s |
Peak memory, MiB |
|---|---|---|---|
8 files of 64 MiB, |
1 |
0.52 |
230 |
2 |
0.41 |
394 |
|
4 |
0.36 |
648 |
|
8 |
0.38 |
622 |
|
8 files of 64 MiB, |
1 |
0.50 |
253 |
2 |
0.39 |
444 |
|
4 |
0.37 |
679 |
|
8 |
0.37 |
680 |
|
2 files of 256 MiB, |
1 |
0.39 |
621 |
2 |
0.36 |
924 |
|
4 |
0.36 |
908 |
|
8 |
0.36 |
970 |
For eight files, --jobs 4 took 0.13 to 0.16 s less than --jobs 1 (a quarter to a third less, start-up included) and needed about 2.8 times the memory, and a value above 4 gained nothing. For two large files the gain was 0.03 s (about 8%), and the peak memory was 1.5 times as large. With two files, --jobs 4 and --jobs 8 restore two archives at a time like --jobs 2, so the differences between those three rows are noise. The gain depends on the disk, the codec, and the sizes of the files, so time your own directory with --jobs 1 and a few larger values before you use it in a script.