Metadata-Version: 2.5
Name: jabara
Version: 0.2.1
Summary: A unified library for compressing LLM training checkpoints: weights and optimizer state
Project-URL: Homepage, https://jabara.iamtatsuki05.com/
Project-URL: Documentation, https://jabara.iamtatsuki05.com/docs/
Project-URL: Repository, https://github.com/iamtatsuki05/jabara
Project-URL: Changelog, https://github.com/iamtatsuki05/jabara/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/iamtatsuki05/jabara/issues
Author: Tatsuki Okada
License-Expression: MIT
License-File: LICENSE
Keywords: checkpoint,compression,llm,lossless,optimizer-state,pytorch,safetensors,training
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: System :: Archiving :: Compression
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.26
Requires-Dist: pydantic>=2.8
Requires-Dist: tomli>=2.0; python_version < '3.11'
Requires-Dist: typed-argument-parser>=1.12.0
Requires-Dist: zstandard>=0.23
Provides-Extra: hdf5
Requires-Dist: h5py>=3.10; extra == 'hdf5'
Provides-Extra: hf
Requires-Dist: accelerate>=1.0; extra == 'hf'
Requires-Dist: torch>=2.4; extra == 'hf'
Requires-Dist: transformers>=5.0; extra == 'hf'
Provides-Extra: lightning
Requires-Dist: lightning>=2.4; extra == 'lightning'
Requires-Dist: torch>=2.4; extra == 'lightning'
Provides-Extra: torch
Requires-Dist: torch>=2.4; extra == 'torch'
Provides-Extra: yaml
Requires-Dist: pyyaml>=6.0; extra == 'yaml'
Provides-Extra: zipnn
Requires-Dist: zipnn<0.6,>=0.5; extra == 'zipnn'
Description-Content-Type: text/markdown

# Jabara

English / [日本語](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/README_JA.md)

Jabara compresses training checkpoints: model weights and optimizer state. Lossless compression, deltas against an earlier checkpoint, and quantization all sit behind one codec interface. By default Jabara restores every tensor bit for bit, every read checks a CRC-32, and an archive gets a lossy codec only when you opt in.

