Unipruning: universal hardware-efficient pruning method for neural network acceleration

EP4427171A1Pending Publication Date: 2024-09-11HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
EP2021856988
Authority / Receiving Office
EP · EP
Patent Type
Applications
Current Assignee / Owner
Filing Date
2021-12-10
Publication Date
2024-09-11

AI Technical Summary

Technical Problem

Existing neural network models face challenges in reducing latency and model size while maintaining accuracy, particularly in real-time production applications, due to high computational intensity and inefficiencies in weight contribution evaluation.

Method used

A method for training and pruning neural networks by obtaining scores for weights based on normalization coefficients and subsequent layer weights, grouping weights by importance, and removing less critical groups to optimize hardware efficiency, followed by retraining to stabilize the model.

Benefits of technology

This approach reduces the neural network's processing requirements, improves performance by maintaining important weights, and allows for efficient hardware utilization, enhancing real-time application capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 1.1
    Figure 1.1
Patent Text Reader

Abstract

Methods and apparatuses are described for obtaining scores for sets of weights within layers of a neural network. Such a score is based on a set of weights in a first layer and one or more of (i) an (optional) normalization coefficient in a subsequent normalization layer and (ii) a set of weights within a second layer. Based on the score the set of weights may be removed from the layer. Such a pruning may reduce the size of the respective layer. Based on a group score, groups of sets of weights may be pruned from one or more layers of the neural network. The size of the groups can be based, for example, on hardware specifications.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] UNIPRUNING: UNIVERSAL HARDWARE-EFFICIENT PRUNING METHOD FOR NEURAL NETWORK ACCELERATION

[0002] Embodiments of the present invention relate to the field of artificial intelligence (Al), in particular to training and pruning of neural networks.

[0003] BACKGROUND

[0004] In recent years, Deep Learning reached a significant breakthrough in many practical applications, such as computer vision (e.g. object detection, segmentation and face identification), natural language processing, speech recognition, and many others. For many years, main goal of research was to improve quality of models, even if model size and latency was impractically high. However, for production solutions, which often require real-time work, latency of the model plays very important role.

[0005] SUMMARY

[0006] The embodiments of the present disclosure provide apparatuses and methods for training and pruning of neural networks.

[0007] The embodiments of the invention are defined by the features of the independent claims, and further advantageous implementations of the embodiments by the features of the dependent claims.

[0008] According to an embodiment a method is provided for training of a neural network, the neural network including at least two layers, the method comprising: obtaining a score for a first set of weights contributing to a feature within a feature tensor, the feature tensor being an output of a first layer of the neural network; wherein the score is based on the first set of weights and the score is further based on one or more of a normalization coefficient, which is applied in a normalization layer directly following the first layer, and / or a second set of weights, the second set including weights that are applied to said feature when applying a second layer to the feature tensor, the second layer following the first layer; and the method further comprising removing the first set of weights from the first layer if a predetermined condition based on the score is fulfilled.

[0009] Obtaining a score by taking into account weights and coefficients that are applied in layers subsequent to a current layer improves the reliability of such scores. Such an importance measurement can be applied to any layer with parameters contributing to channels of features. Thus, channels that are obtained by small weights within a current layer and may make a significant contribution to the final output of the neural network, for example, because of a large normalization coefficient or large weights being applied in the subsequent layer, are represented by an appropriate score for the set of weights.

[0010] In an exemplary implementation, the removing further comprises determining whether or not the predetermined condition based on the score is fulfilled, removing the first set of weights from the first layer if the predetermined condition is fulfilled.

[0011] Based on a condition related to the score a determination whether to remove sets of weights is efficiently performed.

[0012] For example, the obtaining a score further comprises: obtaining a score for each set of weights contributing to a respective feature out of a set of features within the feature tensor.

[0013] A score as explained above is readily applied to other sets of weights.

[0014] In an exemplary implementation, the method further comprises: arranging sets of weights that contribute to respective features out of the set of features, in one or more groups based on the respective score of said sets of weights.

[0015] Groups of sets of weights may be formed in order to meet hardware specifications. This may reduce the amount of processing as it allows for efficient removing of groups of sets.

[0016] For example, the arranging further comprises: sorting the sets of weights based on their respective score; forming groups including a predetermined amount of consecutive sorted sets of weights.

[0017] Forming groups using sorted sets of weights allows for determining a least and / or a most important group out of the arranged groups.

[0018] In an exemplary implementation, the method further comprises obtaining a group score for each group, wherein the group score of a respective group is based on the scores of the sets of weights within said group.

[0019] Obtaining a group score may enable an efficient determination of a least or a most important group out of the arranged groups.

[0020] For example, the group score for a group is obtained by applying a statistical measure to the scores of the sets of weights within said group. Applying a statistical measure to the scores of the sets may provide an efficient implementation to obtain a group score.

[0021] In an exemplary implementation, the removing comprises removing a group of sets of weights from the first layer if a predetermined condition based on the group score of said group is fulfilled.

[0022] Removing an entire group from a layer may reduce the processing amount when applying the layer to a feature tensor.

[0023] For example, for each layer i out of a plurality of N layers within the neural network the arranging in groups is performed and a group score for each group is obtained; and a group of sets of weights is removed from the i-th layer if a predetermined condition based on the group score of said group related to the i-th layer is fulfilled.

[0024] Removing groups from one or more layers within N layers of the neural network may reduce the processing amount when applying said N layers to a feature tensor.

[0025] In an exemplary implementation, the plurality of N layers includes all layers within the neural network.

[0026] Using all layers of the neural network when removing groups of sets of weights may improve the performance of the model when applying the neural network to an input feature tensor.

[0027] For example, the predetermined condition includes removing a predetermined number of groups M having the lowest group score within the group scores of all groups of the N layers.

[0028] Such a condition allows for removing the least important groups from layer and thus improving processing efficiency while maintaining important groups and thus important sets of weights within the layer.

