wino convolution result is different with the direct convolution
hi:
I am using convolution to compute the result, I find wino convolution result is different with the result of direct convolution. here is the parameter of my test:
wino convolution
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit N/A)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mkldnn_verbose,exec,reorder,wino_reorder,undef,in:f32_oihw out:f32_wino_fmt,num:1,144x144x3x3,60.6711
mkldnn_verbose,exec,convolution,jit_wino_4x3:avx512_core,forward_inference,fsrc:nChw16c fwei:wino_fmt fbia:x fdst:nChw16c,alg:convolution_winograd,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,0.613037
direct convolution
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit N/A)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mkldnn_verbose,exec,reorder,jit:uni,undef,in:f32_oihw out:f32_OIhw16i16o,num:1,144x144x3x3,0.121826
mkldnn_verbose,exec,convolution,jit:avx512_common,forward_inference,fsrc:nChw16c fwei:OIhw16i16o fbia:x fdst:nChw16c,alg:convolution_direct,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,0.38916
How large is the difference? Lower accuracy is a known property of the Winograd algorithm.
It's not lower accuracy, I think There might something wrong with the result of Wino Convolution. When I change the input dimension from 144x144x12x12 to 144x144x48x48, the result is the same as Direct Convolution.
@EstherBlanchett,
I tried to poke around with benchdnn and it seems like it does not cover the case of Winograd 4x3 algorithm for inference case. I get either 4x3 without compensation for forward training or 2x3 with compensation for forward inference:
$ MKLDNN_VERBOSE=1 ./benchdnn --conv --dir=FWD_I --cfg=f32 --alg=wino mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit 9008d8ab096ae29f158840231ff431aea8bf3467)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mkldnn_verbose,exec,convolution,jit_fp32_wino_2x3:avx512_core,forward_inference,fsrc:nChw16c fwei:wino_fmt fbia:undef fdst:nChw16c,alg:convolution_winograd,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,1.66992
$ MKLDNN_VERBOSE=1 ./benchdnn --conv --dir=FWD_B --cfg=f32 --alg=wino
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit 9008d8ab096ae29f158840231ff431aea8bf3467)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1
mkldnn_verbose,exec,convolution,jit_wino_4x3:avx512_core,forward_training,fsrc:nChw16c fwei:OIhw16i16o fbia:x fdst:nChw16c,alg:convolution_winograd,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,1.71606
Could you please indicate which oneDNN commit you are using?
It's not lower accuracy, I think There might something wrong with the result of Wino Convolution. When I change the input dimension from 144x144x12x12 to 144x144x48x48, the result is the same as Direct Convolution.
Adding to @vpirogov's comment: can you please post a reproducer?
The fact that results of Winograd and direct convolution algorithms are the same for some shapes / inputs is accidental, in my opinion. Can you please post the relative error when the results are different?
@vpirogov I found that jit_fp32_wino_2x3 was commented out before. I tested the wino_2x3 today and found the result of wino_2x3 does not match either. Here are the top ten of the result of different convolution.
dict_conv
0, 1.150788
1, 0.301778
2, 0.113420
3, 0.647961
4, 0.713772
5, 0.412555
6, 0.305150
7, 0.349601
8, 0.442124
9, 0.634095
10, 0.359346
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit N/A)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mkldnn_verbose,exec,reorder,jit:uni,undef,in:f32_oihw out:f32_OIhw16i16o,num:1,144x144x3x3,0.092041
mkldnn_verbose,exec,convolution,jit:avx512_common,forward_inference,fsrc:nChw16c fwei:OIhw16i16o fbia:x fdst:nChw16c,alg:convolution_direct,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,0.407959
wino_conv2x3
0, 2.990796
1, 1.006861
2, 1.299850
3, 2.308599
4, 1.972430
5, 1.825845
6, 1.797352
7, 2.029741
8, 2.464936
9, 1.100304
10, 0.000000
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit N/A)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mkldnn_verbose,exec,reorder,wino_reorder,undef,in:f32_oihw out:f32_wino_fmt,num:1,144x144x3x3,60.4329
mkldnn_verbose,exec,convolution,jit_fp32_wino_2x3:avx512_core,forward_inference,fsrc:nChw16c fwei:wino_fmt fbia:x fdst:nChw16c,alg:convolution_winograd,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,0.572998
wino_conv4x3
0, 0.283287
1, 0.000000
2, 1.001309
3, 1.180005
4, 1.073981
5, 0.748977
6, 0.779389
7, 0.695304
8, 0.629719
9, 0.465658
10, 0.509043
mkldnn_verbose,info,Intel MKL-DNN v0.21.0 (commit N/A)
mkldnn_verbose,info,Detected ISA is Intel AVX-512 with AVX512BW, AVX512VL, and AVX512DQ extensions
mkldnn_verbose,exec,reorder,wino_reorder,undef,in:f32_oihw out:f32_wino_fmt,num:1,144x144x3x3,60.4729
mkldnn_verbose,exec,convolution,jit_wino_4x3:avx512_core,forward_inference,fsrc:nChw16c fwei:wino_fmt fbia:x fdst:nChw16c,alg:convolution_winograd,mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1,0.603027
@EstherBlanchett,
We need to be able to reproduce this issue to invsetigate it further. This requires a commit hash and a small program that demonstrates the behavior. One thing you can try on your side is running benchdnn with the shapes in question to see whether it can be used as a reproducer.
The error is reproducible by running benchdnn on avx512 compatible machine with f32_full configuration.
./benchdnn --conv --alg=wino --dir=FWD_I --cfg=f32_full mb1_ic144oc144_ih12oh12kh3sh1dh0ph1_iw12ow12kw3sw1dw0pw1
The error was found in both rls-v0.21 and master branches. @EstherBlanchett thanks a lot for finding the issue and will get back to you soon with a patch fixing it.
Hi @EstherBlanchett I went through the error log of above run and found the maximum relative error difference to be 0.0107341. While it is not great but it might be attributed to either
- lower inaccuracy inherent in winograd algorithm (as mentioned earlier by @rsdubtso)
- larger accumulation owing to the input channels (to belabor the second point, increasing the input channels to 296 -- while keeping rest of the parameters, same as before -- increases the "maximum relative error difference" to 0.046
From your reading, it appears that you've observing errors of much larger magnitudes. So I was wondering if you could either specify either the particular source and weight tensor values fed into the convolution or a reproducer.
conv_c_param1_bias.txt conv_c_param0_weight.txt conv_c_input.txt
Hi @alokbakshi Sorry for the delay, Here are the source, weight and bias values fed into the convolution. You can test them.
Hi @EstherBlanchett Thanks for describing the explicit input. I will test this with regular and winograd convolution and will let you know where the issue lies.
Hi @EstherBlanchett
I did test rls-v0.21 branch with your custom source, weight and bias input. I did it via modifying fill_src, fill_wei and fill_bia routines inside the ./benchdnn/conv/conv.cpp file. So for example,
int fill_src(const prb_t *p, dnn_mem_t &mem_dt, dnn_mem_t &mem_fp,
res_t *r) {
static constexpr float inp_d[20736] = { /* comma separated input values read from
the conv_c_input.txt file */ };
/* Memory bookkeeping stuff */
mkldnn::impl::parallel_nd(p->mb, p->ic, p->id, p->ih, p->iw,
[&](int mb, int ic, int id, int ih, int iw) {
const float value = inp_d[src_off_f(p, mb, 0, ic, id, ih, iw)];
((float*)mem_00)[src_off_f(p, mb, 0, ic, id, ih, iw)] = value;
});
/* rest of the code */
return OK;
}
With the above changes, for regular, wino_2x3* and wino_4x3 convolution I got the same result as you had written for direct convolution, namely
0, 1.150788
1, 0.301778
2, 0.113420
3, 0.647961
4, 0.713772
5, 0.412555
6, 0.305150
7, 0.349601
8, 0.442124
9, 0.634095
10, 0.359346
I was wondering if you could share the code using which you got the incorrect winograd convolution results. Most likely, the divergence between results arose out of working with inconsistent memory formats.
*edit: Extra modification was made in wino_2x3 driver to let it accept bias
Marking as not a bug and closing as inactive. @EstherBlanchett -- feel free to reopen if you can provide additional information to reproduce the issue.