CompressedGemma commited on
Commit
d4af382
Β·
verified Β·
1 Parent(s): 02ee2c3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +59 -41
README.md CHANGED
@@ -4,26 +4,28 @@ license: mit
4
 
5
  # HPC-Quantize V2
6
 
7
- ## Holographic Phase Contraction, Geometry-Preserving Weight Analogs, and Coupled Bilinear Factorization for Ultra-Low-Bit (`Q2_K`) LLM Quantization
8
 
9
- **HPC-Quantize V2** is a pure-Python/NumPy ultra-low-bit quantization engine and GGUF re-quantizer (with an integrated desktop GUI in `gui.py`) designed for **2-bit class (`Q2_K`, 2.625 bpw)** compression of large language models.
10
 
11
- > **Core thesis:** At 2 bits per weight (only 4 levels $q \in \{0,1,2,3\}$ and 4-bit sub-block scales $Ls, Lm \in \{0..15\}$), quantization is not an independent rounding problem. It is a **coupled bilinear factorization and global sequence-selection problem** best solved by extracting discrete lattice coordinates from **geometry-preserving weight analogs**, projecting them onto the true weights in an orthogonalized affine basis, and optimizing cross-block state trajectories via a **sequential Sieve and 36-state Viterbi dynamic program**.
12
 
13
- HPC-Quantize V2 (`hpc_quantize_v2/` + `gui.py`) has **zero C or `ctypes` dependencies**, reads and writes standard `llama.cpp`-compatible `.gguf` models and `.gguf`/`.dat` importance matrices (`iMatrix`), and requires no custom inference kernels.
14
 
15
  ---
16
 
17
  ## Key Highlights in V2
18
 
19
  1. **Geometry-Preserving Weight Analogs (`hpc_quantize_v2/analog.py`)**:
20
- Constructs a manifold of surrogate weight blocks $\tilde{x}$ that preserve exact sub-block first and second importance-weighted moments ($\mu_j, \sigma_j^2$), rank order, total block energy, and the $2\times 2$ D6/Vesica fold Gram matrix while regularizing heavy-tailed outliers toward the 4-level `Q2_K` lattice.
21
  2. **Coupled Orthogonal-Basis Bilinear `Q2_K` Factorization (`hpc_quantize_v2/factored.py`)**:
22
- Replaces independent 1-D scale/offset heuristics with an orthogonalized sub-block decomposition $\hat{x}_{j,k} = s_j(q_{j,k} - \bar{q}_j) + (s_j\bar{q}_j - t_j)$, coupled offset compensation $t_j^{\text{coupled}} = \max(0, (d \cdot Ls_j \cdot S_{wq,j} - S_{x,j})/S_{w,j})$, an exact superblock $2\times 2$ bilinear $(d, d_{\min})$ solve, and a vectorized $16\times 16$ joint $(Ls_j, Lm_j)$ sub-block scan.
23
- 3. **Full HPC Machinery in Vectorized NumPy**:
24
- Preserves kurtosis-gated outlier clamping, batched GGML seeds, the 6-state sequential Sieve with bounded parity back-action, the 36-state Viterbi sequence optimizer, D6/Vesica + DC fold-pyramid error shaping, row-aware rolling DC residual carry, and monotone local-safety floors.
25
- 4. **Direct GGUF-to-GGUF + iMatrix Pipeline & GUI (`hpc_quantize_v2/gguf.py`, `gui.py`)**:
26
- Ingests `F32`, `F16`, `BF16`, `Q8_0`, `Q4_0`, and `Q2_K` source GGUFs plus `llama.cpp` iMatrix files, copies metadata/tokenizer KVs and non-quantized tensors byte-for-byte, and emits a stock `llama.cpp`-compatible `Q2_K` GGUF.
 
 
27
 
28
  ---
29
 
@@ -47,7 +49,7 @@ When factoring raw LLM weights directly into this bilinear form, three structura
47
 
48
  ## Mathematical Architecture of HPC-Quantize V2
49
 
50
- ### 1. Geometry-Preserving Weight Analogs
51
 
52
  To prevent outliers from collapsing the discrete code assignment $q \in \{0,1,2,3\}$ while respecting the true linear-layer geometry, V2 constructs a portfolio of **geometry-preserving analogs** $\tilde{x}$ of each eligible weight block before extracting candidate lattice coordinates:
