Comments (4)
Searching on the other issue (#60), I have found that if I define alpha=1 the parameters of all the layers are quantized after the model_save_quantized_weights
function.
However, is this correct? If yes, why is this happening? And why the batch normalization layers are not quantized?
from qkeras.
When you save a model as "model_save_quantized_weights" you might be expecting only integers, or fixed-point literals that are power-of-two, I guess? But numbers can in general be quantized also to values that are outside of the scope of the aforementioned representations. However, some quantization approaches are more sensible then others, of course.
The quantized quantized_bits works on a tensor level and it does something like this:
Wq = alpha * W
Where W is the real-valued weights, Wq is the quantized-values. So for instance if you are computing W*x + b
then you can compute this as: (Wq*x) / alpha + b
. So what do you gain here? well if we limit Wq to only 4-bit numbers, and also x is a n-bit number, then we can use a integer multiplier to compute this, instead of a floating-point multiplier. But of course we still need to divide by alpha. So in general this doesn't necessary help us. But if we limit ourselves to alphas that are power-of-two, then we can compute this division as a shift operation, which if far more efficient. QKeras allows you to limit yourself to only power-of-two alphas, by setting the alpha parameter to "alpha_po2". You can also manually choose alpha=1 then it will always be 1, but then you will likely get worse results with your network.
I recommend you read a survey paper on quantization techniques. I recommend something like this:https://arxiv.org/pdf/2106.08295.pdf. It will help you understand how quantization aware training works.
from qkeras.
Regarding Batch normalization layers, they are typically folded in the preceding active layer (dense or conv typically). This is also described in the paper I mentioned in the subsection "Batch normalization folding".
from qkeras.
Oh, I see. Now I understand. Thank you very much for your help!
from qkeras.
Related Issues (20)
- Error in energy estimation for AveragePooling2D layers
- Using Auto HOT 1
- Very low accuracy following AutoQKeras notebook and CUDA error HOT 1
- How low precision weights and biases are stored in QKeras? HOT 4
- When I use QKeras: Failed to load in-memory CUBIN: CUDA_ERROR_NO_BINARY_FOR_GPU: no kernel image is available for execution on the device [Op:Abs] HOT 2
- Only Qconv layer's output tensors are quantized
- Cannot convert 6.0 to EagerTensor of dtype int64
- How do I save an AutoQKeras model that a different script can load?
- `pyparser` vs `pyparsing`
- Can QKeras support Full integer quantization HOT 8
- Add a custom layer with a bitwise operation
- TFLite compatibility
- How can I get the scale of the QAdaptiveActivation layer
- How do keras and qkeras versions correspond to each other?
- Difference between Qkeras model and Keras model HOT 9
- Adding QKeras to conda forge
- GPU Inferencing in Qkeras
- Any documentation for AutoQkeras?
- Inference of QKeras models HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from qkeras.