gungui98/Pytorch-Depthwise-Conv3d

cuda.amp.autocast doesn't work for this module

Closed this issue · 4 comments

Hi
Thanks for the great work.
I tried running this module with mixed precision (autocast) and got an error indicating the the weights we not converted to half.
It would be great if this can be resolved.

Could you please post some code snippets!

the following code

import torch
from depthwise_conv3d import DepthwiseConv3d
from torch.cuda.amp import autocast

depth_multiplier=2
conv = DepthwiseConv3d(2, 2 * depth_multiplier, kernel_size=3, groups=2).cuda()
input = torch.randn(2, 2, 6, 6, 6, device="cuda", dtype=torch.half).div_(2).requires_grad_()
with autocast():
  output = conv(input)

produces the error

Traceback (most recent call last):
File "", line 2, in
File "/opt/conda/lib/python3.8/site-packages/torch/nn/modules/module.py", line 744, in _call_impl
result = self.forward(*input, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/depthwise_conv3d-1.0.3-py3.8-linux-x86_64.egg/depthwise_conv3d.py", line 93, in forward
return depthwise_conv3d(x, self.weight, self.bias, self.stride, self.padding, self.dilation,
File "/opt/conda/lib/python3.8/site-packages/depthwise_conv3d-1.0.3-py3.8-linux-x86_64.egg/depthwise_conv3d.py", line 26, in forward
output = DWCONV_CUDA.conv_depthwise3d_cuda(
RuntimeError: expected scalar type Half but found Float

I just add a handful fix to the module. In fact, the module supports both full and mixed-precision, please test it in your model and let me know if it works

looks like it works now
Thanks