[0029] In an exemplary implementation, the predetermined condition includes a predetermined threshold for one or more of a score, a group score, an amount of sets of weights.

[0030] These thresholds provide efficient implementations for the condition to determine whether or not to remove weights from a layer.

[0031] For example, removing includes setting weights to be removed to zero.

[0032] Zeroing weights instead of pruning makes the training of the model more stable. In an exemplary implementation, the method further comprises subsequent to the removing, training the neural network for a first predetermined number of epochs.

[0033] Such a procedure allows model to re-learn itself with the constraint that removed parameters are redundant.

[0034] For example, the method further comprises subsequent to the training of the neural network, pruning removed weights; training the pruned neural network for a second predetermined number of epochs.

[0035] A hard pruning of removed (zeroed) weights reduces the size of the model and thus reduces the processing required when applying the trained model. Further training of the pruned model allows for finetuning of the remaining weights (parameters) to improve the performance of the model.

[0036] In an exemplary implementation, a computer program stored on a non-transitory medium and including code instructions, which, when executed on one or more processors, cause the one or more processors to execute steps of the method according to any of the methods described above.

[0037] According to an embodiment, an apparatus is provided for training of a neural network, the neural network including at least two layers, the apparatus comprising: processing circuitry configured to: obtain a score for a first set of weights contributing to a feature within a feature tensor, the feature tensor being an output of a first layer of the neural network; wherein the score is based on the first set of weights and the score is further based on one of a normalization coefficient, which is applied in a normalization layer directly following the first layer, and / or a second set of weights, the second set including weights that are applied to said feature when applying a second layer to the feature tensor, the second layer following the first layer; and remove the first set of weights from the first layer if a predetermined condition based on the score is fulfilled.

[0038] The apparatus provides the advantages of the methods described above.

[0039] The invention can be implemented in hardware (HW) and / or software (SW) or in any combination thereof. Moreover, HW-based implementations may be combined with SW-based implementations.

[0040] Details of one or more embodiments are set forth in the accompanying drawings and the description below. Other features, objects, and advantages will be apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In the following, embodiments of the invention are described in more detail with reference to the attached figures and drawings, in which:

[0042] Fig. 1a is an exemplary scheme of a fully-connected neural network;

[0043] Fig. 1 b is an exemplary scheme of a pruned neural network;

[0044] Fig. 2 is a schematic drawing illustrating channels processed by layers of a neural network;

[0045] Fig. 3 shows exemplary an application of convolution kernels;

[0046] Fig. 4 is a schematic drawing illustrating an attention network;

[0047] Fig. 5 illustrates exemplarily the processing of a feature tensor by layers of a neural network;

[0048] Fig. 6 is an exemplary flowchart of the pruning of a neural network;

[0049] Fig. 7 is an exemplary flowchart of the zeroing of weights according to their importance;

[0050] Fig. 8 is an exemplary flowchart of the removing of a set of weights from a layer;

[0051] Fig. 9 is a block diagram illustrating the removing of a layer within a neural network; and

[0052] Fig. 10 is a block diagram illustrating another example of an encoding apparatus or a decoding apparatus.

[0053] DETALIED DESCRIPTION

[0054] In the following description, reference is made to the accompanying figures, which form part of the disclosure, and which show, by way of illustration, specific aspects of embodiments of the invention or specific aspects in which embodiments of the present invention may be used. It is understood that embodiments of the invention may be used in other aspects and comprise structural or logical changes not depicted in the figures. The following detailed description, therefore, is not to be taken in a limiting sense, and the scope of the present invention is defined by the appended claims. For instance, it is understood that a disclosure in connection with a described method may also hold true for a corresponding device or system configured to perform the method and vice versa. For example, if one or a plurality of specific method steps is described, a corresponding device may include one or a plurality of units, e.g. functional units, to perform the described one or plurality of method steps (e.g. one unit performing the one or plurality of steps, or a plurality of units each performing one or more of the plurality of steps), even if such one or more units are not explicitly described or illustrated in the figures. On the other hand, for example, if a specific apparatus is described based on one or a plurality of units, e.g. functional units, a corresponding method may include one step to perform the functionality of the one or plurality of units (e.g. one step performing the functionality of the one or plurality of units, or a plurality of steps each performing the functionality of one or more of the plurality of units), even if such one or plurality of steps are not explicitly described or illustrated in the figures. Further, it is understood that the features of the various exemplary embodiments and / or aspects described herein may be combined with each other, unless specifically noted otherwise.

[0055] Artificial neural networks

[0056] Artificial neural networks (ANN) or connectionist systems are computing systems vaguely inspired by the biological neural networks that constitute animal brains. Such systems "learn" to perform tasks by considering examples, generally without being programmed with taskspecific rules. For example, in image recognition, they might learn to identify images that contain cats by analyzing example images that have been manually labeled as "cat" or "no cat" and using the results to identify cats in other images. They do this without any prior knowledge of cats, for example, that they have fur, tails, whiskers and cat-like faces. Instead, they automatically generate identifying characteristics from the examples that they process.

[0057] An ANN is based on a collection of connected units or nodes called artificial neurons, which loosely model the neurons in a biological brain. Each connection, like the synapses in a biological brain, can transmit a signal to other neurons. An artificial neuron that receives a signal then processes it and can signal neurons connected to it.

[0058] In ANN implementations, the "signal" at a connection is a real number, and the output of each neuron is computed by some non-linear function of the sum of its inputs. The connections are called edges. Neurons and edges typically have a weight that adjusts as learning proceeds. The weight increases or decreases the strength of the signal at a connection. Neurons may have a threshold such that a signal is sent only if the aggregate signal crosses that threshold. Typically, neurons are aggregated into layers. Different layers may perform different transformations on their inputs. Signals travel from the first layer (the input layer), to the last layer (the output layer), possibly after traversing the layers multiple times.

