Skip to content

Commit

Permalink
Fix q3k imatrix quantization (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler authored Dec 1, 2024
1 parent e5685ce commit 84c89a6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion candle-core/src/quantized/k_quants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ impl GgmlType for BlockQ3K {
if j < 8 {
block.scales[j] = (l & 0xF) as u8;
} else {
block.scales[j - 8] = ((l & 0xF) << 4) as u8;
block.scales[j - 8] |= ((l & 0xF) << 4) as u8;
}
let l = l >> 4;
block.scales[j % 4 + 8] |= (l << (2 * (j / 4))) as u8;
Expand Down
4 changes: 2 additions & 2 deletions candle-core/tests/quantized_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,9 @@ fn imatrix_quantize_q3k() -> Result<()> {
let dequant1 = quant1.dequantize(cpu)?;
let dequant2 = quant2.dequantize(cpu)?;

let _err1 = (dequant1 - &xs)?.abs()?.mean_all()?.to_scalar::<f32>()?;
let err1 = (dequant1 - &xs)?.abs()?.mean_all()?.to_scalar::<f32>()?;
let err2 = (dequant2 - &xs)?.abs()?.mean_all()?.to_scalar::<f32>()?;
assert!(err2 < 0.16);
assert!(err2 < err1, "err2 {err2} > err1 {err1}");

Ok(())
}
Expand Down

0 comments on commit 84c89a6

Please sign in to comment.