53
 
@@ -101,7 +103,7 @@ Tempers extreme sub-block standard deviations $\sigma_j \mapsto \sigma_j^\gamma
101
 
102
  ---
103
 
104
- ### 2. Coupled Orthogonal-Basis Bilinear `Q2_K` Factorization
105
 
106
  Given candidate discrete codes $q_{j,k} \in \{0,1,2,3\}$ (from raw starts and the analog portfolio), V2 projects the continuous and 4-bit scale parameters directly onto the **true weights** $x$:
107
 
@@ -110,21 +112,39 @@ Given candidate discrete codes $q_{j,k} \in \{0,1,2,3\}$ (from raw starts and th
110
  $$
111
  V_{qq,j} = \sum_{k=0}^{15} w_{j,k}(q_{j,k} - \bar{q}_j)^2 = S_{qq,j} - S_{wq,j}\bar{q}_j.
112
  $$
113
- 2. **Monotone 1-D Factorization (`factor_1d`)**:
114
- Factors $s_j \approx d \cdot Ls_j$ under weights $V_{qq,j}$ using multi-start Lloyd iterations followed by an exact vectorized coordinate sweep over integer codes $\{0..15\}$.
115
  3. **Coupled Offset Target**:
116
- Once $(d, Ls_j)$ are chosen, the optimal offset for sub-block $j$ is shifted to absorb the scale rounding residual:
117
  $$
118
  t_j^{\text{coupled}} = \max\!\left(0,\; \frac{d \cdot Ls_j \cdot S_{wq,j} - S_{x,j}}{S_{w,j}}\right)
119
  = \max\!\left(0,\; t_j + \bar{q}_j(d \cdot Ls_j - s_j)\right),
120
  $$
121
  which is then factored into $d_{\min} \cdot Lm_j$ under weights $S_{w,j}$.
122
- 4. **Global $2\times 2$ Bilinear $(d, d_{\min})$ Solve & Joint $16\times 16$ Sub-scale Scan**:
123
- Solves the exact $2\times 2$ linear system for $(d, d_{\min})$ across all 256 weights (augmented by the rank-1 DC spectral penalty), rounds to $\mathbb{F}_{16}$, and performs a vectorized $16\times 16$ joint $(Ls_j, Lm_j)$ minimization per sub-block, followed by $\mathbb{F}_{16}$ ULP neighborhood polishing and D6/Vesica Hadamard code descent.
124
 
125
  ---
126
 
127
- ### 3. Global HPC Pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  ```text
130
  Source Weights + Optional iMatrix
@@ -133,7 +153,7 @@ Source Weights + Optional iMatrix
133
  Kurtosis-Gated Clamp & Batched GGML Seeds (make_qkx2_batch / make_qp_batch)
134
  β”‚
135
  β–Ό
136
- Vectorized Superblock WLS + Factored Candidate Field (6Γ—6 / 24Γ—24 Lattice)
137
  β”‚
138
  β–Ό
139
  6-State Sequential Sieve (Bounded Neighbor Parity Back-Action + Log-Slack)
@@ -142,10 +162,10 @@ Vectorized Superblock WLS + Factored Candidate Field (6Γ—6 / 24Γ—24 Lattice)
142
  36-State Viterbi Global Sequence Optimization (Free-Energy Bins + Manhattan Prior)
143
  β”‚
144
  β–Ό
145
- Sub-block Sieve Assembly + ULP Polish + D6/Vesica Spectral Shaping + Rolling DC Carry
146
  β”‚
147
  β–Ό
148
- Monotone Local-Safety Candidate & Analog-Factored Floors
149
  β”‚
150
  β–Ό
151
  Standard Q2_K GGUF Output
@@ -153,16 +173,16 @@ Standard Q2_K GGUF Output
153
 
154
  ---
155
 
156
- ## Measured Improvements over the C Reference Solver
157
 
158
  Evaluated across 48 synthetic blocks (4 distributions) and a full row (47 superblocks = 12,032 weights) of `blk.0.ffn_down.weight` from `Raon.gguf` weighted by `imatrix.gguf`:
159
 
160
  | Benchmark Suite | Mean Objective Reduction | Median Reduction | Min Reduction | Worse Cases |
161
  | :--- | :---: | :---: | :---: | :---: |
162
- | **Gaussian** ($\mathcal{N}(0, 0.02^2)$) | **+8.89%** | +8.23% | +3.15% | `0 / 12` |
163
- | **Heavy-Tailed** ($\text{Student-}t_3$) | **+10.47%** | +9.26% | +4.97% | `0 / 12` |
164
- | **Offset-Sparse** (50% density + DC shift) | **+14.46%** | +14.83% | +3.67% | `0 / 12` |
165
- | **Sparse** (10% density) | **+36.05%** | +34.05% | +16.91% | `0 / 12` |
166
  | **Real `Raon.gguf` (`blk.0.ffn_down.weight` + `iMatrix`)** | **+15.96%** | β€” | β€” | `0 / 47` |
167
 
168
  Reproduce at any time with:
@@ -182,9 +202,9 @@ Only **Python 3.10+** and **NumPy** (`tkinter` is included with standard Python
182
  pip install numpy
183
  ```
184
 
185
- ### 1. Desktop GUI (`gui.py`)
186
 
187
- Launch the graphical interface to browse a source `.gguf`, attach an `.imatrix`/`.gguf` importance file, inspect eligible tensors, tune analog/HPC parameters, copy the equivalent CLI command, or run quantization with a live progress bar:
188
 
189
  ```bash
190
  python3 gui.py
@@ -198,7 +218,7 @@ python3 gui.py --gguf Raon.gguf --imatrix imatrix.gguf --output Raon-Q2K.gguf
198
 
199
  ### 2. Command-Line Interface (`hpc_quantize_v2`)
200
 
201
- **Quantize a full GGUF model to a `Q2_K` GGUF with an iMatrix:**
202
 
203
  ```bash
204
  python3 -m hpc_quantize_v2 \
@@ -206,6 +226,7 @@ python3 -m hpc_quantize_v2 \
206
  --all-q2k \
207
  --imatrix-gguf imatrix.gguf \
208
  --output Raon-Q2K.gguf \
 
209
  --verbose
210
  ```
211
 
@@ -238,12 +259,11 @@ import numpy as np
238
  from hpc_quantize_v2 import (
239
  HPCConfig,
240
  Q2KQuantizer,
241
- factor_only_solve,
242
  read_imatrix,
243
  )
244
  from hpc_quantize_v2.gguf import write_quantized_gguf
245
 
246
- # 1. Quantize an in-memory tensor (shape must be a multiple of 256)
247
  cfg = HPCConfig(
248
  n_cand_d=6,
249
  n_cand_m=6,
@@ -251,10 +271,11 @@ cfg = HPCConfig(
251
  factor_coupled_q2k=True,
252
  factor_joint_subscales=True,
253
  use_spectral=True,
 
254
  )
255
  quantizer = Q2KQuantizer(cfg)
256
 
257
- weights = np.random.default_rng(0).normal(0, 0.02, size=(16, 256)).astype(np.float32)
258
  result = quantizer.quantize(weights, row_width=256)
259
  print("RMSE:", result.stats.rmse)
260
  reconstructed = result.dequantize()
@@ -277,23 +298,22 @@ print(stats)
277
 
278
  ```text
279
  HPC-Quantize/
280
- β”œβ”€β”€ gui.py # Standalone Tkinter/TTK GUI wrapper
281
  └── hpc_quantize_v2/ # Pure-Python V2 package (zero C dependencies)
282
  β”œβ”€β”€ __init__.py # Public API exports
283
- β”œβ”€β”€ __main__.py # CLI entry point (--gguf, --input, --demo, --bench)
284
  β”œβ”€β”€ config.py # Validated HPCConfig dataclass
285
  β”œβ”€β”€ fp16.py # Bit-exact GGML nearest_int & IEEE fp16 ULP primitives
286
- β”œβ”€β”€ q2k.py # Q2_K 84-byte block packing, unpacking & dequantization
287
  β”œβ”€β”€ analog.py # Geometry-preserving weight analogs (Iso-Moment, Vesica Gram, Subscale)
288
- β”œβ”€β”€ factored.py # Coupled orthogonal-basis bilinear Q2_K block & candidate solver
289
  β”œβ”€β”€ seeds.py # Kurtosis-gated outlier clamping & batched GGML seed solvers
290
  β”œβ”€β”€ spectral.py # Folded error pyramid, DC/Vesica penalty & Hadamard code descent
291
  β”œβ”€β”€ sieve.py # 6-state sequential Sieve with neighbor parity back-action
292
  β”œβ”€β”€ viterbi.py # Vectorized 36-state Viterbi sequence optimizer
293
- β”œβ”€β”€ pipeline.py # End-to-end Q2KQuantizer tensor pipeline
 
294
  β”œβ”€β”€ reference.py # Faithful C-reference solver port for A/B benchmarking
295
- └── tests/
296
- └── test_v2.py # 19 unit tests covering primitives, analogs, solver, GGUF & pipeline
297
  ```
298
 
299
  ## Running the Test Suite
@@ -301,5 +321,3 @@ HPC-Quantize/
301
  ```bash
302
  python3 -m unittest discover -s hpc_quantize_v2/tests -v
303
  ```
304
-
305
- ---
 
4
 
5
  # HPC-Quantize V2
6
 
7
+ ## Holographic Phase Contraction, Geometry-Preserving Weight Analogs, and Algebraic Coupled Bilinear Factorization for Ultra-Low-Bit (`Q2_K`) LLM Quantization
8
 
9
+ **HPC-Quantize V2** is a standalone Python/NumPy ultra-low-bit quantization engine and GGUF re-quantizer (with a real-time telemetry desktop GUI in `gui.py`) built for **2-bit class (`Q2_K`, 2.625 bpw)** compression of large language models.
10
 
11
+ > **Core thesis:** At 2 bits per weight (4 levels $q \in \{0,1,2,3\}$ and 4-bit sub-block scales $Ls, Lm \in \{0..15\}$), quantization is not an independent rounding problem and should not rely on brute-force grid scans. It is a **coupled bilinear factorization and global sequence-optimization problem** best solved by extracting discrete lattice coordinates from **geometry-preserving weight analogs**, projecting them onto the true weights via **closed-form orthogonalized sufficient statistics**, and optimizing cross-block state trajectories with a **6-state sequential Sieve and 36-state Viterbi dynamic program**.
12
 
13
+ HPC-Quantize V2 (`hpc_quantize_v2/` + `gui.py`) has **zero C or `ctypes` dependencies**, reads and writes stock `llama.cpp`-compatible `.gguf` models and `.gguf`/`.dat` importance matrices (`iMatrix`), scales across all CPU cores with **bit-for-bit determinism**, and requires no custom inference kernels.
14
 
15
  ---
16
 
17
  ## Key Highlights in V2
18
 
19
  1. **Geometry-Preserving Weight Analogs (`hpc_quantize_v2/analog.py`)**:
20
+ Constructs a portfolio of surrogate weight blocks $\tilde{x}$ that preserve exact sub-block first and second importance-weighted moments ($\mu_j, \sigma_j^2$), rank order, unit sub-block direction ($\cos\theta = 1$), total block energy, and the $2\times 2$ D6/Vesica fold Gram matrix while regularizing heavy-tailed outliers toward the 4-level `Q2_K` lattice.
21
  2. **Coupled Orthogonal-Basis Bilinear `Q2_K` Factorization (`hpc_quantize_v2/factored.py`)**:
22
+ Replaces independent 1-D scale/offset heuristics with an orthogonalized sub-block decomposition $\hat{x}_{j,k} = s_j(q_{j,k} - \bar{q}_j) + (s_j\bar{q}_j - t_j)$, coupled offset compensation $t_j^{\text{coupled}} = \max(0, (d \cdot Ls_j \cdot S_{wq,j} - S_{x,j})/S_{w,j})$, rank-1 algebraic 1-D code refinement ($S_{vv} - S_{lv}^2/S_{l2}$), and a single-pass vectorized 36-seed candidate lattice evaluator (`81x` faster than per-seed loops).
23
+ 3. **Algebraic Coupled Phase-4 Block Assembly (`hpc_quantize_v2/pipeline.py`)**:
24
+ Replaces legacy brute-force $16\times 16$ sub-block scans, $9\times 9$ weight-level ULP loops, and 256-pass greedy code searches with closed-form sufficient-statistic projections (`1,200–1,475 blocks/sec` in Phase 4, achieving **+2.64% lower objective error** than brute-force Phase 4 in **1/9th the time**).
25
+ 4. **Bit-Identical Multi-Core Execution (`--workers 0`)**:
26
+ Distributes block-independent candidate and analog solves across all CPU cores via zero-copy `fork` shared memory while keeping cross-block Sieve, 36-state Viterbi, and row-aware DC carry strictly sequential β€” producing **100% bit-for-bit identical** GGUF output regardless of worker count.
27
+ 5. **Real-Time Telemetry GUI (`gui.py`) & Direct GGUF-to-GGUF Pipeline (`hpc_quantize_v2/gguf.py`)**:
28
+ Ingests `F32`, `F16`, `BF16`, `Q8_0`, `Q4_0`, and `Q2_K` source GGUFs plus `llama.cpp` iMatrix files, displays live intra-tensor stage/block progress, dual **Tensor ETA** and block-weighted **Whole-Model ETA**, live `RMSE`/`RMSE/Οƒ`, Sieve temperature, and floor hits, and emits a stock `llama.cpp` `Q2_K` GGUF.
29
 
30
  ---
31
 
 
49
 
50
  ## Mathematical Architecture of HPC-Quantize V2
51
 
52
+ ### 1. Geometry-Preserving Weight Analogs (`analog.py`)
53
 
54
  To prevent outliers from collapsing the discrete code assignment $q \in \{0,1,2,3\}$ while respecting the true linear-layer geometry, V2 constructs a portfolio of **geometry-preserving analogs** $\tilde{x}$ of each eligible weight block before extracting candidate lattice coordinates:
55
 
 
103
 
104
  ---
105
 
106
+ ### 2. Coupled Orthogonal-Basis Bilinear `Q2_K` Factorization (`factored.py`)
107
 
108
  Given candidate discrete codes $q_{j,k} \in \{0,1,2,3\}$ (from raw starts and the analog portfolio), V2 projects the continuous and 4-bit scale parameters directly onto the **true weights** $x$:
109
 
 
112
  $$
113
  V_{qq,j} = \sum_{k=0}^{15} w_{j,k}(q_{j,k} - \bar{q}_j)^2 = S_{qq,j} - S_{wq,j}\bar{q}_j.
114
  $$
115
+ 2. **Monotone Rank-1 1-D Factorization (`factor_1d`)**:
116
+ Factors $s_j \approx d \cdot Ls_j$ under weights $V_{qq,j}$ using multi-start Lloyd iterations followed by an exact vectorized rank-1 coordinate sweep maximizing $S_{lv}^2 / S_{l2}$ (since $\sum_j w_j(v_j - d^* L_j)^2 = S_{vv} - S_{lv}^2/S_{l2}$).
117
  3. **Coupled Offset Target**:
118
+ Once $(d, Ls_j)$ are chosen, the optimal offset for sub-block $j$ is shifted in closed form to absorb the scale rounding residual:
119
  $$
120
  t_j^{\text{coupled}} = \max\!\left(0,\; \frac{d \cdot Ls_j \cdot S_{wq,j} - S_{x,j}}{S_{w,j}}\right)
121
  = \max\!\left(0,\; t_j + \bar{q}_j(d \cdot Ls_j - s_j)\right),
122
  $$
123
  which is then factored into $d_{\min} \cdot Lm_j$ under weights $S_{w,j}$.
 
 
124
 
125
  ---
126
 
127
+ ### 3. Batched Algebraic Phase-4 Assembly (`pipeline.py`)
128
+
129
+ Instead of brute-force $16\times 16$ sub-block scans and $9\times 9$ weight-level ULP searches, Phase 4 refines both the Viterbi-selected state and the analog-factored state across all blocks in vectorized batches using three exact algebraic identities:
130
+
131
+ 1. **Closed-Form Coupled Sub-scale Projection**:
132
+ From sufficient statistics $(V_{qq,j}, C_{qx,j}, S_{wq,j}, S_{x,j}, S_{w,j})$, the unconstrained scale minimizer is $s_j^* = \max(0, C_{qx,j}/V_{qq,j})$. Evaluating the local integer neighborhood $Ls_j \in \operatorname{round}(s_j^*/d) + \{-3,\ldots,+3\}$ paired with its closed-form coupled offset $Lm_j \in \operatorname{round}(t_j^*(Ls_j)/m) + \{-1,0,+1\}$ replaces $16\times 16 = 256$ brute-force pairs with $21$ algebraic states.
133
+ 2. **Vesica + DC Augmented $2\times 2$ CramΓ©r Solve & $O(1)$ Scalar Quadratic ULP Polish**:
134
+ With $A_i = Ls_{i\gg 4} q_i$ and $B_i = Lm_{i\gg 4}$, the full extended objective (weighted SSE + Vesica fold pairs + DC carry) is an exact quadratic form in $(d, m)$:
135
+ $$
136
+ J(d, m) = \text{const} + \tilde{S}_{aa} d^2 - 2\tilde{S}_{ab} d m + \tilde{S}_{bb} m^2 - 2\tilde{S}_{xa} d + 2\tilde{S}_{xb} m,
137
+ $$
138
+ where $(\tilde{S}_{aa}, \tilde{S}_{ab}, \tilde{S}_{bb}, \tilde{S}_{xa}, \tilde{S}_{xb})$ include the Vesica pair sums $(A_p + A_{p+128}, B_p + B_{p+128}, x_p + x_{p+128})$ and the row DC sum $(\sum_i A_i, \sum_i B_i, \sum_i x_i + \text{carry})$. The continuous optimum $(d^*, m^*)$ is solved by $2\times 2$ CramΓ©r's rule and the $\mathbb{F}_{16}$ ULP neighborhood is polished in $O(1)$ scalar arithmetic without touching the 256 weights.
139
+ 3. **Closed-Form 1-D Quadratic Vesica/DC Code Projection**:
140
+ Each weight's optimal discrete step $\Delta q_k^*$ under the combined weighted SSE + Vesica + DC objective is computed directly from the 1-D quadratic minimizer:
141
+ $$
142
+ \Delta q_k^* = \operatorname{round}\!\left(\frac{d_{\text{sub},k}\left(w_k e_k + \frac{\lambda_{\text{vw}}}{N}(e_k + e_{k\oplus 128}) + \frac{\lambda_{\text{dc}}}{N} D\right)}{\left(w_k + \frac{\lambda_{\text{vw}} + \lambda_{\text{dc}}}{N}\right) d_{\text{sub},k}^2}\right).
143
+ $$
144
+
145
+ ---
146
+
147
+ ### 4. End-to-End HPC Pipeline
148
 
149
  ```text
150
  Source Weights + Optional iMatrix
 
153
  Kurtosis-Gated Clamp & Batched GGML Seeds (make_qkx2_batch / make_qp_batch)
154
  β”‚
155
  β–Ό
156
+ Vectorized Superblock WLS + Multi-Core Analog-Guided Factored Candidate Field
157
  β”‚
158
  β–Ό
159
  6-State Sequential Sieve (Bounded Neighbor Parity Back-Action + Log-Slack)
 
162
  36-State Viterbi Global Sequence Optimization (Free-Energy Bins + Manhattan Prior)
163
  β”‚
164
  β–Ό
165
+ Batched Algebraic Phase-4 Coupled Assembly + Quadratic ULP Polish + Closed-Form Code Projection
166
  β”‚
167
  β–Ό
168
+ Row-Aware Sequential DC Residual Nudge & Monotone Local-Safety Floors
169
  β”‚
170
  β–Ό
171
  Standard Q2_K GGUF Output
 
173
 
174
  ---
175
 
176
+ ## Measured Benchmarks
177
 
178
  Evaluated across 48 synthetic blocks (4 distributions) and a full row (47 superblocks = 12,032 weights) of `blk.0.ffn_down.weight` from `Raon.gguf` weighted by `imatrix.gguf`:
179
 
180
  | Benchmark Suite | Mean Objective Reduction | Median Reduction | Min Reduction | Worse Cases |
181
  | :--- | :---: | :---: | :---: | :---: |
182
+ | **Gaussian** ($\mathcal{N}(0, 0.02^2)$) | **+8.85%** | +8.45% | +3.17% | `0 / 12` |
183
+ | **Heavy-Tailed** ($\text{Student-}t_3$) | **+10.25%** | +8.30% | +5.04% | `0 / 12` |
184
+ | **Offset-Sparse** (50% density + DC shift) | **+14.07%** | +14.83% | +4.16% | `0 / 12` |
185
+ | **Sparse** (10% density) | **+35.40%** | +32.78% | +17.01% | `0 / 12` |
186
  | **Real `Raon.gguf` (`blk.0.ffn_down.weight` + `iMatrix`)** | **+15.96%** | β€” | β€” | `0 / 47` |
187
 
188
  Reproduce at any time with:
 
202
  pip install numpy
203
  ```
204
 
205
+ ### 1. Desktop GUI with Live Telemetry (`gui.py`)
206
 
207
+ Launch the graphical interface to browse a source `.gguf`, attach an `.imatrix`/`.gguf` importance file, inspect eligible tensors, tune analog/HPC parameters, set CPU worker count, copy the equivalent CLI command, and monitor live quantization with dual progress bars (**Model Progress** and **Tensor Superblocks**) and dual ETAs (**Tensor ETA** and **Model ETA**):
208
 
209
  ```bash
210
  python3 gui.py
 
218
 
219
  ### 2. Command-Line Interface (`hpc_quantize_v2`)
220
 
221
+ **Quantize a full GGUF model to a `Q2_K` GGUF with an iMatrix (using all CPU cores by default):**
222
 
223
  ```bash
224
  python3 -m hpc_quantize_v2 \
 
226
  --all-q2k \
227
  --imatrix-gguf imatrix.gguf \
228
  --output Raon-Q2K.gguf \
229
+ --workers 0 \
230
  --verbose
231
  ```
232
 
 
259
  from hpc_quantize_v2 import (
260
  HPCConfig,
261
  Q2KQuantizer,
 
262
  read_imatrix,
263
  )
264
  from hpc_quantize_v2.gguf import write_quantized_gguf
265
 
266
+ # 1. Quantize an in-memory tensor (workers=0 auto-uses all CPU cores)
267
  cfg = HPCConfig(
268
  n_cand_d=6,
269
  n_cand_m=6,
 
271
  factor_coupled_q2k=True,
272
  factor_joint_subscales=True,
273
  use_spectral=True,
274
+ workers=0,
275
  )
276
  quantizer = Q2KQuantizer(cfg)
277
 
278
+ weights = np.random.default_rng(0).normal(0, 0.02, size=(64, 256)).astype(np.float32)
279
  result = quantizer.quantize(weights, row_width=256)
280
  print("RMSE:", result.stats.rmse)
281
  reconstructed = result.dequantize()
 
298
 
299
  ```text
300
  HPC-Quantize/
301
+ β”œβ”€β”€ gui.py # Standalone Tkinter/TTK GUI with live telemetry dashboard
302
  └── hpc_quantize_v2/ # Pure-Python V2 package (zero C dependencies)
303
  β”œβ”€β”€ __init__.py # Public API exports
304
+ β”œβ”€β”€ __main__.py # CLI entry point (--gguf, --input, --demo, --bench, --workers)
305
  β”œβ”€β”€ config.py # Validated HPCConfig dataclass
306
  β”œβ”€β”€ fp16.py # Bit-exact GGML nearest_int & IEEE fp16 ULP primitives
307
+ β”œβ”€β”€ q2k.py # Q2_K 84-byte block packing, unpacking & batched dequantization
308
  β”œβ”€β”€ analog.py # Geometry-preserving weight analogs (Iso-Moment, Vesica Gram, Subscale)
309
+ β”œβ”€β”€ factored.py # Coupled orthogonal-basis bilinear Q2_K block & vectorized candidate solver
310
  β”œβ”€β”€ seeds.py # Kurtosis-gated outlier clamping & batched GGML seed solvers
311
  β”œβ”€β”€ spectral.py # Folded error pyramid, DC/Vesica penalty & Hadamard code descent
312
  β”œβ”€β”€ sieve.py # 6-state sequential Sieve with neighbor parity back-action
313
  β”œβ”€β”€ viterbi.py # Vectorized 36-state Viterbi sequence optimizer
314
+ β”œβ”€β”€ pipeline.py # End-to-end Q2KQuantizer with multi-core Phase 2b & algebraic Phase 4
315
+ β”œβ”€β”€ gguf.py # GGUF reader, iMatrix loader & GGUF-to-GGUF streaming writer
316
  β”œβ”€β”€ reference.py # Faithful C-reference solver port for A/B benchmarking
 
 
317
  ```
318
 
319
  ## Running the Test Suite
 
321
  ```bash
322
  python3 -m unittest discover -s hpc_quantize_v2/tests -v
323
  ```