feat: make the last layer over 7 bits

This commit is contained in:
jfrery
2021-12-16 18:24:27 +01:00
committed by Jordan Fréry
parent bb332861aa
commit 25e12530d1

View File

@@ -88,7 +88,12 @@ class PostTrainingAffineQuantization:
# Create a QuantizedLinear layer
q_weights = self.quant_params[f"{name}.weight"]
q_bias = self.quant_params[f"{name}.bias"]
q_layer = QuantizedLinear(self.n_bits, q_weights, q_bias)
# Check if layer is last layer from the model
if name == list(self.numpy_model.torch_model.named_children())[-1][0]:
# If last layer, we can use 7 bits (maximum allowed) of precision.
q_layer = QuantizedLinear(7, q_weights, q_bias)
else:
q_layer = QuantizedLinear(self.n_bits, q_weights, q_bias)
# Calibrate and get new calibration_data for next layer/activation
calibration_data = self._calibrate_layers_activation(
name, q_layer, calibration_data