From 611da7fcb05404b0884c5f3cf278ac93268a429b Mon Sep 17 00:00:00 2001 From: Chang Xu Date: Tue, 17 Jan 2023 16:37:29 +0800 Subject: [PATCH] Update PostQuantTraining zero size (#49868) --- .../quantization/post_training_quantization.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/python/paddle/static/quantization/post_training_quantization.py b/python/paddle/static/quantization/post_training_quantization.py index 024c227bca..6176200128 100644 --- a/python/paddle/static/quantization/post_training_quantization.py +++ b/python/paddle/static/quantization/post_training_quantization.py @@ -789,7 +789,7 @@ class PostTrainingQuantization: _logger.info("MSE searching stage ...") for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue var_tensor = var_tensor.flatten() @@ -843,7 +843,7 @@ class PostTrainingQuantization: _logger.info("EMD searching stage ...") for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue var_tensor = var_tensor.flatten() @@ -899,7 +899,7 @@ class PostTrainingQuantization: for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue abs_max_value = float(np.max(np.abs(var_tensor))) @@ -940,7 +940,7 @@ class PostTrainingQuantization: for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue abs_max_value = float(np.max(np.abs(var_tensor))) @@ -975,7 +975,7 @@ class PostTrainingQuantization: for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue min_value = float(np.min(var_tensor)) @@ -992,7 +992,7 @@ class PostTrainingQuantization: def _sample_histogram(self): for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if (not var_tensor.any()) or ( + if (var_tensor.size == 0) or ( var_name not in self._sampling_act_histogram ): self._zero_size_var_names.add(var_name) @@ -1031,7 +1031,7 @@ class PostTrainingQuantization: for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue abs_max_value = float(np.max(np.abs(var_tensor))) @@ -1094,7 +1094,7 @@ class PostTrainingQuantization: ''' for var_name in self._quantized_act_var_name: var_tensor = utils.load_variable_data(self._scope, var_name) - if not var_tensor.any(): + if var_tensor.size == 0: self._zero_size_var_names.add(var_name) continue var_tensor = np.abs(var_tensor) -- GitLab