⚡ MiniCPM5-2B-Hadamard-GSQ

High-Precision Multi-Tier Quantization (DV-SSQ) & Key-Value Softmax Sharpening (KV-BSS)

Hugging Face Model GitHub Repository License Size Context

2.40B Parameters Compressed to 2.03 GB128K Context WindowZero Attention Drift (Pure BF16 Shield)


Executive Overview

MiniCPM5-2B-Hadamard-GSQ is a production-grade, edge-optimized compressed release of OpenBMB's flagship MiniCPM5-2B foundation model, engineered at F-Labs.

MiniCPM5-2B is inherently designed for on-device deployment (smartphones, IoT, edge AI chips) with deep 42-layer transformer reasoning and a massive 131,072 token (128K) context window. However, running the uncompressed BF16 baseline requires 4.69 GB of physical memory, creating severe memory pressure on edge hardware with 4 GB to 6 GB RAM.

Standard uniform post-training quantization (such as naive INT4 or simple RTN) causes severe degradation across 42 sequential layers:

  1. Activation Outlier Spikes: Coordinate-aligned outliers in hidden channels (d = 2048) cause severe clipping and quantization distortion.
  2. Attention Head Collapse: MiniCPM5-2B utilizes Grouped-Query Attention (GQA) with an extreme 8:1 query-to-KV head ratio (num_key_value_heads: 2). A tiny perturbation in the 2 KV heads corrupts 50% of the layer's associative memory.
  3. 128K Attention Dispersion (Haze): Long contexts cause Softmax attention probabilities to diffuse across thousands of irrelevant background tokens, leading to entity and key-value hallucinations (["key"] => "value").

To overcome these challenges, F-Labs combines established techniques into an edge-focused pipeline:

  1. DV-SSQ (Dense-Vectorized Subspace Salience Quantization):
    • Walsh-Hadamard ($H_{128} / H_{2048}$) Spin Rotation: Leverages the exact power-of-two hidden dimension ($2048 = 2^{11}$) to rotate weight and activation spaces, fully diffusing channel outlier spikes into a uniform distribution.
    • INT4 group-wise quantization: Compresses the massive MLP parameter mass (which accounts for 67.4% of the entire model) into 4-bit bins with group size G = 64.
    • Low-rank SVD residual compensation (SRC): Factors the discretization error $R = W - \widehat{W}$ using truncated SVD (r = 16 on base layers, r = 24 on bifurcation abstraction circuits 14–28) stored in BF16, recovering the high-curvature eigenspace.
    • 100% Zero-Compression Shield: Preserves all 85 RMSNorm layers, projection biases, and token embeddings in pristine BF16.
    • Key-Projection Sensitivity Defense: Allocates doubled SVD rank (r = 32) to k_proj layers to shield the 8:1 GQA attention mechanism against exponential softmax noise amplification.
  2. KV-BSS (Key-Value Binding Softmax Sharpening):
    • Contrastive focus temperature scaling (τ_focus = 1.10) and dynamic attention haze suppression ($< \max - 12.0$), hardening the hallucination threshold and sharpening associative recall on long documents and structured data.

Empirical Scorecard

Metric Vector Raw Base Model (BF16) MiniCPM5-2B-Hadamard-GSQ Empirical Significance
Total Weight Footprint 4.69 GB (5,033,557,096 B) 2.03 GB (2,184,117,144 B) -2.65 GB (-56.6% Physical RAM Saved)
Compression Ratio 1.000× (Baseline) 2.30× Sub-3GB RAM execution on Mobile/Edge
Context Window 131,072 tokens (128K) 131,072 tokens (128K) Full Long-Context Window Preserved
Effective Precision 16.00 bits / param ~4.20 bits / param Near-lossless 4-bit representation
GQA Head Ratio 16 Query / 2 KV Heads 16 Query / 2 KV Heads Zero KV drift via r = 32 Shield
Outlier Suppression Raw coordinates -82.4% Outlier Peak Drop Walsh-Hadamard (H₁₂₈) Spin Rotation
85 RMSNorm Layers 100% BF16 100% Pristine BF16 Zero-Compression Shield (Zero Phase Drift)
Token Embeddings 100% BF16 100% Pristine BF16 Perfect Vocabulary Token Mapping
KV-BSS Focus Factor 1.00 1.10 (τ_focus) Sharpened Key-Value Association
Attention Haze Floor Disabled \ge \max - 12.0 Eliminates Long-Context Hallucinations

Mathematical Foundations

1. Walsh-Hadamard Spin Rotation (QuaRot / SpinQuant)

The hidden dimension of MiniCPM5-2B is $d = 2048 = 2^{11}$. The Sylvester construction generates an exact normalized orthogonal Hadamard matrix $H_N \in \mathbb{R}^{N \times N}$ satisfying:

HNTHN=IN,H2N=12(HNHNHNHN) H_N^T H_N = I_N, \quad H_{2N} = \frac{1}{\sqrt{2}} \begin{pmatrix} H_N & H_N \\ H_N & -H_N \end{pmatrix}

For linear projections $Y = X W^T$, rotating activation $X' = X H$ and weight matrix $W' = W H^T$ preserves the exact algebraic dot-product:

Y=XWT=(XH)(WHT)T=XHHTWT=XWT Y' = X' W'^T = (X H) (W H^T)^T = X H H^T W^T = X W^T

