如何将三进制数打包进 8 位字节中
How to pack ternary numbers in 8-bit bytes

原始链接: https://compilade.net/blog/ternary-packing

本文详细介绍了一种用于 BitNet b1.58 等模型中三进制权重(trits)的高效打包方法。为优化存储与性能,作者采用了一种块大小设置,即将 5 个三进制位打包进 8 个比特中,实现了 99.06% 的信息密度效率。 在大型语言模型推理中,解包这些权重的关键难点在于,模运算和除法运算在 SIMD(单指令多数据流)环境中通常执行缓慢或不受支持。为解决这一问题,作者采用了一种定点乘法技术:通过将字节乘以特定常数,无需使用昂贵的除法即可从结果位中提取三进制位。 该方法确保了数据的无损恢复,并显著加快了并行解包的速度。目前,该技术已在 `llama.cpp` 中针对 AVX2 和 ARM NEON 架构完成实现,为处理三进制权重模型提供了高性能解决方案。

抱歉。
相关文章

原文

with efficient SIMD-friendly unpacking


Published:

There are 3 possible values in a digit of a ternary number. 3 possible values, which could actually be anything.

I've been recently nerd-sniped into trying to pack the ternary weights of BitNet b1.58 into something close to that theoretical ideal of log(3) / log(2) bits per ternary digit.

I'll be calling a "ternary digit" a "trit", like a "binary digit" is called a "bit".

Block size

https://github.com/ggml-org/llama.cpp/pull/8151, with SIMD implementations for both AVX2 and ARM NEON.

联系我们 contact @ memedata.com