CompressedGemma commited on
Commit
8c7d826
Β·
verified Β·
1 Parent(s): 279833a

Will make a separate repo for experiments

Browse files
Files changed (2) hide show
  1. README.md +2 -37
  2. __init__.py +0 -26
README.md CHANGED
@@ -10,7 +10,7 @@ GUI screencap
10
 
11
  This requires a CUDA GPU, expect a 50GB model to take around 3-4 hours to quantize on a 3060 12GB.
12
 
13
- About Slimshard: I've only allowed it to work with models that are already open, it is kind of like black magic and I don't want to encourage any nonsense.
14
 
15
  # HPC-Quantize V2
16
 
@@ -35,9 +35,7 @@ HPC-Quantize V2 (`hpc_quantize_v2/` + `gui.py`) has **zero C or `ctypes` depende
35
  4. **Bit-Identical Multi-Core Execution (`--workers 0`)**:
36
  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.
37
  5. **Real-Time Telemetry GUI (`gui.py`) & Direct GGUF-to-GGUF Pipeline (`hpc_quantize_v2/gguf.py`)**:
38
- Ingests `F32`, `F16`, `BF16`, `Q8_0`, `Q4_0`, and `Q2_K` source GGUFs plus `llama.cpp` iMatrix files, supports mixed `Q2_K` + full-HPC `Q4_0` (`hpc_quantize_v2/q4_0.py`) and PyTorch CUDA acceleration (`hpc_quantize_v2/cuda_backend.py`), and emits stock `llama.cpp`-compatible GGUFs.
39
- 6. **SlimShard & CheckFree Universal Single-Shard LLM Recovery (`hpc_quantize_v2/slimshard.py`, `hpc_quantize_v2/slimshard_gui.py`)**:
40
- Reconstructs a complete, runnable Hugging Face `.safetensors` model from **a single surviving `.safetensors` shard** (even without `model.safetensors.index.json`) across any Transformer or MoE architecture (Llama, Qwen2/3, Mistral, Mixtral, DeepSeek, Gemma, GPT-NeoX, Phi, VLMs, and Raon), or compresses a multi-shard HF model into a single self-contained SlimShard using HPC-Quantize V2 (`Q2_K`/`Q4_0`) and SlimMoE expert clustering.
41
 
42
  ---
43
 
@@ -185,31 +183,6 @@ Standard Q2_K GGUF Output
185
 
186
  ---
187
 