[0059] The original goal of the ANN approach was to solve problems in the same way that a human brain would. Overtime, attention moved to performing specific tasks, leading to deviations from biology. ANNs have been used on a variety of tasks, including computer vision, speech recognition, machine translation, social network filtering, playing board and video games, medical diagnosis, and even in activities that have traditionally been considered as reserved to humans, like painting

[0060] Fully connected neural networks (FCNNs) are a type of artificial neural network where the architecture is such that all the nodes, or neurons, in one layer are connected to the neurons in the next layer. Neurons in a fully connected layer have connections to all activations in the previous layer, as seen in regular (non-convolutional) artificial neural networks. Their activations can thus be computed as an affine transformation, with matrix multiplication followed by a bias offset (vector addition of a learned or fixed bias term).

[0061] While this type of algorithm is commonly applied to some types of data, in practice this type of network has some issues in terms of image recognition and classification. Such networks are computationally intense and may be prone to overfitting. When such networks are also 'deep' (meaning there are many layers of nodes or neurons) they can be particularly hard for humans to understand.

[0062] A Multi-Layer Perceptron (MLP) is an example for such a fully connected neural network. A MLP is a supplement of feed forward neural network. It consists of three types of layers — the input layer 1010, output layer 1030 and hidden layer 1020, as shown exemplarily in Fig. 1a. The input layer receives the input signal to be processed. The required task such as prediction and classification is performed by the output layer. An arbitrary number of hidden layers that are placed in between the input and output layer are the true computational engine of the MLP. Similar to a feed forward network in a MLP the data flows in the forward direction from input to output layer. The neurons in the MLP are trained with the back-propagation learning algorithm. MLPs are designed to approximate any continuous function and can solve problems, which are not linearly separable. The major use cases of MLP are pattern classification, recognition, prediction and approximation.

[0063] A convolutional neural network (CNN) employs a mathematical operation called convolution. A convolution is a specialized kind of linear operation. Convolutional networks are neural networks that use a convolution operation in place of a general matrix multiplication in at least one of their layers. Fig. 2 schematically illustrates a general concept of processing by a neural network such as the CNN. A convolutional neural network consists of an input and an output layer, as well as multiple hidden layers. Input layer is the layer to which the input (such as a portion of an image as shown in Fig. 2) is provided for processing. The hidden layers of a CNN typically consist of a series of convolutional layers that convolve with a multiplication or other dot product. The result of a layer is one or more feature maps (f.maps in Fig. 2), sometimes also referred to as channels. There may be a resampling involved in some or all of the layers. If the resampling is a subsampling, the feature maps may become smaller, as illustrated in Fig. 2. Subsampling operation may be joined with the convolution by using stride parameter larger than 1. The activation function in a CNN is usually a ReLU (Rectified Linear Unit) layer, although the other activation functions may be used (e.g. Swish, GELU, sigmoid), and is subsequently followed by additional convolutions such as pooling layers, fully connected layers and normalization layers, referred to as hidden layers because their inputs and outputs are masked by the activation function and final convolution. Though the layers are colloquially referred to as convolutions, this is only by convention. Mathematically, it is technically a sliding dot product or cross-correlation. This has significance for the indices in the matrix, in that it affects how the weight is determined at a specific index point.

[0064] In an exemplary implementation, a convolutional neural network convolves input data of shape N x Cinx Hinx Win(or N x Hinx Winx Cinin some implementations) with a convolutional kernel or filter of size K x K x Cinx Coutand produces output data of shape N x Coutx Houtx Wout(or N xHoutx Woutx Coutin some implementations), where N is the size of a batch, Hinand Houtare height of input and output data, respectively, Winand Woutare width of the input and output data, respectively, Cinis the number of input channels, and Coutis the number of output channels. Here the input data, the output data, and kernels are tensors, fourdimensional arrays of some size along each of the dimensions.

[0065] An example for N — 1 using the second notation is given in Fig. 3, where a 6 x 6 x 3 - dimensional input 310 is convolved by a filter of dimension 3 x 3 x 3 x 2 including two filters 320, 330 of dimension 3 x 3 x 3 to obtain an output 340 of shape 4 x 4 x 2.

[0066] For example, when programming a CNN for image processing, the input may be a tensor of dimension (number of images) x (image width) x (image height) x (image depth). Then after passing through a convolutional layer, the image becomes abstracted to a feature map, having dimensions (number of images) x (feature map width) x (feature map height) x (feature map channels). A convolutional layer within a neural network may have the following attributes: (i) convolutional kernels defined by a width and height (hyper-parameters), (ii) the number of input channels and output channels (hyper-parameter) and (iii) the depth of the convolution filter (the input channels) must be equal to the number channels (depth) of the input feature map.

[0067] In the past, traditional multilayer perceptron (MLP) models have been used for image recognition. However, due to the full connectivity between nodes, they suffered from high dimensionality, and did not scale well with higher resolution images. A 1000*1000-pixel image with RGB color channels has 3 million weights, which is too high to feasibly process efficiently at scale with full connectivity. Also, such network architecture does not take into account the spatial structure of data, treating input pixels which are far apart in the same way as pixels that are close together. This ignores locality of reference in image data, both computationally and semantically. Thus, full connectivity of neurons is wasteful for purposes such as image recognition that are dominated by spatially local input patterns.

[0068] Another approach are Transformer-like models that are built on fully-connected layers and matrix multiplications of data tokens. Such models were applied for the natural language processing (NLP) tasks first and then were adapted, for example, for computer vision tasks as classification, object detection, semantic and instance segmentation, or the like.

