google / qkeras

QKeras: a quantization deep learning library for Tensorflow Keras
Apache License 2.0
533 stars 102 forks source link

How low precision weights and biases are stored in QKeras? #103

Closed wilfredkisku closed 1 year ago

wilfredkisku commented 1 year ago

Being new to quantization in QKeras, is there a way I can get the quantized weights and know how they are exactly stored?

If the (min, max) values for scaling have been used how can I extract those values to verify the effective quantization in each layer?

Thanks.

jurevreca12 commented 1 year ago

QKeras stores the weights in floating-point. So they are "stored" exactly as in regular keras. What qkeras does is apply "fake quantization functions" that have the signature f:Tensor[float]->Tensor[float]. But the output is constrained to the values that a quantized weight could take. I suggest you begin with taking a look at the different quantization functions (quantized_bits, binary...)

wilfredkisku commented 1 year ago

Thanks. I am able to understand the quantization technique that has been used by looking at the functions. Is there a way to store the quantized weights during each epoch of the training phase? I just want to look at the effect of quantization on optimization.

jurevreca12 commented 1 year ago

ah. I see. Well you can look at the weights as such:layer.kernel_quantizer_internal(layer.kernel). And for biases: layer.bias_quantizer_internal(layer.bias).

wilfredkisku commented 1 year ago

Thanks! works like a charm.