SOL-PV-004 // aprender-contracts
Q4_K Super-Block Quantization Error Bound
Certify 4-bit K-quantization cosine similarity >= 0.995 against FP16 reference weights before shipping .apr v2 models.
Measured delta: 4.5 bpw Q4_K retains >= 0.995 cosine similarity vs FP16 (3.5x smaller)
Before (Failing Anti-Pattern)
pub fn uncalibrated_q4(q: u8) -> f32 { f32::from(q) * 0.01 } // uncalibrated scale
After (Verified Code)
pub fn dequant_q4k(q: u8, scale: f32, min: f32) -> f32 {
scale * f32::from(q & 0x0f) - min
}
Verification Contract
metadata:
version: "1.0.0"
kind: pattern
description: "Q4_K super-block affine dequantization accuracy contract"
references:
- "GGML Q4_K super-block quantization specification"
equations:
dequant:
formula: "w_hat = d_b * q_i - m_b"
proof_obligations:
- id: PO-Q4K-001
type: bound
property: "Cosine similarity >= 0.995 with zero NaN weights"
falsification_tests:
- id: FALSIFY-Q4K-001
rule: "q4k_cosine_bound"
prediction: "cosine_sim(q4k, fp16) >= 0.995"
if_fails: "Super-block scale or min unpacking mismatch"
Verified CLI Command & Output
$ pv validate contracts/q4k-superblock.yaml 0 error(s), 0 warning(s) — Contract is valid.