[0069] A transformer model applies an attention layer followed by a feed-forward neural network. A generic attention mechanism, which consists of the queries Q 4011 , keys K 4010 and values V 4012, is shown exemplarily in Fig. 4. The origin of such naming can be found in search engines, where a user’s query is matched against internal engine’s keys and the result is represented by several values. Such an attention layer obtains a plurality of representations of an input sequence, for example the Keys, Queries and Values. To obtain a representation out of said plurality representations, the input sequence is processed by a respective set of weights. This set of weights may be obtained in a training phase. These set of weights may be learned jointly with the remaining parts of a neural network including such an attention layer. During inference, the output is computed as the weighted sum of the processed input sequence.

[0070] Queries, Keys and Values have the size of S x dq, S x dkand S x dvrespectively. Typically, Queries, Keys and Values may have the same dimensionality d. In order to calculate the output of the attention layer, a (scaled) dot-product 4020 between Queries and Keys (— may be calculated, and the softmax function may be applied to obtain attention scores. Next, these scores are multiplied with the Values in a weighted sum 4030 to achieve an output 4040 of the attention layer. The attention mechanism may be formulated as: where the dfcis the dimensionality of the keys and softmax — has the size of S x S.

[0071] Fully-connected layers are frequently used in modern neural networks. A fully-connected layer performs a linear projection of input data of shape N x Cinx S (or N x S x Cinin some implementations) with a weight tensor of size Cinx Coutand produces output data of shape Nx coutx s(°r> correspondingly, N x S x Cout), where N is the size of a batch, S represents the number of tokens, Cincorresponds to number of input channels, and Coutis number of output channels. Here the input data and the output data are tensors, such as three- dimensional arrays of some size along each of the dimensions. The weight tensor is a two- dimensional array of some size along each of the dimensions.

[0072] A normalization layer applies a normalization to activation vectors from hidden layers using the mean and variance of the current batch. This normalization step may be performed right before or right after applying the nonlinear activation function or right before convolutional or fully- connected layer. An exemplary implementation of such a normalization layer is a so-called Batch Normalization (BN). The output tensor y of the batch normalization may be formulated as: where x represents the data tensor, p is the mean of x, a is the standard deviation of x, and y and p are trainable parameters, y represents a multiplicative scaling parameter. The values of p and a may be estimated directly from the input data x or accumulated during training procedure and then applied during the inference.

[0073] Importance of weights within layers of a neural network

[0074] As already indicated, a neural network may include a considerable amount of trainable parameters. The weights determine the contribution of the respective input features (channels) to an output channel in a layer of a neural network. Thus, smaller weights mean smaller contribution. Thus, the magnitude of the weights indicated how much the layer output depends on particular inputs. In order to speed-up processing performed by a neural network while maintaining an acceptable accuracy, the number of weights within one or more layers of a neural network in some embodiments are thus reduced according to an importance of said weights. Such reduction may also enable speeding up learning of the neural network.

[0075] In order to evaluate the importance of a set of weights, a score for said set of weights is obtained. Such a score indicating the importance may be obtained for sets of weights in layers with weights corresponding to features structured in channels, for example, convolutional layers, fully-connected layers, deconvolutional layers, depth-wise convolutions, squeeze-and- excitation blocks, or the like.

[0076] Fig. 5 shows an exemplary scheme of two layers Lk5020 and Lk+15060. Layer Lk5020 receives a plurality of input channels 5010. Said input channels 5010 are processed by the layer Lk5020 including weighting with weights W. In particular, each input channel is weighted by a respective weight before contributing to an output of the layer Lk5020.

[0077] Layer Lk5020 outputs a feature tensor including output features, which may be also referred to as output channels c°utto cut5030. A set of weights WkoUt5021 of layer Lk5020 is applied to the input 5010 of said layer Lk5020 to obtain feature c°ut. In general, all inputs 5010 may contribute to one output. The contributions of the same input to different outputs may differ. Weights applied to some input channels (features) may be zero.

[0078] An exemplary implementation for a convolutional neural network illustrating said channel structure is depicted in Fig. 3. Each channel 311 , 312, 313 of the input 310 is processed by applying a respective set of weights. A set of weights that is applied to a first input channel 311 includes a subset 321 of the first filter 320 and a subset 331 of the second filter 330. A first set of weights 320 is contributing to the first output channel 341. In other words, the input 310 has been processed by the filter 320 to obtain the first output channel 341 . A second set of weights 330 is contributing to the second output channel 342.

[0079] In the exemplary scheme of Fig. 5, the output channels c°utto c°ut5030 may be normalized by a normalization layer 5040 including an optional, trainable scaling coefficient 5041 for each channel. Such normalization layer 5040 may be a batch normalization layer including a trainable scaling coefficient y;. The output of the normalization layer 5040 is an input 5050 to the subsequent layer Lk+15060, thus the outputs of the normalization layer 5040 correspond to the input channels cnto c™ 5050 of layer Lk+15060. In layer Lk+15060, each input channel c-n5050 is processed by applying a respective set of weights W1^15061 to said input channel. ci

[0080] It is noted that normalization layer does not need to be present in general. Rather, after activation applied to the input channels, the output channel may be output to the next layer directly.

[0081] In the exemplary implementation of a convolutional neural network in Fig. 3, a set of weights that is applied to a first input channel 311 includes a subset 321 of the first filter 320 and a subset 331 of the second filter 330. Correspondingly, the set of weights being applied to the second input channel 312 includes the subsets 322 and 332, and the set of weights being applied to the third input channel 313 includes the subsets 323 and 333.

[0082] A score for a set of weights 5021 contributing to a feature within an (output) future tensor 5030 is based on said weights. The score may be obtained by applying a function to the weights within said set of weights 5021. Said function may be for instance a measure or a norm. An example for a norm is a / p-norm

[0083] Some exemplary implementations use norm p=1 or p=2 (square norm) as they may be easy to implement,

[0084] The score in some exemplary implementations is further based on a normalization coefficient, which is applied in a normalization layer 5040 directly following the first layer 5020, and / or a second set of weights 5061 . The second set 5061 includes weights that are applied to said feature when applying a second layer 5060 to the feature tensor 5050. The second layer 5060 follows the first layer 5020 in the processing order. A normalization layer 5040 may be applied to the output 5030 of the first layer to obtain an input to said second layer 5060 following the first layer 5020. Taking into account the normalization coefficient may increase the score for a set of weights having a small score based on the weights within said set but a large normalization coefficient.

[0085] For example, a score Sc. for a set of weights Wk9utin a layer Lk5020 contributing to a feature ctmay be determined by applying a Zp-norm to the weights within the set of weights 5021 and applying a Zq-norm to the normalization coefficients yt5041 :

[0086] For example, a score Sc. for a set of weights Wkoutin a layer Lk5020 contributing to a feature ci may be determined by applying a Zp-norm to the weights within the set of weights 5021 and applying a / p-norm to a second set of weights W^1in a second layer Lk+15060 following the first layer 5020 For example, a score Sc. for a set of weights Wkout in a layer Lk5020 contributing to a feature 1ci

[0087] Ci may be determined by applying a Zp-norm to the weights within the set of weights 5021 , applying a Zq-norm to the normalization coefficients 5041 , and applying a Zp-norm to a second set of weights W1^1in a second layer Lk+15060 following the first layer 5020 ci

[0088] The values for p may be different from the value of q. For example, p may be two and q may be one. The values for p and q may be the same, for example, p = q - 2.

[0089] In the above-mentioned examples, a higher score corresponds to a more important set of weights.

[0090] These scores and values provide merely examples and the present invention is not limited to these exemplary implementations. Any score based on (i) the first set of weights in a first layer and (ii) a normalization coefficient within a subsequent normalization layer and / or a second set of weights in a second layer following the first layer may be applied.

[0091] The exemplary flowchart in Fig. 8 illustrates the removing of weights based on the obtained score. Such a score is obtained S810 for a set of weights. The first set of weights 5021 from the first layer 5020 is removed if a predetermined condition based on the score is fulfilled. Thus, it may be determined S820 whether or not the predetermined condition based on the score is fulfilled. The set of weights 5021 may be removed S830 from the first layer if the predetermined condition is fulfilled (“Yes” in S820). The set of weights 5021 may be kept S840 in the first layer if the predetermined condition is not fulfilled (“No” in S820). The predetermined condition may be based on the score in that the score is an input parameter to the condition.

[0092] Such a predetermined condition may include a threshold for the score. For example, the score is compared to such score threshold and if the score is higher than the threshold, the set of weights is maintained. Otherwise, the set of weights is removed.

[0093] For example, alternatively or in addition, the predetermined condition may include a threshold for an amount of sets of weights to be removed. For instance, sets of weights are ordered according to the score and at most Thr_max sets of weights are removed. Alternatively or in addition, at least Thrjnin sets of weights are removed. In some other exemplary implementation, a predetermined number Thr_N(k) of sets of weights is removed from a k-th layer. Thr nin, Thrjnax and Thr_N(k) may be positive integers. The predetermined condition may include a combination of one or more thresholds, including the exemplarily mentioned thresholds. Such a threshold may be determined, for example, depending on one or more of model size, required accuracy, hardware specification, amount of processing or the like.

[0094] The removing of a set of weights may include a soft pruning of said set of weights. In other words, the weights within the set of weights to be removed are set to zero. The removing of a set of weights may include a hard pruning of said set of weights. In other words, the size of the layer, for example, the number of filters within said layer, is reduced.

[0095] UniZeroing: Soft pruning of redundant weights within a neural network based on a score

[0096] An exemplary flowchart illustrating an exemplary soft pruning of redundant weights based on a score is shown in Fig. 7. In this exemplary embodiment, an input model M of a neural network including L layers is provided S710 together with a pruning hyper parameter indicating a size G of a group and a pruning hyper parameter indicating the size Sprunedof a pruned model.

[0097] A score is obtained as described above for a first set of weights 5021 in a first layer 5020 contributing to a first feature within a feature tensor 5030. Consequently, a score for each set of weights contributing to a respective feature out of a set of features within the feature tensor 5030 may be obtained S715. Said set of features may include said first feature. For example, the set of feature may include all features within the feature tensor 5030. For example, the set of features may include a subset of all features within the feature tensor 5030.

[0098] The sets of weights that contribute to respective features out of the set of features may be arranged in one or more groups based on the respective score of said sets of weights. A group may include a predetermined amount of sets of weights. The amount of sets of weights within a group may be determined by the above-mentioned pruning hyper parameter G. In other words, a group of sets of weights of a layer Lkincludes one or more sets of weights, each set of weights contributing to a respective output channel of a layer Lk.

[0099] The hyper parameter G may be related to hardware constraints. For example, the hyper parameter G may be related to the size of the matrices that may be multiplied by a specific hardware in one clock cycle. If the number of channels of an input model is adapted to a specific hardware parameter, a pruned model may utilize the advantages of such specialized hardware in the case when the number set within a group, i.e. the number of sets of weights to be removed, respects such hardware parameters. For example, G may be 16 or 32. However, the present disclosure is not limited to these exemplary values. Such an arranging may comprise sorting S720 the sets of weights based on their respective score. For example, the sets of weights may be sorted according to the value of the respective score Sc..

[0100] In an exemplary implementation, a maximum score S™axof a layer Lkmay be determined, Sc. < S™axfor all sets of weights contributing to respective features Ct within the feature tensor 5030. Based on the maximum score and the scores of the respective sets of weights, a relative importance R may be obtained for each set of weights:

[0101] In this exemplary implantation, the sets of weights may be sorted by their respective relative importance.

[0102] The groups may be formed S720 including a predetermined amount of consecutive sorted sets of weights. As discussed above, the predetermined amount of sets of weights may be indicated by the pruning hyper parameter G. In other words, G sets of weights of a first layer having the G lowest scores form a first group, and so on.

[0103] A group score SGfor a group may be obtained S725 based on the scores of the sets of weights within said group. The group score of a group may be obtained by applying a statistical measure to the scores of the sets of weights within said group. For example, statistical measure that may be applied to the scores may be median, mean or the like.

[0104] In an exemplary implementation, a maximum group score S™xof a layer Lkmay be determined S725, SG< S™ for all groups within layer Lk. Based on the maximum group score and the group scores of the respective groups, a relative importance RGof a group may be calculated S730:

[0105] A group of sets of weights may be removed from the first layer if a predetermined condition based on the group score of said group is fulfilled.

[0106] Similarly as mentioned above for the sets, the condition may involve thresholds for the groups. Such a predetermined condition may include a threshold for the group score. For example, the group score is compared to such group score threshold and if the group score is higher than the threshold, the group of sets of weights is maintained. Otherwise, the group of set of weights is removed.

[0107] For example, alternatively or in addition, the predetermined condition may include a threshold for an amount of groups to be removed. For instance, groups are ordered according to the group score and at most Thr_group_max groups are removed. Alternatively or in addition, at least Thr_group_min groups are removed. In some other exemplary implementation, a predetermined number Thr_group_N(k) of group is removed from a k-th layer. Thr_group_min, Thr_group_max and Thr_group_N(k) may be positive integers. The predetermined condition may include a combination of one or more thresholds, including the exemplarily mentioned thresholds. Such a threshold may be determined, for example, depending on one or more of model size, required accuracy, hardware specification, amount of processing or the like.

[0108] The removing of a group may include a soft pruning of the sets of weights within said group. In other words the weights within the group to be removed are set to zero. The removing of a group may include a hard pruning of said set of weights. In other words, the size of the layer, for example, the number of filters within said layer, is reduced.

[0109] The steps S715 to S735 are repeated for a plurality of layers L. For each layer i out of a plurality of N layers within the neural network the arranging in groups is performed and a group score for each group is obtained. A group of sets of weights is removed from the i-th layer if a predetermined condition based on the group score of said group related to the i-th layer is fulfilled. The plurality of N layers may include all layers within the neural network.

[0110] In an exemplary implementation, the predetermined condition may include removing a predetermined number of groups M having the lowest group score within the group scores of all groups of the N layers. For example, the predetermined condition may include removing a predetermined number of groups M having the highest relative importance among all groups of the N layers. The predetermined number of groups M may be determined by a desired size of the pruned model.

[0111] In an exemplary embodiment, the removing a group of sets of weights from the first layer if a predetermined condition based on the group score of said group is fulfilled, may be performed according to the steps S740 to S780 in the exemplary flowchart in Fig. 7. The values indicating the relative importance of layers are sorted S740. The amount of removed weights Scuris set S745 to zero. As long as the amount of removed weights Scuris smaller than amount of weights to be removed Spruned, an iteration over the groups starting from the highest relative importance is performed S750. The weights of the group corresponding to the current relative importance RGare zeroed S760. Optional normalization parameters and optional further parameters, for example, activation parameters, that are applied to the output features of the respective sets of weights within the layer, may also be zeroed S760. In addition, the corresponding input channels of the subsequent layer may be zeroed S765. The amount of zeroed weights S' is calculated S770 and added S775 to the amount of removed weights Scurto obtain a new amount of removes weights Scur= Scur+ S'. The steps S750 to S780 are repeated until the requires size of the pruned model Sprunedis obtained. A model M with SPrUned zeroed weights is returned S785. Said model M may be further processed in the UniPruning explained in the following.

[0112] UniPruning: Pruning of zeroed weights within layers of a neural network

[0113] A pruned model of a neural network provides an accelerated processing while having an acceptable accuracy drop. UniPruning is an iterative procedure zeroing weights selected by a pruning rule every B-th epoch, wherein the value of B depends on target model’s architecture and model’s task.

[0114] Any neural network may be represented as a chain function fn( / n-i(- (fiM ■•■)) . where x is an input data and each f operates in some space using trainable parameters. Pruning algorithms aim to reduce dimension size in some set {fi(..., fj} through physically removing trainable parameters of this functions with an intention to keep optimal tradeoff between accuracy after pruning and speed-up on specific hardware or speed-up in terms of FLOPS or the other complexity measure like number of parameters.

[0115] A pruned model may be obtained as shown exemplarily for the UniPruning in the flowchart in Fig. 6. An input model M is provided S610 together with the pruning hyper parameter G indicating the number of filters or sets of weights to unite into a single group, the pruning hyper parameter B indicating the zeroing of weights every B-th epoch and the pruning hyper parameter P indicating a ratio of number of weights after pruning and a total number of weights within said model M. In addition, a total number of epochs for training of the neural network is provided. The number of weights to be removed is calculated S620 as Spruned= sizefmodel) ■ (1 - P). For example, the parameter P may be 0.25 or 0.5. However, the present disclosure is not limited to these exemplary values.

[0116] Sets of weights may be removed from the model, for example, by UniZeroing as explained above with reference to Fig. 7. Subsequent to the removing of the sets of weights, the neural network may be trained for a first predetermined number of epochs. In the example of Fig. 6 a training is performed for a total number of epochs S630, wherein every B-th epoch the UniZeroing S640. UniZeroing receives the model M, the pruning hyper parameter indicating a size G of a group and the pruning hyper parameter indicating the number of weights to be removed Sprunedas an input. The removing or zeroing of weights is followed by B epochs of training S650 of the model. Zeroing weights during a training phase instead of physically pruning may make training more stable. A physical pruning is illustrated in Figs. 1a and b. Fig. 1a shows a fully-connected neural network, with a hidden layer 1020. Each node of the input layer 1010 is connected to each of the nodes of the hidden layer 1020. In Fig. 1b a node or vertex 1040 is pruned and thus some of these connections are removed. Each of the nodes 1050, 1060 has remaining connections to the three remaining nodes of the initially four nodes of the preceding layer 1020.

[0117] Subsequent to the training of the neural network for a first predetermined number of epochs, removed weights may be pruned S660. In other words, the weights that have been zeroed in the last cycle S630 to S650 are physically removed from the respective layer. Such procedure allows model to re-learn itself with the constraint that Sprunedparameters are redundant and only then remove redundant parts.

[0118] The pruned neural network may be trained S670 for a second predetermined number of epochs. The training of the pruned neural network may provide a finetuning of the remaining weights within said model. Thus, an accelerated pruned model Mpis obtained S680.

[0119] In an exemplary neural network, pruning may remove all filters / weights of a layer. In such an exemplary case as depicted in Fig. 9, said layer may be removed from the computational graph if such removing does not break the computational graph. In other words, a removing of layer 910 may be performed, where as a removing of layer 920 may break the graph and is thus not allowed.

[0120] Implementations in hardware and software

[0121] An exemplary device described with references to Fig. 10 may provide means in order to carry out the training of the neural network. However, the present disclosure is not limited to this exemplary device. Any device including processing circuitry may provide means in order to carry out the training of the neural network. A processing circuitry within any of these exemplary devices is configured to obtain a score for a first set of weights contributing to a feature within a feature tensor, the feature tensor being an output of a first layer of the neural network; wherein the score is based on the first set of weights and the score is further based on one of (i) a normalization coefficient, which is applied in a normalization layer directly following the first layer, and / or (ii) a second set of weights, the second set including weights that are applied to said feature when applying a second layer to the feature tensor, the second layer following the first layer; and removing the first set of weights from the first layer if a predetermined condition based on the score is fulfilled.

[0122] In recent years, there appeared a lot of specialized Al hardware such as Neural Processing Units (NPUs) and these devices set special limitations for the models to be deployed. These devices are typically good at parallelizable tasks of tensor and matrix multiplications and additions. For specialized devices FLOPS measure is too abstract and often do not reflect real latency of model. For specific applications, hardware constraints should be taken into account during model’s architecture design.

[0123] NPUs and Graphics Processing Units (GPUs) may include a special computing unit to calculate matrix multiplications in parallel. Thus, NPUs and GPUs may use another data format IV x Cj X H x M / x Co , where the number of channels C = C±■ Coand Cois the number of matrices that may be multiplied in parallel.

[0124] If the number of channels C is not an integer multiple of Co, the hardware has to pad data, for example, with zeroes. This causes additional data copying and calculation decelerations. Thus, a number of channels being an integer multiple of the hardware parameter Comay increase the speed of calculations.

[0125] Fig. 10 is a simplified block diagram of an apparatus 500 that may be used as an encoding apparatus or a decoding apparatus according to an exemplary embodiment.

[0126] A processor 502 in the apparatus 500 can be a central processing unit. Alternatively, the processor 502 can be any other type of device, or multiple devices, capable of manipulating or processing information now-existing or hereafter developed. Although the disclosed implementations can be practiced with a single processor as shown, e.g., the processor 502, advantages in speed and efficiency can be achieved using more than one processor.

[0127] A memory 504 in the apparatus 500 can be a read only memory (ROM) device or a random access memory (RAM) device in an implementation. Any other suitable type of storage device can be used as the memory 504. The memory 504 can include code and data 506 that is accessed by the processor 502 using a bus 512. The memory 504 can further include an operating system 508 and application programs 510, the application programs 510 including at least one program that permits the processor 502 to perform the methods described here. For example, the application programs 510 can include applications 1 through N, which further include a coding application that performs the methods described herein, including the encoding and decoding using a neural network with a subset of partially updatable layers.

[0128] The apparatus 500 can also include one or more output devices, such as a display 518. The display 518 may be, in one example, a touch sensitive display that combines a display with a touch sensitive element that is operable to sense touch inputs. The display 518 can be coupled to the processor 502 via the bus 512.

[0129] Although depicted here as a single bus, the bus 512 of the apparatus 500 can be composed of multiple buses. Further, the secondary storage 514 can be directly coupled to the other components of the apparatus 500 or can be accessed via a network and can comprise a single integrated unit such as a memory card or multiple units such as multiple memory cards. The apparatus 500 can thus be implemented in a wide variety of configurations.

[0130] As shown in Fig. 10, if the techniques are implemented partially in software, a device may store instructions for the software in a suitable, non-transitory computer-readable storage medium and may execute the instructions in hardware using one or more processors to perform the techniques of this disclosure.

[0131] Embodiments and functions described herein, may be implemented in hardware, software, firmware, or any combination thereof. If implemented in software, the functions may be stored on a computer-readable medium or transmitted over communication media as one or more instructions or code and executed by a hardware-based processing unit. Computer-readable media may include computer-readable storage media, which corresponds to a tangible medium such as data storage media, or communication media including any medium that facilitates transfer of a computer program from one place to another, e.g., according to a communication protocol. In this manner, computer-readable media generally may correspond to (1) tangible computer-readable storage media, which is non-transitory, or (2) a communication medium such as a signal or carrier wave. Data storage media may be any available media that can be accessed by one or more computers or one or more processors to retrieve instructions, code and / or data structures for implementation of the techniques described in this disclosure. A computer program product may include a computer-readable medium.

[0132] By way of example, and not limiting, such computer-readable storage media can comprise RAM, ROM, EEPROM, CD-ROM or other optical disk storage, magnetic disk storage, or other magnetic storage devices, flash memory, or any other medium that can be used to store desired program code in the form of instructions or data structures and that can be accessed by a computer. Also, any connection is properly termed a computer-readable medium. For example, if instructions are transmitted from a website, server, or other remote source using a coaxial cable, fiber optic cable, twisted pair, digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of medium. It should be understood, however, that computer-readable storage media and data storage media do not include connections, carrier waves, signals, or other transitory media, but are instead directed to non-transitory, tangible storage media. Disk and disc, as used herein, includes compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks usually reproduce data magnetically, while discs reproduce data optically with lasers. Combinations of the above should also be included within the scope of computer-readable media.

[0133] Instructions may be executed by one or more processors, such as one or more digital signal processors (DSPs), general purpose microprocessors, application specific integrated circuits (ASICs), field programmable logic arrays (FPGAs), or other equivalent integrated or discrete logic circuitry. Accordingly, the term “processor,” as used herein may refer to any of the foregoing structure or any other structure suitable for implementation of the techniques described herein. In addition, in some aspects, the functionality described herein may be provided within dedicated hardware and / or software modules configured for encoding and decoding, or incorporated in a combined codec. Also, the techniques could be fully implemented in one or more circuits or logic elements.

[0134] The techniques of this disclosure may be implemented in a wide variety of devices or apparatuses, including a wireless handset, an integrated circuit (IC) or a set of ICs (e.g., a chip set). Various components, modules, or units are described in this disclosure to emphasize functional aspects of devices configured to perform the disclosed techniques, but do not necessarily require realization by different hardware units. Rather, as described above, various units may be combined in a codec hardware unit or provided by a collection of interoperative hardware units, including one or more processors as described above, in conjunction with suitable software and / or firmware.

[0135] Summarizing, methods and apparatuses are described for obtaining scores for sets of weights within layers of a neural network. Such a score is based on a set of weights in a first layer and one or more of (i) an (optional) normalization coefficient in a subsequent normalization layer and (ii) a set of weights within a second layer. Based on the score the set of weights may be removed from the layer. Such a pruning may reduce the size of the respective layer. Based on a group score, groups of sets of weights may be pruned from one or more layers of the neural network. The size of the groups can be based, for example, on hardware specifications.

Claims

CLAIMS A method for training of a neural network, the neural network including at least two layers, the method comprising: obtaining (S810) a score for a first set of weights (5021) contributing to a feature within a feature tensor (5030), the feature tensor (5030) being an output of a first layer (5020) of the neural network; wherein the score is based on the first set of weights (5021) and the score is further based on one or more of a normalization coefficient (5041), which is applied in a normalization layer (5040) directly following the first layer (5020), and / or a second set of weights (5061), the second set including weights that are applied to said feature when applying a second layer (5060) to the feature tensor (5050), the second layer (5060) following the first layer (5020); and the method further comprising removing (S830) the first set of weights (5021) from the first layer (5020) if a predetermined condition based on the score is fulfilled. The method according to claim 1 , wherein the removing further comprises determining (S820) whether or not the predetermined condition based on the score is fulfilled, removing (S830) the first set of weights (5021) from the first layer (5020) if the predetermined condition is fulfilled. The method according to any of the claims 1 or 2 wherein the obtaining a score further comprises: obtaining (S715) a score for each set of weights contributing to a respective feature out of a set of features within the feature tensor (5030).The method according to claim 3 further comprising: arranging sets of weights that contribute to respective features out of the set of features, in one or more groups based on the respective score of said sets of weights. The method according to claim 4 wherein the arranging further comprises: sorting the sets of weights based on their respective score; forming (S720) groups including a predetermined amount of consecutive sorted sets of weights. The method according to any of the claims 4 or 5 further comprising: obtaining (S725) a group score for each group, wherein the group score of a respective group is based on the scores of the sets of weights within said group. The method according to claim 6, wherein the group score for a group is obtained by applying a statistical measure to the scores of the sets of weights within said group. The method according to any of the claims 6 or 7 wherein the removing comprises removing (S755) a group of sets of weights from the first layer if a predetermined condition based on the group score of said group is fulfilled. The method according to any of the claims 6 or 7, wherein for each layer i out of a plurality of N layers within the neural network the arranging in groups is performed and a group score for each group is obtained; and a group of sets of weights is removed from the i-th layer if a predetermined condition based on the group score of said group related to the i-th layer is fulfilled.The method according to claim 9, wherein the plurality of N layers includes all layers within the neural network. The method according to any of the claims 9 to 10, wherein the predetermined condition includes removing a predetermined number of groups M having the lowest group score within the group scores of all groups of the N layers. The method according to any of the claims 1 to 10, wherein the predetermined condition includes a predetermined threshold for one or more of- a score,- a group score,- an amount of sets of weights. The method according to any of the claims 1 to 12, wherein removing includes setting weights to be removed to zero. The method according to any of the claims 1 to 13, further comprising: subsequent to the removing, training (S650) the neural network for a first predetermined number of epochs. The method according to claim 14, further comprising: subsequent to the training of the neural network, pruning (S670) removed weights; training (S670) the pruned neural network for a second predetermined number of epochs.A computer program stored on a non-transitory medium and including code instructions, which, when executed on one or more processors, cause the one or more processors to execute steps of the method according to any of claims 1 to 15. An apparatus for training of a neural network, the neural network including at least two layers, the apparatus comprising: processing circuitry configured to: obtain (S810) a score for a first set of weights (5021) contributing to a feature within a feature tensor (5030), the feature tensor (5030) being an output of a first layer (5020) of the neural network; wherein the score is based on the first set of weights (5021) and the score is further based on one of a normalization coefficient (5041), which is applied in a normalization layer (5040) directly following the first layer (5020), and / or- a second set of weights (5061), the second set including weights that are applied to said feature when applying a second layer (5060) to the feature tensor (5050), the second layer (5060) following the first layer (5020); and remove (S830) the first set of weights (5021) from the first layer (5020) if a predetermined condition based on the score is fulfilled.25