I’m trying to do QAT for yolov5, but I got the following error:
RuntimeError: Expected self.scalar_type() == ScalarType::Float to be true, but got false.  (Could this error message be improved?  If so, please report an enhancement request to PyTorch.) 
This is the total log:
Traceback (most recent call last):
  File "train.py", line 464, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 269, in train
    pred = model(imgs)  # forward
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/feiyu/yolov5/models/yolo.py", line 132, in forward
    x = self.forward_once(x, profile)  # single-scale inference, train
  File "/home/feiyu/yolov5/models/yolo.py", line 150, in forward_once
    x = m(x)  # run
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/feiyu/yolov5/models/common.py", line 114, in forward
    return self.conv(torch.cat([x[..., ::2, ::2], x[..., 1::2, ::2], x[..., ::2, 1::2], x[..., 1::2, 1::2]], 1))
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/feiyu/yolov5/models/common.py", line 48, in fuseforward
    return self.act(self.conv(x))
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 731, in _call_impl
    hook_result = hook(self, input, result)
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/quantization/quantize.py", line 82, in _observer_forward_hook
    return self.activation_post_process(output)
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/feiyu/anaconda3/lib/python3.7/site-packages/torch/quantization/fake_quantize.py", line 104, in forward
    self.quant_max)
RuntimeError: Expected self.scalar_type() == ScalarType::Float to be true, but got false.  (Could this error message be improved?  If so, please report an enhancement request to PyTorch.)


And here is the code where error occurs:
class Conv(nn.Module):
    # Standard convolution
    def __init__(self, c1, c2, k=1, s=1, p=None, g=1, act=True):  # ch_in, ch_out, kernel, stride, padding, groups
        super().__init__()
        self.conv = nn.Conv2d(c1, c2, k, s, autopad(k, p), groups=g, bias=False)
        self.bn = nn.BatchNorm2d(c2)
        self.act = nn.Hardswish() if act else nn.Identity()

    def forward(self, x):
        return self.act(self.bn(self.conv(x)))

    def fuseforward(self, x):
        return self.act(self.conv(x))

I tried use nn.ReLU to replace nn.Hardswish, but it didn’t work. And I checked the input x dtype, which is always torch.float32.