Winograd Convolution for DNNs: Beyond linear polynomials
Barbara Barabasz, David Gregg

TL;DR
This paper explores a broader set of Winograd algorithms for DNNs, demonstrating significant improvements in floating point accuracy and efficiency across various formats, surpassing traditional methods.
Contribution
It introduces and evaluates a wider range of Winograd algorithms for DNNs, showing they can enhance accuracy and reduce computations compared to existing approaches.
Findings
Up to 6.5 times better accuracy in fp16 for image recognition.
Fewer innermost loop multiplications in bf16 without accuracy loss.
Significant accuracy and efficiency improvements over traditional Winograd algorithms.
Abstract
Winograd convolution is widely used in deep neural networks (DNNs). Existing work for DNNs considers only the subset Winograd algorithms that are equivalent to Toom-Cook convolution. We investigate a wider range of Winograd algorithms for DNNs and show that these additional algorithms can significantly improve floating point (FP) accuracy in many cases. We present results for three FP formats: fp32, fp16 and bf16 (a truncated form of fp32) using 2000 inputs from the ImageNet dataset. We found that in fp16 this approach gives us up to 6.5 times better image recognition accuracy in one important case while maintaining the same number of elementwise multiplication operations in the innermost loop. In bf16 the convolution can be computed using 5% fewer innermost loop multiplications than with currently used Winograd algorithms while keeping the accuracy of image recognition the same as for…
| output size | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| No of | 4 | 2 | 0 | 6 | 4 | 2 | 0 | 8 | 6 | 4 | 2 | 0 |
| of degree | ||||||||||||
| No of | 0 | 1 | 2 | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3 | 4 |
| of degree | ||||||||||||
| Ratio | 4 | 6.25 | 9 | 2.25 | 3.06 | 4 | 5.06 | 1.78 | 2.25 | 2.78 | 3.36 | 4 |
| method | dir | T-C() | T-C() | T-C() |
|---|---|---|---|---|
| ratio | ||||
| 70 | 70 | 70 | 70 | |
| 70 | 10 | 0.05 | 0.05 | |
| 70 | 70 | 70 | 68 |
| method | dir | W() | W() | W() | W() |
|---|---|---|---|---|---|
| ratio | |||||
| 70 | 70 | 70 | 70 | 70 | |
| 70 | 65 | 0.1 | 0.05 | 0.05 | |
| 70 | 70 | 70 | 70 | 62 |
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
MethodsConvolution
Winograd Convolution for DNNs: Beyond linear polynomials
Barbara Barabasz and David Gregg
School of Computer Science and Statistics, Trinity College Dublin, Dublin 2, Ireland
[email protected],[email protected]
Abstract.
Winograd convolution is widely used in deep neural networks (DNNs). Existing work for DNNs considers only the subset Winograd algorithms that are equivalent to Toom-Cook convolution. We investigate a wider range of Winograd algorithms for DNNs and show that these additional algorithms can significantly improve floating point (FP) accuracy in many cases. We present results for three FP formats: , and (a truncated form of ) using 2000 inputs from the ImageNet dataset. We found that in this approach gives us up to times better image recognition accuracy in one important case while maintaining the same number of elementwise multiplication operations in the innermost loop. In the convolution can be computed using fewer innermost loop multiplications than with currently used Winograd algorithms while keeping the accuracy of image recognition the same as for direct convolution method.
Key words and phrases:
DNN and convolution and Winograd convolution and accuracy and floating point
1. Motivation
In DNNs, and especially in Convolutional Neural Networks (CNNs), a huge amount of time is spent computing convolution. The simple direct algorithm has a complexity of . In contrast, fast convolution algorithms, such as FFT, Toom-Cook, and Winograd convolution require fewer operations.
The family of Winograd algorithms is based on (1) transforming tiles of the input and kernel into a modulo polynomials domain (the Winograd domain), where (2) convolution becomes the elementwise multiplication (Hadamard product) with complexity , and (3) transforming the result back to the orginal domain. Winograd’s method is not a convolution algorithm itself; instead it generates fast convolution algorithms that operate on fixed-sized tiles of input, kernel and output.
Winograd’s can be used to generate a wide variety of convolution algorithms with different trade-offs. It requires a set of polynomials as input to generate the convolution algorithm. These polynomials can be linear () or superlinear ().
If only linear polynomials are used as inputs, Winograd’s method becomes much simpler, and the resulting algorithms are guaranteed to need only the theoretically minimum number of operations for the elementwise multiplication. The set of Winograd algorithms generated using only linear polynomials is also equivalent to the set of algorithms that can be generated using the Toom-Cook method. Toom-Cook is much simpler than the Winograd method, and as a result it is used to generate the algorithms used in many implementations of “Winograd” convolution.
The selected tile size is critical to the performance of Winograd convolution. A larger tile size increases the number of elementwise multiplication operations needed for that tile, but also computes more results per tile. Taking account of extra operations needed at the boundary of each tile, larger tiles reduce the number of elementwise multiplication operations per computed output point. However, the floating point error also grows exponentially with the tile size [1], so existing implementations of Winograd for DNNs typically use a small tile size.
In this paper we investigate the effect of higher-order polynomials on the accuracy of Winograd convolution for DNNs. Our experiments show that using order-2 polynomials can dramatically reduce the measured floating point error as compared to linear polynomials. However, higher order polynomials also increase the required number of multiplications in Hadamard product. This paper addresses the question: Is there a benefit in using the Winograd method with super-linear polynomials for DNNs, as compared to the simpler Toom-Cook method?
We make the following contributions:
- •
We demonstrate how the Winograd algorithm with higher-order polynomials can be adapted to DNN convolution
- •
We present experimental results for one and two dimensional Winograd convolution, with kernels of the size (1D) or (2D), and find that higher-order polynomials can significantly redude the FP error.
- •
We show how using higher-order polynomials offer similar trade-offs between elementwise multiplications and FP accuracy, as compared with adjusting the block size.
- •
We experimentally identify cases where using higher-order polynomials can improve recognition without increasing elementwise multiplications when using half precision (), and where we can improve the performance keeping the accuracy of image recognition in bfloat precision ().
2. Toom-Cook versus Winograd algorithm
2.1. Winograd algorithm definition
Convolution can be expressed as polynomial multiplication. Mapping the elements of kernel vector and input vector to coefficients of polynomials and respectively, the elements of output vector (convolution of and ) are equal to the coefficients of polynomial . The Winograd family of algorithms for convolution is based on Chinese Reminder Theorem (CRT) for polynomials [2]. It says that for polynomial in ring of polynomials over a field , where are irreducible and pairwise coprime there exists such as the unique solution of systems of congruences: and
[TABLE]
Where and .
To compute the result of the convolution - the coefficients of the product of polynomials and - we put , and . Operations modulo are equal to finding the remainder from division by ; so if we assume that all polynomials are of the first degree then the results in modulo arithmetic are all constant polynomials (scalars): , . Then we can perform the computations of for as single multiplication: . These operations for all are represented by Hadamard product of two vectors consist of elements and (see Figure 1).
The commonly used DNN two-dimensional Winograd convolution algorithm [5] uses the Matrix Exchange Theorem [3] and expresses the computations formula for in the following form:
[TABLE]
Where matrices and represents kernel and input values.
In this paper we use the modified version of the Winograd algorithm with polynomial of degree equal to and pseudo-point . The exact algorithm to compute matrix elements and a more detailed theoretical description of the method can be found in [3] [9] [1].
To the best of our knowledge all Winograd algorithms used in DNNs require that all are of the first degree (i.e linear). All such algorithms derived using Winograd’s method with linear polynomials can also be found using the Toom-Cook method ([10, 4]). Toom-Cook was anlyzed and applied to signal processing problems by S. Winograd in the s. Winograd also proved that Toom-Cook guarantees that the generated convolution algorithm will use the theoretically minimum possible number of elementwise multiplications needed to compute convolution of size with a kernel of size . We denote these algorithms as ) [12].
If we use polynomial of degree , then the results of and are polynomials not scalars (see Figure 2). Thus to compute we need to multiply two polynomials , rather than using simple scalar multiplication. However, to solve this subproblem (i.e. computing the coefficients of the product of two polynomials and ) we can apply any suitable algorithm, including the Toom-Cook algorithm . All polynomials used in the Winograd algorithm have to be pairwise coprime, and similarly all polynomials used in the Toom-Cook algorithm to solve the sub-problem also need to be pairwise coprime. But polynomials in the two different groups do not need to be coprime. This means that we can use the same polynomials of the first degree (points) in both algorithms. In the Figure 2 we can have . Some points offer superior floating point accuracy, such as [math], and (polynomials , and ) [1].
The approach with polynomials, of degree requires two steps of transformations (see Figure 2). Firstly, we transform input/kernel into the ”Polynomials Winograd domain”. That means to transform input/kernel into polynomials of the degree greater than zero. We then transform both those polynomials into scalars in the ”Winograd domain”. To perform the second transformation we use the Toom-Cook algorithm. Similarly, after computing Hadamard product we first transform the result into ”Polynomials Winograd domain” and after this into the original domain. Each of these transforms can be represented by a matrix which multiplied by the input/kernel/output to compute the transformation. We can merge the matrices for these two stages of transformation into a single transformation, allowing us to create three matrices , and applied to the kernel, input and result of the Hadamard product respectively. For the clarity, we denote matrices constructed for Toom-Cook algorithm as , and .
2.2. Constructing the Transform Matrices
2.2.1. Matrices and
: We use the function to map the polynomial to the vector: We use to denote the remainder from polynomial division of by . Rows of the matrix and which stand for transformation with polynomials of the first degree are identical to those in the Toom-Cook algorithm. (Note that we use matrices that are not scaled by factors ). To construct the submatrices that correspond to the transformation with the polynomial of the degree higher than one, we have to compose the matrix with , where represents transformation to the “Polynomials’ Winograd domain” and the matrix stands for transformation to the “Winograd domain” and is equal to matrix of apropriate size (). Analougusly, matrix — where is generated by the Toom-Cook algorithm — and stands for transformation into the “Polynomials’ Winograd domain” with polynomial of the degree higher than . The last rows and represent the pseudo point needed to construct the modified version of the algorithm ([3], [1]). Below we present an example of the construction of matrices and for kernel of size and output of size , choosing polynomials and . To solve the subproblem we use Toom-Cook algorithm with points [math], .
The exact algorithms to compute matrices and are presented in algorithm (1).
2.2.2. Matrix
First we construct auxiliary matrix that includes blocks for , where is the number of the polynomials . The C matrix represents transformation from the “Polynomials’ Winograd domain” into the “Winograd domain”. The rows stand by transformation with polynomials of the first degree are equal to identity matrix. Blocks stand for transformation with polynomial of degree greater than represents transformation with matrix , generated for subproblem with . A second matrix includes the rest of operations, that is modulo (remainder) from product of polynomials and the polynomial obtained from extended Euclidean algorithm (see formula 1). Additional zeros in rows of matrix and column with coefficients of the polynomial implement the modified version of the Winograd algorithm.
We present an example of constructing matrix for kernels of the size and outputs of size , chosing polynomials: and (as in previous subsection). Matrix is generated by the Toom-Cook algorithm with points .
Next, we construct the blocks of matrix . The polynomials get from extended Euclidean algorithm [2] are: , .
2.3. Optimality of Winograd algorithm
Toom-Cook algorithms for dimensional convolution have an optimal number of multiplications for fixed and . While computing convolution in DNNs, we break our input into the pieces of the size equal to algorithm input tile. This results in overlap of input tiles at boundaries. The exact number of overlapping input values for whole input depends on the kernel and input/output sizes (see description in [5]). We express the performance of the algorithm as the ratio of the number of multiplications per single output point. Thus, Toom-Cook algorithm requires multiplications to compute output points, so we have ratio equal to . For algorithm , the . For Toom-Cook convolution with a fixed kernel size the decreases with tile size. The bigger input/output tile, the fewer elementwise multiplications are needed. The elementwise multiplication dominates the execution time of DNN convolution, so reductions in these multiply operations translate to reduced execution time. Unfortunately, with increasing the input/output size the floating point error of the computations increase exponentially [1].
When we apply Toom-Cook algorithm the is equal to . In the Winograd method, as we can see from matrix construction, introducing polynomials of the degree greater than results in larger matrix sizes, which means the bigger number of multiplications. Every Toom-Cook algorithm used to solve subproblem in Winograd algorithm requires polynomials of the first degree. The bigger number and higher degree polynomials we use the more multiplications per output point are required. To compute we can use:
- •
polynomials of the first degree with (Toom-Cook algorithm)
- •
polynomials of the first degree and of the second degree with
- •
polynomial of the first degree and of the third degree with
- •
polynomials of the second degree with
- •
polynomial of the fourth degree with
We can notice that in above example using the polynomial of the th degree do not change input (mapped to the polynomial of the rd degree) and kernel (mapped to the polynomial of the nd degree) pending transformations, so this case only introduce additional multiplications into convolution computations. Analogously using polynomial of the rd degree does not change the kernel. The Winograd method for fixed kernel and output size allows us to construct algorithms with different s, while the Toom-Cook method has a constant for given and . Thus, for a fixed kernel size, we can construct sets of Winograd matrices with the same but other output/input size. For example for and , with polynomials of the first degree, and one polynomial of the second degree, we have the same see table 1. Given these choices with the same computational , we can investigate the floating point error of such algorithms and use the more accurate one.
3. Tests Results
3.1. Random data
We tested the accuracy of the Winograd convolution algorithm for the kernel of the size (1D) and (2D). We studied a range of output tile sizes from – (1D) and – (2D). We run our initial experiments over loops where kernel and input values were choosen randomly from range with a normal distribution. We computed the Euclidean error of Winograd convolution performed in and compared it with the direct convolution in .
We investigated Winograd convolution algorithm with the most promising configurations of polynomials of the first and second degree (as we use the kernel of size or ). The best results for each computation and polynomial degree configuration are presented in figure 3. We construct the first degree polynomials using known good root points: [math], , , , , , , , [1]. As second degree polynomials, we considered those with the coefficients equal to [math], and , coprime with the polynomials of the first degree. That is: , and . To solve the subproblem for the polynomial of degree greater than , we use Toom-Cook convolution algorithm and root points [math], and . In our tests, we noticed that in some cases (up to around for and for ) the Winograd algorithm with one polynomial of the second degree gives a smaller floating point error than Toom-Cook, see Figure 3). When we use only one polynomial of the second degree we found that works the best as it provides only two coefficients, not three.
3.2. Experiments with real data ImageNet on VGG16
We next run experiments for the vgg16 CNN [6] (using Tensorflow Slim) with thirteen 2D convolution layers, with kernel size . As inputs we use images from the ImageNet validation set. The computations were done in . We also simulated and by performing the operations in single precision and casting the results to the lower precision.
We tested the Toom-Cook algorithms with outputs , and . This means the of multiplications per single ouptut point equals , and respectively (see Table 1). For comparision we choose the Winograd algorithm with one polynomial of the second degree for even output sizes, from up to . The of multiplications per single output point are equal to , , and respectively. In our initial tests on random data, we have found that using the polynomial of the second degree works best. Polynomials of the first degree for were constructed with the root points used for . For given output and kernel sizes we can construct Winograd algorithms with different computational s. In our tests, we used Winograd algorithms with only one polynomial of degree 2. We could achieve better accuracy by using more degree-2, but this would be at the cost of a worse computational . We focus on the cases where the image recognition accuracy decreases – equal to in and between and in . We do not present the all possible results, e.g. for with 2 polynomials of the second degree (), but our results are indicative.
We looked at the percentage of image recognition (top-1) for vgg16 network with Winograd convolution layers in comparison to the same network with direct convolution using the same floating point precision. In Tables 2, 3 we present the percentage accuracy of image recognition for different FP precision. For the output sizes we consider, we do not see any changes using . In , all investigated Toom-Cook algorithms failed. In the percentage of image recognition is the same as for direct convolution for Toom-Cook algorithm with output ( equal to ), but for output size the accuracy decreases.
With , we see that using Winograd convolution instead of Toom-Cook with the same performance (equal to ), increases the recognition accuracy from to . The main problem we face with is that it cannot store the same range of values as . Then using the same good root points (like [math], and ) more than once results in lower intermediate values, and less likelihood of overflow.
Using , the decrease in image recognition appears for bigger input sizes than in . The format allow us to represent nearly the same range of values as single precision. However, the lower number of bits results in lower accuracy of values representation and larger floating point error from operations. In our tests we can observe the impact of this for network with Toom-Cook convolution algorithm with output of the size . We have not found a configuration of polynomials that would give us the accuracy of image recognition better than with the equal to . We construct the Winograd algorithm with the accuracy of image recognition equal to (the same accuracy we get using of a direct convolution algorithm) with .
4. Related work
In the DNN research literature the term “Winograd convolution algorithm” is used for both Winograd and Toom-Cook convolution, and in practice the Toom-Cook algorithm is used to generate the convolution matrices. The general Winograd algorithm described in this paper is not explored a lot in literature. We can find a description of the approach in Winograd [12], but not for the multi-channel multiple kernel convolution used for DNNs. A simple example how to construct matrices is presented in [3]. A more general and detailed description can be found in [9]. Selesnick and Burrus [8] considered cyclic convolution methods using cyclotomic polynomials in their theoretical work.
Meng and Brothers in [7] apply the idea of using complex points and (root points of polynomial ) for quantization network. We present a general definition of the method and present floating point accuracy for a couple of different versions of the algorithm.
There is some work done on the improvement of the FP accuracy of Winograd (Toom-Cook) convolution for DNNs. Vincent at al. [11] present the result for one set of matrices, that scaling matrices and give the more accurate results. Scaling improves the conditioning of used matrices but it is not necessarily always equivalent to decrease the floating point error of computation, particularly for the small size of matrices used in DNNs.
There are also a couple of methods that allow to increasing the accuracy of dot product computations for matrices transformation, such as more accurate summation algorithms, Strassen matrix multiplication [13], etc. However, they require more operations for the transforms, for sorting elements, or for compensated summation, and/or make the implementation more complicated. In contrast, our approach does not require additional operations for the transformations. All of those methods for improving FP accuracy could also be used together with the presented method to reduce floating point error even more. These include pairwise summation over channels, Huffman based summation method and mixed precision computations proposed in [1].
5. Conclusions
This paper asks the question: Is there a benefit in using the Winograd method with superlinear polynomials for DNNs, as compared to the simpler Toom-Cook method (which is equivalent to Winograd with linear polynomials)? We describe the construction of Winograd transformation matrices in general case. We show that the main benefit of using superlinear polynomials is that the same good root points can be used multiple times, which improves FP accuracy. The Toom-Cook method allows a trade-off of elementwise multiplications against FP accuracy by varying the tile size. The presented Winograd method offers an larger space of trade-offs between computation and accuracy using higher order polynomials. Thus, it allows us find attractive trade-offs that are not available using Toom-Cook.
We find that in precision we can construct an algorithm that maintains the same accuracy of image recognition as Toom-Cook but has better of elementwise multiplications per single output point than Toom-Cook. In precision we can obtain better accuracy using Winograd convolution algorithm with one polynomial of the second degree, as compared to Toom-Cook (for the case kernel , output ) with the same of number of elementwise multiplications per output point. The presented Winograd convolution algorithm does not require additional operations in the transformation to/from the ”Winograd domain”, and although the Winograd method itself is complex, the generated convolution algorithm does not require a more advanced implementation.
Acknowledgements
This work was supported by Science Foundation Ireland grant 12/IA/1381. We also extend our thanks to Andrew Mundy from Arm Research for his contribution.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Barabasz, B., Anderson, A., Soodhalter, K.M., Gregg, D.: Error analysis and improving the accuracy of winograd convolution for dnns. Co RR abs/1803.10986 (2018), http://arxiv.org/abs/1803.10986
- 2[2] Biggs, N.L.: Discrete Mathematics. Oxford University Press, New York, NY, USA, 2nd. edn. (2002)
- 3[3] Blahut, R.E.: Fast Algorithms for Signal Processing. Cambridge University Press, New York, NY, USA (2010)
- 4[4] Cook, S.A.: On the Minimum Computation Time of Functions. Ph.D. thesis, Harvard University, Cambridge, Mass. (1966)
- 5[5] Lavin, A., Gray, S.: Fast algorithms for convolutional neural networks. In: 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR). pp. 4013–4021. IEEE, Las Vegas, Nevada (2016)
- 6[6] Liu, S., Deng, W.: Very deep convolutional neural network based image classification using small training sample size. In: 2015 3rd IAPR Asian Conference on Pattern Recognition (ACPR). pp. 730–734 (Nov 2015). https://doi.org/10.1109/ACPR.2015.7486599
- 7[7] Meng, L., Brothers, J.: Efficient winograd convolution via integer arithmetic. Co RR abs/1901.01965 (2019)
- 8[8] Selesnick, I.W., Burrus, C.S.: Extending winograd’s small convolution algorithm to longer lengths. In: 1994 IEEE International Symposium on Circuits and Systems, ISCAS 1994, London, England, UK, May 30 - June 2, 1994. pp. 449–452 (1994)