188
-
189
- ![image](https://cdn-uploads.huggingface.co/production/uploads/69de1a493a21cb7c029dc694/1dnR4EyTnOub1vXgyn9k4.png)
190
-
191
- ### 5. SlimShard & CheckFree Universal Single-Shard LLM Recovery (`slimshard.py` & `slimshard_gui.py`)
192
-
193
- `hpc_quantize_v2.slimshard` provides two single-shard workflows for arbitrary Hugging Face `.safetensors` models (Llama, Qwen2/3, Mistral, Mixtral, DeepSeek, Gemma, GPT-NeoX, Phi, VLMs with `text_config`, and Raon):
194
-
195
- 1. **CheckFree Single-Shard Recovery (`recover`)**:
196
- Reconstructs a full, loadable Hugging Face model when **only one `.safetensors` shard** is available (with zero access to the remaining shards):
197
- - **Exact Surviving Tensor Copy**: Every tensor present in the surviving shard is copied verbatim.
198
- - **CheckFree Variance-Preserving Layer Interpolation**: Missing Transformer layers $\ell$ between surviving depth anchors $\ell_a < \ell < \ell_b$ (or extrapolated past $\ell_{\max}$ with smooth depth progression) are reconstructed via row-RMS/variance-preserving interpolation:
199
- $$
200
- \tilde{W}^{(\ell)} = \left((1 - \alpha) W^{(\ell_a)} + \alpha W^{(\ell_b)}\right) \cdot \frac{(1 - \alpha)\|W^{(\ell_a)}\|_{\text{rms}} + \alpha \|W^{(\ell_b)}\|_{\text{rms}}}{\|(1 - \alpha) W^{(\ell_a)} + \alpha W^{(\ell_b)}\|_{\text{rms}}},
201
- \qquad \alpha = \frac{\ell - \ell_a}{\ell_b - \ell_a},
202
- $$
203
- separately tracking hybrid attention families (e.g. **RDA** vs. **Gated MLA** and **Raon-mHC** 4-stream parameters).
204
- - **Per-Expert MXFP8 / FP16 Depth Interpolation**: Preserves exact routed expert identity $e \in \{0,\ldots,E-1\}$ across all MoE layers (`moe.experts`, `mlp.experts`, `block_sparse_moe.experts`, `feed_forward.experts`). For pre-quantized MXFP8 (`F8_E4M3` + `UE8M0` `weight_scale_inv`) experts, bracketing anchor experts are dequantized to FP32, CheckFree-interpolated with row-RMS preservation, and re-quantized in lockstep to production block-32 MXFP8.
205
- - **Causal Forward-Calibrated `embed_tokens` & `lm_head` Synthesis**: When `embed_tokens` and `lm_head` reside in a missing shard, `slimshard` extracts the principal right-singular input subspace $B_{\text{in}}$ from Layer 0, regularizes it via `subblock_isomoment_analog`, runs an exact multi-layer causal forward pass over the reconstructed layer stack (supporting both 4-stream `RaonMHC` + `RDA`/`MLA` and standard 1-stream GQA/SwiGLU Transformers), projects background vocabulary rows strictly orthogonal to the network's fixed-point drift $\mu_{\text{out}}$, zeroes `<|reserved_*|>`/control tokens, and solves the regularized dual transition system in chunked 16K-row BF16 streams.
206
- - **Index-Free Inference (`infer_weight_map_from_shard`)**: Even if `model.safetensors.index.json` is missing, `slimshard` automatically infers the full model's tensor map from the surviving shard and `config.json`.
207
-
208
- 2. **Self-Contained SlimShard Compression (`build` & `regenerate`)**:
209
- Compresses a multi-shard HF model into a single self-contained `.safetensors` file combining HPC-Quantize V2 (`Q2_K` / `Q4_0` / `exact`) with **SlimMoE** expert centroid + quantized residual clustering (`--expert-keep-ratio`), from which `regenerate` reconstructs the full HF checkpoint.
210
-
211
- ---
212
-
213
  ## Measured Benchmarks
214
 
215
  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`:
@@ -351,8 +324,6 @@ HPC-Quantize/
351
  β”œβ”€β”€ pipeline.py # End-to-end Q2KQuantizer with multi-core Phase 2b & algebraic Phase 4
352
  β”œβ”€β”€ gguf.py # GGUF reader, iMatrix loader & GGUF-to-GGUF streaming writer
353
  β”œβ”€β”€ reference.py # Faithful C-reference solver port for A/B benchmarking
354
- └── tests/
355
- └── test_v2.py # 20 unit tests covering primitives, analogs, solver, GGUF & parallelism
356
  ```
357
 
358
  ## Running the Test Suite
@@ -360,9 +331,3 @@ HPC-Quantize/
360
  ```bash
361
  python3 -m unittest discover -s hpc_quantize_v2/tests -v
362
  ```
363
-
364
- ---
365
-
366
- ## License
367
-
368
- Released under the **MIT License**. Always verify the license of the underlying base model before redistributing quantized GGUF weights.
 
10
 
11
  This requires a CUDA GPU, expect a 50GB model to take around 3-4 hours to quantize on a 3060 12GB.
12
 
13
+ I prefer to llama-quantize to 8_0, then to generate a imatrix from that 8_0, and finally to quantize the 8_0 file to Q2K.
14
 
15
  # HPC-Quantize V2
16
 
 
35
  4. **Bit-Identical Multi-Core Execution (`--workers 0`)**:
36
  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.
37
  5. **Real-Time Telemetry GUI (`gui.py`) & Direct GGUF-to-GGUF Pipeline (`hpc_quantize_v2/gguf.py`)**:
38
+ 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.
 
 
39
 
40
  ---
41
 
 
183
 
184
  ---
185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  ## Measured Benchmarks
187
 
188
  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`:
 
324
  β”œβ”€β”€ pipeline.py # End-to-end Q2KQuantizer with multi-core Phase 2b & algebraic Phase 4
325
  β”œβ”€β”€ gguf.py # GGUF reader, iMatrix loader & GGUF-to-GGUF streaming writer
326
  β”œβ”€β”€ reference.py # Faithful C-reference solver port for A/B benchmarking
 
 
327
  ```
328
 
329
  ## Running the Test Suite
 
331
  ```bash
332
  python3 -m unittest discover -s hpc_quantize_v2/tests -v
333
  ```
 
 
 
 
 
 
__init__.py CHANGED
@@ -34,27 +34,6 @@ from .pipeline import Q2KQuantizer, QuantizedTensor, TensorStats
34
  from .q2k import Q2KBlock, QK_K, dequantize_params, pack_codes, unpack_codes
35
  from .q4_0 import QK4_0, dequantize_q4_0_bytes, quantize_tensor_q4_0
36
 
37
-
38
- def __getattr__(name: str):
39
- if name in {
40
- "SafetensorsWriter",
41
- "build_slimshard",
42
- "export_hf_bundle",
43
- "infer_weight_map_from_shard",
44
- "inspect_recovery_plan",
45
- "recover_from_shard",
46
- "regenerate",
47
- "slimshard_info",
48
- }:
49
- from . import slimshard as _ss
50
-
51
- return getattr(_ss, name)
52
- if name == "launch_slimshard_gui":
53
- from .slimshard_gui import launch_slimshard_gui
54
-
55
- return launch_slimshard_gui
56
- raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
57
-
58
  __all__ = [
59
  "HPCConfig",
60
  "cuda_device_name",
@@ -85,11 +64,6 @@ __all__ = [
85
  "QK4_0",
86
  "dequantize_q4_0_bytes",
87
  "quantize_tensor_q4_0",
88
- "SafetensorsWriter",
89
- "build_slimshard",
90
- "recover_from_shard",
91
- "regenerate",
92
- "slimshard_info",
93
  "pack_codes",
94
  "unpack_codes",
95
  ]
 
34
  from .q2k import Q2KBlock, QK_K, dequantize_params, pack_codes, unpack_codes
35
  from .q4_0 import QK4_0, dequantize_q4_0_bytes, quantize_tensor_q4_0
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  __all__ = [
38
  "HPCConfig",
39
  "cuda_device_name",
 
64
  "QK4_0",
65
  "dequantize_q4_0_bytes",
66
  "quantize_tensor_q4_0",
 
 
 
 
 
67
  "pack_codes",
68
  "unpack_codes",
69
  ]