Compare codecs on your own checkpoint¶
jabara bench and jabara.bench.compare run candidate codecs on your own tensors. A comparison runs every candidate on the same tensors, with the same chunking and the same thread pool, in memory. It writes no archive and no file. The report has one row for each candidate and role.
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.
$ python make_checkpoint.py
Run it from the command line¶
Name the candidates and set --repeats. Without --candidates, bench runs every lossless codec that needs no base, plus the delta codecs when you pass --base. It skips a codec whose optional package is missing and names it in a jabara: skipped ... line on stderr. Stdout holds only the report.
$ jabara bench checkpoint-1000/model.safetensors --candidates raw/1,zstd/1,bytegroup-zstd/1 --repeats 3
... threads, best of 3, 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
bytegroup-zstd/1 weight: ... bytes (...% of original), encode ... MB/s, decode ... MB/s, exact
--base adds the delta codecs (see Store a checkpoint as a difference against a base), and --json prints the report as JSON. PATH can be an archive, a safetensors file, a torch file, or a directory.
Run it from Python¶
load_records reads the same inputs as the command, candidates_for builds one candidate for each codec id, and compare runs them:
from jabara.bench import BenchReport, candidates_for, compare
from jabara.files import load_records
new = load_records("checkpoint-1100/model.safetensors")
old = load_records("checkpoint-1000/model.safetensors")
candidates = candidates_for(["bytegroup-zstd/1", "xor-delta/1"])
report = compare(new, candidates, base=old, repeats=3, threads=1)
for row in report.rows:
print(row.candidate, row.role, row.needs_base, row.check_decode, row.bit_exact, row.fallback_tensors)
print(report.environment.threads, report.environment.repeats, report.environment.warmup_passes)
print(BenchReport.model_validate_json(report.model_dump_json()) == report)
bytegroup-zstd/1 weight False False True 0
xor-delta/1 weight True False True 0
1 3 1
True
report.model_dump_json() is the JSON that jabara bench --json prints. JSON schemas gives its JSON schema.
What the seconds include and exclude¶
encode_seconds and decode_seconds time the codec's work on the chunks in memory: Codec.encode, or Codec.decode plus the length and CRC-32 check of each decoded chunk. Throughput is the raw bytes divided by those seconds. The seconds leave out creating the thread pool, building the codecs, joining the chunks, comparing the output, and file access. They are the codec's share of a save or a load, not the time of the whole operation. Two flags mark the rows where a save or a load does more work that no row times:
needs_baseis true when a tensor of the row uses a delta codec. A save and a load decode the whole base tensor first.check_decodeis true when a tensor of the row uses a lossy codec. A save decodes it once more to check it and to computemax_abs_err.
Every save also computes the CRC-32 of the input and writes the file, and every load reads the file. To time a whole save or load, time compress_file and decompress_file on your files.
Warm-up, round order, and repeats¶
Before the first row, each distinct codec and parameter set codes a slice of at most 64 KiB, so that no row pays for starting the pool's threads or for a codec's lazy imports. Then each role runs warmup_passes untimed rounds (one) and repeats timed rounds. In a round, each candidate in turn encodes and decodes once. The candidate order reverses on every other timed round, so a steady drift in the machine's speed does not favour one candidate in every round. Right before each timed encode and each timed decode, the pool's threads and the calling thread run an untimed busy loop for 0.1 s, which the report records in spin_seconds. Command line describes the output line.
encode_seconds and decode_seconds are the smallest of the timed runs, and encode_seconds_all and decode_seconds_all hold every run in order. Keep these limits in mind:
With
repeats=1, the one timed round runs in the order that you gave, so a candidate's position affects its time. With an oddrepeats, one more round runs forward than in reverse.The warm-up and the order reversal are meant to limit position effects, but their effect has not been measured. If a conclusion rests on a small difference, run each order or repeat the run.
A difference between two candidates that is smaller than the spread of their
_alllists does not rank them.jabara benchdefaults to--repeats 3, andcomparetorepeats=1.
Rows that need a second look¶
fallback_tensors. The number of tensors for which the candidate chose a delta codec, found no reference in the base, and used its fallback. For those tensors, the row measures the fallback codec. A delta candidate with no reference for any tensor raisesMissingBaseErrorinstead of producing a row.decode_error. A decode pass raisedChecksumError. The row keeps the reader's message,decode_secondsandmax_abs_errareNone, andbit_exactis false. A broken codec has no decode time, so it cannot rank as fast. The command printsdecode failed (<message>)in place of the decode throughput.bit_exactandlossless.losslessis the codec's own flag, andbit_exactis recomputed from the decoded bytes. The command exits with status 0 even with aNOT EXACTrow, so read the lines.stored_bytes. The sum of the chunk payload lengths. It leaves out the index and the magic bytes of an archive, so it is not a file size.threads. The size of the thread pool that codes the chunks. How a row scales with it is the codec's own behaviour, so compare rows only from reports made with the samethreads.
The report does not measure memory.
Measure each candidate in its own process for numbers you publish¶
Candidates in one call can change each other's times. One cause is the memory allocator: the memory that one candidate frees decides how many new pages the next one must fault in. The busy loop reduces this effect for some candidates and increases it for others, so one call is still not fair. DESIGN.md, "Comparison" gives the sizes of these effects on one machine, with and without the busy loop. A process cannot reset its allocator, so for numbers that you publish, run each candidate in its own process. Each jabara bench command is one process, so name one candidate per command:
$ jabara bench checkpoint-1000/model.safetensors --candidates zstd/1 --repeats 3
... threads, best of 3, 1 warm-up, chunk ... bytes
zstd/1 weight: ... bytes (...% of original), encode ... MB/s, decode ... MB/s, exact
$ jabara bench checkpoint-1000/model.safetensors --candidates bytegroup-zstd/1 --repeats 3
... threads, best of 3, 1 warm-up, chunk ... bytes
bytegroup-zstd/1 weight: ... bytes (...% of original), encode ... MB/s, decode ... MB/s, exact
Add --json to keep each report. Sizes, bit_exact, and decode_error are the same as in one call with all the candidates. Times still vary from process to process, so run each command more than once and compare the spread before you rank two candidates.
Timings are not comparable across machines or settings¶
A time depends on the processor, the load on the machine, threads, repeats, the chunk size, and the library versions. A report's environment records them: cpu_model, cpu_count, load_average_1m, threads, repeats, warmup_passes, spin_seconds, chunk_size, and the versions of Python, numpy, zstandard, and the optional packages. Compare two reports only when their environments agree on those fields. Sizes do not depend on the machine's speed or load, but they can change with another zstandard version, which environment also records.