![The result of the live demo: for a small checkpoint, the stored size of each codec as a bar split into weights, first moment, and second moment, with five lossless codecs marked bit-exact and two lossy codecs marked with their largest error.](https://raw.githubusercontent.com/iamtatsuki05/jabara/v0.2.1/docs/assets/readme-demo.png)

- **Live demo:** https://jabara.iamtatsuki05.com/demo/ (runs in your browser and uploads nothing)
- **Project page:** https://jabara.iamtatsuki05.com/
- **Results viewer:** https://jabara.iamtatsuki05.com/results/
- **Documentation:** [English](https://jabara.iamtatsuki05.com/docs/) / [日本語](https://jabara.iamtatsuki05.com/docs/ja/)

## Who it is for

Jabara is for checkpoints that you keep and read back later: the checkpoints of seed and hyperparameter sweeps, intermediate checkpoints kept for analysis, and runs that resume after an interruption or that someone else resumes. Saves and loads take longer than without Jabara, and a framework cannot memory-map an archive, so it is not a format to serve a model from. [Who Jabara is for](https://jabara.iamtatsuki05.com/docs/explanation/use-cases.html) gives the measured sizes and costs, and [Compress the checkpoints of many runs](https://jabara.iamtatsuki05.com/docs/how-to/compress-many-runs.html) shows the commands for a finished sweep. [Jabara and general-purpose archivers](https://jabara.iamtatsuki05.com/docs/explanation/archivers.html) compares it with `tar`, `zip`, `gzip`, and `zstd`.

## What you can do

- **Take many file formats through one registry.** `jabara compress` reads safetensors, `torch.save` files (without unpickling them), NumPy, GGUF, Keras and HDF5, ONNX, TensorFlow and MindSpore checkpoints, Core ML weight files, and Flax msgpack files, and a lossless archive restores each file byte for byte. A new format is one `CheckpointFormat` subclass plus the code that finds the tensor bytes in the file, and the built-in format modules are 86 to 290 lines each ([Checkpoint file formats](https://jabara.iamtatsuki05.com/docs/reference/formats.html)).
- **Split an archive by size or by count, and join it back.** `--part-size 2GB` or `--parts 4` cuts each archive, and `jabara split` and `jabara join` change an archive that exists without encoding it again ([Split an archive into parts and join it back](https://jabara.iamtatsuki05.com/docs/how-to/split-archives.html)).
- **Handle a whole run.** `--recursive` takes every checkpoint directory of a run, and `compress --dry-run` lists what it would do before it changes anything ([Compress the checkpoints of many runs](https://jabara.iamtatsuki05.com/docs/how-to/compress-many-runs.html)).
- **Store deltas.** `--delta first` codes each later checkpoint against the first one and `--delta previous` against the one before it, which saves only a few points more and restores slower. `--base` takes a directory too, and `jabara.hf.attach(trainer, delta="first")` saves deltas from a `Trainer` ([Delta checkpoints](https://jabara.iamtatsuki05.com/docs/how-to/delta-checkpoints.html)).
- **Read options from a file.** `--config FILE` takes JSON, YAML, or TOML, and `--show-config` prints the settings without running the command ([Run from a config file](https://jabara.iamtatsuki05.com/docs/how-to/run-from-a-config-file.html)).
- **Find your way in the command.** `-h` and `-H` print the short and the full help, `jabara man COMMAND` shows the manual page, and `jabara codecs --long` lists each codec with the works it builds on ([Command-line reference](https://jabara.iamtatsuki05.com/docs/reference/cli.html)).
- **Hand it to an agent.** The repository ships an agent skill for Claude Code, Codex CLI, GitHub Copilot CLI, Cursor, and Gemini CLI, an `AGENTS.md`, and a test of the command's contract ([Use Jabara from an AI agent](https://jabara.iamtatsuki05.com/docs/how-to/use-from-an-agent.html)).

## Install

Jabara needs Python 3.10 or newer. Install it from PyPI into a virtual environment:

```console
$ python -m venv .venv
$ source .venv/bin/activate
$ pip install "jabara[torch]"
```

In a uv project, run `uv add "jabara[torch]"` instead.

The extras are `torch` (PyTorch state, and the tensor names and roles of `.pt` files), `hf` (the Hugging Face `Trainer` adapter), `lightning` (the PyTorch Lightning plugin), `zipnn` (the `zipnn/1` codec), `yaml` (YAML config files), and `hdf5` (HDF5 and Keras files). See [Installation](https://jabara.iamtatsuki05.com/docs/getting-started/installation.html).

## Quickstart

Compress a checkpoint directory, check it, and restore it. `compress` replaces each `*.safetensors` file and `optimizer.pt` with a verified `.jbr` archive and leaves the other files alone. It also takes the files that Accelerate, PyTorch Lightning, DeepSpeed, and Megatron-LM write with `torch.save`, without unpickling them, TensorFlow data shards, MindSpore `.ckpt` files, and a Flax model's `flax_model.msgpack`, and, when you name the file, NumPy `.npy` and `.npz`, GGUF, Keras `.keras` and HDF5 files, ONNX models and their external data, Core ML `weight.bin` files, and any Flax `.msgpack` file. Each format is one class in a registry, and a lossless archive restores the file byte for byte (see [Checkpoint file formats](https://jabara.iamtatsuki05.com/docs/reference/formats.html)).

```console
$ jabara compress checkpoint-1000
checkpoint-1000/model.safetensors.jbr: ... -> ... bytes (...% of original)
checkpoint-1000/optimizer.pt.jbr: ... -> ... bytes (...% of original)
$ jabara verify checkpoint-1000
ok checkpoint-1000/model.safetensors.jbr
ok checkpoint-1000/optimizer.pt.jbr
$ jabara decompress checkpoint-1000
checkpoint-1000/model.safetensors
checkpoint-1000/optimizer.pt
```

Save and load a PyTorch state from Python:

```python
import torch
from jabara.torch import load_state, save_state

model = torch.nn.Linear(16, 16)
optimizer = torch.optim.AdamW(model.parameters())
model(torch.randn(4, 16)).sum().backward()
optimizer.step()

save_state(optimizer.state_dict(), "optimizer.jbr")
optimizer.load_state_dict(load_state("optimizer.jbr"))
```

The [tutorial](https://jabara.iamtatsuki05.com/docs/getting-started/tutorial.html) explains both examples. Every command that has options also reads them from a JSON, YAML, or TOML file with `--config FILE`; see [Run from a config file](https://jabara.iamtatsuki05.com/docs/how-to/run-from-a-config-file.html).

An archive can also be written as several files, parts of at most a given size (`jabara compress --part-size 2GiB`) or a given number of parts (`--parts 4`). Every command reads the parts as one archive, and `jabara join` gives back the archive byte for byte; see [Split an archive into parts and join it back](https://jabara.iamtatsuki05.com/docs/how-to/split-archives.html).

## Codecs

| Codec | Type | Needs a base |
| --- | --- | --- |
| `bytegroup-zstd/1` | lossless | no |
| `quant8-linear/1` | lossy | no |
| `quant8-log/1` | lossy | no |
| `raw/1` | lossless | no |
| `sub-delta/1` | lossless | yes |
| `xor-delta/1` | lossless | yes |
| `zipnn/1` | lossless | no |
| `zstd/1` | lossless | no |

A codec that needs a base stores each tensor as its difference from the same tensor in an earlier archive. The [codec reference](https://jabara.iamtatsuki05.com/docs/reference/codecs.html) gives the dtypes, the parameters, and the error bounds of the lossy codecs.

## Extend Jabara

To extend Jabara, subclass one of these abstract base classes. You change no other code. Each example is a complete script, and a test runs all of them.

- `Codec` turns one chunk of one tensor into bytes and back: [examples/extend/custom_codec.py](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/examples/extend/custom_codec.py), and with a validated parameter, [examples/extend/codec_with_params.py](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/examples/extend/codec_with_params.py).
- `Assigner` chooses the codec for each tensor: [examples/extend/custom_assigner.py](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/examples/extend/custom_assigner.py).
- `StateSchema` names the role of each tensor from its path in the nested state: [examples/extend/custom_schema.py](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/examples/extend/custom_schema.py).

## Documentation

Read the documentation on the [published site](https://jabara.iamtatsuki05.com/docs/). GitHub shows its MyST sources as raw text.

- [Installation](https://jabara.iamtatsuki05.com/docs/getting-started/installation.html) and the [tutorial](https://jabara.iamtatsuki05.com/docs/getting-started/tutorial.html)
- [Command-line reference](https://jabara.iamtatsuki05.com/docs/reference/cli.html), and [Use Jabara from an AI agent](https://jabara.iamtatsuki05.com/docs/how-to/use-from-an-agent.html) with the agent skill in [skills/jabara/](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/skills/jabara/SKILL.md) for Claude Code, Codex, GitHub Copilot, Gemini CLI, Cursor, and other agents
- [Built-in codecs](https://jabara.iamtatsuki05.com/docs/reference/codecs.html)
- [Archive format](https://jabara.iamtatsuki05.com/docs/reference/archive-format.html) and [JSON schemas](https://jabara.iamtatsuki05.com/docs/reference/schemas.html)
- [Python API](https://jabara.iamtatsuki05.com/docs/reference/api.html)
- [DESIGN.md](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/DESIGN.md) sets the data shapes and module boundaries.

To build the site from the clone, run `uv run --group docs sphinx-build -W --keep-going -b html docs docs/_build/html` and open `docs/_build/html/index.html`. [docs/README.md](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/docs/README.md) gives the Japanese build and explains how the sources are tested.

To work on Jabara, run `uv sync` in the clone to install the locked `dev` group, then `uv run tox` to run the tests, ruff, and mypy.

## License

MIT. See [LICENSE](https://github.com/iamtatsuki05/jabara/blob/v0.2.1/LICENSE).
