Error in MovingAverageQuantizer with per_axis=True due to missing parameters in _add_range_weights
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 55/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- python, tensorflow
- Ambito
- machine-learning
Direzione di ricerca
Inizia in tensorflow_model_optimization/python/core/quantization/keras/quantizers.py, in MovingAverageQuantizer.build e _add_range_weights, quindi esamina l’asserzione di _FakeQuantWithMinMaxVars in quant_ops.py. Riproduci l’esempio con per_axis=True e verifica che le variabili min/max abbiano la forma di lista prevista senza compromettere il percorso per_axis=False.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
Using the MovingAverageQuantizer with parameter per_axis set to True results in this error:
tensorflow_model_optimization\python\core\quantization\keras\quant_ops.py", line 335, in _FakeQuantWithMinMaxVars *
assert len(min_var.get_shape()) == 1
It's caused by this helper function _add_range_weights called by the build function of the MovingAverageQuantizer where the per_axis and tensor_shape parameters are not passed on resulting in only initializing a scalar for the min/max variables. Which later fails the assert.
System information
TensorFlow version: 2.12.0 (binary)
TensorFlow Model Optimization version: 0.7.4 (binary)
Python version: 3.9.16
Describe the expected behavior
There should be a list of values in the min/max variables.
Describe the current behavior
Throws and error because of failed assert in _FakeQuantWithMinMaxVars
Code to reproduce the issue
import keras
import tensorflow_model_optimization as tfmot
class CustomConv2DQuantizeConfig(tfmot.quantization.keras.QuantizeConfig):
def get_weights_and_quantizers(self, layer):
return [(layer.kernel, tfmot.quantization.keras.quantizers.MovingAverageQuantizer(num_bits=8, per_axis=True, symmetric=True, narrow_range=True))]
def get_activations_and_quantizers(self, layer):
return [(layer.activation, tfmot.quantization.keras.quantizers.MovingAverageQuantizer(num_bits=8, per_axis=False, symmetric=False, narrow_range=False))]
def set_quantize_weights(self, layer, quantize_weights):
layer.kernel = quantize_weights[0]
def set_quantize_activations(self, layer, quantize_activations):
layer.activation = quantize_activations[0]
def get_output_quantizers(self, layer):
return []
def get_config(self):
return {}
annotated_model = keras.Sequential([
keras.Input(shape=(32,32,3)),
tfmot.quantization.keras.quantize_annotate_layer(keras.layers.Conv2D(32, kernel_size=(3, 3)), CustomConv2DQuantizeConfig())
])
with tfmot.quantization.keras.quantize_scope(
{'CustomConv2DQuantizeConfig': CustomConv2DQuantizeConfig}):
quant_aware_model = tfmot.quantization.keras.quantize_apply(annotated_model)
Additional context
Changing the build function of MovingAverageQuantizer to pass the mentioned parameters like:
def build(self, tensor_shape, name, layer):
return self._add_range_weights(layer, name, self.per_axis, tensor_shape)
fixes the issue and results in the expected behavior.
- Lingua principale
- Python
- Stelle
- 1.6k
- Fork
- 349
- Merge medio
- 3g 2h
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tensorflow/model-optimization
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
tensorflow/model-optimization#1301 · 1 commento ·
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
tensorflow/model-optimization#1272 ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 50/100
tensorflow/model-optimization#1270 · 2 commenti ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
tensorflow/model-optimization#1241 ·
-
bug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
tensorflow/model-optimization#1182 · 1 commento ·
Tutte le issue di tensorflow/model-optimization
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 75/100
-
hcocena Apertapolicies-accepted pre-review precheck-passed
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
Bioconductor/BiocContributions#214 · 5 commenti ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
TencentCloud/Octop#1169 · 1 commento ·
-
[开源推荐] 在老板拷问你之前,先让 AI 灵魂拷问你 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value Apertaarea: dashboard area: tests bug perceived difficulty: 2 python
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · 1 commento ·