pare-quant 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.
Files changed (58) hide show
  1. pare_quant-0.1.0/.gitignore +53 -0
  2. pare_quant-0.1.0/LICENSE +176 -0
  3. pare_quant-0.1.0/PKG-INFO +194 -0
  4. pare_quant-0.1.0/README.md +153 -0
  5. pare_quant-0.1.0/benchmarks/bench_triton_kernel.py +172 -0
  6. pare_quant-0.1.0/benchmarks/make_tables.py +267 -0
  7. pare_quant-0.1.0/benchmarks/run_all.py +207 -0
  8. pare_quant-0.1.0/benchmarks/run_lm_eval.py +172 -0
  9. pare_quant-0.1.0/docs/index.md +37 -0
  10. pare_quant-0.1.0/mkdocs.yml +50 -0
  11. pare_quant-0.1.0/notebooks/01_quantization_basics.ipynb +42 -0
  12. pare_quant-0.1.0/notebooks/02_rtn_and_model_patching.ipynb +38 -0
  13. pare_quant-0.1.0/pare/__init__.py +99 -0
  14. pare_quant-0.1.0/pare/__main__.py +191 -0
  15. pare_quant-0.1.0/pare/calibration/__init__.py +0 -0
  16. pare_quant-0.1.0/pare/calibration/hessian.py +73 -0
  17. pare_quant-0.1.0/pare/calibration/layerwise.py +241 -0
  18. pare_quant-0.1.0/pare/calibration/observer.py +72 -0
  19. pare_quant-0.1.0/pare/calibration/runner.py +96 -0
  20. pare_quant-0.1.0/pare/config.py +96 -0
  21. pare_quant-0.1.0/pare/core/__init__.py +16 -0
  22. pare_quant-0.1.0/pare/core/dtype.py +97 -0
  23. pare_quant-0.1.0/pare/core/functional.py +214 -0
  24. pare_quant-0.1.0/pare/core/pack.py +144 -0
  25. pare_quant-0.1.0/pare/core/scale.py +137 -0
  26. pare_quant-0.1.0/pare/eval/__init__.py +0 -0
  27. pare_quant-0.1.0/pare/eval/lambada.py +88 -0
  28. pare_quant-0.1.0/pare/eval/perplexity.py +100 -0
  29. pare_quant-0.1.0/pare/eval/throughput.py +157 -0
  30. pare_quant-0.1.0/pare/kernels/__init__.py +0 -0
  31. pare_quant-0.1.0/pare/kernels/matmul_int4.py +248 -0
  32. pare_quant-0.1.0/pare/layers/__init__.py +0 -0
  33. pare_quant-0.1.0/pare/layers/linear.py +281 -0
  34. pare_quant-0.1.0/pare/model/__init__.py +0 -0
  35. pare_quant-0.1.0/pare/model/io.py +216 -0
  36. pare_quant-0.1.0/pare/model/patcher.py +103 -0
  37. pare_quant-0.1.0/pare/schemes/__init__.py +0 -0
  38. pare_quant-0.1.0/pare/schemes/awq.py +384 -0
  39. pare_quant-0.1.0/pare/schemes/base.py +93 -0
  40. pare_quant-0.1.0/pare/schemes/gptq.py +289 -0
  41. pare_quant-0.1.0/pare/schemes/rtn.py +65 -0
  42. pare_quant-0.1.0/pare/schemes/smoothquant.py +278 -0
  43. pare_quant-0.1.0/pare/sensitivity.py +106 -0
  44. pare_quant-0.1.0/pyproject.toml +73 -0
  45. pare_quant-0.1.0/scripts/validate_awq_llama2.py +62 -0
  46. pare_quant-0.1.0/scripts/validate_gptq_llama2.py +59 -0
  47. pare_quant-0.1.0/scripts/validate_smoothquant_llama2.py +87 -0
  48. pare_quant-0.1.0/tests/__init__.py +0 -0
  49. pare_quant-0.1.0/tests/conftest.py +109 -0
  50. pare_quant-0.1.0/tests/test_core.py +269 -0
  51. pare_quant-0.1.0/tests/test_fp8.py +187 -0
  52. pare_quant-0.1.0/tests/test_gptq_numerical.py +302 -0
  53. pare_quant-0.1.0/tests/test_model_io.py +199 -0
  54. pare_quant-0.1.0/tests/test_nf4.py +268 -0
  55. pare_quant-0.1.0/tests/test_schemes.py +152 -0
  56. pare_quant-0.1.0/tests/test_sensitivity.py +195 -0
  57. pare_quant-0.1.0/tests/test_smoke.py +297 -0
  58. pare_quant-0.1.0/tests/test_triton_kernel.py +283 -0
