Skip to main content

Lossless delta-compressed weight format for fine-tuned neural network models

Project description

deltatensors

Near-lossless delta compression for fine-tuned neural network models.

Instead of storing 50 fine-tunes of the same base model, store one base and 50 small .wdelta delta files. deltatensors compresses the delta between a base and fine-tuned model, and reconstructs with sub-1% perplexity difference.

Tested on Qwen2.5-0.5B fine-tuned on WikiText-2:

  • Perplexity: 19.11 (original) → 19.22 (reconstructed) — 0.58% perplexity difference
  • Less degradation than standard int4 quantization of the full model
  • 294 MB delta vs 953 MB fine-tuned model (3.2x)
  • ~2.8x total storage reduction across 10 fine-tunes
base_model.safetensors   1.0 GB
checkpoint_01.wdelta     294 MB
checkpoint_02.wdelta     294 MB
...
checkpoint_10.wdelta     294 MB
─────────────────────────────────
Total                    3.9 GB    vs  11 GB naive

Install

pip install deltatensors
pip install torch safetensors  # for loading from safetensors directories

Quick start

import deltatensors as dt

# save delta between a fine-tuned and base model (streaming, O(1) RAM)
dt.save_delta_from_paths("checkpoint.wdelta", "qwen-wiki/", "qwen-base/", strategy="int4")

# reconstruct without loading the full base into RAM
recon_sd = dt.load_delta_from_paths("checkpoint.wdelta", "qwen-base/")

# inspect a delta file without a base model
info = dt.inspect("checkpoint.wdelta")
print(info)
# {'path': 'checkpoint.wdelta', 'size_mb': 294.2, 'strategy': 'int4', 'n_tensors': 290, ...}

Compression strategies

Strategy Quality Compression
int4 near-lossless (~0.5% PPL) best
sparse tunable via sparsity= good
quantized BitDelta-style 1-bit aggressive

int4 uses outlier extraction (top k% weights stored in float16) + 4-bit quantization for the remainder. This was the strategy used for the example at the start.

Why not LoRA?

LoRA constrains the delta to be low-rank during training, which limits expressiveness. deltatensors compresses arbitrary full fine-tune deltas after training - no constraints on how you fine-tune.

Roadmap

  • Lineage — chain multiple .wdelta files to track and reconstruct full fine-tuning histories

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deltatensors-0.1.0.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deltatensors-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

Details for the file deltatensors-0.1.0.tar.gz.

File metadata

  • Download URL: deltatensors-0.1.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for deltatensors-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49a625f1e56ac11dc48e01a7caea605b41cb0184cf6a376d2265262440dc8871
MD5 4d816260c8e95d315496087a3d0473c1
BLAKE2b-256 e526d9debfaa6f3d74d367d85ad0d2b563b80a35cddef6a976eb175e9fd87d4e

See more details on using hashes here.

File details

Details for the file deltatensors-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: deltatensors-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for deltatensors-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37a3febee72ef365de927bfdd3663db47bb054fef9d810df89a8ab00da8d02b4
MD5 af03a137eb9838be560cd18575cd7092
BLAKE2b-256 1569d36db64602ffcbb6246f1d7ceef65a0110497098b7d58025353db22de964

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page