google / gemmlowp

Low-precision matrix multiplication
Apache License 2.0
1.77k stars 451 forks source link

error result when W and X don't range from -1 to 1 #167

Closed pingfengluo closed 5 years ago

pingfengluo commented 5 years ago

when I change W and X range (-20 to 20) , gemm result loss too much pricision. diff --git a/doc/quantization_example.cc b/doc/quantization_example.cc index d7b147d..f7178b9 100644 --- a/doc/quantization_example.cc +++ b/doc/quantization_example.cc @@ -157,7 +157,7 @@ class MatrixWithStorage { : storage(rows * cols), matrix_map(storage.data(), rows, cols) {} void MakeRandom() { static std::mt19937 random_engine;

the gemm result is: Difference between ACTUAL and REFERENCE float results: -0.27 3.05 -0.269 -0.269 0.881 1.47

bjacob commented 5 years ago

It is to be expected that as the min-max interval becomes wider, the 8bit-representable values get more diluted, so the quantization error on every value becomes larger. That is why neural network quantization needs to carefully pick the right min-max for each array.

mtu commented 4 years ago

@bjacob “That is why neural network quantization needs to carefully pick the right min-max for each array.” ===> How to pick the right min-max for each array in neural network ?