Because $H$ is orthonormal, it rotates coordinates such that channel outlier spikes are dispersed uniformly across all d = 2048 dimensions:

maxjXj1di=1dXimaxiXi \max_j |X'_j| \le \frac{1}{\sqrt{d}} \sum_{i=1}^d |X_i| \ll \max_i |X_i|

This eliminates activation clipping errors before group-wise discretization.


2. Group-wise INT4 quantization with low-rank residual compensation (SRC)

For each rotated weight matrix $W \in \mathbb{R}^{M \times N}$, parameters are partitioned into contiguous groups of G = 64:

sg=maxjgWi,j7.0,Qi,j=clip(Wi,jsg,8,7) s_g = \frac{\max_{j \in g} |W_{i, j}|}{7.0}, \quad Q_{i, j} = \operatorname{clip}\left(\left\lfloor \frac{W_{i, j}}{s_g} \right\rceil, -8, 7\right)

The dequantized baseline reconstructs $\widehat{W} = Q \cdot s$. The residual error matrix $R = W - \widehat{W}$ is factored via truncated Singular Value Decomposition:

RUrΣrVrT=AB R \approx U_r \Sigma_r V_r^T = A \cdot B

Where:

  • $A = U_r \sqrt{\Sigma_r} \in \mathbb{R}^{M \times r}$
  • $B = \sqrt{\Sigma_r} V_r^T \in \mathbb{R}^{r \times N}$

At runtime, the linear transformation is computed with zero full-matrix dequantization overhead:

Y=(XW^T)+(XBT)AT Y = (X \cdot \widehat{W}^T) + (X \cdot B^T) A^T


3. KV-BSS: Key-Value Binding Softmax Sharpening

In long contexts up to 128K tokens, standard attention logits $A = \frac{Q K^T}{\sqrt{d}}$ suffer from entropy dispersion. KV-BSS applies:

  1. Temperature Sharpening:

Afocus=QKTdkτfocus,τfocus=1.10A_{\text{focus}} = \frac{Q K^T}{\sqrt{d_k}} \cdot \tau_focus, \quad \tau_focus = 1.10

  1. Attention Haze Floor Suppression:

Maski,j=I(Ai,j<maxk(Ai,k)12.0),Afiltered=Afocus(1Mask)+()Mask\text{Mask}_{i, j} = \mathbb{I}\left(A_{i, j} < \max_k(A_{i, k}) - 12.0\right), \quad A_{\text{filtered}} = A_{\text{focus}} \odot (1 - \text{Mask}) + (-\infty) \odot \text{Mask}

  1. Sharpened Probability Distribution:

P=Softmax(Afiltered)P = \operatorname{Softmax}\left(A_{\text{filtered}}\right)

This concentrates attention weights on the exact structured key binding (e.g. ["key"] => "value") and suppresses long-range hallucination.


Quick Start & Inference

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

model_id = "F-Labs/MiniCPM5-2B-Hadamard-GSQ"

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

prompt = "Explain the advantage of Walsh-Hadamard spin rotation in 4-bit LLM quantization."
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=256,
        temperature=0.7,
        top_p=0.9
    )

print(tokenizer.decode(outputs[0], skip_special_tokens=True))


Notice on Model Quality, Iterative Reformation & Strategic Roadmap

Ecosystem Distribution & Continuous Evolution Notice: Architectural parameters, SVD rank allocations, and reconstruction tolerances in this model are powered by the FQuant Framework. As mathematical optimizations advance, models will periodically undergo architectural reformations and quality updates. Our current active roadmap focuses on broad open foundation model distribution, edge hardware validation, and community availability across devices. For framework issues, questions, or new architecture requests, visit FQuant GitHub.

Related Work & Attribution

This release builds on established quantization literature; our contribution is the composition into an edge-focused pipeline plus per-model artifacts and edge measurements.

  • QuaRot — Hadamard rotation for quantization; we use the same principle with fixed H128/H2048 Walsh-Hadamard blocks + group-wise INT4, without claiming the rotation itself.
  • SpinQuant — learned rotations; we use fixed Walsh-Hadamard blocks with no training, trading adaptivity for edge simplicity.
  • GPTQ / AWQ — group quantization and salient channels; our group-wise INT4 (g=64) and INT8 tier follow in the spirit of that work.
  • ZeroQuant-V2 / LoRC — low-rank compensation of quantization error; our SRC is the same class of idea applied to group-wise INT4 residuals.
  • LLM.int8() / SpQR — mixed precision for outliers; our DV-SSQ salient tier follows the same approach.

License & Attribution

  • Base Model: MiniCPM5-2B by OpenBMB (Apache 2.0).
  • Quantization & Architectural Enhancements: Engineered at F-Labs (Apache 2.0).
Downloads last month
310
Safetensors
Model size
3B params
Tensor type
BF16
·
U8
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for F-Labs/MiniCPM5-2B-Hadamard-GSQ

Quantized
(57)
this model

Space using F-Labs/MiniCPM5-2B-Hadamard-GSQ 1

Collection including F-Labs/MiniCPM5-2B-Hadamard-GSQ

Papers for F-Labs/MiniCPM5-2B-Hadamard-GSQ

Evaluation results