@@ -0,0 +1,53 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ .Python
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ *.egg
11
+ *.whl
12
+
13
+ # Virtual environments
14
+ .venv/
15
+ venv/
16
+ env/
17
+ .env
18
+
19
+ # Testing
20
+ .pytest_cache/
21
+ .coverage
22
+ htmlcov/
23
+ *.xml
24
+
25
+ # Jupyter
26
+ .ipynb_checkpoints/
27
+ *.ipynb_checkpoints
28
+
29
+ # Claude
30
+ .claude/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+
38
+ # pyenv
39
+ .python-version
40
+
41
+ # macOS
42
+ .DS_Store
43
+ .AppleDouble
44
+ .LSOverride
45
+
46
+ # Build / packaging
47
+ *.so
48
+ *.dylib
49
+ MANIFEST
50
+
51
+ # Results (large binary outputs — not tracked)
52
+ results/*.json
53
+ results/*.log
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other
42
+ transformations represent, as a whole, an original work of authorship.
43
+ For the purposes of this License, Derivative Works shall not include
44
+ works that remain separable from, or merely link (or bind by name)
45
+ to the interfaces of, the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by You, whether in the original License, and any additions
49
+ to, modifications of, or is a Contribution.
50
+
51
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
52
+ whom a Contribution has been received by the Licensor and included
53
+ within the Work.
54
+
55
+ 2. Grant of Copyright License. Subject to the terms and conditions of
56
+ this License, each Contributor hereby grants to You a perpetual,
57
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
58
+ copyright license to reproduce, prepare Derivative Works of,
59
+ publicly display, publicly perform, sublicense, and distribute the
60
+ Work and such Derivative Works in Source or Object form.
61
+
62
+ 3. Grant of Patent License. Subject to the terms and conditions of
63
+ this License, each Contributor hereby grants to You a perpetual,
64
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
65
+ (except as stated in this section) patent license to make, have made,
66
+ use, offer to sell, sell, import, and otherwise transfer the Work,
67
+ where such license applies only to those patent claims licensable
68
+ by such Contributor that are necessarily infringed by their
69
+ Contribution(s) alone or by the combination of their Contribution(s)
70
+ with the Work to which such Contribution(s) was submitted. If You
71
+ institute patent litigation against any entity (including a
72
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
73
+ or a Contribution incorporated within the Work constitutes direct
74
+ or contributory patent infringement, then any patent licenses
75
+ granted to You under this License for that Work shall terminate
76
+ as of the date such litigation is filed.
77
+
78
+ 4. Redistribution. You may reproduce and distribute copies of the
79
+ Work or Derivative Works thereof in any medium, with or without
80
+ modifications, and in Source or Object form, provided that You
81
+ meet the following conditions:
82
+
83
+ (a) You must give any other recipients of the Work or Derivative
84
+ Works a copy of this License; and
85
+
86
+ (b) You must cause any modified files to carry prominent notices
87
+ stating that You changed the files; and
88
+
89
+ (c) You must retain, in the Source form of any Derivative Works
90
+ that You distribute, all copyright, patent, trademark, and
91
+ attribution notices from the Source form of the Work,
92
+ excluding those notices that do not pertain to any part of
93
+ the Derivative Works; and
94
+
95
+ (d) If the Work includes a "NOTICE" text file, as part of your
96
+ distribution, You must include a readable copy of the
97
+ attribution notices contained within such NOTICE file, in
98
+ at least one of the following places: within a NOTICE text
99
+ file distributed as part of the Derivative Works; within
100
+ the Source form or documentation, if provided along with the
101
+ Derivative Works; or, within a display generated by the
102
+ Derivative Works, if and wherever such third-party notices
103
+ normally appear. The contents of the NOTICE file are for
104
+ informational purposes only and do not modify the License.
105
+ You may add Your own attribution notices within Derivative
106
+ Works that You distribute, alongside or in addition to the
107
+ NOTICE text from the Work, provided that such additional
108
+ attribution notices cannot be construed as modifying the License.
109
+
110
+ You may add Your own license statement for Your modifications and
111
+ may provide additional grant of rights to use, copy, modify, merge,
112
+ publish, distribute, sublicense, and/or sell copies of the
113
+ Contribution, either on an unrestricted basis or subject to terms
114
+ and conditions.
115
+
116
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
117
+ any Contribution intentionally submitted for inclusion in the Work
118
+ by You to the Licensor shall be under the terms and conditions of
119
+ this License, without any additional terms or conditions.
120
+ Notwithstanding the above, nothing herein shall supersede or modify
121
+ the terms of any separate license agreement you may have executed
122
+ with Licensor regarding such Contributions.
123
+
124
+ 6. Trademarks. This License does not grant permission to use the trade
125
+ names, trademarks, service marks, or product names of the Licensor,
126
+ except as required for reasonable and customary use in describing the
127
+ origin of the Work and reproducing the content of the NOTICE file.
128
+
129
+ 7. Disclaimer of Warranty. Unless required by applicable law or
130
+ agreed to in writing, Licensor provides the Work (and each
131
+ Contributor provides its Contributions) on an "AS IS" BASIS,
132
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
133
+ implied, including, without limitation, any warranties or conditions
134
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
135
+ PARTICULAR PURPOSE. You are solely responsible for determining the
136
+ appropriateness of using or reproducing the Work and assume any
137
+ risks associated with Your exercise of permissions under this License.
138
+
139
+ 8. Limitation of Liability. In no event and under no legal theory,
140
+ whether in tort (including negligence), contract, or otherwise,
141
+ unless required by applicable law (such as deliberate and grossly
142
+ negligent acts) or agreed to in writing, shall any Contributor be
143
+ liable to You for damages, including any direct, indirect, special,
144
+ incidental, or exemplary damages of any character arising as a
145
+ result of this License or out of the use or inability to use the
146
+ Work (including but not limited to damages for loss of goodwill,
147
+ work stoppage, computer failure or malfunction, or all other
148
+ commercial damages or losses), even if such Contributor has been
149
+ advised of the possibility of such damages.
150
+
151
+ 9. Accepting Warranty or Liability. While redistributing the Work or
152
+ Derivative Works thereof, You may choose to offer, and charge a fee
153
+ for, acceptance of support, warranty, indemnity, or other liability
154
+ obligations and/or rights consistent with this License. However, in
155
+ accepting such obligations, You may offer such obligations only on
156
+ Your own behalf and on Your sole responsibility, not on behalf of
157
+ any other Contributor, and only if You agree to indemnify, defend,
158
+ and hold each Contributor harmless for any liability incurred by,
159
+ or claims asserted against, such Contributor by reason of your
160
+ accepting any warranty or additional liability.
161
+
162
+ END OF TERMS AND CONDITIONS
163
+
164
+ Copyright 2026 Yasmin Moslem
165
+
166
+ Licensed under the Apache License, Version 2.0 (the "License");
167
+ you may not use this file except in compliance with the License.
168
+ You may obtain a copy of the License at
169
+
170
+ http://www.apache.org/licenses/LICENSE-2.0
171
+
172
+ Unless required by applicable law or agreed to in writing, software
173
+ distributed under the License is distributed on an "AS IS" BASIS,
174
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
175
+ See the License for the specific language governing permissions and
176
+ limitations under the License.
@@ -0,0 +1,194 @@
1
+ Metadata-Version: 2.4
2
+ Name: pare-quant
3
+ Version: 0.1.0
4
+ Summary: Production-ready quantization for large language and multimodal models
5
+ Author: Yasmin Moslem
6
+ License: Apache-2.0
7
+ License-File: LICENSE
8
+ Keywords: awq,gptq,llm,machine-learning,multimodal,nlp,quantization
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Requires-Python: >=3.11
16
+ Requires-Dist: numpy>=1.24.0
17
+ Requires-Dist: safetensors>=0.4.0
18
+ Requires-Dist: torch>=2.1.0
19
+ Provides-Extra: all
20
+ Requires-Dist: datasets>=2.18.0; extra == 'all'
21
+ Requires-Dist: transformers>=4.40.0; extra == 'all'
22
+ Requires-Dist: triton>=3.0.0; extra == 'all'
23
+ Provides-Extra: calibration
24
+ Requires-Dist: datasets>=2.18.0; extra == 'calibration'
25
+ Provides-Extra: dev
26
+ Requires-Dist: ipykernel>=6.0; extra == 'dev'
27
+ Requires-Dist: jupyter>=1.0; extra == 'dev'
28
+ Requires-Dist: mkdocs-material>=9.5; extra == 'dev'
29
+ Requires-Dist: mkdocstrings[python]>=0.25; extra == 'dev'
30
+ Requires-Dist: mypy>=1.9.0; extra == 'dev'
31
+ Requires-Dist: pytest-cov; extra == 'dev'
32
+ Requires-Dist: pytest>=8.0; extra == 'dev'
33
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
34
+ Provides-Extra: eval
35
+ Requires-Dist: datasets>=2.18.0; extra == 'eval'
36
+ Provides-Extra: kernels
37
+ Requires-Dist: triton>=3.0.0; extra == 'kernels'
38
+ Provides-Extra: transformers
39
+ Requires-Dist: transformers>=4.40.0; extra == 'transformers'
40
+ Description-Content-Type: text/markdown
41
+
42
+ # Pare
43
+
44
+ Quantize any LLM in one line. Switch between GPTQ, AWQ, SmoothQuant, and RTN by changing a config field — same API, same model, same output format.
45
+
46
+ ---
47
+
48
+ ## Pick your trade-off
49
+
50
+ WikiText-2 perplexity (PPL ↓), A40 46 GB:
51
+
52
+ | Method | Llama-2-7B | Llama-3-8B | Qwen2.5-7B |
53
+ |--------|-----------|-----------|-----------|
54
+ | FP16 baseline | 5.47 | 6.14 | 6.85 |
55
+ | RTN INT8 | 5.48 (+0.01) | 6.14 (+0.01) | 6.85 (+0.00) |
56
+ | SmoothQuant INT8 | 5.58 (+0.11) | 6.25 (+0.11) | 6.96 (+0.11) |
57
+ | AWQ INT4 | 5.67 (+0.20) | 6.67 (+0.53) | 7.13 (+0.28) |
58
+ | GPTQ INT4 | 5.74 (+0.27) | 8.75 (+2.61) | 7.04 (+0.19) |
59
+
60
+ Throughput on Llama-2-7B (BS=1): FP16 33 tok/s · RTN/SmoothQuant ~2.3 tok/s · AWQ/GPTQ ~1.2 tok/s †
61
+
62
+ † Dequantize-on-the-fly. With the optional Triton kernel: **8.8× faster at BS=1, 2.8× at BS=4**.
63
+
64
+ ---
65
+
66
+ ## Quickstart
67
+
68
+ ```python
69
+ from transformers import AutoModelForCausalLM, AutoTokenizer
70
+ from pare import quantize, QuantConfig
71
+ from pare.calibration.data import load_wikitext2_calibration
72
+
73
+ model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
74
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
75
+ calib = load_wikitext2_calibration(tokenizer, n_samples=128, seq_len=2048)
76
+ # or use your own: a list of tokenized tensors of shape (seq_len,)
77
+
78
+ # Default is AWQ. Change scheme= to switch methods.
79
+ config = QuantConfig(bits=4, scheme="awq", group_size=128) # ← swap to "gptq", "rtn", "smoothquant"
80
+ model = quantize(model, config, calibration_data=calib, device="cuda")
81
+ ```
82
+
83
+ Save and reload:
84
+
85
+ ```python
86
+ from pare import save_quantized, load_quantized
87
+
88
+ save_quantized(model, "llama2-awq-int4/")
89
+ # [pare] Saved 224 quantized layers to llama2-awq-int4 (3821 MB)
90
+
91
+ from transformers import AutoConfig, AutoModelForCausalLM
92
+ config = AutoConfig.from_pretrained("meta-llama/Llama-2-7b-hf")
93
+ model = AutoModelForCausalLM.from_config(config) # architecture only, no weights
94
+ model = load_quantized(model, "llama2-awq-int4/")
95
+ ```
96
+
97
+ ---
98
+
99
+ ## Installation
100
+
101
+ ```bash
102
+ pip install pare-quant # core
103
+ pip install "pare-quant[all]" # + transformers, datasets, Triton kernel
104
+ ```
105
+
106
+ Python ≥ 3.11 · PyTorch ≥ 2.1
107
+
108
+ ---
109
+
110
+ ## Methods
111
+
112
+ | `scheme=` | Calibration | Quality | When to use |
113
+ |-----------|-------------|---------|-------------|
114
+ | `"awq"` ★ | Yes | ★★★★ | **Default.** Best robustness across architectures; recommended starting point |
115
+ | `"gptq"` | Yes | ★★★★★ | Highest quality when used with `act_order=True`; can underperform AWQ without it |
116
+ | `"smoothquant"` | Yes | ★★★★ | INT8 W+A; closest to FP16 PPL; no INT4 |
117
+ | `"rtn"` | No | ★★★ | No calibration needed; good baseline or for NF4/FP8 |
118
+
119
+ ★ Default: `QuantConfig()` uses AWQ. AWQ consistently outperforms GPTQ (without `act_order=True`) on modern architectures — on Llama-3-8B the gap is 6.67 vs 8.75 PPL. GPTQ with `act_order=True` is the highest-quality option but requires more tuning.
120
+
121
+ All schemes support `bits=4` or `bits=8`. Use `group_size=128` (default) for best INT4 quality.
122
+
123
+ ### Additional options
124
+
125
+ **`act_order=True`** — Sort quantization by activation magnitude (improves GPTQ quality on modern architectures):
126
+ ```python
127
+ QuantConfig(bits=4, scheme="gptq", group_size=128, act_order=True)
128
+ ```
129
+
130
+ **Mixed-precision** — Automatically promote sensitive layers to higher bits:
131
+ ```python
132
+ QuantConfig(bits=4, scheme="awq", sensitive_bits=8, sensitivity_threshold=0.05)
133
+ # [pare] 12 of 224 layers promoted to INT8 based on activation-weighted error
134
+ ```
135
+
136
+ **NF4** — Normal float 4-bit codebook (QLoRA-compatible base model format):
137
+ ```python
138
+ from pare.core.dtype import QuantDtype
139
+ QuantConfig(bits=4, dtype=QuantDtype.NF4, scheme="rtn")
140
+ ```
141
+
142
+ **FP8** — 8-bit float for A100/H100:
143
+ ```python
144
+ QuantConfig(bits=8, dtype=QuantDtype.FP8_E4M3, scheme="rtn")
145
+ ```
146
+
147
+ ---
148
+
149
+ ## Inference speedup (Triton kernel)
150
+
151
+ The optional Triton INT4 kernel fuses dequantization into the matmul, avoiding materialising the full FP16 weight matrix. Applies to INT4 schemes (AWQ, GPTQ, RTN). Enable per-layer after quantization:
152
+
153
+ ```python
154
+ from pare.layers.linear import QuantizedLinear
155
+
156
+ for m in model.modules():
157
+ if isinstance(m, QuantizedLinear):
158
+ m.use_kernel = True
159
+ ```
160
+
161
+ | Batch size | Without kernel | With kernel | Speedup |
162
+ |------------|---------------|-------------|---------|
163
+ | 1 (decode) | 2.09 ms/layer | 0.24 ms/layer | **8.8×** |
164
+ | 4 | 2.18 ms/layer | 0.78 ms/layer | **2.8×** |
165
+ | 16 | 2.66 ms/layer | 3.18 ms/layer | 0.8× |
166
+
167
+ Requires `pip install triton>=3.0`.
168
+
169
+ ---
170
+
171
+ ## Hardware
172
+
173
+ | | Minimum |
174
+ |-|---------|
175
+ | Quantizing a 7B model | 20 GB VRAM (layerwise strategy peaks at ~2 GB) |
176
+ | RTN / GPTQ / AWQ / NF4 | Any CUDA GPU |
177
+ | SmoothQuant W+A | Any CUDA GPU |
178
+ | FP8 | PyTorch ≥ 2.1 (A100 via software; H100 native) |
179
+ | Triton kernel | CUDA GPU + `triton ≥ 3.0` |
180
+
181
+ ---
182
+
183
+ ## Citation
184
+
185
+ ```bibtex
186
+ @misc{moslem2026pare,
187
+ author = {Moslem, Yasmin},
188
+ title = {Pare: Production-ready quantization for large language and multimodal models},
189
+ year = {2026},
190
+ url = {https://github.com/TinyAdapt/Pare},
191
+ }
192
+ ```
193
+
194
+ Apache 2.0
@@ -0,0 +1,153 @@
1
+ # Pare
2
+
3
+ Quantize any LLM in one line. Switch between GPTQ, AWQ, SmoothQuant, and RTN by changing a config field — same API, same model, same output format.
4
+
5
+ ---
6
+
7
+ ## Pick your trade-off
8
+
9
+ WikiText-2 perplexity (PPL ↓), A40 46 GB:
10
+
11
+ | Method | Llama-2-7B | Llama-3-8B | Qwen2.5-7B |
12
+ |--------|-----------|-----------|-----------|
13
+ | FP16 baseline | 5.47 | 6.14 | 6.85 |
14
+ | RTN INT8 | 5.48 (+0.01) | 6.14 (+0.01) | 6.85 (+0.00) |
15
+ | SmoothQuant INT8 | 5.58 (+0.11) | 6.25 (+0.11) | 6.96 (+0.11) |
16
+ | AWQ INT4 | 5.67 (+0.20) | 6.67 (+0.53) | 7.13 (+0.28) |
17
+ | GPTQ INT4 | 5.74 (+0.27) | 8.75 (+2.61) | 7.04 (+0.19) |
18
+
19
+ Throughput on Llama-2-7B (BS=1): FP16 33 tok/s · RTN/SmoothQuant ~2.3 tok/s · AWQ/GPTQ ~1.2 tok/s †
20
+
21
+ † Dequantize-on-the-fly. With the optional Triton kernel: **8.8× faster at BS=1, 2.8× at BS=4**.
22
+
23
+ ---
24
+
25
+ ## Quickstart
26
+
27
+ ```python
28
+ from transformers import AutoModelForCausalLM, AutoTokenizer
29
+ from pare import quantize, QuantConfig
30
+ from pare.calibration.data import load_wikitext2_calibration
31
+
32
+ model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
33
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
34
+ calib = load_wikitext2_calibration(tokenizer, n_samples=128, seq_len=2048)
35
+ # or use your own: a list of tokenized tensors of shape (seq_len,)
36
+
37
+ # Default is AWQ. Change scheme= to switch methods.
38
+ config = QuantConfig(bits=4, scheme="awq", group_size=128) # ← swap to "gptq", "rtn", "smoothquant"
39
+ model = quantize(model, config, calibration_data=calib, device="cuda")
40
+ ```
41
+
42
+ Save and reload:
43
+
44
+ ```python
45
+ from pare import save_quantized, load_quantized
46
+
47
+ save_quantized(model, "llama2-awq-int4/")
48
+ # [pare] Saved 224 quantized layers to llama2-awq-int4 (3821 MB)
49
+
50
+ from transformers import AutoConfig, AutoModelForCausalLM
51
+ config = AutoConfig.from_pretrained("meta-llama/Llama-2-7b-hf")
52
+ model = AutoModelForCausalLM.from_config(config) # architecture only, no weights
53
+ model = load_quantized(model, "llama2-awq-int4/")
54
+ ```
55
+
56
+ ---
57
+
58
+ ## Installation
59
+
60
+ ```bash
61
+ pip install pare-quant # core
62
+ pip install "pare-quant[all]" # + transformers, datasets, Triton kernel
63
+ ```
64
+
65
+ Python ≥ 3.11 · PyTorch ≥ 2.1
66
+
67
+ ---
68
+
69
+ ## Methods
70
+
71
+ | `scheme=` | Calibration | Quality | When to use |
72
+ |-----------|-------------|---------|-------------|
73
+ | `"awq"` ★ | Yes | ★★★★ | **Default.** Best robustness across architectures; recommended starting point |
74
+ | `"gptq"` | Yes | ★★★★★ | Highest quality when used with `act_order=True`; can underperform AWQ without it |
75
+ | `"smoothquant"` | Yes | ★★★★ | INT8 W+A; closest to FP16 PPL; no INT4 |
76
+ | `"rtn"` | No | ★★★ | No calibration needed; good baseline or for NF4/FP8 |
77
+
78
+ ★ Default: `QuantConfig()` uses AWQ. AWQ consistently outperforms GPTQ (without `act_order=True`) on modern architectures — on Llama-3-8B the gap is 6.67 vs 8.75 PPL. GPTQ with `act_order=True` is the highest-quality option but requires more tuning.
79
+
80
+ All schemes support `bits=4` or `bits=8`. Use `group_size=128` (default) for best INT4 quality.
81
+
82
+ ### Additional options
83
+
84
+ **`act_order=True`** — Sort quantization by activation magnitude (improves GPTQ quality on modern architectures):
85
+ ```python
86
+ QuantConfig(bits=4, scheme="gptq", group_size=128, act_order=True)
87
+ ```
88
+
89
+ **Mixed-precision** — Automatically promote sensitive layers to higher bits:
90
+ ```python
91
+ QuantConfig(bits=4, scheme="awq", sensitive_bits=8, sensitivity_threshold=0.05)
92
+ # [pare] 12 of 224 layers promoted to INT8 based on activation-weighted error
93
+ ```
94
+
95
+ **NF4** — Normal float 4-bit codebook (QLoRA-compatible base model format):
96
+ ```python
97
+ from pare.core.dtype import QuantDtype
98
+ QuantConfig(bits=4, dtype=QuantDtype.NF4, scheme="rtn")
99
+ ```
100
+
101
+ **FP8** — 8-bit float for A100/H100:
102
+ ```python
103
+ QuantConfig(bits=8, dtype=QuantDtype.FP8_E4M3, scheme="rtn")
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Inference speedup (Triton kernel)
109
+
110
+ The optional Triton INT4 kernel fuses dequantization into the matmul, avoiding materialising the full FP16 weight matrix. Applies to INT4 schemes (AWQ, GPTQ, RTN). Enable per-layer after quantization:
111
+
112
+ ```python
113
+ from pare.layers.linear import QuantizedLinear
114
+
115
+ for m in model.modules():
116
+ if isinstance(m, QuantizedLinear):
117
+ m.use_kernel = True
118
+ ```
119
+
120
+ | Batch size | Without kernel | With kernel | Speedup |
121
+ |------------|---------------|-------------|---------|
122
+ | 1 (decode) | 2.09 ms/layer | 0.24 ms/layer | **8.8×** |
123
+ | 4 | 2.18 ms/layer | 0.78 ms/layer | **2.8×** |
124
+ | 16 | 2.66 ms/layer | 3.18 ms/layer | 0.8× |
125
+
126
+ Requires `pip install triton>=3.0`.
127
+
128
+ ---
129
+
130
+ ## Hardware
131
+
132
+ | | Minimum |
133
+ |-|---------|
134
+ | Quantizing a 7B model | 20 GB VRAM (layerwise strategy peaks at ~2 GB) |
135
+ | RTN / GPTQ / AWQ / NF4 | Any CUDA GPU |
136
+ | SmoothQuant W+A | Any CUDA GPU |
137
+ | FP8 | PyTorch ≥ 2.1 (A100 via software; H100 native) |
138
+ | Triton kernel | CUDA GPU + `triton ≥ 3.0` |
139
+
140
+ ---
141
+
142
+ ## Citation
143
+
144
+ ```bibtex
145
+ @misc{moslem2026pare,
146
+ author = {Moslem, Yasmin},
147
+ title = {Pare: Production-ready quantization for large language and multimodal models},
148
+ year = {2026},
149
+ url = {https://github.com/TinyAdapt/Pare},
150
+ }
151
+ ```
152
+
153
+ Apache 2.0