Metadata-Version: 2.4
Name: fireworks-delta-compression
Version: 0.1.0
Summary: Delta compression utilities used by the Fireworks AI hot-load and incremental snapshot pipelines
Author-email: Fireworks AI <info@fireworks.ai>
License: The MIT License
        
        Copyright (c) Fireworks (https://fireworks.ai)
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
Project-URL: Homepage, https://fireworks.ai
Keywords: delta-compression,safetensors,model-weights,fireworks
Classifier: Development Status :: 4 - Beta
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: System :: Archiving :: Compression
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch<3,>=2.1
Requires-Dist: safetensors<1,>=0.4
Requires-Dist: numpy<3,>=1.20
Requires-Dist: zstd<2,>=1.5
Requires-Dist: packaging>=21
Dynamic: license-file

# fireworks-delta-compression

Delta compression utilities used by the Fireworks AI serving stack to ship
incremental model weight updates (hot-loads) over the wire.

This package exposes the same compression / decompression backends that the
Fireworks serving servers use internally, so you can produce or consume
deltas on the customer side without copy-pasting source from the monorepo
and without risk of dependency version drift.

## Install

```bash
pip install fireworks-delta-compression
```

## Quick start

```python
import torch
from fireworks_delta_compression import (
    delta_compress,
    delta_decompress,
)

src = torch.randn(1024, 1024, dtype=torch.bfloat16)
dst = src + 1e-3 * torch.randn_like(src)

compressed_diff, checksum = delta_compress(
    src=src,
    dst=dst,
    compression_format="arc_v3",
)

restored = delta_decompress(
    src=src,
    compressed_diff=compressed_diff,
    checksum=checksum,
    compression_format="arc_v3",
)
torch.testing.assert_close(restored, dst)
```

## Supported compression formats

| Format    | Backend                            |
| --------- | ---------------------------------- |
| `arc_v1`  | XOR diff + zlib                    |
| `arc_v2`  | XOR diff + zstd                    |
| `arc_v3`  | ARC v3 (typed, multi-strategy)     |

## Higher-level helpers

* `delta_compress_dicts_to_file` / `delta_decompress_dict_from_file` — work
  on `dict[str, torch.Tensor]` and persist to safetensors with checksums in
  the metadata block.
* `delta_compress_files_to_file` — read two safetensors files and write the
  delta out as a third safetensors file.
* `delta_compress_dirs` / `decompress_delta_into_source` — walk a directory
  of safetensors shards in parallel.
* `delta_decompress_inplace` — mmap-based in-place decompression that
  rewrites the base safetensors file with the diff applied (no extra
  RAM copy).

## Versioning

Dependencies (`torch`, `safetensors`, `numpy`, `zstd`) use loose compatible-
release pins so this wheel installs cleanly alongside customer code. The
upper bounds (`<3`, `<1`, `<3`, `<2`) protect against silent breakage from
major-version upgrades; bump them after validating against a new server
release.

## License

MIT — see [LICENSE](LICENSE).
