quantgap 0.1.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.
- quantgap-0.1.0/.gitignore +16 -0
- quantgap-0.1.0/CHANGELOG.md +16 -0
- quantgap-0.1.0/LICENSE +202 -0
- quantgap-0.1.0/PKG-INFO +311 -0
- quantgap-0.1.0/README.md +247 -0
- quantgap-0.1.0/docs/DECISIONS.md +116 -0
- quantgap-0.1.0/docs/RESULTS.md +52 -0
- quantgap-0.1.0/docs/SPEC.md +706 -0
- quantgap-0.1.0/docs/chart.svg +1589 -0
- quantgap-0.1.0/docs/demo.tape +24 -0
- quantgap-0.1.0/docs/faq.md +60 -0
- quantgap-0.1.0/docs/method.md +122 -0
- quantgap-0.1.0/docs/packs.md +67 -0
- quantgap-0.1.0/docs/results/bartowski__qwen2.5-0.5b-instruct-q2_k.json +88 -0
- quantgap-0.1.0/docs/results/bartowski__qwen2.5-0.5b-instruct-q3_k_m.json +88 -0
- quantgap-0.1.0/docs/results/bartowski__qwen2.5-0.5b-instruct-q4_k_m.json +88 -0
- quantgap-0.1.0/docs/results/bartowski__qwen2.5-0.5b-instruct-q5_k_m.json +88 -0
- quantgap-0.1.0/docs/results/bartowski__qwen2.5-0.5b-instruct-q6_k.json +88 -0
- quantgap-0.1.0/docs/results/bartowski__qwen2.5-0.5b-instruct-q8_0.json +88 -0
- quantgap-0.1.0/docs/results/qwen__qwen2.5-0.5b-instruct-q4_k_m.json +88 -0
- quantgap-0.1.0/pyproject.toml +77 -0
- quantgap-0.1.0/src/quantgap/__init__.py +3 -0
- quantgap-0.1.0/src/quantgap/backends/__init__.py +60 -0
- quantgap-0.1.0/src/quantgap/backends/base.py +118 -0
- quantgap-0.1.0/src/quantgap/backends/hf.py +77 -0
- quantgap-0.1.0/src/quantgap/backends/llamacpp.py +99 -0
- quantgap-0.1.0/src/quantgap/backends/mlx.py +86 -0
- quantgap-0.1.0/src/quantgap/backends/openai_compat.py +164 -0
- quantgap-0.1.0/src/quantgap/cli.py +521 -0
- quantgap-0.1.0/src/quantgap/config.py +60 -0
- quantgap-0.1.0/src/quantgap/hub/__init__.py +1 -0
- quantgap-0.1.0/src/quantgap/hub/packs.py +142 -0
- quantgap-0.1.0/src/quantgap/hub/resolve.py +247 -0
- quantgap-0.1.0/src/quantgap/hub/submit.py +87 -0
- quantgap-0.1.0/src/quantgap/models.py +202 -0
- quantgap-0.1.0/src/quantgap/pack/__init__.py +4 -0
- quantgap-0.1.0/src/quantgap/pack/reader.py +142 -0
- quantgap-0.1.0/src/quantgap/pack/runner.py +301 -0
- quantgap-0.1.0/src/quantgap/pack/writer.py +162 -0
- quantgap-0.1.0/src/quantgap/probes/__init__.py +11 -0
- quantgap-0.1.0/src/quantgap/probes/build.py +484 -0
- quantgap-0.1.0/src/quantgap/probes/data/SOURCES.md +15 -0
- quantgap-0.1.0/src/quantgap/probes/data/probes_v1.jsonl +160 -0
- quantgap-0.1.0/src/quantgap/probes/registry.py +34 -0
- quantgap-0.1.0/src/quantgap/probes/render.py +158 -0
- quantgap-0.1.0/src/quantgap/report/__init__.py +0 -0
- quantgap-0.1.0/src/quantgap/report/chart.py +92 -0
- quantgap-0.1.0/src/quantgap/report/jsonout.py +25 -0
- quantgap-0.1.0/src/quantgap/report/table.py +82 -0
- quantgap-0.1.0/src/quantgap/score/__init__.py +4 -0
- quantgap-0.1.0/src/quantgap/score/compare.py +33 -0
- quantgap-0.1.0/src/quantgap/score/damage.py +103 -0
- quantgap-0.1.0/src/quantgap/score/kld.py +73 -0
- quantgap-0.1.0/src/quantgap/score/recommend.py +78 -0
- quantgap-0.1.0/src/quantgap/score/run.py +260 -0
- quantgap-0.1.0/src/quantgap/score/stats.py +33 -0
- quantgap-0.1.0/src/quantgap/tokcheck.py +71 -0
- quantgap-0.1.0/src/quantgap/util.py +95 -0
- quantgap-0.1.0/tests/__init__.py +0 -0
- quantgap-0.1.0/tests/conftest.py +170 -0
- quantgap-0.1.0/tests/test_backends_hf.py +40 -0
- quantgap-0.1.0/tests/test_backends_llamacpp.py +44 -0
- quantgap-0.1.0/tests/test_cli.py +107 -0
- quantgap-0.1.0/tests/test_damage.py +36 -0
- quantgap-0.1.0/tests/test_default_install.py +13 -0
- quantgap-0.1.0/tests/test_hub.py +128 -0
- quantgap-0.1.0/tests/test_kld.py +75 -0
- quantgap-0.1.0/tests/test_openai_compat.py +119 -0
- quantgap-0.1.0/tests/test_pack_roundtrip.py +113 -0
- quantgap-0.1.0/tests/test_recommend.py +73 -0
- quantgap-0.1.0/tests/test_site.py +70 -0
- quantgap-0.1.0/tests/test_tokcheck.py +33 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
First version.
|
|
6
|
+
|
|
7
|
+
- `quantgap pack`: run a reference model once, save a shareable pack (top-k log probabilities,
|
|
8
|
+
hashes, manifest). Optional upload to the Hugging Face Hub.
|
|
9
|
+
- `quantgap score`: KLD (mean, worst 1%, worst 0.1%, bootstrap interval), top-1 agreement,
|
|
10
|
+
perplexity ratio, per-group numbers, and visible-damage checks (loops, wrong script, JSON).
|
|
11
|
+
- `quantgap compare`: score many quants, table, quality-vs-size chart, memory-budget recommendation.
|
|
12
|
+
- `quantgap submit`: dry-run or open a pull request with a hashed result.
|
|
13
|
+
- Backends: llama.cpp (GGUF), MLX (untested), any OpenAI-compatible server with prompt logprobs,
|
|
14
|
+
Transformers.
|
|
15
|
+
- Probe set v1: 160 openly licensed texts in 6 groups.
|
|
16
|
+
- Static leaderboard builder (`site/build.py`).
|
quantgap-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
quantgap-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: quantgap
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: How much did this quant lose? Measure how far a quantized LLM drifts from the original, without running the original.
|
|
5
|
+
Project-URL: Homepage, https://github.com/saqlain2204/quantgap
|
|
6
|
+
Project-URL: Issues, https://github.com/saqlain2204/quantgap/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/saqlain2204/quantgap/blob/main/CHANGELOG.md
|
|
8
|
+
Author-email: Mohammed Saqlain <saqlain2204@gmail.com>
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: benchmark,gguf,kl-divergence,llama.cpp,llm,local-llm,mlx,quantization
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: httpx>=0.27
|
|
24
|
+
Requires-Dist: huggingface-hub>=0.24
|
|
25
|
+
Requires-Dist: matplotlib>=3.8
|
|
26
|
+
Requires-Dist: numpy>=1.26
|
|
27
|
+
Requires-Dist: pyarrow>=15
|
|
28
|
+
Requires-Dist: pydantic>=2.7
|
|
29
|
+
Requires-Dist: rich>=13.7
|
|
30
|
+
Requires-Dist: typer>=0.12
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Requires-Dist: accelerate>=0.33; extra == 'all'
|
|
33
|
+
Requires-Dist: llama-cpp-python>=0.3; extra == 'all'
|
|
34
|
+
Requires-Dist: protobuf; extra == 'all'
|
|
35
|
+
Requires-Dist: sentencepiece; extra == 'all'
|
|
36
|
+
Requires-Dist: torch>=2.3; extra == 'all'
|
|
37
|
+
Requires-Dist: transformers>=4.44; extra == 'all'
|
|
38
|
+
Provides-Extra: dev
|
|
39
|
+
Requires-Dist: accelerate>=0.33; extra == 'dev'
|
|
40
|
+
Requires-Dist: gguf>=0.10; extra == 'dev'
|
|
41
|
+
Requires-Dist: protobuf; extra == 'dev'
|
|
42
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
43
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
44
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
45
|
+
Requires-Dist: sentencepiece; extra == 'dev'
|
|
46
|
+
Requires-Dist: tokenizers>=0.19; extra == 'dev'
|
|
47
|
+
Requires-Dist: torch>=2.3; extra == 'dev'
|
|
48
|
+
Requires-Dist: transformers>=4.44; extra == 'dev'
|
|
49
|
+
Provides-Extra: hf
|
|
50
|
+
Requires-Dist: accelerate>=0.33; extra == 'hf'
|
|
51
|
+
Requires-Dist: torch>=2.3; extra == 'hf'
|
|
52
|
+
Requires-Dist: transformers>=4.44; extra == 'hf'
|
|
53
|
+
Provides-Extra: llamacpp
|
|
54
|
+
Requires-Dist: llama-cpp-python>=0.3; extra == 'llamacpp'
|
|
55
|
+
Provides-Extra: mlx
|
|
56
|
+
Requires-Dist: mlx-lm>=0.20; extra == 'mlx'
|
|
57
|
+
Provides-Extra: pack
|
|
58
|
+
Requires-Dist: accelerate>=0.33; extra == 'pack'
|
|
59
|
+
Requires-Dist: protobuf; extra == 'pack'
|
|
60
|
+
Requires-Dist: sentencepiece; extra == 'pack'
|
|
61
|
+
Requires-Dist: torch>=2.3; extra == 'pack'
|
|
62
|
+
Requires-Dist: transformers>=4.44; extra == 'pack'
|
|
63
|
+
Description-Content-Type: text/markdown
|
|
64
|
+
|
|
65
|
+
<p align="center">
|
|
66
|
+
<img src="https://raw.githubusercontent.com/saqlain2204/quantgap/main/assets/logo-banner.svg" alt="quantgap: how much did this quant lose?" width="560">
|
|
67
|
+
</p>
|
|
68
|
+
|
|
69
|
+
<h1 align="center">quantgap: how much did this quant lose?</h1>
|
|
70
|
+
|
|
71
|
+
<p align="center">
|
|
72
|
+
<a href="https://github.com/saqlain2204/quantgap/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/saqlain2204/quantgap/actions/workflows/ci.yml/badge.svg"></a>
|
|
73
|
+
<a href="https://huggingface.co/quantgap-packs"><img alt="Packs on Hugging Face" src="https://img.shields.io/badge/packs-Hugging%20Face-f59e0b"></a>
|
|
74
|
+
<a href="https://saqlain2204.github.io/quantgap/"><img alt="Leaderboard" src="https://img.shields.io/badge/leaderboard-site-f59e0b"></a>
|
|
75
|
+
<img alt="Python 3.11+" src="https://img.shields.io/badge/python-3.11%2B-3b82f6">
|
|
76
|
+
<a href="LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-3b82f6"></a>
|
|
77
|
+
</p>
|
|
78
|
+
|
|
79
|
+
**quantgap measures how far a quantized model drifts from the original, on your own machine, without running the original.**
|
|
80
|
+
|
|
81
|
+
```text
|
|
82
|
+
Which quant should I download? Q4_K_M? UD-Q4_K_XL? IQ3_XXS? NVFP4?
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
People answer that with feelings. quantgap answers it with a number: how much each quant moved away
|
|
86
|
+
from the real model, measured the same way for every publisher and every format.
|
|
87
|
+
|
|
88
|
+
## Quickstart
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install "quantgap[llamacpp]"
|
|
92
|
+
|
|
93
|
+
# how much did this one file lose?
|
|
94
|
+
quantgap score hf://<publisher>/<model>-GGUF/<file>.gguf
|
|
95
|
+
|
|
96
|
+
# score many quants of one model, draw a chart, and get a pick for your memory
|
|
97
|
+
quantgap compare --repo <publisher>/<model>-GGUF --glob "*Q4*" --budget 16GB --chart chart.svg
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
You need a **pack** for the model (the original's answers on a fixed set of texts, made once and
|
|
101
|
+
shared). Pass one with `--pack`, or let quantgap look one up on the Hub. See
|
|
102
|
+
[Make a pack for your own model](#make-a-pack-for-your-own-model).
|
|
103
|
+
|
|
104
|
+
## Sample result (real, small, one machine)
|
|
105
|
+
|
|
106
|
+
Model: `Qwen/Qwen2.5-0.5B-Instruct` (Apache-2.0). Its pack is public at
|
|
107
|
+
[quantgap-packs/Qwen2.5-0.5B-Instruct](https://huggingface.co/datasets/quantgap-packs/Qwen2.5-0.5B-Instruct),
|
|
108
|
+
so `quantgap score hf://bartowski/Qwen2.5-0.5B-Instruct-GGUF/Qwen2.5-0.5B-Instruct-Q4_K_M.gguf` finds it by itself. The numbers below were measured by quantgap on one
|
|
109
|
+
CPU laptop, against a pack made from the original weights. Full table, hashes and settings:
|
|
110
|
+
[docs/RESULTS.md](docs/RESULTS.md).
|
|
111
|
+
|
|
112
|
+
| Publisher | Quant | Size | KLD mean (95% interval) | Worst 1% | Top-1 | PPL ratio | Loops (quant / original) | Wrong script | JSON ok |
|
|
113
|
+
|---|---|---|---|---|---|---|---|---|---|
|
|
114
|
+
| bartowski | Q8_0 | 531.1 MB | 0.0027 (0.0024 to 0.0031) | 0.027 | 97.1% | 1.003 | 5 / 6 | 0 | 2 / 2 |
|
|
115
|
+
| bartowski | Q6_K | 505.7 MB | 0.0069 (0.0057 to 0.0083) | 0.064 | 95.5% | 1.008 | 8 / 6 | 0 | 2 / 2 |
|
|
116
|
+
| bartowski | Q5_K_M | 420.1 MB | 0.0241 (0.0190 to 0.0298) | 0.264 | 92.3% | 1.024 | 5 / 6 | 0 | 2 / 2 |
|
|
117
|
+
| bartowski | Q4_K_M | 397.8 MB | 0.0389 (0.0316 to 0.0478) | 0.376 | 89.9% | 1.041 | 6 / 6 | 0 | 2 / 2 |
|
|
118
|
+
| Qwen | Q4_K_M | 491.4 MB | 0.0787 (0.0627 to 0.0950) | 0.807 | 85.8% | 1.064 | 7 / 6 | 0 | 2 / 2 |
|
|
119
|
+
| bartowski | Q3_K_M | 355.5 MB | 0.0828 (0.0672 to 0.1009) | 0.852 | 85.9% | 1.073 | 7 / 6 | 0 | 2 / 2 |
|
|
120
|
+
| bartowski | Q2_K | 338.6 MB | 0.2052 (0.1672 to 0.2386) | 2.080 | 77.8% | 1.200 | 9 / 6 | 0 | 2 / 2 |
|
|
121
|
+
|
|
122
|
+
Quick mode (first 25% of each group, 12 greedy prompts), llama.cpp on CPU, one machine. Lower KLD is better. Loops are counted out of 12 prompts, so differences of one or two are noise.
|
|
123
|
+
|
|
124
|
+

