does mkldnn support depthwise convolution?
does it support depthwise convolution? If it supports, there is any example?
Hi @kriszhangyf,
Formally speaking MKL-DNN supports groups which covers the functionality of depth-wise convolution:
dst[n][c][oh][ow] <-- src[n, c, ih, iw] (*) wei[c][1][1][kh][kw]
Here wei is 5D tensor of weights with number of groups = c, oc = 1, ic = 1, and kh x kw spatial.
But for now we don't have an optimized (jitted) version of those. MKL-DNN will fallback to gemm-based convolution. Though, we have plans to add the jitted version as well (so far the forward pass only).
Does it means that the out channel is still c? can it supports the depthwide conv as src[n, c, ih, iw] * wei[oc, 1, kh, hw] -> dst[n, oc, oh, ow]? which oc = g*c
Convolution has strict definition, so
src[n, ic, ih, iw] (*) wei[oc, 1, kh, hw]
is illegal, since ic in source doesn't match ic in weights.
Hi @emfomenk,
Are there any updates on the optimized depthwise convolution?
Thanks
Hi,
we recently tuned gemm-based implementation for depthwise convolution (see 967d7bf). Also we will promote avx2 specialized version for forward pass (maybe in few days).
If you want to check performance for mobilenet or xception convolutions, you may use benchdnn with corresponding input file (see 3768fb22).
Just a quick update: optimized avx2 version is here 3edac962.
That's awesome! Thanks! I'm still struggling with compiling intel-caffe on macOS. Hope I can test it soon.
@emfomenk Hi! Thank you for your answer! Is there any instructions about how to integrate this in Intel caffe?
Hi @fei1107,
Depthwise convolution uses regular grouped API (basically ic = oc = g), so I think IntelCaffe already supports it (since IntelCaffe supports grouped convolutions).
@emfomenk Thanks! Do you mean that when ic = oc = g, Intel caffe will automatically run on the optimized depthwise convolution code rather than general convolution?
I would think so. Whenever you feed IntelCaffe with the topology like the one below optimized depthwise convolution should be used.
...
layer {
type: "Convolution"
bottom: "conv1" # with num_output: 32
...
convolution_param {
num_output: 32
group: 32
...
}
}
...
@emfomenk Many thanks! Does the depthwise conv support quantization for int8 on avx512 right now? And one last question, how can I fuse the convolution and relu layer in intel caffe, do I have to set some flag, or it can fuse automatically?Really appreciate for your answer!
Does the depthwise conv support quantization for int8 on avx512 right now?
Not sure I understand the question.
-
If you are asking whether MKL-DNN supports int8 depthwise convolution then the answer is yes, thought we don't have a kernel with direct implementation (so int8-gemm-based fallback will be used).
-
If you are asking whether you can quantize the input/weights (
f32 -> int8) or dequantize output (int8 -> f32) then the answer is also yes. You can do that via reorders. -
Also you can apply
output_scalingfactor for int8 depthwise convolution output.
Long story short, everything applicable for regular convolution is applicable for depthwise convolution as well (since in MKL-DNN depthwise convolution is treated as the regular one).
how can I fuse the convolution and relu layer in intel caffe, do I have to set some flag, or it can fuse automatically?
AFAIK, IntelCaffe will do some fusion on the fly. In particular it can merge convlutions followed by relu. It also can fuse convolutions followed by batch-normalization (on inference), and residual blocks (conv + relu + sum). For more details see: compile rules in net.cpp. You can also try running your topology and look at the output of IntelCaffe. If you run ResNet-50 you most likely will see something like:
...
I0305 23:44:59.466156 3880 remove_batch_norm.cpp:276] Dropped Layer: bn_conv1 # <-- batch normalization is fused
...
I0305 23:44:59.466895 3880 net.cpp:739] Dropped layer: res2a_branch2a_relu # <-- relu is fused
...
@emfomenk That's so great! I will try that after my network's training is done. Once again , thanks for your reply!
Hi,
What would happen if ic == g but oc == ic*n (is a multiple)?
Hi @sfraczek, oc a multiple of ic = g is a valid convolution. In this case, within each group there are n output filters for each input filter. But note that unlike the case of depthwise convolutions (g = ic = oc), there is currently no jitted implementation, so convolutions such as mb1_g32ic32oc64_ih10oh10kh3ph1 will dispatch to gemm-based implementation.