Per-Tensor quantization support for Conv2D layers
See original GitHub issueSystem information
- TensorFlow version (you are using): TF nightly 2.3
- Are you willing to contribute it (Yes/No): No
Motivation
I’ve been testing TF QAT features by following the tutorials and guides on the following website:
https://www.tensorflow.org/model_optimization/guide/quantization/training_comprehensive_guide
To my understanding is that TF only have per-axis support for Conv2D layers and still working on per-tensor support. Right now, I’m working with a deployment target that requires per-tensor quantization for Conv2D, and just simply passing a CustomQuantizeConfig class to Conv2D layer and changing the weight quantizers Per-axis to False will cause errors with the TF quantize API.
Hence I’m wondering if there are any resources or additional experimental features that I can try out to perform per-tensor quantization for Conv2D layers?
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (3 by maintainers)

Top Related StackOverflow Question
Hi @nutsiepully , thank you for getting back to me. I’m wondering if there are any example that can help me quantize the Conv2D weight per-tensor, instead of per-axis? The examples in the comprehensive QAT guide is only for Dense Layers, and it’s not directly applicable for Conv2D layer.
I’ve been using this configurations for Conv2D which is called
Default8BitConvQuantizeConfig, that I found here:https://github.com/tensorflow/model-optimization/blob/fcaa2306d62a419c5bce700275748b8b08711dbc/tensorflow_model_optimization/python/core/quantization/keras/default_8bit/default_8bit_quantize_registry.py#L486
I ended up modifying the line
self.weight_quantizer = default_8bit_quantizers.Default8BitConvWeightsQuantizer()(which is per-axis by default) to per-tensor by setting the argumentper-axis = False:https://github.com/tensorflow/model-optimization/blob/fcaa2306d62a419c5bce700275748b8b08711dbc/tensorflow_model_optimization/python/core/quantization/keras/default_8bit/default_8bit_quantizers.py
Unfortunately by simply changing that has caused a size mismatch since some of the underlying works are based on the assumption that Conv2D is per-axis quantization
@danielmimimi hey, I have moved away from TF framework for a while now , hence I cannot recall the issue I’ve come across here.