| Crates.io | ggml-quants |
| lib.rs | ggml-quants |
| version | 0.1.0 |
| created_at | 2024-11-25 06:15:30.380031+00 |
| updated_at | 2025-06-03 04:59:29.686403+00 |
| description | GGml defined quantized data types and their quant/dequant algorithm |
| homepage | |
| repository | https://github.com/InfiniTensor/gguf |
| max_upload_size | |
| id | 1459936 |
| size | 50,576 |
ggml-quants 是一个 Rust 库,用于实现 ggml 定义的量化数据类型及其对应的量化和反量化算法。
ggml-quants 提供了一组高效的量化工具,用于将浮点数数据压缩为更小的量化格式(如 Q4_0, Q8_1 等),并支持从量化数据还原为浮点数。
该库的核心功能包括:
rayon 并行加速正反量化计算;use ggml_quants::{Quantize, Q8_1};
// 原始浮点数数据
let data: [f32; 32] = [
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,
0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6,
1.7, 1.8, 1.9, 2.0, 2.1, 2.2, 2.3, 2.4,
2.5, 2.6, 2.7, 2.8, 2.9, 3.0, 3.1, 3.2,
];
// 量化数据
let quantized = Q8_1::quantize(&data);
// 反量化数据
let dequantized: [f32; 32] = quantized.dequantize();
在 gguf 项目中,模型权重通常以浮点数形式存储(如 f32 或 f16),这会占用大量内存,成为限制性能的主要因素。通过使用 ggml-quants 提供的量化工具,可以在能够容忍的精度损失下,将权重从 f32 压缩为更小的格式(如 Q4_0 或 Q8_1),从而: