From 4cd4cf43525bd06a14565e02e3b1515803a3f5c9 Mon Sep 17 00:00:00 2001 From: jfrery Date: Mon, 6 Dec 2021 16:54:35 +0100 Subject: [PATCH] fix: put_back_round --- concrete/quantization/quantized_activations.py | 4 +++- concrete/quantization/quantized_array.py | 5 ++--- concrete/quantization/quantized_layers.py | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/concrete/quantization/quantized_activations.py b/concrete/quantization/quantized_activations.py index 4fd55c443..4b8dd8f09 100644 --- a/concrete/quantization/quantized_activations.py +++ b/concrete/quantization/quantized_activations.py @@ -55,7 +55,9 @@ class QuantizedActivation(ABC): assert self.q_out is not None qoutput_activation = qoutput_activation / self.q_out.scale + self.q_out.zero_point - qoutput_activation = (qoutput_activation).clip(0, 2 ** self.q_out.n_bits - 1).astype(int) + qoutput_activation = ( + numpy.rint(qoutput_activation).clip(0, 2 ** self.q_out.n_bits - 1).astype(int) + ) # TODO find a better way to do the following (see issue #832) q_out = copy.copy(self.q_out) diff --git a/concrete/quantization/quantized_array.py b/concrete/quantization/quantized_array.py index cb2c383a6..0e316985f 100644 --- a/concrete/quantization/quantized_array.py +++ b/concrete/quantization/quantized_array.py @@ -59,7 +59,7 @@ class QuantizedArray: qvalues = self.values / scale + zero_point qvalues = ( - qvalues.round() + numpy.rint(qvalues) .clip(-self.offset, 2 ** (self.n_bits) - 1 - self.offset) .astype(int) # Careful this can be very large with high number of bits ) @@ -100,8 +100,7 @@ class QuantizedArray: """ self.qvalues = ( - (self.values / self.scale + self.zero_point) - .round() + numpy.rint(self.values / self.scale + self.zero_point) .clip(-self.offset, 2 ** (self.n_bits) - 1 - self.offset) .astype(int) ) diff --git a/concrete/quantization/quantized_layers.py b/concrete/quantization/quantized_layers.py index c4eea1ba3..fae472903 100644 --- a/concrete/quantization/quantized_layers.py +++ b/concrete/quantization/quantized_layers.py @@ -96,7 +96,7 @@ class QuantizedLinear: numpy_q_out = m_matmul * numpy_q_out numpy_q_out = self.q_out.zero_point + bias_part + numpy_q_out - numpy_q_out = numpy_q_out.clip(0, 2 ** self.q_out.n_bits - 1).astype(int) + numpy_q_out = numpy.rint(numpy_q_out).clip(0, 2 ** self.q_out.n_bits - 1).astype(int) # TODO find a more intuitive way to do the following (see issue #832) # We should be able to reuse q_out quantization parameters