NativeQ4Matrix.quantize constructor
NativeQ4Matrix.quantize(
- Float32List w,
- int rows,
- int cols
Quantizes float weights with llama.cpp's Q4_0 rule.
Implementation
factory NativeQ4Matrix.quantize(Float32List w, int rows, int cols) {
if (cols % 32 != 0) {
throw ArgumentError('Q4 needs cols to be a multiple of 32, got $cols');
}
final qs = NativeKernels.allocate<Uint8>(rows * cols ~/ 2);
final scales = NativeKernels.allocate<Uint16>(rows * cols ~/ 32 * 2);
_quantizeQ4(w.address, qs, scales, rows, cols);
return NativeQ4Matrix._(rows, cols, qs, scales);
}