Hi again,
I have some good news: Though there is indeed a bug, you will not need to wait for an update of Concrete-ML to fix the problem. You can fix the problem by changing the network to make it compatible with Concrete-ML.
The problem is actually in the network design: the network needs to quantize its inputs and in Brevitas this is done using a QuantIdentity
layer.
There were some other issues with your network that I could see:
-
bit_width
needs to be specified for activations and the new QuantIdentity
layer
- do not use
return_quant_tensor
or set it to False
These guidelines are documented in the Step-by-step guide here: Step-by-step Guide - Concrete ML . If the documentation is not very clear, let me know, and we’ll improve it.
I applied these modifications to your model, giving this new one:
class QDenseClassifier(nn.Module):
def __init__(self,
hparams: dict,
bits: int,
act_quant: brevitas.quant = Int8ActPerTensorFloat,
weight_quant: brevitas.quant = Int8WeightPerTensorFloat):
super(QDenseClassifier, self).__init__()
self.hparams = hparams
self.input_quant = qnn.QuantIdentity(act_quant=act_quant, bit_width=bits)
self.dense1 = qnn.QuantLinear(hparams['n_feats'], hparams['hidden_dim'], weight_quant=weight_quant, weight_bit_width=bits, bias=True)
self.dp1 = qnn.QuantDropout(0.1)
self.act1 = qnn.QuantReLU(act_quant=act_quant, bit_width=bits)
self.dense2 = qnn.QuantLinear(hparams['hidden_dim'], 1, weight_bit_width=bits, weight_quant=weight_quant, bias=True)
def forward(self, src):
x = self.dense1(self.input_quant(src))
x = self.dp1(x)
x = self.act1(x)
x = self.dense2(x)
return x
Hope this helps you make progress with your experiments! It seems you are doing fine-tuning, I suggest, if you are not already doing so, looking at the fine-tuning demo: concrete-ml/use_case_examples/cifar_brevitas_finetuning at release/0.6.x · zama-ai/concrete-ml · GitHub