Model compression method, training method, multimedia data processing method and device
Patent Information
- Application Number
- CN202311235188.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-22
- Publication Date
- 2024-11-01
- Estimated Expiration
- 2043-09-22
AI Technical Summary
Due to the large number of parameters, existing large language generation models take up a lot of memory and computing resources, and the quantization process causes serious loss of model accuracy.
By generating a weight scaling factor for each processing layer and scaling the weight parameters of the processing layer, the distribution of calculation results is concentrated, reducing the loss of model accuracy caused by the quantization process, and quantification is performed based on activation value distribution information to obtain a compression model.
It effectively reduces the storage space and computing resource requirements of the hardware environment for model deployment, and at the same time reduces the accuracy loss during the model compression process, achieving compression of the model with small accuracy loss.
Smart Images

Figure CN117370798A8_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, in particular to the technical fields of deep learning, natural language processing, computer vision, etc. In particular, it relates to a model compression method, a training method, a multimedia data processing method and a device. Background Art
[0002] The language generation model based on GPT (Generative Pre-trained Transformer) is widely used in the field of natural language processing. However, due to the large number of parameters in the language generation model, for example, the number of parameters of the GPT-3 model can reach 170 billion. Therefore, it takes up a lot of memory and computing resources when deploying the language generation model. Summary of the invention
[0003] The present invention provides a model compression method, a training method, and a multimedia data processing method.
[0004] According to one aspect of the present disclosure, a model compression method is provided, comprising: inputting multimedia data into a model to be compressed, obtaining an activation value matrix of each processing layer in N cascaded processing layers in the model to be compressed, wherein the activation value matrix of the nth processing layer represents output features obtained after the multimedia data is processed by n-1 processing layers, N is an integer greater than 1, n=2, ...N; generating a weight scaling factor for each processing layer according to distribution information of activation values in the activation value matrix; scaling the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain parameters to be quantized for each processing layer; and quantizing the parameters to be quantized for each processing layer in turn based on a predetermined quantization accuracy to obtain a compression model.
[0005] According to another aspect of the present disclosure, a method for training a compression model is provided, comprising: inputting first multimedia data as sample data into the compression model to obtain a first probability vector for multiple predetermined categories; the first multimedia data is annotated with first category information; determining a loss value of the compression model based on the first category information and the first probability vector; and adjusting model parameters of the compression model based on the loss value to obtain a trained compression model, wherein the compression model is a compressed deep learning model obtained by using the model compression method described above.
[0006] According to another aspect of the present disclosure, a method for processing multimedia data is provided, including: inputting the multimedia data to be processed into a compression model to obtain a probability vector representing the category to which the multimedia data belongs; the probability vector includes a probability value that the multimedia data belongs to each of a plurality of predetermined categories; and determining, based on the probability vector, a target category to which the multimedia data belongs in the plurality of predetermined categories, wherein the compression model includes a compressed deep learning model obtained by using the model compression method described above.
[0007] According to another aspect of the present disclosure, a model compression device is provided, comprising: a first acquisition module, a generation module, a scaling module and a quantization module. The first acquisition module is used to input multimedia data into the model to be compressed, and obtain the activation value matrix of each processing layer in the N cascaded processing layers in the model to be compressed, wherein the activation value matrix of the nth processing layer represents the output features obtained after the multimedia data is processed by n-1 processing layers, N is an integer greater than 1, n=2, ...N; the generation module is used to generate the weight scaling factor of each processing layer according to the distribution information of the activation values in the activation value matrix; the scaling module is used to scale the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain the parameters to be quantized of each processing layer; and the quantization module is used to quantize the parameters to be quantized of each processing layer in turn based on a predetermined quantization accuracy to obtain a compression model.
[0008] According to another aspect of the present disclosure, a training device for a compression model is provided, comprising: a second acquisition module, a first determination module and an adjustment module. The second acquisition module is used to input first multimedia data as sample data into the compression model to obtain first probability vectors for multiple predetermined categories; the first multimedia data is annotated with first category information; the first determination module is used to determine the loss value of the compression model based on the first category information and the first probability vector; and the adjustment module is used to adjust the model parameters of the compression model based on the loss value to obtain a trained compression model, wherein the compression model is a compressed deep learning model obtained by the model compression method described above.
[0009] According to another aspect of the present disclosure, a multimedia data processing device is provided, comprising: a third obtaining module and a second determining module. The third obtaining module is used to input the multimedia data to be processed into a compression model to obtain a probability vector representing the category to which the multimedia data belongs; the probability vector includes a probability value that the multimedia data belongs to each of a plurality of predetermined categories; and the second determining module is used to determine, according to the probability vector, a target category to which the multimedia data belongs in the plurality of predetermined categories, wherein the compression model includes a compressed deep learning model obtained by using the model compression method described above.
[0010] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method as described above.
[0011] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method as described above.
[0012] According to another aspect of the present disclosure, a computer program product is provided, comprising a computer program, wherein the computer program implements the method described above when executed by a processor.
[0013] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0014] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0015] Figure 1 An exemplary system architecture to which a model compression method, a training method or a multimedia data processing method and apparatus according to an embodiment of the present disclosure can be applied is schematically shown;
[0016] Figure 2 A flowchart of a model compression method according to an embodiment of the present disclosure is schematically shown;
[0017] Figure 3 A schematic diagram schematically illustrates weight scaling in the processing layer P3330 according to an embodiment of the present disclosure;
[0018] Figure 4A A schematic diagram of determining parameters to be quantized according to some embodiments of the present disclosure is schematically shown;
[0019] Figure 4B Schematically showing a schematic diagram of determining parameters to be quantized according to other embodiments of the present disclosure;
[0020] Figure 4C A schematic diagram schematically shows a method of determining parameters to be quantized according to some other embodiments of the present disclosure;
[0021] Figure 5 The exemplary architecture diagram of the model to be compressed according to the embodiment of the present disclosure is schematically shown;
[0022] Figure 6 A flowchart of a compression model training method according to an embodiment of the present disclosure is schematically shown;
[0023] Figure 7 A flowchart of a multimedia data processing method according to an embodiment of the present disclosure is schematically shown;
[0024] Figure 8 A block diagram of a model compression device according to an embodiment of the present disclosure is schematically shown;
[0025] Fig. 9 A block diagram of a compression model training device according to an embodiment of the present disclosure is schematically shown;
[0026] Fig.10 A block diagram schematically shows a multimedia data processing device according to an embodiment of the present disclosure; and
[0027] Fig.11 A block diagram of an electronic device suitable for implementing a model compression method, a compression model training method or a multimedia data processing method according to an embodiment of the present disclosure is schematically shown. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0029] In large language generation models, Cache Key-Value (CacheKV) technology is generally introduced to improve the model's reasoning performance. The principle of Cache KV is to cache the reusable calculation results of the i-th round. When performing the i+1th round of calculation, the cached i-th round calculation results are directly read, and the cached i-th round calculation results and the i+1th round calculation results are spliced to obtain the final i+1th round calculation results.
[0030] Introducing Cache KV into the language generation of large models improves the model reasoning speed while also increasing the number of model parameters. By quantifying the model parameters, the size of the model can be reduced to reduce the hardware requirements.
[0031] However, since the calculation results cached in the Cache KV are highly discrete, when the large language generation model is quantized, a relatively serious loss of accuracy of the large language generation model is caused.
[0032] In view of this, an embodiment of the present disclosure provides a model compression method, which generates a weight scaling factor for each processing layer according to the distribution information of activation values in the activation value matrix; according to the weight scaling factor of each processing layer, the weight parameters of each processing layer are scaled, so that the calculation results of each processing layer are distributed more concentratedly, reducing the loss of model accuracy in the quantization process, saving data storage, and making the data storage space required for the compressed model less than a preset value, thereby reducing the storage space and computing resource requirements of the hardware environment for model deployment.
[0033] Figure 1 An exemplary system architecture to which the model compression method and apparatus according to an embodiment of the present disclosure can be applied is schematically shown.
[0034] It should be noted that Figure 1 The examples shown are only examples of system architectures to which the embodiments of the present disclosure can be applied, in order to help those skilled in the art understand the technical content of the present disclosure, but do not mean that the embodiments of the present disclosure cannot be used in other devices, systems, environments or scenarios. For example, in another embodiment, the exemplary system architecture to which the model compression method and apparatus can be applied may include a terminal device, but the terminal device may implement the model compression method and apparatus provided by the embodiments of the present disclosure without interacting with the server.
[0035] like Figure 1 As shown, the system architecture 100 according to this embodiment may include a first terminal device 101, a second terminal device 102, a third terminal device 103, a network 104, and a server 105. The network 104 is used to provide a medium for a communication link between the first terminal device 101, the second terminal device 102, the third terminal device 103, and the server 105. The network 104 may include various connection types, such as wired and / or wireless communication links, etc.
[0036] The user can use the first terminal device 101, the second terminal device 102, and the third terminal device 103 to interact with the server 105 through the network 104 to receive or send messages, etc. Various communication client applications can be installed on the first terminal device 101, the second terminal device 102, and the third terminal device 103, such as knowledge reading applications, web browser applications, search applications, instant messaging tools, email clients, and / or social platform software, etc. (only as examples).
[0037] The first terminal device 101, the second terminal device 102, and the third terminal device 103 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0038] The server 105 may be a server that provides various services, such as a background management server (only as an example) that provides support for the content browsed by the user using the first terminal device 101, the second terminal device 102, and the third terminal device 103. The background management server may analyze and process the received data such as user requests, and feed back the processing results (such as web pages, information, or data obtained or generated according to user requests) to the terminal device.
[0039] It should be noted that the model compression method provided in the embodiment of the present disclosure can generally be executed by the first terminal device 101, the second terminal device 102, and the third terminal device 103. Correspondingly, the model compression device provided in the embodiment of the present disclosure can also be set in the first terminal device 101, the second terminal device 102, and the third terminal device 103.
[0040] Alternatively, the model compression method provided in the embodiment of the present disclosure may also be generally executed by the server 105. Accordingly, the model compression device provided in the embodiment of the present disclosure may generally be arranged in the server 105. The model compression method provided in the embodiment of the present disclosure may also be executed by a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105. Accordingly, the model compression device provided in the embodiment of the present disclosure may also be arranged in a server or server cluster that is different from the server 105 and can communicate with the first terminal device 101, the second terminal device 102, the third terminal device 103 and / or the server 105.
[0041] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0042] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision, disclosure and application of user personal information involved comply with the provisions of relevant laws and regulations, take necessary confidentiality measures, and do not violate public order and good morals.
[0043] In the technical solution of the present disclosure, the user's authorization or consent is obtained before obtaining or collecting the user's personal information.
[0044] Figure 2 The flowchart of the model compression method according to the embodiment of the present disclosure is schematically shown.
[0045] like Figure 2 As shown, the method 200 includes operations S210 to S240.
[0046] In operation S210, multimedia data is input into the model to be compressed, and an activation value matrix of each processing layer in the N cascaded processing layers in the model to be compressed is obtained.
[0047] In operation S220, a weight scaling factor of each processing layer is generated according to distribution information of activation values in the activation value matrix.
[0048] In operation S230, the weight parameters of each processing layer are scaled according to the weight scaling factor of each processing layer to obtain the parameters to be quantized of each processing layer.
[0049] In operation S240, based on a predetermined quantization accuracy, the parameters to be quantized of each processing layer are quantized in turn to obtain a compression model.
[0050] According to an embodiment of the present disclosure, the multimedia data may include at least one of the following: image, text, audio, video, etc. The model to be compressed may be a model corresponding to the type of the multimedia data.
[0051] For example, if the multimedia data is text, the model to be compressed may be the ERNIE model or a generative pre-trained Transformer model (GPT).
[0052] For example: if the multimedia data is an image, the model to be compressed can be a residual network (Residual Network, ResNet) series model (such as ResNet-50), a vision transformer model (Vision Transformer, ViT), an end-to-end object detection model based on Transformer (End-to-End Object Detection with Transformers, DERT), etc.
[0053] For example, if the multimedia data is a video, the model to be compressed can be a Swin-Transformer model, etc.
[0054] According to an embodiment of the present disclosure, the N processing layers cascaded in the model to be compressed may correspond to the type of the model to be compressed. For example, the model to be compressed may be a generative pre-trained Transformer model, and the N processing layers may include a normalization layer, a multi-head attention layer, a fully connected layer, an overlay layer, a feedforward neural network layer, etc.
[0055] According to an embodiment of the present disclosure, the activation value matrix of the nth processing layer represents the output features obtained after the n-1 processing layers located before the nth processing layer process the multimedia data, where N is an integer greater than 1, n=2, ... N. For example: the activation value matrix of the multi-head attention layer is the output features obtained after the normalization layer processes the multimedia data; the activation value matrix of the fully connected layer is the output features obtained after the normalization layer processes the multimedia data, and then input into the multi-head attention layer, and the output features obtained after processing based on the multi-head attention mechanism.
[0056] According to an embodiment of the present disclosure, the distribution information of the activation value can characterize the degree of discreteness of the activation value in the activation value matrix. When the elements in the activation value matrix are the same, the larger the range of the activation value, the higher the degree of discreteness of the activation value. For example, the degree of discreteness of the activation value matrix with an activation value range of 1 to 100 is higher than the degree of discreteness of the activation value range of 1 to 10. The higher the degree of discreteness, the more parameters are truncated during the quantization process, and the greater the loss of model accuracy.
[0057] For example, for a certain processing layer, the activation value matrix may be a 3x4 dimensional matrix, in which the minimum activation value may be 1 and the maximum activation value may be 100. Based on the matrix multiplication calculation of the activation value matrix and the weight parameters in the processing layer, the output result matrix (i.e., the activation value of the next processing layer) obtained has a large degree of discreteness.
[0058] According to an embodiment of the present disclosure, the weight scaling factor may represent the value used to scale the weight parameters in each processing layer. For example, for a certain processing layer, after the weight parameters are scaled according to the weight scaling factor, the distribution of the weight parameters can be relatively concentrated. Therefore, when a 3x4-dimensional matrix is multiplied by the scaled weight matrix of the processing layer, an output result matrix with relatively concentrated data distribution can be obtained.
[0059] According to an embodiment of the present disclosure, based on an activation value matrix with relatively concentrated data distribution, since there are fewer discrete points in the activation value matrix, less feature information is lost in the parameters to be quantized when the activation value matrix is truncated, thereby effectively reducing the loss of model accuracy caused by the quantization process.
[0060] According to an embodiment of the present disclosure, a weight scaling factor for each processing layer is generated based on the distribution information of activation values in an activation value matrix; and the weight parameters of each processing layer are scaled based on the weight scaling factor of each processing layer, so that the calculation results of each processing layer are distributed more concentratedly, thereby reducing the loss of model accuracy in the quantization process and saving data storage capacity, so that the data storage space required for the compression model is less than a preset value, thereby reducing the storage space and computing resource requirements of the hardware environment for model deployment.
[0061] Reference below Figure 3 to Figure 5 , combined with specific embodiments Figure 2 The method shown is further explained.
[0062] Figure 3 A schematic diagram schematically shows weight scaling in the processing layer P3330 according to an embodiment of the present disclosure.
[0063] like Figure 3 As shown, in embodiment 300 , the model to be compressed may include a cascaded processing layer P1 310 , a processing layer P2 320 , a processing layer P3 330 , and a processing layer P4 340 .
[0064] According to an embodiment of the present disclosure, multimedia data is input into the processing layer P1310, and the output features are then input into the output features of the processing layer P2320, that is, the activation value matrix 321 of the processing layer P3330. In the processing layer P3330, the activation value matrix 321 is matrix multiplied with the weight matrix 331 to obtain a first output result 332. In the first output result 332, the color of the color block can represent the size of the first output result value, and the darker the color, the larger the output result value. It can be seen that in the first output result 332, the color distribution of the color blocks is quite different, indicating that the output result value distribution in the first output result 332 is relatively dispersed.
[0065] According to an embodiment of the present disclosure, the weight scaling threshold of each processing layer can be determined based on the distribution information of the activation value of each processing layer; and the weight scaling factor of each processing layer can be generated based on the activation value of each processing layer and the weight scaling threshold of each processing layer.
[0066] For example, the range of activation values can be determined based on all activation values X11 to X34 in the activation value matrix 321, and the maximum activation value can be determined as the weight scaling threshold X max , the threshold value X can be scaled according to the activation value in the activation value matrix 321 and the weight of the processing layer according to formula (1). max , generate the weight scaling factor S of the processing layer ij .
[0067] S ij =X ij / X max (1)
[0068] Among them, X ij represents the element value at the i-th row and j-th column in the activation value matrix; X max Represents the maximum activation value in the activation value matrix; S ij Indicates that X ij The corresponding weight scaling factor.
[0069] According to an embodiment of the present disclosure, the weight scaling factor S corresponding to each activation value in the activation value matrix 321 can be obtained according to formula (1): ij , and obtain the weight scaling factor matrix 322.
[0070] Since the distribution information of the activation value of each processing layer has a certain relationship with the processed multimedia data, different batches of multimedia data can be input into the compression model based on M rounds, where M is an integer greater than 1, to obtain different activation value distribution information for different batches of multimedia data in each processing layer.
[0071] According to an embodiment of the present disclosure, determining the weight scaling threshold of each processing layer according to the distribution information of the activation values of each processing layer may include the following operations: for each processing layer, determining a first scaling threshold according to the distribution information of the activation values corresponding to the multimedia data input in the m-1th round, where m is an integer greater than 1 and less than or equal to M; determining a second scaling threshold according to the distribution information of the activation values corresponding to the multimedia data input in the mth round; and in response to the second scaling threshold being greater than the first scaling threshold, determining the second scaling threshold as the weight scaling threshold.
[0072] For example: for a certain processing layer, for the distribution information of the activation values corresponding to the multimedia data input in the first round, the maximum value of the activation values in the processing layer obtained in the first round can be determined as the first scaling threshold abs-max1. For the distribution information of the activation values corresponding to the multimedia data input in the second round, the maximum value of the activation values in the processing layer obtained in the second round can be determined as the second scaling threshold abs-max2. When abs-max1 is less than abs-max2, abs-max2 is determined as the weight scaling threshold. And so on, until the Mth round of multimedia data processing is completed, the maximum value of the M scaling thresholds corresponding to the M rounds can be used as the weight scaling threshold.
[0073] According to an embodiment of the present disclosure, the distribution information of the activation value corresponding to the multimedia data input in the m-1th round may represent the numerical range of the activation value, for example: 1 to 100; and the maximum activation value 100 may be determined as the first scaling threshold.
[0074] Similarly, the distribution information of the activation values corresponding to the multimedia data input in the mth round can represent the numerical range of the activation values, for example, 1 to 50; then the maximum activation value 50 can be determined as the second scaling threshold. Since the second scaling threshold 50 is less than the first scaling threshold 100, the weight scaling threshold is determined to be 100.
[0075] According to an embodiment of the present disclosure, a weight scaling factor matrix with element values ranging from 0 to 1 is obtained based on dividing each element value in the activation value matrix by the maximum element value in the activation value matrix, so as to narrow the value range of the weight parameter matrix, make the weight parameter distribution concentrated, and facilitate quantization.
[0076] According to an embodiment of the present disclosure, scaling the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain the parameters to be quantized of each processing layer may include the following operations:
[0077] According to the weight scaling factor of each processing layer, the weight parameters of each processing layer are scaled to obtain the weight-scaled target model; the multimedia is input into the weight-scaled target model to obtain the activation value of each processing layer; and according to the distribution information of the activation value of each processing layer, the quantized parameters of each processing layer are obtained.
[0078] like Figure 3 As shown, each element in the weight scaling factor matrix 322 can be multiplied with each element in the initial weight parameter matrix 331 according to the element position to obtain each element in the updated weight parameter matrix 333.
[0079] For example: the element S in the first row and first column of the weight scaling factor matrix 322 is 11 and the element W in the first row and first column of the initial weight parameter matrix 331 11 Multiplying them together, we can get the element W in the first row and first column of the updated weight parameter matrix 333 11’ .
[0080] According to an embodiment of the present disclosure, after the weight parameter matrix of the processing layer P3330 is changed, a weight-scaled target model can be obtained. At this time, the target model after the multimedia input weight is scaled, and the activation value matrix 321 of the processing layer P3330 remains unchanged, and the activation value matrix 321 is matrix-multiplied with the updated weight parameter matrix 333 to obtain a second output result 334. In the second output result 334, the color of the color block can represent the size of the second output result value, and the darker the color, the larger the output result value. It can be seen that in the second output result 334, the color of the color block is evenly distributed, indicating that the output result value distribution in the second output result 334 is relatively concentrated.
[0081] According to the embodiments of the present disclosure, by comparing the first output result 332 and the second output result 334, it can be understood that for the same processing layer, when the activation value matrix is the same, after the weight parameter matrix is scaled, the discreteness of the output result value distribution is significantly reduced, thereby effectively reducing the loss of accuracy in the model compression process, thereby achieving saving of data storage space and hardware resource occupancy while reducing the loss of model prediction accuracy.
[0082] According to an embodiment of the present disclosure, obtaining the parameters to be quantized of each processing layer according to the distribution information of the activation values of each processing layer may include the following operations: obtaining a truncation threshold of each processing layer according to the distribution information of the activation values of each processing layer; and truncating the parameters of each processing layer based on the truncation threshold to obtain the parameters to be quantized of each processing layer.
[0083] According to an embodiment of the present disclosure, the distribution information of the activation value can characterize the value range of the activation value. For example, when quantizing the activation value in a cache unit (Cache) of a certain processing layer, the maximum activation value among all activation values currently cached in the cache unit can be determined as the parameter truncation threshold. Based on the maximum activation value, all activation values currently cached by the processing layer are truncated to obtain the parameter to be quantized of the processing layer. The parameter to be quantized can be the maximum activation value of the processing layer.
[0084] According to an embodiment of the present disclosure, the maximum activation value among all activation values is used as the truncation threshold, so each processing layer has only one quantization factor, which can effectively improve the data processing speed of the quantization process.
[0085] However, each processing layer has only one quantization factor. This quantization method has a coarse granularity and may result in low quantization accuracy in some application scenarios.
[0086] In view of this, the embodiments of the present disclosure can construct a distribution matrix based on the distribution information of the activation values of each processing layer; segment the distribution matrix to obtain sub-distribution information of the activation values corresponding to each segmented area; and determine the parameter truncation threshold corresponding to each segmented area based on the sub-distribution information to improve the quantization accuracy.
[0087] According to an embodiment of the present disclosure, taking the multi-head attention layer as an example, the activation value in the cache unit of the processing layer generally includes two dimensions: the number of heads and the number of hidden channels in each head.
[0088] For example, the distribution matrix may be segmented according to the number of processing channels of each processing layer to obtain sub-distribution information of activation values corresponding to each segmented region.
[0089] Figure 4ASchematically shows a schematic diagram of determining parameters to be quantized according to some embodiments of the present disclosure.
[0090] like Figure 4A As shown, in the embodiment 400A, the second output result 334 can be used as the activation value matrix of the next processing layer. The first distribution matrix 410 can be constructed based on the distribution information of the activation value of the second output result 334. The first distribution matrix 410 is divided according to the number of channels. The elements of each column in the distribution matrix 410 represent the activation values of the same processing channel. Therefore, the distribution matrix 410 can be divided by column to obtain the first segmentation area 411, the second segmentation area 412, the third segmentation area 413 and the fourth segmentation area 414.
[0091] According to an embodiment of the present disclosure, determining a parameter cutoff threshold corresponding to each segmented region based on sub-distribution information may include the following operations: determining a maximum activation value corresponding to each segmented region based on the sub-distribution information; and determining the maximum activation value corresponding to each segmented region as the parameter cutoff threshold corresponding to each segmented region.
[0092] For example: for the activation value X corresponding to the first segmented area 411 11’ , activation value X 21’ , activation value X 31’ , activate the value X 11’ , activation value X 21’ , activation value X 31’ The maximum activation value X in 11’ Determine as X maxl The activation value corresponding to the first segmented region 411 is truncated, and the first parameter to be quantized 421 obtained can be the activation value X 11’ By analogy, the second parameter to be quantized 422, the third parameter to be quantized 423 and the fourth parameter to be quantized 424 corresponding to the other three segmented regions can be obtained. The first parameter to be quantized 421, the second parameter to be quantized 422, the third parameter to be quantized 423 and the fourth parameter to be quantized 424 are concatenated to obtain the final parameter to be quantized 430.
[0093] According to an embodiment of the present disclosure, the activation value matrix is segmented according to the number of channels of each processing layer, and a parameter to be quantized can be obtained for each segmented area, so that fine-grained quantization of the activation value can be achieved and the quantization accuracy can be improved.
[0094] The dimension of the parameter to be quantized determined in embodiment 400A is proportional to the number of channels. Although the quantization accuracy can be improved, the computation time is also increasing with the increase of the number of channels. In order to balance the computation time and quantization accuracy, the activation values of each processing layer can be clustered to obtain clustering results; and based on the clustering results, the distribution matrix can be segmented to obtain sub-distribution information of the activation values corresponding to each segmented area.
[0095] Figure 4B A schematic diagram of determining parameters to be quantized according to some other embodiments of the present disclosure is schematically shown.
[0096] like Figure 4B As shown, in embodiment 400B, a second distribution matrix 440 may be constructed based on the distribution information of the activation values of the second output result 334. The activation values in the second distribution matrix 440 are clustered according to any clustering algorithm to obtain a clustering result. The clustering result may include the number of clusters obtained after clustering the activation values and the activation value corresponding to each cluster.
[0097] According to an embodiment of the present disclosure, three clusters may be obtained according to the clustering results, and the second distribution matrix 440 may be segmented according to the activation value corresponding to each cluster to obtain a fifth segmented region 441 , a sixth segmented region 442 , and a seventh segmented region 443 .
[0098] The activation value X corresponding to the fifth segmented region 441 11’ Activation value X 32’ , activate the value X 11’ ~Activation value X 32’ The maximum activation value X in 32’ Determine as X max5 The activation value corresponding to the fifth segmented region 441 is truncated, and the fifth parameter to be quantized 451 obtained can be the activation value X 32’ By analogy, the sixth parameter to be quantized 452 and the seventh parameter to be quantized 453 corresponding to the other segmented regions can be obtained. The fifth parameter to be quantized 451, the sixth parameter to be quantized 452 and the seventh parameter to be quantized 453 are concatenated to obtain the final parameter to be quantized 460.
[0099] According to an embodiment of the present disclosure, by clustering activation values, activation values with a relatively concentrated numerical range can be segmented into the same area, and a higher-precision quantization of the model can be achieved based on less computational time.
[0100] According to an embodiment of the present disclosure, segmenting the distribution matrix to obtain sub-distribution information of the activation value corresponding to each segmented area may include the following operations: evenly segmenting the distribution matrix according to a predetermined number of areas to obtain sub-distribution information of the activation value corresponding to each segmented area.
[0101] Figure 4C A schematic diagram of determining parameters to be quantized according to some further embodiments of the present disclosure is schematically shown.
[0102] like Figure 4C As shown, in embodiment 400C, a third distribution matrix 470 can be constructed according to the distribution information of the activation value of the second output result 334. The third distribution matrix 470 can be evenly divided according to the predetermined number of area divisions to obtain an eighth segmentation area 471 and a ninth segmentation area 472, and the number of activation values in each segmentation area is the same.
[0103] The activation value X corresponding to the eighth segmented area 471 11’ ~Activation value X 32’ , activate the value X 11’ ~Activation value X 32’ The maximum activation value X in 32’ Determine as X max8 The activation value corresponding to the eighth segmented region 471 is truncated, and the obtained eighth parameter to be quantized 481 may be the activation value X 32’ By analogy, the ninth parameters to be quantized 482 corresponding to the other segmented regions can be obtained. The eighth parameter to be quantized 481 and the ninth parameter to be quantized 482 are concatenated to obtain the final parameter to be quantized 490.
[0104] According to the embodiments of the present disclosure, the number of predetermined areas can be pre-set based on the needs of actual application scenarios, so as to realize the quantification of the model with higher precision based on the needs of actual application scenarios, for example, the needs for computational time consumption.
[0105] According to an embodiment of the present disclosure, based on a predetermined quantization accuracy, the parameters to be quantized of each processing layer are quantized in turn to obtain a compression model, which may include the following operations: for each processing layer, a quantization factor is determined according to the predetermined quantization accuracy and the distribution information of the parameters to be quantized of each processing layer; and according to the quantization factor, the parameters to be quantized of each processing layer are quantized to obtain a compression model.
[0106] According to an embodiment of the present disclosure, for each processing layer, a quantization factor is determined according to a predetermined quantization accuracy and distribution information of the parameters to be quantized of each processing layer, which may include the following operations: determining the maximum parameter value of each processing layer according to the distribution information of the parameters to be quantized of each processing layer; and obtaining the quantization factor according to the predetermined quantization accuracy and the maximum parameter value.
[0107] For example: for a certain processing layer, the parameters to be quantized may include the activation value X 32’ and activation value X 14’ , at the activation value X32' Greater than activation value X 14' In the case of , the maximum parameter value can be determined as the activation value X 32' .
[0108] According to the embodiments of the present disclosure, the parameters to be quantized may be quantized according to equations (2) and (3) to obtain a compression model.
[0109]
[0110] x q = clip(round(s·x), -2 b-1 , 2 b-1 ) (3)
[0111] Where s represents the quantization factor, b represents the predetermined quantization accuracy, α represents the parameter with the largest absolute value among the parameters to be quantized; x q Represents the quantized parameter, x represents the parameter to be quantized; round() represents the rounding operation, and clip represents truncation with the maximum and minimum values.
[0112] According to the embodiments of the present disclosure, since the weight parameters of each processing layer are scaled, the distribution of the activation values of each processing layer is relatively concentrated. When the activation values are quantized, the precision loss of the quantization process can be effectively reduced, thereby achieving compression of the model with less precision loss, saving the data storage capacity of the model parameters and the demand for hardware resources of the deployment environment.
[0113] When applying the model compression method provided by the embodiment of the present disclosure to compress the large language generation model, in order not to change the prediction accuracy of the large language generation model, the weight scaling process between the two processing layers with data interaction should be mathematically equivalent. For example: in the transformer network, the query weight parameter matrix (Q) and the key weight parameter matrix (K) need to perform matrix multiplication operations. Therefore, after the weight parameters in the query weight parameter matrix are reduced based on the weight scaling factor, the key weight parameter matrix needs to be enlarged according to the inverse of the same weight scaling factor, so that the result of the matrix multiplication is mathematically equivalent to the result of the matrix multiplication before the weight scaling.
[0114] Figure 5 An exemplary architecture diagram of a model to be compressed according to an embodiment of the present disclosure is schematically shown.
[0115] like Figure 5As shown, the model to be compressed 500 may include a normalization layer (LayerNorm) 510, a value feature processing layer (V) 520_1, a query feature processing layer (Q) 520_2, a key feature processing layer (K) 520_3, a first cache unit (Cache) 530_1, a second cache unit (Cache) 530_2, a first matrix multiplication processing layer (BatchedMatMul, BMM) 540_1, a second matrix multiplication processing layer (BatchedMatMul, BMM) 540_2, a Softmax layer 550, and an output layer (Out proj) 560.
[0116] For the query feature processing layer (Q) 520_2 and the key feature processing layer (K) 520_3, the updated weight parameters in the key feature processing layer (K) 520_3 are based on the initial weight parameter matrix W k With the first weight scaling factor matrix S k The updated weight parameters in the query feature processing layer (Q) 520_2 are based on the initial weight parameter matrix W q The inverse of the first weight scaling factor matrix 1 / S k The first weight scaling factor matrix is obtained by performing element-by-element multiplication. The first weight scaling factor matrix is obtained according to the activation values cached in the first cache unit 530_1 in accordance with the calculation method of the weight factor described above.
[0117] When the second matrix multiplication processing layer 540_2 performs matrix multiplication on the query feature and the key feature, the operation result does not change, so that when the query feature processing layer (Q) 520_2 and the key feature processing layer (K) 520_3 insert scaling factors to scale the weight parameter matrix, an operation result mathematically equivalent to that before the weight parameter matrix is scaled can be obtained, thereby ensuring the accuracy of the model prediction results.
[0118] Similarly, the updated weight parameters in the value feature processing layer (V) 520_1 are based on the initial weight parameter matrix W v With the second weight scaling factor matrix S v The updated weight parameters in the output layer (Out proj) 560 are based on the initial weight parameter matrix W o With the second weight scaling factor matrix S v The reciprocal of is obtained by element-wise multiplication. Among them, the second weight scaling factor matrix S v It is obtained according to the calculation method of the weight factor described above based on the activation value cached in the second cache unit 530_2.
[0119] When the first matrix multiplication processing layer 540_2 performs matrix multiplication operation on the value feature and the output result of the Softmax layer 550, and then inputs the operation result into the output layer 560 for operation, the operation result of the output layer 560 does not change. Thus, when the scaling factor is inserted into the value feature processing layer (V) 520_1 and the output layer (Out proj) 560 to scale the weight parameter matrix, an operation result mathematically equivalent to that before the weight parameter matrix is scaled can be obtained, thereby ensuring the accuracy of the model prediction results.
[0120] According to an embodiment of the present disclosure, since the weight scaling factor matrix is integrated into the weight parameters of each processing layer, the distribution of activation values cached in the first cache unit 530_1 or the second cache unit 530_2 in each round is relatively concentrated, thereby reducing the loss of the model caused by the quantization process.
[0121] Figure 6 A flowchart of a compression model training method according to an embodiment of the present disclosure is schematically shown.
[0122] like Figure 6 As shown, the training method 600 may include operations S610 to S630.
[0123] In operation S610, first multimedia data as sample data is input into a compression model to obtain first probability vectors for a plurality of predetermined categories.
[0124] In operation S620, a loss value of a compression model is determined according to the first category information and the first probability vector.
[0125] In operation S630, model parameters of the compression model are adjusted based on the loss value to obtain a trained compression model.
[0126] According to an embodiment of the present disclosure, the compression model may be obtained by compressing the compression model according to the method described above. The sample data may be part of the sample data in the training set for pre-training the compression model. For example, 5%, 10% or any other proportion of data may be randomly extracted from the training set to obtain the sample data. The first multimedia data as the sample data may include category information, for example, may include first category information. The first category information represents a category among a plurality of predetermined categories.
[0127] According to an embodiment of the present disclosure, the sample data may have the same definition scope as the multimedia data described above. The compression model may output a first probability vector after processing the first multimedia data. The first probability vector includes the probability value predicted by the compression model for each of a plurality of predetermined categories. For example, the type of the first multimedia data may be an image, and the predetermined category may be an attribute of a target object in the image, such as a person, an animal, a building, etc. The type of the first multimedia data may be text, and the predetermined category may be a semantic attribute word of the text.
[0128] According to an embodiment of the present disclosure, a predetermined loss function may be used to calculate the loss value of the compression model according to the probability value corresponding to the category represented by the first category information in the first probability vector. The predetermined loss function may be, for example, a cross entropy loss function, a mean square error loss function (i.e., an L2 loss function), or a hinge loss function, etc., which is not limited in the present disclosure.
[0129] According to the embodiments of the present disclosure, the network parameters such as weight parameters in the compression model can be adjusted by using a gradient descent algorithm with the goal of minimizing the loss value, thereby realizing the training of the compression model.
[0130] Figure 7 The flowchart of the multimedia data processing method according to the embodiment of the present disclosure is schematically shown.
[0131] like Figure 7 As shown, the multimedia data processing method 700 may include operations S710 to S720.
[0132] In operation S710, multimedia data to be processed is input into a compression model to obtain a probability vector representing a category to which the multimedia data belongs.
[0133] In operation S720, a target category to which the multimedia data belongs among a plurality of predetermined categories is determined according to the probability vector.
[0134] According to an embodiment of the present disclosure, the compression model may be a deep learning model obtained by compressing the compression model according to the model compression method described above, or may be a model obtained by training the compressed deep learning model according to the compression model training method described above.
[0135] According to an embodiment of the present disclosure, the implementation principle of operation S710 is similar to the implementation principle of operation S610 described above. The probability vector may include a probability value that the multimedia data belongs to each of the plurality of predetermined categories, which will not be described in detail herein.
[0136] According to an embodiment of the present disclosure, the predetermined category corresponding to the maximum probability value in the probability vector can be used as the target category to which the multimedia data belongs. When the multimedia data is text, the compression model can be, for example, a model obtained by compressing and training the Wenxin model, etc. When the multimedia data is an image, the compression model can be, for example, a model obtained by compressing and training ResNet-50, etc.
[0137] Based on the model compression method provided by the embodiment of the present disclosure, the embodiment of the present disclosure also provides a model compression device. Figure 8 The model compression device is described in detail.
[0138] Figure 8 A block diagram of a model compression device according to an embodiment of the present disclosure is schematically shown.
[0139] like Figure 8 As shown, the model compression device 800 may include: a first obtaining module 810 , a generating module 820 , a scaling module 830 and a quantization module 840 .
[0140] The first acquisition module 810 is used to input multimedia data into the model to be compressed, and obtain the activation value matrix of each processing layer in the N cascaded processing layers in the model to be compressed, wherein the activation value matrix of the nth processing layer represents the output features obtained after the multimedia data is processed by n-1 processing layers, and N is an integer greater than 1, n=2,...N.
[0141] The generating module 820 is used to generate a weight scaling factor for each processing layer according to the distribution information of the activation values in the activation value matrix.
[0142] The scaling module 830 is used to scale the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain the parameters to be quantized of each processing layer.
[0143] The quantization module 840 is used to quantize the parameters to be quantized of each processing layer in turn based on a predetermined quantization accuracy to obtain a compression model.
[0144] According to an embodiment of the present disclosure, the scaling module may include: a scaling submodule, a first obtaining submodule and a second obtaining submodule. The scaling submodule is used to scale the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain a weight-scaled target model. The first obtaining submodule is used to input the multimedia into the weight-scaled target model to obtain an activation value of each processing layer. The second obtaining submodule is used to obtain the parameters to be quantized of each processing layer according to the distribution information of the activation value of each processing layer.
[0145] According to an embodiment of the present disclosure, the second obtaining submodule may include: a first obtaining unit and a first processing unit. The first obtaining unit is used to obtain a parameter truncation threshold of each processing layer according to the distribution information of the activation value of each processing layer. The first processing unit is used to truncate the parameters of each processing layer based on the parameter truncation threshold to obtain the parameters to be quantized of each processing layer.
[0146] According to an embodiment of the present disclosure, the first obtaining unit may include: a construction subunit, a segmentation subunit and a first determination subunit. The construction subunit is used to construct a distribution matrix according to the distribution information of the activation value of each processing layer. The segmentation subunit is used to segment the distribution matrix to obtain sub-distribution information of the activation value corresponding to each segmented area. The first determination subunit is used to determine the parameter truncation threshold corresponding to each segmented area according to the sub-distribution information.
[0147] According to an embodiment of the present disclosure, the segmentation subunit is used to segment the distribution matrix according to the number of processing channels of each processing layer to obtain sub-distribution information of the activation value corresponding to each segmented area.
[0148] According to an embodiment of the present disclosure, the segmentation subunit is used to: cluster the activation values of each processing layer to obtain a clustering result; and based on the clustering result, segment the distribution matrix to obtain sub-distribution information of the activation value corresponding to each segmented area.
[0149] According to an embodiment of the present disclosure, the segmentation subunit is used to evenly segment the distribution matrix according to a predetermined number of regions to obtain sub-distribution information of the activation value corresponding to each segmented region.
[0150] According to an embodiment of the present disclosure, the first determination subunit is used to: determine the maximum activation value corresponding to each segmented region according to the sub-distribution information; and determine the maximum activation value corresponding to each segmented region as the parameter truncation threshold corresponding to each segmented region.
[0151] According to an embodiment of the present disclosure, the generation module may include: a first determination submodule and a generation submodule. The first determination submodule is used to determine the weight scaling threshold of each processing layer according to the distribution information of the activation value of each processing layer. The generation submodule is used to generate the weight scaling factor of each processing layer according to the activation value of each processing layer and the weight scaling threshold of each processing layer.
[0152] According to an embodiment of the present disclosure, the first determination submodule may include: a first determination unit, a second determination unit, and a third determination unit. The first determination unit is used to determine, for each processing layer, a first scaling threshold according to the distribution information of the activation value corresponding to the multimedia data input in the m-1th round, where m is an integer greater than 1 and less than or equal to M. The second determination unit is used to determine the second scaling threshold according to the distribution information of the activation value corresponding to the multimedia data input in the mth round. The third determination unit is used to determine that the second scaling threshold is a weight scaling threshold in response to the second scaling threshold being greater than the first scaling threshold.
[0153] According to an embodiment of the present disclosure, the first determining unit may include: a second determining subunit and a third determining subunit. The second determining subunit is configured to determine the maximum activation value of each processing layer corresponding to the m-1th round according to the distribution information of the activation value corresponding to the multimedia data input in the m-1th round. The third determining subunit is configured to determine the maximum activation value of each processing layer corresponding to the m-1th round as the first scaling threshold.
[0154] According to an embodiment of the present disclosure, the second determining unit may include: a fourth determining subunit and a fifth determining subunit. The fourth determining subunit is configured to determine the maximum activation value of each processing layer corresponding to the mth round according to the distribution information of the activation value corresponding to the multimedia data input in the mth round. The fifth determining subunit is configured to determine the maximum activation value of each processing layer corresponding to the mth round as the second scaling threshold.
[0155] According to an embodiment of the present disclosure, the quantization module may include: a second determination submodule and a quantization submodule. The second determination submodule is used to determine a quantization factor for each processing layer according to a predetermined quantization accuracy and distribution information of the parameters to be quantized of each processing layer. The quantization submodule is used to quantize the parameters to be quantized of each processing layer according to the quantization factor to obtain a compression model.
[0156] According to an embodiment of the present disclosure, the second determination submodule may include: a fourth determination unit and a second acquisition unit. The fourth determination unit is used to determine the maximum parameter value of each processing layer based on the distribution information of the to-be-quantized parameter of each processing layer. The second acquisition unit is used to obtain a quantization factor according to a predetermined quantization accuracy and the maximum parameter value.
[0157] Based on the training method of the compression model provided by the embodiment of the present disclosure, the embodiment of the present disclosure also provides a training device for the compression model. Fig. 9 The training setup for the compression model is described in detail.
[0158] Fig. 9 A block diagram of a training device for a compression model according to an embodiment of the present disclosure is schematically shown.
[0159] like Fig. 9 As shown, the training device 900 may include: a second obtaining module 910 , a first determining module 920 and an adjusting module 930 .
[0160] The second obtaining module 910 is used to input the first multimedia data as sample data into the compression model to obtain first probability vectors for multiple predetermined categories; the first multimedia data is marked with first category information.
[0161] The first determination module 920 is used to determine the loss value of the compression model according to the first category information and the first probability vector.
[0162] The adjustment module 930 is used to adjust the model parameters of the compression model according to the loss value to obtain a trained compression model. The compression model is a compressed deep learning model obtained by using the model compression method described above.
[0163] Based on the method for processing multimedia data provided by the embodiment of the present disclosure, the embodiment of the present disclosure also provides a device for processing multimedia data. Fig.10 A device for processing multimedia data is described in detail.
[0164] Fig.10 A block diagram schematically shows a device for processing multimedia data according to an embodiment of the present disclosure.
[0165] like Fig.10 As shown, the processing device 1000 may include a third obtaining module 1010 and a second determining module 1020 .
[0166] The third obtaining module 1010 is used to input the multimedia data to be processed into the compression model to obtain a probability vector representing the category to which the multimedia data belongs; the probability vector includes a probability value of the multimedia data belonging to each of the plurality of predetermined categories.
[0167] The second determination module 1020 is used to determine the target category to which the multimedia data in the plurality of predetermined categories belongs according to the probability vector. The compression model is a compressed deep learning model obtained by using the model compression method described above. It can also be a model obtained by training the compressed model using the compression model training method described above.
[0168] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0169] According to an embodiment of the present disclosure, an electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method described above.
[0170] According to an embodiment of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute the method as described above.
[0171] According to an embodiment of the present disclosure, a computer program product includes a computer program, and the computer program implements the method described above when executed by a processor.
[0172] Fig.11 A schematic block diagram of an example electronic device 1100 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0173] like Fig.11 As shown, the device 1100 includes a computing unit 1101, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1102 or a computer program loaded from a storage unit 1108 into a random access memory (RAM) 1103. In the RAM 1103, various programs and data required for the operation of the device 1100 can also be stored. The computing unit 1101, the ROM 1102, and the RAM 1103 are connected to each other via a bus 1104. An input / output (I / O) interface 1105 is also connected to the bus 1104.
[0174] A number of components in the device 1100 are connected to the I / O interface 1105, including: an input unit 1106, such as a keyboard, a mouse, etc.; an output unit 1107, such as various types of displays, speakers, etc.; a storage unit 1108, such as a disk, an optical disk, etc.; and a communication unit 1109, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 1109 allows the device 1100 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0175] The computing unit 1101 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 1101 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 1101 performs the various methods and processes described above, such as a model compression method, a training method for a compression model, or a method for processing multimedia data. For example, in some embodiments, the model compression method, the training method for a compression model, or the method for processing multimedia data may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 1108. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 1100 via the ROM 1102 and / or the communication unit 1109. When the computer program is loaded into the RAM 1103 and executed by the computing unit 1101, one or more steps of the model compression method, the training method for a compression model, or the method for processing multimedia data described above may be performed. Alternatively, in other embodiments, the computing unit 1101 may be configured to execute a model compression method, a compression model training method, or a multimedia data processing method in any other suitable manner (e.g., by means of firmware).
[0176] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0177] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0178] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0179] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0180] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0181] A computer system may include a client and a server. The client and the server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises through computer programs running on respective computers and having a client-server relationship to each other. The server may be a cloud server, a server in a distributed system, or a server combined with a blockchain.
[0182] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0183] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A model compression method, comprising: Inputting multimedia data into a model to be compressed, obtaining an activation value matrix of each processing layer in N cascaded processing layers in the model to be compressed, wherein the activation value matrix of the nth processing layer represents output features obtained after the multimedia data is processed by n-1 processing layers located before the nth processing layer, where N is an integer greater than 1, n=2, ...N; Generating a weight scaling factor for each processing layer according to distribution information of activation values in the activation value matrix; According to the weight scaling factor of each processing layer, scaling the weight parameter of each processing layer to obtain the parameter to be quantized of each processing layer; and Based on a predetermined quantization accuracy, the parameters to be quantized of each processing layer are quantized in turn to obtain a compression model.
2. The method according to claim 1, wherein: The step of scaling the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain the parameters to be quantized of each processing layer includes: According to the weight scaling factor of each processing layer, the weight parameters of each processing layer are scaled to obtain a weight-scaled target model; Inputting the multimedia into the weight-scaled target model to obtain an activation value of each processing layer; and According to the distribution information of the activation value of each processing layer, the parameters to be quantized of each processing layer are obtained.
3. The method according to claim 2, wherein: The obtaining the to-be-quantized parameter of each processing layer according to the distribution information of the activation value of each processing layer comprises: Obtaining a cutoff threshold of each processing layer according to the distribution information of the activation value of each processing layer; and Based on the truncation threshold, the parameters of each processing layer are truncate to obtain the parameters to be quantized of each processing layer.
4. The method according to claim 3, wherein: The step of obtaining the cutoff threshold of each processing layer according to the distribution information of the activation value of each processing layer includes: Constructing a distribution matrix according to the distribution information of the activation values of each processing layer; Segmenting the distribution matrix to obtain sub-distribution information of activation values corresponding to each segmented region; and A truncation threshold corresponding to each segmented region is determined according to the sub-distribution information.
5. The method according to claim 4, wherein: The step of segmenting the distribution matrix to obtain sub-distribution information of activation values corresponding to each segmented region includes: The distribution matrix is segmented according to the processing channel identifier of the model to be compressed to obtain sub-distribution information of the activation value corresponding to each segmented area.
6. The method according to claim 4, wherein: The step of segmenting the distribution matrix to obtain sub-distribution information of activation values corresponding to each segmented region includes: Clustering the activation values of each processing layer to obtain a clustering result; and Based on the clustering result, the distribution matrix is segmented to obtain sub-distribution information of the activation value corresponding to each segmented area.
7. The method according to claim 4, wherein: The step of segmenting the distribution matrix to obtain sub-distribution information of activation values corresponding to each segmented region includes: The distribution matrix is evenly divided according to a predetermined number of regions to obtain sub-distribution information of activation values corresponding to each divided region.
8. The method according to claim 5, wherein: The step of determining a truncation threshold corresponding to each segmented region according to the sub-distribution information includes: Determining a maximum activation value corresponding to each segmented region according to the sub-distribution information; and The maximum activation value corresponding to each segmented region is determined as the truncation threshold corresponding to each segmented region.
9. The method according to claim 1, wherein: Generating a weight scaling factor for each processing layer according to the distribution information of the activation value of each processing layer includes: Determining a weight scaling threshold of each processing layer according to distribution information of activation values of each processing layer; and A weight scaling factor for each processing layer is generated according to the activation value of each processing layer and the weight scaling threshold of each processing layer.
10. The method according to claim 9, wherein: The distribution information of the activation values of each processing layer includes the distribution information of the activation values corresponding to the multimedia data input in M rounds, where M is an integer greater than 1; Determining the weight scaling threshold of each processing layer according to the distribution information of the activation value of each processing layer includes: For each of the processing layers, determining a first scaling threshold according to distribution information of activation values corresponding to the multimedia data input in the m-1th round, where m is an integer greater than 1 and less than or equal to M; determining a second scaling threshold according to distribution information of activation values corresponding to the multimedia data input in the mth round; and In response to the second scaling threshold being greater than the first scaling threshold, the second scaling threshold is determined to be the weight scaling threshold.
11. The method according to claim 10, wherein: The determining a first scaling threshold according to distribution information of activation values corresponding to the multimedia data input in the (m-1)th round includes: determining, according to the distribution information of the activation values corresponding to the multimedia data input in the m-1th round, the maximum activation value of each processing layer corresponding to the m-1th round; and The maximum activation value of each processing layer corresponding to the (m-1)th round is determined as the first scaling threshold.
12. The method according to claim 10, wherein: The determining, according to the distribution information of the activation value corresponding to the multimedia data input in the mth round, a second scaling threshold value includes: determining, according to the distribution information of the activation values corresponding to the multimedia data input in the m-th round, the maximum activation value of each processing layer corresponding to the m-th round; and The maximum activation value of each processing layer corresponding to the m-th round is determined as the second scaling threshold.
13. The method according to claim 1, wherein: Based on a predetermined quantization precision, the parameters to be quantized of each processing layer are quantized in turn to obtain a compression model, including: For each processing layer, determining a quantization factor according to the predetermined quantization accuracy and distribution information of the parameters to be quantized of each processing layer; According to the quantization factor, the parameters to be quantized of each processing layer are quantized to obtain the compression model.
14. The method according to claim 13, wherein: The step of determining a quantization factor for each processing layer according to the predetermined quantization accuracy and distribution information of the parameters to be quantized of each processing layer includes: distribution information of the to-be-quantized parameters of each processing layer, and determining the maximum parameter value of each processing layer; and The quantization factor is obtained according to the predetermined quantization accuracy and the maximum parameter value.
15. A method for training a compression model, comprising: Inputting first multimedia data as sample data into a compression model to obtain first probability vectors for a plurality of predetermined categories; The first multimedia data is marked with first category information; Determining a loss value of the compression model according to the first category information and the first probability vector; as well as According to the loss value, the model parameters of the compression model are adjusted to obtain a trained compression model, wherein the compression model is a compressed deep learning model obtained by the method described in any one of claims 1 to 14.
16. A method for processing multimedia data, comprising: Inputting the multimedia data to be processed into a compression model to obtain a probability vector representing the category to which the multimedia data belongs; The probability vector includes a probability value that the multimedia data belongs to each of a plurality of predetermined categories; as well as According to the probability vector, determine the target category to which the multimedia data belongs in the multiple predetermined categories, wherein the compression model includes a compressed deep learning model obtained by the method according to any one of claims 1 to 14.
17. A model compression device, comprising: A first obtaining module is used to input multimedia data into a model to be compressed, and obtain an activation value matrix of each processing layer in N cascaded processing layers in the model to be compressed, wherein the activation value matrix of the nth processing layer represents output features obtained after the multimedia data is processed by n-1 processing layers located before the nth processing layer, where N is an integer greater than 1, n=2, ...N; A generating module, configured to generate a weight scaling factor for each processing layer according to distribution information of activation values in the activation value matrix; A scaling module, configured to scale the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain the parameters to be quantized of each processing layer; and The quantization module is used to quantize the parameters to be quantized of each processing layer in turn based on a predetermined quantization accuracy to obtain a compression model.
18. The device according to claim 17, wherein: The scaling module comprises: A scaling submodule, used for scaling the weight parameters of each processing layer according to the weight scaling factor of each processing layer to obtain a weight-scaled target model; A first obtaining submodule is used to input the multimedia into the weight-scaled target model to obtain the activation value of each processing layer; and The second obtaining submodule is used to obtain the to-be-quantized parameter of each processing layer according to the distribution information of the activation value of each processing layer.
19. The device according to claim 18, wherein: The second obtaining submodule includes: A first obtaining unit, configured to obtain a cutoff threshold of each processing layer according to distribution information of an activation value of each processing layer; and The first processing unit is used to perform truncation processing on the parameters of each processing layer based on the truncation threshold to obtain the parameters to be quantized of each processing layer.
20. The device according to claim 19, wherein The first obtaining unit comprises: A construction subunit, configured to construct a distribution matrix according to the distribution information of the activation values of each processing layer; a segmentation subunit, configured to segment the distribution matrix to obtain sub-distribution information of activation values corresponding to each segmented region; and The first determining subunit is used to determine a truncation threshold corresponding to each segmented area according to the sub-distribution information.
21. The device according to claim 20, wherein: The segmentation subunit is used for: The distribution matrix is segmented according to the number of processing channels of the model to be compressed to obtain sub-distribution information of the activation value corresponding to each segmented area.
22. The device according to claim 20, wherein: The segmentation subunit is used for: Clustering the activation values of each processing layer to obtain a clustering result; as well as Based on the clustering result, the distribution matrix is segmented to obtain sub-distribution information of the activation value corresponding to each segmented area.
23. The device according to claim 20, wherein: The segmentation subunit is used for: The distribution matrix is evenly divided according to a predetermined number of regions to obtain sub-distribution information of activation values corresponding to each divided region.
24. The device according to claim 20, wherein: The first determining subunit is used to: Determine a maximum activation value corresponding to each segmented region according to the sub-distribution information; as well as The maximum activation value corresponding to each segmented region is determined as the truncation threshold corresponding to each segmented region.
25. The device according to claim 17, wherein: The generating module comprises: A first determination submodule is configured to determine a weight scaling threshold of each processing layer according to distribution information of activation values of each processing layer; and A generating submodule is used to generate a weight scaling factor for each processing layer according to the activation value of each processing layer and the weight scaling threshold of each processing layer.
26. The device according to claim 25, wherein The distribution information of the activation values of each processing layer includes the distribution information of the activation values corresponding to the multimedia data input in M rounds, where M is an integer greater than 1; The first determining submodule includes: A first determining unit is configured to determine, for each processing layer, a first scaling threshold according to distribution information of activation values corresponding to the multimedia data input in the m-1th round, where m is an integer greater than 1 and less than or equal to M; a second determining unit, configured to determine a second scaling threshold according to distribution information of activation values corresponding to the multimedia data input in the mth round; and A third determining unit is configured to determine, in response to the second scaling threshold being greater than the first scaling threshold, that the second scaling threshold is the weight scaling threshold.
27. The device according to claim 26, wherein: The first determining unit includes: a second determining subunit, configured to determine the maximum activation value of each processing layer corresponding to the m-1th round according to the distribution information of the activation values corresponding to the multimedia data input in the m-1th round; and The third determining subunit is used to determine the maximum activation value of each processing layer corresponding to the (m-1)th round as the first scaling threshold.
28. The device according to claim 26, wherein The second determining unit includes: a fourth determining subunit, configured to determine the maximum activation value of each processing layer corresponding to the m-th round according to the distribution information of the activation values corresponding to the multimedia data input in the m-th round; and The fifth determining subunit is used to determine the maximum activation value of each processing layer corresponding to the m-th round as the second scaling threshold.
29. The device according to claim 17, wherein: The quantization module comprises: A second determination submodule is used to determine a quantization factor for each processing layer according to the predetermined quantization accuracy and distribution information of the parameters to be quantized of each processing layer; The quantization submodule is used to quantize the parameters to be quantized of each processing layer according to the quantization factor to obtain the compression model.
30. The device according to claim 29, wherein The second determining submodule includes: a fourth determining unit, for determining the maximum parameter value of each processing layer based on the distribution information of the to-be-quantized parameter of each processing layer; and The second obtaining unit is used to obtain the quantization factor according to the predetermined quantization accuracy and the maximum parameter value.
31. A training device for a compression model, comprising: A second obtaining module, used for inputting the first multimedia data as sample data into the compression model to obtain first probability vectors for a plurality of predetermined categories; The first multimedia data is marked with first category information; A first determination module, configured to determine a loss value of the compression model according to the first category information and the first probability vector; as well as An adjustment module is used to adjust the model parameters of the compression model according to the loss value to obtain a trained compression model, wherein the compression model is a compressed deep learning model obtained by the method described in any one of claims 1 to 14.
32. A multimedia data processing device, comprising: A third obtaining module, used for inputting the multimedia data to be processed into the compression model to obtain a probability vector representing the category to which the multimedia data belongs; The probability vector includes a probability value that the multimedia data belongs to each of a plurality of predetermined categories; as well as A second determination module is used to determine the target category to which the multimedia data in the multiple predetermined categories belongs based on the probability vector, wherein the compression model includes a compressed deep learning model obtained by the method described in any one of claims 1 to 14.
33. An electronic device comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 16.
34. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-16.
35. A computer program product comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 16.
