Model generation method and device for linear quantization and electronic equipment
By generating a linear quantization model and adjusting the model parameters, the problem of converting a nonlinear quantization model into a linear quantization model is solved, resulting in reduced storage overhead and improved prediction speed and accuracy, while avoiding data privacy risks.
Patent Information
- Application Number
- CN202310318090.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2026-01-23
- Estimated Expiration
- 2043-03-28
AI Technical Summary
When deploying deep neural network models to hardware devices, how can we effectively convert nonlinear quantization models into linear quantization models to reduce storage overhead and improve prediction speed and accuracy?
By acquiring the first processing model of the nonlinear quantization model, a linear quantization model is generated, and the model parameters are adjusted to reduce storage overhead and improve prediction speed and accuracy.
This reduces model storage overhead, improves model prediction speed and accuracy, avoids data privacy issues, and reduces data acquisition costs.
Smart Images

Figure CN116542300B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of artificial intelligence, and in particular, to a linear quantization model generation method and device and electronic equipment. BACKGROUND
[0002] When deploying a deep neural network model on a hardware device, in order to reduce model storage and speed up model inference, the model can be quantized based on compression techniques such as quantization techniques. Model quantization refers to mapping floating-point numbers to corresponding integer domains in a specific processing manner. According to different mapping manners, model quantization is usually divided into non-linear quantization and linear quantization. The quantization interval of non-linear quantization is not equal, and the quantization interval of linear quantization is equal.
[0003] Because the weights and feature values in a deep neural network model are usually not uniform, using non-linear quantization can achieve higher prediction accuracy. However, in actual inference, the calculation complexity of non-linear quantization is high, so model quantization usually uses linear quantization.
[0004] Therefore, it is very important to convert a given non-linear quantization model into a linear quantization model. SUMMARY
[0005] The present disclosure aims to at least partially solve one of the technical problems in the related art.
[0006] The present disclosure proposes a linear quantization model generation method, device and electronic equipment to generate a linear quantization model from a given non-linear quantization model, thereby reducing model storage overhead and improving model prediction speed. In addition, the training or learning of the linear quantization model can be guided according to the output of the non-linear quantization model, which can improve the prediction accuracy of the linear quantization model, i.e., the expression ability of the non-linear quantization model can be used to improve the accuracy of the linear quantization model prediction.
[0007] The first aspect of the present disclosure provides a linear quantization model generation method, comprising:
[0008] obtaining a first processing model of non-linear quantization, and generating a second processing model of linear quantization according to the first processing model;
[0009] obtaining input data, and inputting the input data into the first processing model to obtain first quantized features output by at least one first network layer in the first processing model;
[0010] inputting the input data into the second processing model to obtain second quantized features output by at least one second network layer in the second processing model;
[0011] According to a difference between the first quantized feature output by the at least one first network layer and the second quantized feature output by the at least one second network layer, the model parameter in the second processing model is adjusted to obtain a target processing model.
[0012] The second aspect embodiment of the present disclosure provides another linear quantization model generation device, which comprises:
[0013] The first acquisition module is configured to acquire a first processing model of nonlinear quantization.
[0014] The generation module is configured to generate a second processing model of linear quantization according to the first processing model.
[0015] The second acquisition module is configured to acquire input data.
[0016] The first input module is configured to input the input data into the first processing model to obtain a first quantized feature output by at least one first network layer in the first processing model.
[0017] The second input module is configured to input the input data into the second processing model to obtain a second quantized feature output by at least one second network layer in the second processing model.
[0018] The adjustment module is configured to adjust a model parameter in the second processing model according to a difference between the first quantized feature output by the at least one first network layer and the second quantized feature output by the at least one second network layer, to obtain a target processing model.
[0019] The third aspect embodiment of the present disclosure provides an electronic device, comprising: at least one processor; and a memory connected with the at least one processor in communication; wherein the memory stores instructions executable 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 execute the linear quantization model generation method provided by the first aspect embodiment of the present disclosure.
[0020] The fourth aspect embodiment of the present disclosure provides a non-transitory computer readable storage medium storing computer instructions, the computer instructions being used to enable the computer to execute the linear quantization model generation method provided by the first aspect embodiment of the present disclosure.
[0021] The fifth aspect embodiment of the present disclosure provides a computer program, comprising a computer program which, when executed by a processor, implements the linear quantization model generation method of the first aspect embodiment of the present disclosure.
[0022] The above-mentioned one embodiment of the present disclosure has at least the following advantages or benefits:
[0023] By obtaining the first processing model of nonlinear quantization, and generating the second processing model of linear quantization according to the first processing model; obtaining the to-be-input data, and inputting the to-be-input data into the first processing model to obtain the first quantized feature output by at least one first network layer in the first processing model; inputting the to-be-input data into the second processing model to obtain the second quantized feature output by at least one second network layer in the second processing model; and adjusting the model parameters in the second processing model according to the difference between the first quantized feature output by the at least one first network layer and the second quantized feature output by the at least one second network layer, to obtain a target processing model. Thus, the linear quantization model can be generated according to the given nonlinear quantization model, the storage cost of the model can be reduced, and the prediction speed of the model can be improved. In addition, the training or learning of the linear quantization model can be guided according to the output of the nonlinear quantization model, and the prediction accuracy of the linear quantization model can be improved, that is, the expression ability of the nonlinear quantization model can be used to improve the prediction accuracy of the linear quantization model.
[0024] Additional aspects and advantages of the present disclosure will be in part apparent and in part pointed out hereinafter in the description of the disclosure. BRIEF DESCRIPTION OF DRAWINGS
[0025] The above-mentioned and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments, taken in conjunction with the accompanying drawings, in which:
[0026] Figure 1 Flowchart of the linear quantization model generation method provided by the first embodiment of the present disclosure;
[0027] Figure 2 Flowchart of the linear quantization model generation method provided by the second embodiment of the present disclosure;
[0028] Figure 3 Flowchart of the linear quantization model generation method provided by the third embodiment of the present disclosure;
[0029] Figure 4 Flowchart of the linear quantization model generation method provided by the fourth embodiment of the present disclosure;
[0030] Figure 5 Flowchart of the linear quantization model generation method provided by the fifth embodiment of the present disclosure;
[0031] Figure 6 Flowchart of the linear quantization model generation method provided by the fifth embodiment of the present disclosure;
[0032] Figure 7 A structural schematic diagram of a linear quantization model generation apparatus provided by Embodiment Six of the present disclosure is shown.
[0033] Figure 8 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0034] Embodiments of the present disclosure are described in detail below with reference to the accompanying drawings, in which like or similar elements are denoted by the same or similar reference signs, and examples of which are shown in the drawings. The embodiments described below by reference to the drawings are exemplary and are intended to explain the present disclosure, and cannot be understood as a limitation of the present disclosure.
[0035] A linear quantization model generation method, apparatus and electronic device of embodiments of the present disclosure are described below with reference to the accompanying drawings.
[0036] Figure 1 A flowchart of a linear quantization model generation method provided by Embodiment One of the present disclosure is shown.
[0037] The linear quantization model generation method of embodiments of the present disclosure can be applied to any electronic device to enable the electronic device to perform a linear quantization model generation function.
[0038] The electronic device can be any device with computing capability, such as a personal computer, a mobile terminal, a server, etc. The mobile terminal can be a mobile phone, a tablet computer, a personal digital assistant, a wearable device, etc. with various operating systems, touch screens and / or display screens.
[0039] As shown in Figure 1 The linear quantization model generation method can include the following steps:
[0040] Step 101: Obtain a first processing model of nonlinear quantization, and generate a second processing model of linear quantization according to the first processing model.
[0041] In embodiments of the present disclosure, the first processing model of nonlinear quantization can be given or pre-trained.
[0042] In embodiments of the present disclosure, the application scenarios of the first processing model and the second processing model are not limited.
[0043] In one possible implementation of embodiments of the present disclosure, the first processing model and the second processing model can be applied to an image recognition scenario. For example, the first processing model can be a nonlinear quantization image recognition model, and correspondingly, the second processing model can be a linear quantization image recognition model.
[0044] The image recognition model can include, but is not limited to, an image classification model (inputting image data and outputting a category to which the image data belongs), an object detection model (inputting image data and outputting two-dimensional detection information (such as two-dimensional position information of at least one detection box and a category to which a target in the detection box belongs) and / or three-dimensional detection information (such as an orientation angle, a depth, and a size of a target in the detection box) in the image data), a character recognition model (inputting image data and outputting a character recognition result or an OCR (Optical Character Recognition) recognition result), an image retrieval model (inputting image data and outputting an image, a video, or the like), and the like.
[0045] In another possible implementation of the embodiments of the present disclosure, the first processing model and the second processing model can be applied to a text recognition scene or a text processing scene. For example, the first processing model can be a nonlinear quantized text processing model, and correspondingly, the second processing model can be a linear quantized text processing model.
[0046] The text processing model can include, but is not limited to, a text classification model (inputting text data and outputting a category to which the text data belongs), an entity word extraction model (inputting text data and outputting an entity word in the text data), a text translation model (inputting text data in a first language and outputting text data in a second language, where the first language is different from the second language, for example, the first language can be Chinese, and the second language can be English), and the like.
[0047] In another possible implementation of the embodiments of the present disclosure, the first processing model and the second processing model can be applied to a speech recognition scene or a speech processing scene. For example, the first processing model can be a nonlinear quantized speech processing model, and correspondingly, the second processing model can be a linear quantized speech processing model.
[0048] The speech processing model can include, but is not limited to, a speech recognition model (inputting speech data and outputting text information), a timbre conversion model (inputting speech data in a first timbre and outputting speech data in a second timbre, where the first timbre is different from the second timbre, for example, the first timbre can be an old man's voice, and the second timbre can be a child's voice), a speech translation model (inputting speech data in a first language and outputting speech data in a second language), and the like.
[0049] In the embodiments of the present disclosure, the linear quantized second processing model can be generated according to the first processing model. For example, a linear quantization manner of the first processing model can be set, and the first processing model is linearly quantized according to the linear quantization manner to obtain the linear quantized second processing model.
[0050] In step 102, the to-be-input data is obtained and input into the first processing model to obtain first quantized features output by at least one first network layer in the first processing model.
[0051] In the embodiments of the present disclosure, the to-be-input data is related to the application scenarios of the first processing model and the second processing model. For example, when the first processing model and the second processing model are applied to an image recognition scenario, the to-be-input data can be image data; for another example, when the first processing model and the second processing model are applied to a text recognition scenario or a text processing scenario, the to-be-input data can be text data; for another example, when the first processing model and the second processing model are applied to a speech recognition scenario or a speech processing scenario, the to-be-input data can be speech data (or audio data).
[0052] In the embodiments of the present disclosure, the first processing model can include at least one network layer (denoted as a first network layer in the present disclosure), and when the number of the first network layers is multiple, the output of a previous first network layer is the input of a next first network layer.
[0053] In the embodiments of the present disclosure, the to-be-input data can be input into the first processing model to obtain quantized features (denoted as first quantized features in the present disclosure) output by at least one first network layer in the first processing model.
[0054] In step 103, the to-be-input data is input into the second processing model to obtain second quantized features output by at least one second network layer in the second processing model.
[0055] In the embodiments of the present disclosure, the second processing model can also include at least one network layer (denoted as a second network layer in the present disclosure), and the number of the second network layers is the same as that of the first network layers.
[0056] Similarly, the to-be-input data can be input into the second processing model to obtain quantized features (denoted as second quantized features in the present disclosure) output by at least one second network layer in the second processing model.
[0057] In step 104, model parameters in the second processing model are adjusted according to the difference between the first quantized features output by at least one first network layer and the second quantized features output by at least one second network layer to obtain a target processing model.
[0058] In the embodiments of the present disclosure, the model parameters in the second processing model can be adjusted according to the difference (or quantization difference) between the first quantized features output by at least one first network layer and the second quantized features output by at least one second network layer to obtain the target processing model.
[0059] In a possible implementation of the embodiments of the present disclosure, the value (i.e., the loss value) of the first loss function can be determined according to the difference between the first quantized features output by the at least one first network layer and the second quantized features output by the at least one second network layer, which is denoted as the second loss value in the present disclosure.
[0060] As a possible implementation, when the number of the first network layers and the second network layers is one, the second loss value can be determined according to the difference between the first quantized features output by the first network layer and the second quantized features output by the second network layer, where the second loss value is positively correlated with the difference, that is, the greater the difference, the greater the value of the second loss value, and vice versa, the smaller the difference, the smaller the value of the second loss value.
[0061] As another possible implementation, when the number of the first network layers and the second network layers is both multiple, the loss value of the i th layer can be determined according to the difference between the first quantized features output by the i th first network layer in the first processing model and the second quantized features output by the i th second network layer in the second processing model, so that in the present disclosure, the second loss value can be determined according to the loss values of the layers.
[0062] Wherein, i is a positive integer, and i is less than or equal to M, M is the number of the first network layers or the second network layers.
[0063] Therefore, in the present disclosure, the model parameters in the second processing model can be adjusted according to the second loss value to obtain the target processing model of linear quantization.
[0064] As an example, the model parameters in the second processing model can be adjusted according to the second loss value to minimize the second loss value.
[0065] It should be noted that the above only takes the end condition or termination condition of model training as an example of minimizing the second loss value, and in actual application, other end conditions can also be set, such as the number of training times reaching a set number, the training time reaching a set time, etc., and the present disclosure does not limit this.
[0066] The linear quantization model generation method of this disclosure involves obtaining a first processing model of nonlinear quantization and generating a second processing model of linear quantization based on the first processing model; obtaining input data and inputting the input data into the first processing model to obtain a first quantization feature output by at least one first network layer in the first processing model; inputting the input data into the second processing model to obtain a second quantization feature output by at least one second network layer in the second processing model; and adjusting the model parameters in the second processing model based on the difference between the first quantization feature output by at least one first network layer and the second quantization feature output by at least one second network layer to obtain a target processing model. Therefore, a linear quantization model can be generated based on a given nonlinear quantization model, reducing model storage overhead and improving prediction speed. Furthermore, using the output of the nonlinear quantization model to guide the training or learning of the linear quantization model can improve the prediction accuracy of the linear quantization model; that is, the expressive power of the nonlinear quantization model can be used to improve the prediction accuracy of the linear quantization model.
[0067] To clearly illustrate how the above embodiments obtain the input data, this disclosure also proposes a linear quantization model generation method.
[0068] Figure 2 This is a flowchart illustrating the linear quantization model generation method provided in Embodiment 2 of this disclosure.
[0069] like Figure 2 As shown, the linear quantization model generation method may include the following steps:
[0070] Step 201: Obtain the first processing model for nonlinear quantization, and generate the second processing model for linear quantization based on the first processing model.
[0071] The explanation of step 201 can be found in the relevant description in any embodiment of this disclosure, and will not be repeated here.
[0072] Step 202: Obtain randomly generated initial input data.
[0073] In this embodiment of the disclosure, randomly generated initial input data can be obtained, which can also be referred to as randomly distributed data.
[0074] The data type of the initial input data matches the data to be input. For example, when the data to be input is image data, the initial input data is also image data. Similarly, when the data to be input is text data, the initial input data is also text data. And when the data to be input is voice data (or audio data), the initial input data is also voice data (or audio data).
[0075] In step 203, statistical information of the BatchNorm module in each first network layer in the first processing model is obtained; wherein the statistical information is used to indicate the first mean and / or the first variance of the output feature of the BatchNorm module.
[0076] In the embodiments of the present disclosure, the first processing model can be pre-trained by using sample data, wherein the data type of the sample data matches the to-be-input data, and after the first processing model is trained, the statistical information of the BatchNorm module in each first network layer in the first processing model can be obtained, wherein the statistical information is used to indicate the first mean and / or the first variance of the output feature of the BatchNorm module.
[0077] For example, the output feature of the BatchNorm module in each first network layer in the first processing model can be obtained after one sample data is input into the first processing model, and the corresponding multiple output features of the BatchNorm module in each first network layer can be obtained after multiple sample data are input, and the statistical information of the BatchNorm module in the first network layer can be determined according to the multiple output features.
[0078] In step 204, the initial input data is input into the first processing model to obtain the target feature of multiple dimensions output by the BatchNorm module in each first network layer.
[0079] In the embodiments of the present disclosure, the initial input data can be input into the first processing model to obtain the target feature of multiple dimensions output by the BatchNorm module in each first network layer.
[0080] For example, taking the first processing model as a nonlinear quantification image recognition model, the output of the BatchNorm module can be c target features b x h x w, wherein c represents a dimension component, b represents a batch (that is, a batch of images, and multiple images are included in the same batch), h represents a height component of the feature, and w represents a width component of the feature.
[0081] In step 205, the first loss value is generated according to the statistical information of the BatchNorm module in each first network layer and the target feature of multiple dimensions.
[0082] In the embodiments of the present disclosure, the value of the second loss function can be determined according to the statistical information of the BatchNorm module in each first network layer and the target feature of multiple dimensions output by the BatchNorm module in the first network layer, which is recorded as the first loss value in the present disclosure.
[0083] As an example, for any one layer of the first network layer, the second mean and / or the second variance can be determined according to the target features of multiple dimensions output by the BatchNorm module in the layer of the first network layer, and the first loss value can be determined according to the statistical information of the BatchNorm module in the layer of the first network layer and the second mean and / or the second variance.
[0084] In step 206, the initial input data is adjusted according to the first loss value to obtain the to-be-input data.
[0085] In the embodiments of the present disclosure, the initial input data can be adjusted according to the first loss value to obtain the to-be-input data.
[0086] As an example, the initial input data can be adjusted according to the first loss value to minimize the first loss value, so that the adjusted initial input data can be used as the to-be-input data.
[0087] In step 207, the to-be-input data is input into the first processing model to obtain the first quantized features output by at least one layer of the first network layer in the first processing model.
[0088] In step 208, the to-be-input data is input into the second processing model to obtain the second quantized features output by at least one layer of the second network layer in the second processing model.
[0089] In step 209, the model parameters in the second processing model are adjusted according to the difference between the first quantized features output by at least one layer of the first network layer and the second quantized features output by at least one layer of the second network layer to obtain the target processing model.
[0090] The explanation of steps 207 to 209 can be referred to the related description in any embodiment of the present disclosure, which will not be repeated here.
[0091] The model generation method of linear quantization in the embodiments of the present disclosure can realize model quantization in a data-free manner, that is, automatically generate the training data required for the linear quantization model, which can reduce the cost of data acquisition and avoid data privacy and other problems.
[0092] In order to clearly illustrate how the second loss value is generated according to the statistical information of the BatchNorm module in each layer of the first network layer and the target features of multiple dimensions in any embodiment of the present disclosure, the present disclosure further provides a model generation method of linear quantization.
[0093] Figure 3 The flowchart of the model generation method of linear quantization provided in Embodiment Three of the present disclosure.
[0094] As Figure 3As shown, the model generation method of linear quantization can include the following steps:
[0095] In step 301, a first processing model of nonlinear quantization is obtained, and a second processing model of linear quantization is generated according to the first processing model.
[0096] In step 302, initial input data randomly generated is obtained, and statistical information of a BatchNorm module in each first network layer in the first processing model is obtained.
[0097] The statistical information is used to indicate a first mean and / or a first variance of the output features of the BatchNorm module.
[0098] In step 303, the initial input data is input into the first processing model to obtain target features of multiple dimensions output by the BatchNorm module in each first network layer.
[0099] The explanation of steps 301-303 can be referred to the related description in any embodiment of the present disclosure, which will not be repeated here.
[0100] In step 304, for any first network layer, a second mean and / or a second variance of the target features of multiple dimensions output by the BatchNorm module in the first network layer are determined.
[0101] In the embodiments of the present disclosure, for any first network layer in the first processing model, the second mean and / or the second variance of the target features of multiple dimensions output by the BatchNorm module in the first network layer can be determined.
[0102] In step 305, according to the statistical information of the BatchNorm module in the first network layer, and according to the second mean and / or the second variance, a first sub-loss value corresponding to the first network layer is determined.
[0103] In the embodiments of the present disclosure, according to the statistical information of the BatchNorm module in the first network layer, and according to the second mean and / or the second variance, the first sub-loss value corresponding to the first network layer can be determined.
[0104] As an example, when the statistical information is used to indicate the first mean of the output features of the BatchNorm module, the first sub-loss value corresponding to the first network layer can be determined according to a first difference between the first mean indicated by the statistical information of the BatchNorm module in the first network layer and the second mean. The first sub-loss value is positively correlated with the first difference.
[0105] As another example, when the statistical information is used to indicate the first variance of the output feature of the BatchNorm module, the first sub-loss value corresponding to the first network layer can be determined according to a second difference between the first variance and the second variance indicated by the statistical information of the BatchNorm module in the first network layer. The first sub-loss value is positively correlated with the second difference.
[0106] As another example, when the statistical information is used to indicate the first variance of the output feature of the BatchNorm module, the first sub-loss value corresponding to the first network layer can be determined according to a second difference between the first variance and the second variance indicated by the statistical information of the BatchNorm module in the first network layer. The first sub-loss value is positively correlated with the second difference.
[0107] As an example, the first loss term can be determined according to a second difference between the first variance and the second variance indicated by the statistical information of the BatchNorm module in the first network layer, where the first loss term is positively correlated with the second difference, and the second loss term can be determined according to a first difference between the first mean value and the second mean value indicated by the statistical information of the BatchNorm module in the first network layer, where the second loss term is positively correlated with the first difference. Therefore, in the present disclosure, the first sub-loss value corresponding to the first network layer can be determined according to the first loss term and the second loss term.
[0108] The first sub-loss value is positively correlated with the first loss term, and the first sub-loss value is also positively correlated with the second loss term.
[0109] Step 306: determining the first loss value according to the first sub-loss values of the first network layers.
[0110] In the embodiments of the present disclosure, the first loss value can be determined according to the first sub-loss values of the first network layers in the first processing model.
[0111] As a possible implementation manner, the mean value of the first sub-loss values of the first network layers can be taken as the first loss value.
[0112] As another possible implementation manner, the cumulative sum of the first sub-loss values of the first network layers can be taken as the first loss value.
[0113] As a further possible implementation, weights of the layers of the first network can be obtained, and the first sub-loss values of the layers of the first network are weighted and summed according to the weights of the layers of the first network to obtain the first loss value.
[0114] At step 307, the initial input data is adjusted according to the first loss value to obtain to-be-input data.
[0115] At step 308, the to-be-input data is input into the first processing model to obtain first quantized features output by at least one layer of the first network in the first processing model.
[0116] At step 309, the to-be-input data is input into the second processing model to obtain second quantized features output by at least one layer of the second network in the second processing model.
[0117] At step 310, model parameters in the second processing model are adjusted according to a difference between the first quantized features output by the at least one layer of the first network and the second quantized features output by the at least one layer of the second network to obtain a target processing model.
[0118] The explanation of steps 307 to 310 can be referred to the related description in any embodiment of the present disclosure, and will not be repeated here.
[0119] The linear quantization model generation method of the embodiments of the present disclosure can realize generation of training data required for generating a linear quantization model according to statistical information of BatchNorm modules in the layers of the first network in the first processing model, and improves the effectiveness of data generation.
[0120] In order to clearly illustrate how the first loss value is generated according to the difference between the first quantized features output by the layers of the first network and the second quantized features output by the layers of the second network in any embodiment of the present disclosure, the present disclosure further provides a linear quantization model generation method.
[0121] Figure 4 A flowchart of the linear quantization model generation method provided in Embodiment Four of the present disclosure is shown.
[0122] As shown in Figure 4 , the linear quantization model generation method can include the following steps:
[0123] At step 401, a first processing model of non-linear quantization is obtained, and a second processing model of linear quantization is generated according to the first processing model.
[0124] At step 402, to-be-input data is obtained, and the to-be-input data is input into the first processing model to obtain first quantized features output by multiple layers of the first network in the first processing model.
[0125] In step 403, the to-be-input data is input into the second processing model to obtain second quantized features output by a plurality of second network layers in the second processing model.
[0126] The explanations of steps 401 to 403 can refer to the related descriptions in any embodiment of the present disclosure, which will not be repeated here.
[0127] In step 404, for any second network layer, a first network layer corresponding to the second network layer is determined from the plurality of first network layers.
[0128] In the embodiments of the present disclosure, for any second network layer in the second processing model, a first network layer corresponding to the second network layer can be determined from the plurality of first network layers in the first processing model. For example, for an i-th second network layer in the second processing model, the first network layer corresponding to the i-th second network layer can be an i-th first network layer in the first processing model.
[0129] wherein i is a positive integer, i is less than or equal to M, and M is the number of the first network layers or the second network layers.
[0130] In step 405, a second sub-loss value corresponding to the second network layer is generated according to a difference between the second quantized features output by the second network layer and the first quantized features output by the corresponding first network layer.
[0131] In the embodiments of the present disclosure, the second sub-loss value corresponding to the second network layer can be generated according to the difference between the second quantized features output by the second network layer and the first quantized features output by the first network layer corresponding to the second network layer.
[0132] wherein the second sub-loss value is positively correlated with the difference.
[0133] In step 406, a second loss value is determined according to the second sub-loss values corresponding to the plurality of second network layers.
[0134] In the embodiments of the present disclosure, the second loss value can be determined according to the second sub-loss values corresponding to the plurality of second network layers.
[0135] As a possible implementation manner, a mean value of the second sub-loss values of the plurality of second network layers can be taken as the second loss value.
[0136] As another possible implementation manner, a cumulative sum of the second sub-loss values of the plurality of second network layers can be taken as the second loss value.
[0137] As still another possible implementation manner, weights of the plurality of second network layers can be obtained, and the second sub-loss values of the plurality of second network layers are weighted and summed according to the weights of the plurality of second network layers to obtain the second loss value.
[0138] Therefore, the second loss value can be determined according to different manners, and flexibility and applicability of the method can be improved.
[0139] In step 407, the model parameters in the second processing model are adjusted according to the second loss value to obtain a target processing model.
[0140] The explanation of step 407 can be referred to the related description in any embodiment of the present disclosure, which will not be repeated here.
[0141] The model generation method of linear quantization in the embodiments of the present disclosure can determine the loss value corresponding to the second processing model according to the sub-loss value corresponding to each layer of the second network in the second processing model, and can improve the accuracy of loss calculation.
[0142] In order to clearly illustrate how the second processing model of linear quantization is generated according to the first processing model in any embodiment of the present disclosure, the present disclosure further provides a model generation method of linear quantization.
[0143] Figure 5 The flowchart of the model generation method of linear quantization provided in the fifth embodiment of the present disclosure.
[0144] As shown in the flowchart, the model generation method of linear quantization can include the following steps: Figure 5
[0145] In step 501, a first processing model of non-linear quantization is obtained.
[0146] The explanation of step 501 can be referred to the related description in any embodiment of the present disclosure, which will not be repeated here.
[0147] In step 502, a linear quantization manner corresponding to at least one layer of the first network in the first processing model is obtained.
[0148] In the embodiments of the present disclosure, the linear quantization manner corresponding to each layer of the first network in the first processing model can adopt a standard linear stack quantization manner, or can be selected according to different hardware platforms, which is not limited in the present disclosure.
[0149] In step 503, at least one layer of the first network is linearly quantized according to the linear quantization manner corresponding to the at least one layer of the first network to obtain a second processing model of linear quantization.
[0150] In the embodiments of the present disclosure, each layer of the first network can be linearly quantized according to the linear quantization manner of the layer of the first network to obtain a second network layer corresponding to the layer in the second processing model.
[0151] In step 504, the to-be-input data is obtained and input into the first processing model to obtain first quantized features output by at least one first network layer in the first processing model.
[0152] In step 505, the to-be-input data is input into the second processing model to obtain second quantized features output by at least one second network layer in the second processing model.
[0153] In step 506, the model parameters in the second processing model are adjusted according to a difference between the first quantized features output by the at least one first network layer and the second quantized features output by the at least one second network layer, to obtain a target processing model.
[0154] The explanation of steps 504 to 506 can refer to the related description in any embodiment of the present disclosure, and will not be repeated here.
[0155] The linear quantization model generation method of the embodiments of the present disclosure can realize conversion of a nonlinear quantization model into a hardware-friendly linear quantization model according to linear quantization manners of network layers corresponding to each layer of the nonlinear quantization model, and improve the effectiveness of linear quantization model generation.
[0156] In related technologies, when performing model quantization, two quantization manners, data-based and data-free, are divided according to whether calibration data is used, wherein the data-based quantization manner usually needs to provide certain calibration data to simulate the quantization process, and improve the prediction accuracy of the quantization model by minimizing the error on the calibration data. The data-free quantization manner no longer depends on the calibration manner, but performs quantization simulation through data or model statistical information.
[0157] The above-mentioned data-based quantization manner usually needs to provide calibration data homologous to the target data set, and needs to consume certain manpower and material resources for data collection. Moreover, in the data collection process, data privacy and other problems are often encountered. To solve this problem, the data-free quantization manner can be used for model quantization.
[0158] Therefore, it is very important to convert a nonlinear quantization model into a linear quantization model without using calibration data.
[0159] In any one of the embodiments of the present disclosure, for a given nonlinear quantization model, first, data imitation can be performed through the statistical information of each network layer in the nonlinear quantization model. At the same time, the linear quantization mode of each network layer in the nonlinear model can be defined according to the nonlinear model to obtain the corresponding linear quantization model. Then, the imitated data can be operated through the nonlinear quantization model and the linear quantization model respectively to obtain the output of each network layer in the model. Finally, the accuracy of the linear quantization model is restored by minimizing the quantization difference of the output of each network layer in the model, so as to obtain a deployment-friendly linear quantization model.
[0160] In this way, the nonlinear quantization model can be converted into a hardware-friendly linear quantization model, and the accuracy of the nonlinear quantization model is fully utilized. In addition, the data cost is reduced in a data-free manner, and the problems of data privacy and the like are avoided.
[0161] The process of converting the nonlinear quantization model into the linear quantization model in a data-free manner will be described in detail below. Figure 6
[0162] The process of converting the nonlinear quantization model into the linear quantization model mainly includes the following steps: inputting the nonlinear quantization model, performing data imitation, generating the linear quantization model, minimizing the difference between the linear quantization and the nonlinear quantization on the imitated data, and outputting the linear quantization model with restored accuracy, etc.
[0163] (1) Input the nonlinear quantization model.
[0164] (2) Perform data imitation. The statistical information of the nonlinear quantization model is mainly used, wherein the statistical information mainly refers to the mean and / or variance of the BatchNorm module (located between two convolution modules, or located between the convolution module and the activation function) in each network layer of the model, and the mean and / or variance in the statistical information are used as learning labels. Then, a random distribution data to be learned is given, and the random distribution data is input into the nonlinear quantization model to obtain the feature mean and / or variance output by the BatchNorm module in each network layer of the nonlinear quantization model, and the learning labels are compared to calculate the loss value. The loss value is gradually optimized through the back propagation method, and finally the trained imitated data (denoted as input data in the present disclosure) can be obtained.
[0165] (3) According to the input nonlinear quantization model, redefine the linear quantization mode of each network layer. The linear quantization mode can adopt a standard linear quantization mode, or can be selected according to different hardware platforms, so as to obtain a linear quantization model to be optimized.
[0166] (4) After (2) and (3) are completed, the cloned data is respectively input into the nonlinear quantization model and the linear quantization model to be optimized, and the quantized features output by each network layer of the nonlinear quantization model and the quantized features output by each network layer of the linear quantization model are obtained respectively. However, the quantization differences of each network layer in the two models can be calculated, and the quantization differences of each network layer are added as the quantization difference loss. Finally, according to the difference loss, the model parameters of each network layer of the linear quantization model are optimized by back propagation, so as to reduce the quantization difference between the two models and improve the accuracy of the linear quantization model.
[0167] (5) The linear quantization model with restored accuracy is output.
[0168] In summary, the nonlinear quantization model can be converted into a hardware-friendly linear quantization model. The expression capability of the nonlinear quantization model is used to improve the prediction accuracy of the linear quantization model. The data-free method reduces the data cost and avoids data privacy problems.
[0169] The linear quantization model generation method provided by the above Figures 1 to 5 The present disclosure also provides a linear quantization model generation device. The linear quantization model generation device corresponds to the linear quantization model generation method provided by the above Figures 1 to 5 The linear quantization model generation device corresponds to the linear quantization model generation method provided by the above
[0170] Figure 7 The linear quantization model generation device provided by the above
[0171] As Figure 7 shown, the linear quantization model generation device 700 can include a first acquisition module 701, a generation module 702, a second acquisition module 703, a first input module 704, a second input module 705, and an adjustment module 706.
[0172] The first acquisition module 701 is configured to acquire a first processing model of nonlinear quantization.
[0173] The generation module 702 is configured to generate a second processing model of linear quantization according to the first processing model.
[0174] The second acquisition module 703 is configured to acquire input data.
[0175] The first input module 704 is configured to input the to-be-input data into the first processing model to obtain first quantized features output by at least one first network layer in the first processing model.
[0176] The second input module 705 is configured to input the to-be-input data into the second processing model to obtain second quantized features output by at least one second network layer in the second processing model.
[0177] The adjustment module 706 is configured to adjust model parameters in the second processing model according to a difference between the first quantized features output by the at least one first network layer and the second quantized features output by the at least one second network layer, to obtain a target processing model.
[0178] In a possible implementation of the embodiments of the present disclosure, the second acquisition module 703 is specifically configured to: acquire initial input data randomly generated; acquire statistical information of a BatchNorm module in each first network layer; the statistical information is used to indicate a first mean and / or a first variance of output features of the BatchNorm module; input the initial input data into the first processing model to obtain target features of multiple dimensions output by the BatchNorm module in each first network layer; generate a first loss value according to the statistical information of the BatchNorm module in each first network layer and the target features of the multiple dimensions; and adjust the initial input data according to the first loss value to obtain the to-be-input data.
[0179] In a possible implementation of the embodiments of the present disclosure, the second acquisition module 703 is specifically configured to: for any first network layer, determine a second mean and / or a second variance of the target features of the multiple dimensions output by the BatchNorm module in the first network layer; determine a first sub-loss value corresponding to the first network layer according to the statistical information of the BatchNorm module in the first network layer and according to the second mean and / or the second variance; and determine the first loss value according to the first sub-loss values of the first network layers.
[0180] In a possible implementation of the embodiments of the present disclosure, the second acquisition module 703 is specifically configured to: determine a first loss term according to a difference between the first variance and the second variance indicated by the statistical information of the BatchNorm module in the first network layer; determine a second loss term according to a difference between the first mean and the second mean indicated by the statistical information of the BatchNorm module in the first network layer; and determine the first sub-loss value corresponding to the first network layer according to the first loss term and the second loss term.
[0181] In a possible implementation of the embodiment of the present disclosure, the adjusting module 706 is specifically configured to: generate a second loss value according to a difference between the first quantized features output by the at least one first network layer and the second quantized features output by the at least one second network layer; and adjust the model parameters in the second processing model according to the second loss value to obtain the target processing model.
[0182] In a possible implementation of the embodiment of the present disclosure, the first network layer and the second network layer are both multi-layer, and the adjusting module 706 is specifically configured to: for any one second network layer, determine a corresponding first network layer from the multi-layer first network layer; generate a second sub-loss value corresponding to the second network layer according to a difference between the second quantized features output by the second network layer and the first quantized features output by the corresponding first network layer; and determine the second loss value according to the second sub-loss values corresponding to the multi-layer second network layer.
[0183] In a possible implementation of the embodiment of the present disclosure, the adjusting module 706 is specifically configured to: take a mean value of the second sub-loss values of the multi-layer second network layer as the second loss value; take a cumulative sum of the second sub-loss values of the multi-layer second network layer as the second loss value; obtain weights of the multi-layer second network layer, and perform weighted summation on the second sub-loss values of the multi-layer second network layer according to the weights of the multi-layer second network layer to obtain the second loss value.
[0184] In a possible implementation of the embodiment of the present disclosure, the generating module 702 is specifically configured to: obtain a linear quantization manner corresponding to the at least one first network layer; and perform linear quantization processing on the at least one first network layer according to the linear quantization manner corresponding to the at least one first network layer to obtain the linearly quantized second processing model.
[0185] In a possible implementation of the embodiment of the present disclosure, the to-be-input data is image data, the first processing model is a nonlinearly quantized image recognition model, and the second processing model or the target processing model is a linearly quantized image recognition model; or the to-be-input data is text data, the first processing model is a nonlinearly quantized text processing model, and the second processing model or the target processing model is a linearly quantized text processing model; or the to-be-input data is voice data, the first processing model is a nonlinearly quantized voice processing model, and the second processing model or the target processing model is a linearly quantized voice processing model.
[0186] The linear quantization model generation apparatus of this disclosure acquires a first processing model of nonlinear quantization and generates a second processing model of linear quantization based on the first processing model; acquires input data and inputs the input data into the first processing model to obtain a first quantization feature output by at least one first network layer in the first processing model; inputs the input data into the second processing model to obtain a second quantization feature output by at least one second network layer in the second processing model; and adjusts the model parameters in the second processing model based on the difference between the first quantization feature output by at least one first network layer and the second quantization feature output by at least one second network layer to obtain a target processing model. Therefore, it is possible to generate a linear quantization model based on a given nonlinear quantization model, which can reduce the model's storage overhead and improve the model's prediction speed. Furthermore, by guiding the training or learning of the linear quantization model based on the output of the nonlinear quantization model, the prediction accuracy of the linear quantization model can be improved; that is, the expressive power of the nonlinear quantization model can be used to improve the prediction accuracy of the linear quantization model.
[0187] To implement the above embodiments, this disclosure also proposes an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements the linear quantization model generation method proposed in any of the foregoing embodiments of this disclosure.
[0188] To implement the above embodiments, this disclosure also proposes a non-transitory computer-readable storage medium storing a computer program that, when executed by a processor, implements the linear quantization model generation method as proposed in any of the foregoing embodiments of this disclosure.
[0189] To implement the above embodiments, this disclosure also proposes a computer program product that, when the instructions in the computer program product are executed by a processor, performs a linear quantization model generation method as proposed in any of the foregoing embodiments of this disclosure.
[0190] Figure 8 A block diagram of an exemplary electronic device suitable for implementing embodiments of the present disclosure is shown. Figure 8 The electronic device 12 shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments disclosed herein.
[0191] like Figure 8 As shown, the electronic device 12 is represented in the form of a general-purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting different system components (including system memory 28 and processing unit 16).
[0192] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. Examples of these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0193] Electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by electronic device 12, including volatile and non-volatile media, removable and non-removable media.
[0194] Memory 28 may include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 30 and / or cache memory 32. Electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be used to read and write non-removable, non-volatile magnetic media (… Figure 8 Not shown; usually referred to as a "hard drive"). Although Figure 8 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disc drive for reading and writing to a removable non-volatile optical disc (e.g., a compact disc read-only memory (CD-ROM), a digital video disc read-only memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this disclosure.
[0195] Program / utility 40 having a set of program modules 42 can be stored in memory 28 by way of example, such program modules 42 include an operating system, one or more application programs, other program modules, and program data, each or some combination thereof, which can include implementation of the network environment in each or some combination thereof. Program modules 42 generally carry out the functions and / or methodologies described in embodiments of the disclosure.
[0196] Electronic device 12 can also communicate with one or more external devices 14 such as a keyboard or pointing device, a display 24, etc. which can be used in connection with the electronic device 12, and / or one or more devices that enable a user to interact with the electronic device 12 and / or one or more devices that enable the electronic device 12 to communicate with one or more other computing devices. Such communication can be via input / output (I / O) interface 22. Similarly, the electronic device 12 can communicate with one or more networks such as a local area network (LAN), a wide area network (WAN), e.g., the Internet, and / or a public network, such as the Internet via network adapter 20. As will be appreciated, the network adapter 20 can include any Figure 8 As shown, network adapter 20 communicates with the other components of electronic device 12 via bus 18. It should be understood that although not shown, other hardware and / or software components could be used in conjunction with electronic device 12. These include, but are not limited to, microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data archival storage systems, etc.
[0197] Processing unit 16 can execute the various functions and data processing by running programs stored in system memory 28, such as implementing the methods described in the aforementioned embodiments.
[0198] In the description of the specification, the description of the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present disclosure. In the description of the specification, the illustrative description of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any suitable manner in any one or more embodiments or examples. In addition, the person skilled in the art can combine and combine the different embodiments or examples described in the specification and the features of the different embodiments or examples without contradiction.
[0199] Moreover, the terms "first", "second", etc. are used herein only to describe different instances, and do not imply or suggest relative importance or a number of indicated technical features. Thus, features defined with "first", "second" can include at least one of such features, either explicitly or implicitly. In the description of the disclosure, the meaning of "a plurality of" is at least two, for example, two, three, etc., unless otherwise explicitly and specifically limited.
[0200] Any process or method descriptions or blocks in flow charts herein, and elsewhere, can be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps in the process. Alternate implementations are included within the scope of the preferred embodiments of the present disclosure in which additional functionality can be added or further orders of execution can be implemented without departing from the spirit of the disclosure.
[0201] Logic and / or steps represented in flow charts herein, and elsewhere, can be embodied in computer-readable media, for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor- containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions, or a combination thereof. For purposes of this specification, a "computer- readable medium" can be any apparatus that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. The computer-readable medium can specifically include a hardware apparatus, such as a wired or wireless communication link, a portable memory device, a memory in a mobile phone, a memory in a computer, etc. More specific examples (a non-exhaustive list) of the computer-readable medium include the following: an electrical connection (electrical) having one or more wires, a portable computer diskette (magnetic), a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber (optical), and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium can be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, for example via an optical scanner, then compiled, interpreted, or otherwise processed, and stored in a computer memory in order to be executed.
[0202] It should be understood that portions of the present disclosure can be realized with hardware, software, firmware or a combination thereof. In the above embodiments, a plurality of steps or methods can be realized with software or firmware stored in a memory and executed by a suitable instruction execution system. As such, if realized with hardware and in another embodiment, any one or a combination of the following technologies known in the art can be used: discrete logic circuit with logic gate circuit for implementing logic functions on data signals, application specific integrated circuit with suitable combination logic gate circuit, programmable gate array (PGA), field programmable gate array (FPGA), etc.
[0203] Those skilled in the art of the present technology can understand that all or part of the steps carried out by the above-mentioned embodiment method can be completed by a program instructing the relevant hardware, and the program can be stored in a computer readable storage medium. When the program is executed, it includes one of the steps of the method embodiment or a combination thereof.
[0204] In addition, each functional unit in each embodiment of the present disclosure can be integrated into one processing module, or each unit can exist physically alone, or two or more units can be integrated into one module. The above-mentioned integrated module can be realized in the form of hardware or in the form of a software functional module. When the integrated module is realized in the form of a software functional module and sold or used as an independent product, it can also be stored in a computer readable storage medium.
[0205] The above-mentioned storage medium can be a read-only memory, a magnetic disk or an optical disk, etc. Although the embodiments of the present disclosure have been shown and described above, it should be understood that the above-mentioned embodiments are exemplary and cannot be understood as limiting the present disclosure, and those skilled in the art can make changes, modifications, replacements and variations to the above-mentioned embodiments within the scope of the present disclosure.
Claims
1. A method for generating linearly quantized models, characterized in that, The method includes: Obtain a first processing model for nonlinear quantization, and generate a second processing model for linear quantization based on the first processing model; The input data is obtained and input into the first processing model to obtain the first quantized feature output by at least one first network layer in the first processing model; The input data is input into the second processing model to obtain the second quantized feature output by at least one second network layer in the second processing model; Based on the difference between the first quantization feature output by the at least one first network layer and the second quantization feature output by the at least one second network layer, the model parameters in the second processing model are adjusted to obtain the target processing model; The input data is image data, the first processing model is a non-linear quantized image recognition model, and the second processing model or the target processing model is a linear quantized image recognition model. or, The input data is text data, the first processing model is a non-linear quantized text processing model, and the second processing model or the target processing model is a linear quantized text processing model. or, The input data is speech data, the first processing model is a non-linear quantized speech processing model, and the second processing model or the target processing model is a linear quantized speech processing model.
2. The method according to claim 1, characterized in that, The process of obtaining the input data includes: Get the randomly generated initial input data; Obtain statistical information of the batch normalization BatchNorm module in each layer of the first network layer; wherein, the statistical information is used to indicate the first mean and / or first variance of the output features of the BatchNorm module; The initial input data is input into the first processing model to obtain target features of multiple dimensions output by the BatchNorm module in each layer of the first network. A first loss value is generated based on the statistical information of the BatchNorm module in each of the first network layers and the target features of the multiple dimensions. The initial input data is adjusted based on the first loss value to obtain the input data to be obtained.
3. The method according to claim 2, characterized in that, The step of generating a first loss value based on the statistical information of the BatchNorm module in each of the first network layers and the target features of the multiple dimensions includes: For any of the first network layers, determine the second mean and / or second variance of the target features in multiple dimensions output by the BatchNorm module in the first network layer; Based on the statistical information of the BatchNorm module in the first network layer, and based on the second mean and / or the second variance, the first sub-loss value corresponding to the first network layer is determined; The first loss value is determined based on the first sub-loss value of the first network layer in each layer.
4. The method according to claim 3, characterized in that, The step of determining the first sub-loss value corresponding to the first network layer based on the statistical information of the BatchNorm module in the first network layer, and based on the second mean and / or the second variance, includes: The first loss term is determined based on the difference between the first variance and the second variance indicated by the statistical information of the BatchNorm module in the first network layer; The second loss term is determined based on the difference between the first mean and the second mean indicated by the statistical information of the BatchNorm module in the first network layer; Based on the first loss term and the second loss term, determine the first sub-loss value corresponding to the first network layer.
5. The method according to claim 1, characterized in that, The step of adjusting the model parameters in the second processing model based on the difference between the first quantization feature output by the at least one first network layer and the second quantization feature output by the at least one second network layer to obtain the target processing model includes: A second loss value is generated based on the difference between the first quantization feature output by the at least one first network layer and the second quantization feature output by the at least one second network layer; Based on the second loss value, the model parameters in the second processing model are adjusted to obtain the target processing model.
6. The method according to claim 5, characterized in that, Both the first network layer and the second network layer are multi-layered. The step of generating a second loss value based on the difference between the first quantization feature output by the at least one first network layer and the second quantization feature output by the at least one second network layer includes: For any second network layer, determine the first network layer corresponding to the second network layer from the multiple first network layers; Based on the difference between the second quantization feature output by the second network layer and the first quantization feature output by the corresponding first network layer, a second sub-loss value corresponding to the second network layer is generated. The second loss value is determined based on the second sub-loss value corresponding to the second layer of the multi-layer second network.
7. The method according to claim 6, characterized in that, The step of determining the second loss value based on the second sub-loss value corresponding to the multi-layer second network layer includes: The average of the second sub-loss values of the multi-layer second network layer is taken as the second loss value; The sum of the second sub-loss values of the multi-layer second network layer is used as the second loss value; Obtain the weights of the multi-layer second network layer, and sum the second sub-loss values of the multi-layer second network layer according to the weights of the multi-layer second network layer to obtain the second loss value.
8. The method according to any one of claims 1-7, characterized in that, The step of generating a second processing model with linear quantization based on the first processing model includes: Obtain the linear quantization method corresponding to the at least one first network layer; Based on the linear quantization method corresponding to the at least one first network layer, the at least one first network layer is linearly quantized to obtain a second linear quantization processing model.
9. A linear quantization model generation device, characterized in that, The device includes: The first acquisition module is used to acquire the first processing model for nonlinear quantization. The generation module is used to generate a second processing model with linear quantization based on the first processing model; The second acquisition module is used to acquire the data to be input. The first input module is used to input the data to be input into the first processing model to obtain the first quantized feature output by at least one first network layer in the first processing model; The second input module is used to input the data to be input into the second processing model to obtain the second quantized feature output by at least one second network layer in the second processing model; An adjustment module is used to adjust the model parameters in the second processing model based on the difference between the first quantization feature output by the at least one first network layer and the second quantization feature output by the at least one second network layer, so as to obtain the target processing model. The input data is image data, the first processing model is a non-linear quantized image recognition model, and the second processing model or the target processing model is a linear quantized image recognition model. or, The input data is text data, the first processing model is a non-linear quantized text processing model, and the second processing model or the target processing model is a linear quantized text processing model. or, The input data is speech data, the first processing model is a non-linear quantized speech processing model, and the second processing model or the target processing model is a linear quantized speech processing model.
10. An electronic device, characterized in that, include: 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 to enable the at least one processor to perform the method of any one of claims 1-8.
11. A non-transitory computer-readable storage medium storing computer instructions, characterized in that, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-8.
Citation Information
Patent Citations
Quantization and inverse quantization method in large-scale MIMO channel state information feedback
CN110311718A
Deep neural network compression method based on multi-bit neural network nonlinear quantization
CN110633787A