|
|
125
|
+
|
|
126
|
+
**One finding worth a second look:** the two files labelled `Q4_K_M` are not the same quality. The official Qwen file (491 MB) drifted about twice as far (KLD 0.0787) as bartowski's (398 MB, KLD 0.0389), and the intervals do not overlap. We did not investigate why. A label like `Q4_K_M` names a recipe, not one fixed result, which is the point of measuring.
|
|
127
|
+
|
|
128
|
+
The numbers fall steadily with file size: Q8_0 and Q6_K stay close to the original, Q4_K_M is a clear
|
|
129
|
+
step away, and Q2_K has drifted a lot. This is a small model on one machine in quick mode, so treat it as
|
|
130
|
+
a demonstration of the tool, not a verdict on these quants.
|
|
131
|
+
|
|
132
|
+
## How it works
|
|
133
|
+
|
|
134
|
+
```
|
|
135
|
+
(once per model: big machine, Kaggle, or HF Jobs)
|
|
136
|
+
original model ──► quantgap pack ──► pack (small files) ──► Hugging Face Hub
|
|
137
|
+
│
|
|
138
|
+
(you, on your own laptop) ▼
|
|
139
|
+
quant file / server ──► backend ──► per-position scores ──► quantgap score ◄── pack
|
|
140
|
+
│
|
|
141
|
+
table + chart + result JSON
|
|
142
|
+
│
|
|
143
|
+
quantgap submit ──► pull request ──► leaderboard
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
1. **Pack (once).** `quantgap pack` runs the full-size model over 160 fixed texts and saves its
|
|
147
|
+
top 32 next-token guesses at every position. That is about 20 MB, not many GB. **Teacher
|
|
148
|
+
forcing** means we feed the same text to both models and compare their guesses at every
|
|
149
|
+
position. Nobody generates anything, so it is fair and fast.
|
|
150
|
+
2. **Score (anyone).** `quantgap score` runs your quant on the same texts on your own machine
|
|
151
|
+
(llama.cpp, MLX, Transformers, or any vLLM server) and compares.
|
|
152
|
+
3. **Share.** `quantgap submit` sends the result, with the SHA-256 of the quant file and of the
|
|
153
|
+
pack, so anyone can re-run it and get the same number.
|
|
154
|
+
|
|
155
|
+
## What the numbers mean
|
|
156
|
+
|
|
157
|
+
**Lower KLD is better.**
|
|
158
|
+
|
|
159
|
+
| Number | In plain words |
|
|
160
|
+
|---|---|
|
|
161
|
+
| **KLD mean** | One number for how far the quant's next-token probabilities are from the original's. 0 means identical. A 95% interval comes with it. |
|
|
162
|
+
| **KLD worst 1%** | The 99th percentile. A mean can hide rare big failures. This catches them. |
|
|
163
|
+
| **Top-1 agreement** | How often the quant's best guess is the same as the original's. |
|
|
164
|
+
| **Perplexity ratio** | How much more surprised the quant is by real text. 1.0 means no change. |
|
|
165
|
+
| **Loops** | Short greedy generations where the model repeats itself. Shown next to the original's count. |
|
|
166
|
+
| **Wrong script** | A Chinese, Cyrillic, Arabic or Hindi character appears in English, code, math or JSON text where the original had none. |
|
|
167
|
+
| **Valid JSON** | Of 8 prompts that ask for a JSON object, how many parse. Shown next to the original's count. |
|
|
168
|
+
|
|
169
|
+
Numbers are also given for each group of texts: general, chat, code, math, multilingual
|
|
170
|
+
(Hindi, Chinese, Spanish, Arabic) and JSON. The maths is explained in plain words in
|
|
171
|
+
[docs/method.md](docs/method.md).
|
|
172
|
+
|
|
173
|
+
## What quantgap does not tell you
|
|
174
|
+
|
|
175
|
+
- **It is not a skill benchmark.** It measures drift from the original, not how good the model is
|
|
176
|
+
at your task. Less drift is not always better for you.
|
|
177
|
+
- **It is not a speed benchmark.** Use `llama-bench` or [llmfit](https://github.com/AlexsJones/llmfit) for speed.
|
|
178
|
+
- **The KLD is a lower bound.** To keep packs small we keep the original's top 32 guesses and
|
|
179
|
+
lump everything else into one bucket. That can only make two models look closer, never further
|
|
180
|
+
apart. It ranks quants well. Its absolute values are a little lower than llama.cpp's
|
|
181
|
+
full-vocabulary numbers. Compare quantgap numbers with quantgap numbers.
|
|
182
|
+
- **Ollama is not supported yet.** Ollama does not return the model's scores for the input text.
|
|
183
|
+
You can score the GGUF file Ollama already downloaded (`ollama show --modelfile NAME` prints
|
|
184
|
+
its path).
|
|
185
|
+
- **Big models need someone with a big machine.** The MVP targets models up to about 32B
|
|
186
|
+
parameters.
|
|
187
|
+
|
|
188
|
+
## Make a pack for your own model
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
pip install "quantgap[pack]"
|
|
192
|
+
quantgap pack <org>/<model> --revision <full commit sha> --license <license> --push <you>/<name>
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Free option: [`notebooks/make_pack_kaggle.ipynb`](notebooks/make_pack_kaggle.ipynb) runs it on a
|
|
196
|
+
Kaggle T4 x2. Details, memory guidance and licensing rules are in [docs/packs.md](docs/packs.md).
|
|
197
|
+
Check that the model's license allows sharing its outputs first.
|
|
198
|
+
|
|
199
|
+
You fine-tuned a small model and want to know how much Q4_K_M hurts it? Make a pack for your
|
|
200
|
+
fine-tune, then score the GGUF against it.
|
|
201
|
+
|
|
202
|
+
## Backends
|
|
203
|
+
|
|
204
|
+
| Backend | For | Install | Status |
|
|
205
|
+
|---|---|---|---|
|
|
206
|
+
| `llamacpp` | GGUF on CPU, CUDA, Metal | `pip install "quantgap[llamacpp]"` | tested here (real GGUF files) |
|
|
207
|
+
| `openai` | any OpenAI-compatible server that returns prompt logprobs (vLLM: NVFP4, AWQ, GPTQ, FP8) | built in, use `--base-url` | tested against a fake server that follows the vLLM docs, not a live GPU |
|
|
208
|
+
| `hf` | Transformers, bitsandbytes | `pip install "quantgap[hf]"` | tested here (the reference path) |
|
|
209
|
+
| `mlx` | Apple silicon | `pip install "quantgap[mlx]"` | **written but not run on a Mac yet** |
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# a vLLM server
|
|
213
|
+
quantgap score openai://Qwen2.5-0.5B-Instruct-NVFP4 --base-url http://localhost:8000/v1 --pack <pack>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
A server only reports its own top-N tokens, so those results are marked **approximate**.
|
|
217
|
+
|
|
218
|
+
## Submit a result
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
quantgap score ./my-quant.gguf --pack <pack> # writes quantgap-results/<name>.json
|
|
222
|
+
quantgap submit quantgap-results/<name>.json --dry-run # shows exactly what would be sent
|
|
223
|
+
export HF_TOKEN=hf_...
|
|
224
|
+
quantgap submit quantgap-results/<name>.json # opens a pull request
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
`--quick` results are for a fast first look and cannot be submitted.
|
|
228
|
+
|
|
229
|
+
## Use it in CI
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
quantgap score --backend openai --base-url "$URL" --model-name "$NAME" --json out.json openai://"$NAME"
|
|
233
|
+
python -c "import json,sys; sys.exit(json.load(open('out.json'))['metrics']['kld_mean'] > 0.02)"
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Fail the build if your inference engine fork starts to drift.
|
|
237
|
+
|
|
238
|
+
## Commands
|
|
239
|
+
|
|
240
|
+
```
|
|
241
|
+
quantgap pack MODEL_REPO [--revision SHA] [--k 32] [--device auto|cuda|cpu] [--out DIR] [--push ORG/NAME]
|
|
242
|
+
quantgap packs list | show PACK_REF
|
|
243
|
+
quantgap score QUANT [--pack PACK_REF] [--backend auto|llamacpp|mlx|openai|hf] [--quick] [--json OUT]
|
|
244
|
+
quantgap compare QUANT... | --repo ORG/REPO --glob "*Q4*.gguf" [--budget 16GB] [--chart out.svg]
|
|
245
|
+
quantgap submit RESULT.json [--dry-run]
|
|
246
|
+
quantgap inspect RESULT.json
|
|
247
|
+
quantgap doctor [--selftest]
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
`quantgap doctor` tells you which backends are installed and which extra to add.
|
|
251
|
+
|
|
252
|
+
## Comparison with other tools
|
|
253
|
+
|
|
254
|
+
| Project | What it does | What quantgap adds |
|
|
255
|
+
|---|---|---|
|
|
256
|
+
| llama.cpp `llama-perplexity --kl-divergence` | Built-in KLD of a GGUF against a saved logits file from the BF16 model. | You must run the BF16 model yourself and the logits file is huge. quantgap shares small packs, works beyond GGUF, and adds a report. We learned from it: it is the prior art. |
|
|
257
|
+
| [kld-sweep](https://github.com/cmhamiche/kld-sweep) | Loops `llama-perplexity` over a folder of GGUFs, with CSV and a chart. | Same idea, nice and simple. quantgap removes the need for a local BF16 run and adds damage checks and a shared leaderboard. |
|
|
258
|
+
| [mlx-kld](https://github.com/asher/mlx-kld) | KLD for MLX and GGUF with a local teacher cache. | quantgap makes the "teacher cache" a shareable pack and covers more backends. |
|
|
259
|
+
| [GGUF-Tool-Suite](https://github.com/Thireus/GGUF-Tool-Suite) | Builds custom mixed quants to a target size. | It makes quants, quantgap judges them. They fit together. |
|
|
260
|
+
| [quant-fidelity-frontier](https://github.com/delirious6423/quant-fidelity-frontier) | Collects numbers that publishers reported. | quantgap measures with one method and records hashes. |
|
|
261
|
+
| [llmfit](https://github.com/AlexsJones/llmfit) | Which models fit your hardware, and how fast. | quantgap is the measured-quality half. |
|
|
262
|
+
|
|
263
|
+
## FAQ
|
|
264
|
+
|
|
265
|
+
**Why are my numbers a bit different from llama.cpp's KLD?** quantgap keeps the top 32 guesses and
|
|
266
|
+
a tail bucket, so it is a lower bound. See [docs/faq.md](docs/faq.md).
|
|
267
|
+
|
|
268
|
+
**Why not Ollama?** Ollama does not return the model's scores for the input text, so we cannot
|
|
269
|
+
compare fairly. Score the GGUF file it downloaded instead.
|
|
270
|
+
|
|
271
|
+
**Is my data sent anywhere?** No. quantgap has no telemetry. It only talks to the Hugging Face Hub
|
|
272
|
+
(downloads, and uploads you ask for) and to a server you name with `--base-url`.
|
|
273
|
+
|
|
274
|
+
**Why does it stop with a tokenizer error?** The quant must use the same token ids as the pack.
|
|
275
|
+
quantgap checks and never fixes a mismatch silently.
|
|
276
|
+
|
|
277
|
+
More in [docs/faq.md](docs/faq.md).
|
|
278
|
+
|
|
279
|
+
## Not yet
|
|
280
|
+
|
|
281
|
+
- Scoring through Ollama (it does not return the model's scores for the input text).
|
|
282
|
+
- Task benchmarks such as MMLU or coding pass rates. quantgap measures drift, not skill.
|
|
283
|
+
- Packing models above about 32B parameters (memory limits on free hardware).
|
|
284
|
+
- Vision and audio models.
|
|
285
|
+
- Speed benchmarks (use `llama-bench` or llmfit).
|
|
286
|
+
- KV-cache quantization effects.
|
|
287
|
+
|
|
288
|
+
## Development
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
git clone https://github.com/saqlain2204/quantgap && cd quantgap
|
|
292
|
+
pip install -e ".[dev]" llama-cpp-python
|
|
293
|
+
python scripts/make_tiny_model.py # tiny model + tiny GGUF for tests (also built by the tests)
|
|
294
|
+
python -m pytest
|
|
295
|
+
python -m ruff check . && python -m ruff format --check .
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for how to add a backend and how to submit a pack. The
|
|
299
|
+
original build spec is in [docs/SPEC.md](docs/SPEC.md).
|
|
300
|
+
|
|
301
|
+
## Credits
|
|
302
|
+
|
|
303
|
+
- **llama.cpp** and its `--kl-divergence` tooling are the prior art this builds on.
|
|
304
|
+
- **[kld-sweep](https://github.com/cmhamiche/kld-sweep)** and **[mlx-kld](https://github.com/asher/mlx-kld)** are related work.
|
|
305
|
+
- Probe texts come from Wikipedia (CC BY-SA 4.0), Dolly-15k (CC BY-SA 3.0) and GSM8K (MIT). See
|
|
306
|
+
[`SOURCES.md`](src/quantgap/probes/data/SOURCES.md).
|
|
307
|
+
|
|
308
|
+
## License
|
|
309
|
+
|
|
310
|
+
Code: Apache-2.0. Results dataset: CC BY 4.0. Each pack's dataset card states the license of the
|
|
311
|
+
original model and that the pack holds model outputs (log probabilities), not weights.
|