lmzip 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
lmzip-1.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fanxin Sun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
lmzip-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,135 @@
1
+ Metadata-Version: 2.4
2
+ Name: lmzip
3
+ Version: 1.0.0
4
+ Summary: Lossless compression for model weights: 34.7% off BF16, byte for byte, with a store you can read through
5
+ Author: Fanxin Sun
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/FanxinSun/lmz
8
+ Project-URL: Repository, https://github.com/FanxinSun/lmz
9
+ Project-URL: Issues, https://github.com/FanxinSun/lmz/issues
10
+ Project-URL: Funding, https://buymeacoffee.com/fanxinsun
11
+ Keywords: compression,lossless,safetensors,gguf,llm,model-weights,bfloat16,fp8,quantization,zstd,rans,entropy-coding,fuse,filesystem,model-store,checkpoint,machine-learning
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Operating System :: MacOS
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Programming Language :: C
24
+ Classifier: Topic :: System :: Archiving :: Compression
25
+ Classifier: Topic :: System :: Filesystems
26
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Provides-Extra: zstd
31
+ Requires-Dist: zstandard>=0.21; extra == "zstd"
32
+ Dynamic: license-file
33
+
34
+ # lmz
35
+
36
+ [![tests](https://github.com/FanxinSun/lmz/actions/workflows/tests.yml/badge.svg)](https://github.com/FanxinSun/lmz/actions/workflows/tests.yml)
37
+ [![PyPI](https://img.shields.io/pypi/v/lmzip)](https://pypi.org/project/lmzip/)
38
+ [![Python](https://img.shields.io/pypi/pyversions/lmzip)](https://pypi.org/project/lmzip/)
39
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
40
+
41
+ **Smaller checkpoints. Byte for byte.**
42
+
43
+ Lossless compression built for model weights. `zstd -1` takes 22.7% off a
44
+ Llama-3.1-8B BF16 checkpoint. lmz takes **34.7%** — and **64.6%** off the
45
+ directory as Hugging Face actually ships it, which is **13 GB more than zstd
46
+ on one 8B model**.
47
+
48
+ Nothing is approximated. Every byte comes back.
49
+
50
+ ```
51
+ pip install lmzip
52
+ lmz compress ./Llama-3.1-8B-Instruct/
53
+ ```
54
+
55
+ ## What it saves
56
+
57
+ Real checkpoints, every round-trip verified byte-identical.
58
+
59
+ | | size | after | saved | zstd -1 |
60
+ |---|---|---|---|---|
61
+ | **Llama-3.1-8B, whole HF directory** | 32.13 GB | 11.38 GB | **64.6%** | 22.7% |
62
+ | **Llama-3.1-8B, 4 BF16 shards** | 16.06 GB | 10.49 GB | **34.7%** | 22.7% |
63
+ | Ministral-8B, whole directory | 32.11 GB | 11.55 GB | **64.0%** | 22.7% |
64
+ | Pythia-160m, 3 training checkpoints | 1.81 GiB | 644 MiB | **65.3%** | 22.7% |
65
+ | bge-m3 directory (FP32 container) | 4.59 GB | 2.45 GB | **46.5%** | — |
66
+ | 8-bit AdamW optimizer state ×2 | 161 MiB | 119 MiB | **26.1%** | — |
67
+
68
+ On BF16 weights lmz beats the published state of the art, and sits 0.3 points
69
+ off the bound no lossless coder of any kind can pass:
70
+
71
+ | on real Llama BF16 | saved |
72
+ |---|---|
73
+ | **lmz** | **34.7%** |
74
+ | [ZipNN](https://github.com/zipnn/zipnn) (published, same model) | 33.6% |
75
+ | [DFloat11](https://arxiv.org/pdf/2504.11651) (published) | ~30% |
76
+ | bzip2 -9 | 30.7% |
77
+ | xz -6 | 29.9% |
78
+ | zstd -19 | 23.6% |
79
+ | theoretical joint-entropy bound | 35.0% |
80
+
81
+ **Three things a general compressor structurally cannot do**, which is where
82
+ most of the margin comes from: store a tensor once when a directory ships it
83
+ twice, code a checkpoint as the difference from the one before it, and split
84
+ on a float's own bit-fields instead of byte boundaries.
85
+
86
+ ## Where it is not worth it
87
+
88
+ Stated plainly, because a compressor that only advertises its wins should not
89
+ be believed:
90
+
91
+ | | lmz | best alternative | verdict |
92
+ |---|---|---|---|
93
+ | Quantised GGUF (Q8_0 / Q4_K_M) | 6.7% / 5.1% | 5.5% / 2.5% | the quantiser already took it |
94
+ | FP8 safetensors | 17.14% | zstd -3, 17.11% | **just use zstd**, the gap is 0.03 points |
95
+ | Text, code, JSON, binaries | = zstd | zstd | lmz *is* zstd here, by design |
96
+ | Read speed | slower | a plain file | see below |
97
+
98
+ Reading a compressed file transparently can never beat a plain one by more
99
+ than `1/(1−saved)` — you still have to read the archive. That is 1.5× on BF16
100
+ and 1.05× on Q4_K, so on a fast SSD the mount is *slower*. It buys disk, not
101
+ speed.
102
+
103
+ ## Also included
104
+
105
+ ```
106
+ lmz add ./my-model/ && lmz mount ~/models # read a compressed model as ordinary
107
+ # files; llama.cpp needs no patch
108
+ lmz fs ~/.lmz/data ~/data # a read-write compressed filesystem;
109
+ # 32.1% where btrfs+zstd gets 18.9%
110
+ ```
111
+
112
+ ## Buy me a coffee
113
+
114
+ lmz is free, MIT-licensed and unfunded. If it saved you disk or bandwidth —
115
+
116
+ ### [☕ **Buy me a coffee**](https://buymeacoffee.com/fanxinsun)
117
+
118
+ or [Alipay](assets/alipay.jpg) (打开支付宝,扫一扫). Thank you.
119
+
120
+ ## Documentation
121
+
122
+ - [**How it works**](docs/how-it-works.md) — why a float array defeats a
123
+ general-purpose compressor, and the bit-level choices that close the gap
124
+ - [**Measured results**](docs/results.md) — every number, with its conditions
125
+ - [**Using lmz**](docs/usage.md) — command line, Python API, the mount and the
126
+ filesystem
127
+ - [**Limitations**](docs/limitations.md) — where it does not pay, and what the
128
+ 81 tests check
129
+
130
+ Python 3.10+, no runtime dependencies. zstd comes from the standard library on
131
+ 3.14+; a C compiler, if present, is used once to build the SIMD kernel into the
132
+ package directory — nothing is installed system-wide. Runs straight from a
133
+ checkout with `./lmz-cli` if you would rather not install it at all.
134
+
135
+ Check what is active with `lmz doctor`.
lmzip-1.0.0/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # lmz
2
+
3
+ [![tests](https://github.com/FanxinSun/lmz/actions/workflows/tests.yml/badge.svg)](https://github.com/FanxinSun/lmz/actions/workflows/tests.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/lmzip)](https://pypi.org/project/lmzip/)
5
+ [![Python](https://img.shields.io/pypi/pyversions/lmzip)](https://pypi.org/project/lmzip/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
7
+
8
+ **Smaller checkpoints. Byte for byte.**
9
+
10
+ Lossless compression built for model weights. `zstd -1` takes 22.7% off a
11
+ Llama-3.1-8B BF16 checkpoint. lmz takes **34.7%** — and **64.6%** off the
12
+ directory as Hugging Face actually ships it, which is **13 GB more than zstd
13
+ on one 8B model**.
14
+
15
+ Nothing is approximated. Every byte comes back.
16
+
17
+ ```
18
+ pip install lmzip
19
+ lmz compress ./Llama-3.1-8B-Instruct/
20
+ ```
21
+
22
+ ## What it saves
23
+
24
+ Real checkpoints, every round-trip verified byte-identical.
25
+
26
+ | | size | after | saved | zstd -1 |
27
+ |---|---|---|---|---|
28
+ | **Llama-3.1-8B, whole HF directory** | 32.13 GB | 11.38 GB | **64.6%** | 22.7% |
29
+ | **Llama-3.1-8B, 4 BF16 shards** | 16.06 GB | 10.49 GB | **34.7%** | 22.7% |
30
+ | Ministral-8B, whole directory | 32.11 GB | 11.55 GB | **64.0%** | 22.7% |
31
+ | Pythia-160m, 3 training checkpoints | 1.81 GiB | 644 MiB | **65.3%** | 22.7% |
32
+ | bge-m3 directory (FP32 container) | 4.59 GB | 2.45 GB | **46.5%** | — |
33
+ | 8-bit AdamW optimizer state ×2 | 161 MiB | 119 MiB | **26.1%** | — |
34
+
35
+ On BF16 weights lmz beats the published state of the art, and sits 0.3 points
36
+ off the bound no lossless coder of any kind can pass:
37
+
38
+ | on real Llama BF16 | saved |
39
+ |---|---|
40
+ | **lmz** | **34.7%** |
41
+ | [ZipNN](https://github.com/zipnn/zipnn) (published, same model) | 33.6% |
42
+ | [DFloat11](https://arxiv.org/pdf/2504.11651) (published) | ~30% |
43
+ | bzip2 -9 | 30.7% |
44
+ | xz -6 | 29.9% |
45
+ | zstd -19 | 23.6% |
46
+ | theoretical joint-entropy bound | 35.0% |
47
+
48
+ **Three things a general compressor structurally cannot do**, which is where
49
+ most of the margin comes from: store a tensor once when a directory ships it
50
+ twice, code a checkpoint as the difference from the one before it, and split
51
+ on a float's own bit-fields instead of byte boundaries.
52
+
53
+ ## Where it is not worth it
54
+
55
+ Stated plainly, because a compressor that only advertises its wins should not
56
+ be believed:
57
+
58
+ | | lmz | best alternative | verdict |
59
+ |---|---|---|---|
60
+ | Quantised GGUF (Q8_0 / Q4_K_M) | 6.7% / 5.1% | 5.5% / 2.5% | the quantiser already took it |
61
+ | FP8 safetensors | 17.14% | zstd -3, 17.11% | **just use zstd**, the gap is 0.03 points |
62
+ | Text, code, JSON, binaries | = zstd | zstd | lmz *is* zstd here, by design |
63
+ | Read speed | slower | a plain file | see below |
64
+
65
+ Reading a compressed file transparently can never beat a plain one by more
66
+ than `1/(1−saved)` — you still have to read the archive. That is 1.5× on BF16
67
+ and 1.05× on Q4_K, so on a fast SSD the mount is *slower*. It buys disk, not
68
+ speed.
69
+
70
+ ## Also included
71
+
72
+ ```
73
+ lmz add ./my-model/ && lmz mount ~/models # read a compressed model as ordinary
74
+ # files; llama.cpp needs no patch
75
+ lmz fs ~/.lmz/data ~/data # a read-write compressed filesystem;
76
+ # 32.1% where btrfs+zstd gets 18.9%
77
+ ```
78
+
79
+ ## Buy me a coffee
80
+
81
+ lmz is free, MIT-licensed and unfunded. If it saved you disk or bandwidth —
82
+
83
+ ### [☕ **Buy me a coffee**](https://buymeacoffee.com/fanxinsun)
84
+
85
+ or [Alipay](assets/alipay.jpg) (打开支付宝,扫一扫). Thank you.
86
+
87
+ ## Documentation
88
+
89
+ - [**How it works**](docs/how-it-works.md) — why a float array defeats a
90
+ general-purpose compressor, and the bit-level choices that close the gap
91
+ - [**Measured results**](docs/results.md) — every number, with its conditions
92
+ - [**Using lmz**](docs/usage.md) — command line, Python API, the mount and the
93
+ filesystem
94
+ - [**Limitations**](docs/limitations.md) — where it does not pay, and what the
95
+ 81 tests check
96
+
97
+ Python 3.10+, no runtime dependencies. zstd comes from the standard library on
98
+ 3.14+; a C compiler, if present, is used once to build the SIMD kernel into the
99
+ package directory — nothing is installed system-wide. Runs straight from a
100
+ checkout with `./lmz-cli` if you would rather not install it at all.
101
+
102
+ Check what is active with `lmz doctor`.
@@ -0,0 +1,40 @@
1
+ """lmz - fast lossless compression for large model weights.
2
+
3
+ Model weights compress poorly with general-purpose tools because a float
4
+ array looks like noise byte for byte. It is not: in a BF16 tensor the
5
+ sign-and-exponent byte of every element takes only a few dozen distinct
6
+ values, while the mantissa byte really is close to random. Separating those
7
+ into distinct planes lets the exponents be entropy coded properly and the
8
+ mantissas be passed through untouched, which is both smaller and faster than
9
+ compressing the interleaved bytes.
10
+
11
+ import lmz
12
+ lmz.compress("model.safetensors", "model.lmz")
13
+ lmz.decompress("model.lmz", "restored.safetensors")
14
+
15
+ Output is byte-for-byte identical to the input.
16
+
17
+ A model can also be kept in the store and read in place, so nothing is ever
18
+ expanded onto disk:
19
+
20
+ import lmz
21
+ lmz.Store().add("./my-model", "my-model") # compressed, once
22
+
23
+ lmz mount ~/models # every runtime reads it as
24
+ # ordinary model files
25
+ """
26
+
27
+ __version__ = "1.0.0"
28
+
29
+ from .api import (DEFAULT_CHUNK_SIZE, DEFAULT_LEVEL, Stats, backends, compress,
30
+ decompress, info, read_tensor, verify)
31
+ from .api import MappedArchive, append, extract # noqa: F401
32
+ from .format import FormatError
33
+ from .lmzfs import LmzFS # noqa: F401
34
+ from .store import Store, mount # noqa: F401
35
+
36
+ __all__ = [
37
+ "compress", "decompress", "verify", "info", "read_tensor", "backends",
38
+ "MappedArchive", "append", "extract", "Store", "mount", "LmzFS",
39
+ "Stats", "FormatError", "DEFAULT_LEVEL", "DEFAULT_CHUNK_SIZE", "__version__",
40
+ ]
@@ -0,0 +1,5 @@
1
+ import sys
2
+
3
+ from .cli import main
4
+
5
+ sys.exit(main())