When trying to train both the float and the quantized model, unless current_model.double()
is called before training, or within training/evalulation of the model the input tensors are set to floats via outputs = current_model(local_batch.float())
and criterion_loss = criterion(outputs,local_labels.float())
the following error occurs:
current_model = models.three_layer_model_bv()
Traceback (most recent call last):
File "C:/Users/Ben/PycharmProjects/pytorch-jet-classify/train.py", line 203, in
outputs = current_model(local_batch)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\models.py", line 56, in forward
test = self.fc1(x)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\brevitas\nn\quant_linear.py", line 201, in forward
output = linear(input, quant_weight, quant_bias)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\functional.py", line 1610, in linear
ret = torch.addmm(bias, input, weight.t())
RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'mat1' in call to _th_addmm`
current_model = models.three_layer_model()
Traceback (most recent call last):
File "C:/Users/Ben/PycharmProjects/pytorch-jet-classify/train.py", line 203, in
outputs = current_model(local_batch)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\models.py", line 21, in forward
x = self.act(self.fc1(x))
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\modules\module.py", line 550, in call
result = self.forward(*input, **kwargs)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\modules\linear.py", line 87, in forward
return F.linear(input, self.weight, self.bias)
File "C:\Users\Ben\PycharmProjects\pytorch-jet-classify\venv\lib\site-packages\torch\nn\functional.py", line 1610, in linear
ret = torch.addmm(bias, input, weight.t())
RuntimeError: Expected object of scalar type Float but got scalar type Double for argument #2 'mat1' in call to _th_addmm
We need to either understand:
- Why this is occurring and if we can fix it without settings
current_model.double()
or local_batch.float()
- If setting
current_model.double()
doesn't effect the quantization of the network via brevitas
- if setting 'local_batch.float()'/
local_labels.float()
doesn't effect quantization of the network via brevitas
The currently implemented method is using local_batch.float()
/ local_labels.float()
within model training/evaluation, as it seems to have a noticeable impact on model size. (model.double() model size was ~45KB, local_batch.float() model size was ~18KB for the unquantized model)
Found information so far (to look into further at some point)
https://discuss.pytorch.org/t/runtimeerror-expected-object-of-scalar-type-double-but-got-scalar-type-float-for-argument-2-weight/38961/8
https://stackoverflow.com/questions/56741087/how-to-fix-runtimeerror-expected-object-of-scalar-type-float-but-got-scalar-typ/56741419
pytorch/pytorch#2138