Weight processing method and device and data processing method and device

By quantizing and converting the initial weight of the neural network model into target weights, the data to be processed is shifted, and the problem of time-consuming multiplication operations in deep neural networks is solved, achieving more efficient data processing.

CN119861899APending Publication Date: 2025-04-22SMARTER SILICON (SHANGHAI) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311362398.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-10-19
Publication Date
2025-04-22

AI Technical Summary

Technical Problem

In deep neural networks, multiplication operations occupy a large number of computing resources, resulting in a long time-consuming model training and inference process.

Method used

By quantifying the initial weight of the neural network model into the first encoding and converting it into the target weight, the to-process data is shifted using the target weight, replacing the traditional multiplication operation.

Benefits of technology

The weight processing of neural network models is simplified, computational complexity is reduced, data processing efficiency is improved, and the need for adders is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119861899A_ABST
    Figure CN119861899A_ABST
Patent Text Reader

Abstract

The invention provides a weight processing method and device and a data processing method and device, and the weight processing method comprises the steps: converting the initial weight of a neural network model into a first code, and enabling the number of target values in the first code to be smaller than a preset value; and converting the first code into a target weight, wherein the target weight is used for representing the bit position of each target numerical value in the first code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a weight processing method and device, and a data processing method and device. Background Art

[0002] According to statistics, in mainstream deep neural networks, multiplication accounts for more than 80% of the network operations and is the most important operation in the network. Multiplication is relatively complex and consists of shift operations, 'AND' operations, and addition operations. During the training or reasoning process of the neural network model, it is necessary to perform multiple multiplication operations on the model. Due to the complexity of the multiplication operation, the model training or reasoning process takes a long time. Summary of the invention

[0003] In view of this, the present application provides a weight processing method including:

[0004] quantizing the initial weights of the neural network model into a first code, wherein the number of target values ​​in the first code is less than a preset value;

[0005] The first code is converted into a target weight, where the target weight is used to characterize the bit position of each target value in the first code.

[0006] In the above method, the first bit of each bit of the first code is a sign bit, and the remaining bits are value bits; the number of target values ​​in the value bits is less than a preset value, and the value of the first code corresponds to the value of the initial weight;

[0007] The converting the first code into a target weight comprises:

[0008] If the value bits of the first code do not contain the target value, using the value of the sign bit of the first code as the target weight;

[0009] If the numerical bits of the first code contain multiple target numerical values, the target weight is generated based on the bit positions of the target numerical values ​​in the first code; wherein the first bit of the target weight is a sign bit, the sign bit of the target weight is consistent with the sign bit in the initial weight, and the numerical bits include multiple groups of valid position sequences corresponding to the multiple target numerical values ​​and arranged in order, and the numerical value of each group of valid position sequences represents the bit position of the corresponding target numerical value in the first code.

[0010] A data processing method, comprising:

[0011] Obtaining a target weight of the neural network model, wherein the target weight is obtained by quantizing an initial weight in the neural network model into a first code and converting the first code, wherein the number of target values ​​in the first code is less than a preset value, and the target weight is used to characterize a bit position of each target value in the first code;

[0012] Based on the target weight, at least shift processing is performed on the data to be processed that is input into the neural network model to obtain a processing result corresponding to the data to be processed.

[0013] In the above method, the target weight includes a numerical sequence; wherein the numerical sequence includes at least a sign bit; the first bit of the numerical sequence is a sign bit, which is used to represent the sign bit of the initial weight; the other bits are numerical bits, and the numerical bits include a plurality of groups of valid position sequences corresponding to the plurality of target values ​​and arranged in order, and the numerical value of each group of valid position sequences represents the bit position of the corresponding target value in the first code; the first bit of each bit of the first code is a sign bit, and the number of target values ​​in the remaining bits is less than a preset value, and the numerical value size corresponds to the numerical value size of the initial weight.

[0014] In the above method, based on the target weight, at least shifting the data to be processed input into the neural network model to obtain the processing result corresponding to the data to be processed includes:

[0015] In the case where both the target weight and the data to be processed are not zero, determining at least one shift number of the data to be processed based on the target weight; wherein the value of each group of valid position sequences in the target weight corresponds to the number of shifts each time;

[0016] Shifting the data to be processed respectively according to a plurality of shift numbers and then accumulating them to obtain a shift result;

[0017] Calculating the sign bits of the data to be processed and the target weight to obtain a sign code;

[0018] Based on the symbol code and the shift result, a processing result corresponding to the data to be processed is obtained.

[0019] In the above method, the step of calculating the sign bits of the data to be processed and the target weight to obtain the sign code includes:

[0020] Inverting a target numerical sequence and then adding 1 to obtain a second code, wherein the target numerical sequence is composed of the numerical value of the sign bit of the data to be processed and the numerical sequence of the entire data to be processed;

[0021] Perform an AND operation on the second code and the sign bit of the target weight to obtain a third code;

[0022] The third code is padded so that the number of bits of the padded third code is consistent with the number of bits of the shift result, and the padded third code is a symbol code.

[0023] In the above method, obtaining the processing result corresponding to the data to be processed based on the symbol encoding and the shift result includes:

[0024] A sum operation is performed on the symbol code and the shift result to obtain a processing result corresponding to the data to be processed.

[0025] A weight processing device, comprising:

[0026] A quantization unit, used to quantize the initial weights of the neural network model into a first code, wherein the number of target values ​​in the first code is less than a preset value;

[0027] A conversion unit is used to convert the first code into a target weight, where the target weight is used to represent the bit position of each target value in the first code.

[0028] A data processing device, comprising:

[0029] An acquisition unit, used to obtain a target weight of the neural network model, wherein the target weight is obtained by quantizing an initial weight in the neural network model into a first code and converting the first code, wherein the number of target values ​​in the first code is less than a preset value, and the target weight is used to characterize a bit position of each target value in the first code;

[0030] A processing unit is used to perform at least a shift process on the data to be processed input into the neural network model based on the target weight to obtain a processing result corresponding to the data to be processed.

[0031] The above-mentioned data processing device, the processing unit, includes:

[0032] At least one shift component, used to perform a shift operation on the data to be processed, the shift number corresponding to the shift operation is the value corresponding to each group of valid position sequences of the target weight corresponding to the data to be processed; wherein the first bit of the target weight is a sign bit, and the other bits are value bits, the value bits include multiple groups of valid position sequences corresponding to the multiple target values ​​and arranged in sequence, and the number of shift components is consistent with the number of groups of valid position sequences;

[0033] A symbol calculation unit, used for processing the value of the sign bit of the data to be processed and the value of the sign bit in the target weight to obtain a symbol code;

[0034] The accumulation unit is used to accumulate the shifted values ​​output by each shift component to obtain a shift result, and accumulate the shift result with the symbol code to obtain a processing result corresponding to the data to be processed after outputting the accumulation. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0036] Figure 1 A method flow chart of a weight processing method provided in an embodiment of the present application;

[0037] Figure 2 A device structure diagram of a weight processing device provided in an embodiment of the present application;

[0038] Figure 3 A method flow chart of a data processing method provided in an embodiment of the present application;

[0039] Figure 4 A flowchart of another method of a data processing method provided in an embodiment of the present application;

[0040] Figure 5 A device structure diagram of a data processing device provided in an embodiment of the present application;

[0041] Figure 6 A diagram of another device structure of a data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0042] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0043] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "comprise one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0044] The present application can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, distributed computing environments including any of the above devices or equipment, etc.

[0045] The embodiment of the present application provides a weight processing method, which can be applied to a variety of system platforms, and its execution subject can be a processor of a computer terminal or various mobile devices. The method flow chart of the method is as follows: Figure 1 As shown, specifically including:

[0046] S101: quantizing the initial weights of the neural network model into a first code.

[0047] Wherein, the number of target values ​​in the first code is less than a preset value.

[0048] It should be noted that the target value is "1". The number of target values ​​in the first code does not exceed a preset value, which can be set according to the data type of the initial weight, or obtained according to the experience of the prophet. Each bit of the first code includes a sign bit and a value bit, wherein the first bit of each bit of the first code is a sign bit, and the remaining bits are value bits. The value of the sign bit can be represented by "0" or "1" to represent the sign of the first code, wherein the value of the sign bit is "0" to represent the symbol "+", and the value of the sign bit is "1" to represent the symbol "-". The numerical value of the first code corresponds to the numerical value of the initial weight.

[0049] It should also be noted that the initial weight can be int8 data, the initial weight is a binary number, and after the initial weight is quantized into a first code, the first code is also a binary number. The value of the first code is the sum of a finite number of powers of 2, where the number of powers of 2 corresponding to the first code is less than the preset value, and the power values ​​of each power of 2 are the bit positions of the target value in the first code.

[0050] In the process of quantizing the initial weight, a code with a value close to the initial weight can be selected as the first code on the basis that the number of target values ​​in the first code is less than the preset value. Taking int8 as an example, if the preset value is 4 and the initial weight is 53=(00110101), the initial weight can be quantized to (00110100)=52; if the preset value is 2 and the initial weight is 67=(01000011), the initial weight can be quantized to (01000000)=64; if the preset value is 3 and the initial weight is 63=(00111111), the initial weight can be quantized to (01000000)=64.

[0051] Optionally, in order to facilitate the quantization process, a lookup table can be established to calculate the data range of the original data corresponding to each quantized value. During quantization, the original data is sent to the lookup table to find the matching quantized value.

[0052] S102: Convert the first code into a target weight.

[0053] The target weight is used to represent the bit position of each target value in the first code.

[0054] It should be noted that when the value of the first code is zero, the target weight converts the sign of the sign bit in the first code into a corresponding value, and the value corresponding to the sign is the target weight. When the value of the first code is not zero, the first code is compressed according to the bit position of the target value "1" in the first code to obtain the target weight.

[0055] The first bit of the target weight is the sign bit, which is consistent with the sign bit in the initial weight. The value bit includes multiple groups of valid position sequences corresponding to multiple target values ​​and arranged in order. The value of each group of valid position sequences represents the bit position of the corresponding target value in the first code. Since the value bit in the first code has a maximum of 7 bits, 3 bits can be used to represent the bit position of the target value in the first code.

[0056] Taking int8 as an example, if the first code is 00010001, the compressed target weight is: 0100000; if the first code is 00100000, the compressed target weight is: 0101; if the first code is 10001010, the compressed target weight is: 1011001. In the target weight, the first bit is the sign bit, and the remaining bits are value bits. Each value bit constitutes at least one valid position sequence, and each valid position sequence is the binary value of the bit position where the target value is located in the first code.

[0057] In general, in order to ensure the processing efficiency of the data to be processed in the neural network model, the number of bits of the target weight is usually guaranteed to be less than the number of bits of the initial weight during the quantization and conversion process. However, if the processing result of the target weight in the neural network model on the data to be processed is closer to the processing result of the initial weight, the number of bits of the target weight may also be greater than the number of bits of the initial weight. For example, the initial weight is 53=(00110101), and the maximum number of target values ​​allowed by the first code is 3 bits. Therefore, the first code obtained by the quantized initial weight can be: (00110100)=52. In the first code, the bit positions of each target value "1" from 0 from right to left are the 2nd, 4th and 5th bits. Therefore, the conversion result of the first code into the target weight is: 0010100101. At this time, the number of bits of the target weight is greater than the number of bits of the initial weight and the first code; wherein the first bit of the target weight is the sign bit, and the valid position sequence (010) composed of the first three numerical bits after the sign bit represents the 2nd bit position in the above-mentioned first code, the valid position sequence (100) composed of the middle three numerical bits represents the 4th bit position in the above-mentioned first code, and the valid position sequence (101) composed of the last three numerical bits represents the 5th bit position in the above-mentioned first code.

[0058] In particular, if all the numerical bits are 0, the target weight only retains the sign bit and does not store the numerical bit, and the first code is compressed to 1 bit.

[0059] In the method provided in the embodiment of the present application, after the training of the neural network model is completed, the weights in the neural network model are quantized and converted, and the target weights obtained after the conversion are applied to simplify the calculation of the feature data, reduce the processing flow, and improve the efficiency of the neural network model in data processing.

[0060] and Figure 1 Corresponding to the method described above, the embodiment of the present application further provides a weight processing device for Figure 1 The specific implementation of the method in the embodiment of the present application, the weight processing device provided in the embodiment of the present application can be applied to a computer terminal or various mobile devices, and its structural diagram is as follows Figure 2 As shown, specifically including:

[0061] A quantization unit 201, configured to quantize the initial weights of the neural network model into a first code, wherein the number of target values ​​in the first code is less than a preset value;

[0062] The conversion unit 202 is used to convert the first code into a target weight, where the target weight is used to represent the bit position of each target value in the first code.

[0063] In the embodiment of the present application, the first bit of each bit of the first code is a sign bit, and the remaining bits are value bits; the number of target values ​​in the value bits is less than a preset value, and the value of the first code corresponds to the value of the initial weight. If the value bits of the first code do not contain the target value, the value of the sign bit of the first code is used as the target weight; if the value bits of the first code contain multiple target values, the target weight is generated based on the bit position of the target value in the first code; wherein the first bit of the target weight is a sign bit, the sign bit of the target weight is consistent with the sign bit in the initial weight, and the value bits include multiple groups of valid position sequences corresponding to the multiple target values ​​and arranged in order, and the value of each group of valid position sequences represents the corresponding target value in the first code. The method of the present application can simplify the weights of the neural network model and speed up the process of reprocessing data.

[0064] Based on the weight processing method and device provided in the above embodiment, the present application also provides a data processing method, the method flow chart of which is as follows: Figure 3 As shown, specifically including:

[0065] S301: Obtain target weights of a neural network model.

[0066] Among them, the target weight is obtained by quantizing the initial weight in the neural network model into a first code and converting the first code. The number of target values ​​in the first code is less than a preset value, and the target weight is used to characterize the bit position of each target value in the first code.

[0067] In the present application, after completing the training of the neural network model and compressing the weights in the neural network model, the target weight of the neural network model is obtained in the process of applying the neural network model to process the feature data. The target weight includes a numerical sequence; wherein the first bit of the numerical sequence is a sign bit, which is used to represent the sign bit of the initial weight; the other bits are numerical bits, and the numerical values ​​of the numerical bits are used to represent the bit position where the target numerical value after the initial weight is quantized to the first encoding is located; the first bit of each bit of the first encoding is a sign bit, and the remaining bits contain at least one target numerical value, and the numerical value corresponds to the numerical value of the initial weight.

[0068] The target weights can be obtained by processing the initial weights provided by the model trainer and configuring them in the model when the network is deployed; or by converting the initial weights each time the model is used to continue data processing. If the target weights are configured in the model after the initial weights are quantized and compressed when the network is deployed, then when the neural network model is used for data processing, the target weights are directly applied to implement the data processing process of the neural network model. If the target weights are obtained by quantizing and compressing the initial weights each time the neural network model is used, then before the neural network model is used for data processing, the initial weights in the neural network model are first quantized and compressed, and after obtaining the target weights, the target weights are applied to implement the data processing process of the neural network model.

[0069] S302: Based on the target weight, at least shift the data to be processed that is input into the neural network model to obtain a processing result corresponding to the data to be processed.

[0070] The data to be processed is feature data after being input into the neural network model, or feature data input into the neural network model and preprocessed. Specifically, the data to be processed may be text, image, video or audio data.

[0071] It should be noted that, when the target weight is not zero, the numerical sequence included in the target weight includes multiple groups of valid position sequences. According to each group of valid position sequences of the target weight, the shift number corresponding to each group of valid position sequences is determined. The data to be processed are shifted according to each shift number and then added to obtain the processing result corresponding to the data to be processed.

[0072] It should also be noted that, among the bits of the data to be processed, the first bit is a sign bit, and a value of the sign bit of "0" indicates that the data to be processed is a positive number, and a value of the sign bit of "1" indicates that the data to be processed is a negative number, and the other bits are numerical bits. Shifting the data to be processed specifically shifts each numerical bit in the data to be processed, and shifts the numerical sequence corresponding to each numerical bit of the data to be processed to the left.

[0073] After the data to be processed is shifted, the sign bit of the data to be processed can be further processed, and the value of the sign bit in the processing result corresponding to the data to be processed is obtained according to the sign bit of the data to be processed and the sign bit of the target weight. Among them, the processing of the sign bit of the data to be processed and the target weight is to negate the data to be processed and add 1, and then perform the AND operation on the code obtained by negating and adding 1 and the sign bit of the target weight to perform the bit filling, and the filling result is the symbol code for processing the sign bit of the data to be processed and the target weight. Finally, the shifted result and the sign code are added to obtain the processing result of the data to be processed.

[0074] The processing result obtained by the present application is consistent with the calculation result of the multiplication and addition operation. Among them, the present application only needs to shift the data to be processed to obtain the final result, while the prior art needs to obtain the final result through multiple multiplication and addition operations. Taking the data to be processed as 42 and the initial weight as 67 as an example, the binary complement of the data to be processed is: 00101010, and the binary complement of the initial weight is: 01000011. If it is necessary to multiply the data to be processed with the initial weight, the calculation process of the multiplication and addition algorithm of the prior art includes numerical bit operation and sign bit operation, wherein the numerical bit operation process is as follows:

[0075] 000000000010101010+0000000001010100+0000000000000000

[0076] +00000000000000000+000000000000000+0000000000000000

[0077] +0001010100000000=0000101011111110

[0078] The sign bit operation process is as follows:

[0079] {(~{00101010}+1)&0,7'b0}=0000000000000000

[0080] Therefore, the calculation result of the prior art is:

[0081] 0000101011111110+0000000000000000=0000101011111110

[0082] Among them, since the binary number obtained by multiplying two numbers exceeds the original number of bits, the data to be processed 42=00101010 is expanded to 0000000000101010 before the multiplication operation. It can be seen from the above formula that the calculation process of multiplication using the prior art requires multiple addition operations. The larger the initial weight, the longer the addition process required. Based on the method provided by S301 to S302 of this embodiment, the initial weight 67=01000011 can be quantized to 68=01000100. Since 68=64+4=2 6 +2 2Therefore, the binary numbers corresponding to the power values ​​of two powers of 2 are used as the valid position sequence in the target weight, and the target weight obtained after bit compression of the quantized 68=01000100 is 0110010. The calculation process of shifting the processed data 42 using the method provided in the embodiment of the present application includes numerical bit operation and sign bit operation, wherein the numerical bit operation process is as follows:

[0083] 0000000000101010<<6=0000101010000000

[0084] 0000000000101010<<2=0000000010101000

[0085] 0000101010000000+0000000010101000=0000101100101000

[0086] The sign bit operation process is as follows:

[0087] {(~{00101010}+1)&0,7'b0}=0000000000000000

[0088] Therefore, the results obtained by calculating using the embodiments of the present application are:

[0089] 0000101100101000+0000000000000000=0000101100101000

[0090] It should be noted that, in the process of quantizing the initial weight into the first code, it is necessary to consider that the value of the quantized first code is close to the value of the initial weight. Referring to the above embodiment, the initial weight 67=01000011 is quantized into the first code 68=01000100, and the two values ​​are close. After compressing the first code, the result obtained by calculation is close to the result of applying the initial weight to the processed data and calculating in the prior art. Therefore, after quantizing and compressing the initial weight, the accuracy of the neural network model can still be maintained.

[0091] It can be seen from the above example that in the process of applying the prior art to perform multiplication calculations on the initial weights and the data to be processed, a large number of additions are required to obtain the final result. After the initial weights are quantized and compressed, only the data to be processed needs to be shifted and then added to obtain the final result. The data processing method of the present application can greatly reduce the demand for adders in the neural network model during the calculation process, simplify complex multiplication operations into shift operations, and simplify the hardware implementation. While saving chip area and power consumption, it also improves the efficiency of data processing by the neural network model.

[0092] In the method provided in the embodiment of the present application, the target weight of the neural network model is obtained, wherein the data to be processed are shifted and added according to the numerical values ​​corresponding to the multiple groups of valid position sequences in the target weight to obtain the shift result; then the sign bit of the target weight and the data to be processed are calculated to obtain the calculation result; the two results are added to obtain the processing result corresponding to the data to be processed. The data processing process of the present application uses simple shift processing and logical operations to replace the multiplication and addition operation process in the neural network model, so as to improve the processing speed of the data in the neural network model.

[0093] Specifically, refer to Figure 4 , based on the target weight, at least shift processing is performed on the data to be processed input into the neural network model, and the processing result corresponding to the data to be processed is obtained in the following specific implementation process:

[0094] S401: When both the target weight and the data to be processed are not zero, determining at least one shift number of the data to be processed based on the target weight.

[0095] The value of each valid position sequence in the target weight corresponds to the number of shifts each time. The target weight is obtained by quantizing and compressing the initial weight.

[0096] The present application replaces the multiplication and addition algorithm of the initial weight and the data to be processed in the prior art by means of shift processing. Therefore, in the multiplication and addition algorithm, if any one of the initial weight and the data to be processed is zero, the result obtained must be zero, and there is no need to perform the multiplication and addition algorithm or shift processing. If the initial weight is not zero, the target weight obtained after quantization and compression is also not zero. If the data to be processed is not zero, the process of shifting the data to be processed can be realized.

[0097] When the initial weight is quantized, the corresponding quantization value can be found from the preset lookup table according to the value of the initial weight. The binary number corresponding to the quantization value is the first code after the initial weight is quantized. The first code contains a target value "1" that is less than the preset value. Taking the first code as int8 data as an example, except for the first bit which is the sign bit, the other bits in the int8 data are value bits, and the value bits are up to 7 bits. If there is only one target value "1" in each value bit, it can be represented by a 3-bit value; at the same time, when there are at most two target values ​​"1", a maximum of 2×3=6 bits can be used. In addition to the sign bit, the original 8-bit first code can be compressed to a maximum of 7 bits. If there is no target value in the first code, the initial weight is represented as zero, and the target weight obtained after compression is only 1 bit, that is, the target weight only contains the sign bit. For example, if the first code is 00010001, the target weight after compression is: 0100000; if the first code is 00100000, the target weight after compression is: 0101; if the first code is 10001010, the target weight after compression is: 1011001.

[0098] S402: Shift the data to be processed respectively according to a plurality of shift amounts and then accumulate them to obtain a shift result.

[0099] Before the data to be processed is shifted, the data to be processed may be expanded. If the value of the sign bit of the data to be processed is "1", the values ​​of the bits to be expanded are all "1", and if the value of the sign bit of the data to be processed is "0", the values ​​of the bits to be expanded are all "0".

[0100] In this application, the calculation method of accumulating the shifted data according to multiple shift numbers is as follows:

[0101] {8{sign a}, sign a ,a]<<b1+{8{sign a}, sign a ,a}b0

[0102] Among them, b1 and b0 represent the shift number, 8{sign a} Fill 8 bits with the same value as the sign bit on the left side of the data to be processed. a represents each bit in the data to be processed, sign a The value representing the sign bit of the data to be processed.

[0103] It should be noted that the specific number of bits for expanding the data to be processed can be set according to actual computing requirements.

[0104] S403: Calculate the sign bits of the data to be processed and the target weight to obtain a sign code.

[0105] Specifically, the process of obtaining the symbol encoding is as follows:

[0106] Inverting a target numerical sequence and then adding 1 to obtain a second code, wherein the target numerical sequence is composed of the numerical value of the sign bit of the data to be processed and the numerical sequence of the entire data to be processed;

[0107] Perform an AND operation on the second code and the sign bit of the target weight to obtain a third code;

[0108] The third code is padded so that the number of bits of the padded third code is consistent with the number of bits of the shift result, and the padded third code is a symbol code.

[0109] In this application, the calculation method of calculating the symbol encoding is as follows:

[0110] {(~{sign a ,sign a ,a}+1)&sign b ,7'b0}

[0111] Among them, ~{sign a ,sign a ,a} means to invert the value of the sign bit of the data to be processed and the overall value sequence of the data to be processed, & refers to the AND operation, 7′b0 means to add 7 bits of zero to the right side of the third code obtained after the AND operation, sign b is the value of the sign bit in the target weight.

[0112] S404: Based on the symbol encoding and the shift result, obtain a processing result corresponding to the data to be processed.

[0113] Specifically, a sum operation is performed on the symbol encoding and the shift result to obtain a processing result corresponding to the data to be processed.

[0114] In the method provided by the present application, after the neural network model is trained, the initial weight of the neural network model is quantized into a first code, the first code contains the target value "1" whose number is less than the preset value, and the first code is compressed according to the bit position where the target value "1" is located to obtain the target weight. After the feature data is input into the neural network model, the feature data or the pre-processed feature data is used as the data to be processed. Based on the target weight of the neural network model, multiple shift numbers are obtained, and the data to be processed are shifted and added according to each shift number, and the logical operation of the sign bit is performed at the same time to obtain the processing result corresponding to the data to be processed. Among them, before the data to be processed is subjected to multiple shift processing, the data to be processed is expanded, and then the expanded data to be processed is shifted and added according to each shift number; at the same time, the value of the sign bit of the data to be processed and the overall numerical sequence of the data to be processed are inverted and added to obtain the second code, and then the second code and the sign bit of the target weight are operated and the third code is obtained; the third code after the padding and the shift result are added to obtain the processing result. The method provided in this application utilizes simple shift processing and logical operations to replace the multiplication and addition operations in the neural network model, thereby improving the data processing speed in the neural network model.

[0115] The specific implementation processes and derivative methods of the above-mentioned embodiments are all within the protection scope of this application.

[0116] and Figure 3 Corresponding to the method described above, the embodiment of the present application further provides a data processing device for Figure 3 In order to implement the method in the embodiment of the present application, the data processing device provided in the embodiment of the present application can be applied to a computer terminal or various mobile devices, and its structural diagram is as follows: Figure 5 As shown, specifically including:

[0117] An acquisition unit 501 is used to obtain a target weight of a neural network model, wherein the target weight is obtained by quantizing an initial weight in the neural network model into a first code and converting the first code, wherein the number of target values ​​in the first code is less than a preset value, and the target weight is used to characterize a bit position of each target value in the first code;

[0118] The processing unit 502 is used to perform at least a shift process on the data to be processed input into the neural network model based on the target weight to obtain a processing result corresponding to the data to be processed.

[0119] Further, refer to Figure 6 , the processing unit comprises:

[0120] At least one shift component 601 is used to process data (such as Figure 6The IFM in the shift operation is performed, and the shift number corresponding to the shift operation (such as Figure 6 b0 and b1 in are the target weights corresponding to the data to be processed (such as Figure 6 The value corresponding to each valid position sequence of the target weight (Weight). For example, the target weight 0100010 contains two valid position sequences of 100 and 010, respectively. The value corresponding to the valid position sequence 100 is 4, and the value corresponding to the valid position sequence 010 is 2. The first bit of the target weight is a sign bit, and the other bits are value bits. The value bits include multiple valid position sequences corresponding to the multiple target values ​​and arranged in order. The number of shift components is consistent with the number of valid position sequences.

[0121] A symbol calculation unit 602 is used to process the value of the sign bit of the data to be processed and the value of the sign bit in the target weight to obtain a symbol code;

[0122] The accumulation unit 603 is used to accumulate the shifted values ​​output by each shift component to obtain a shift result, and accumulate the shift result with the symbol code to output the accumulated processing result corresponding to the data to be processed.

[0123] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0124] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, computer software, or a combination of both.

[0125] In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0126] The above description of the disclosed embodiments enables those skilled in the art to implement or use the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A weight processing method, comprising: quantizing the initial weights of the neural network model into a first code, wherein the number of target values ​​in the first code is less than a preset value; The first code is converted into a target weight, where the target weight is used to characterize the bit position of each target value in the first code.

2. According to the method of claim 1, the first bit of each bit of the first code is a sign bit, and the remaining bits are value bits; the number of target values ​​in the value bits is less than a preset value, and the value of the first code corresponds to the value of the initial weight; The converting the first code into a target weight comprises: If the value bits of the first code do not contain the target value, using the value of the sign bit of the first code as the target weight; If the numerical bits of the first code contain multiple target numerical values, the target weight is generated based on the bit positions of the target numerical values ​​in the first code; wherein the first bit of the target weight is a sign bit, the sign bit of the target weight is consistent with the sign bit in the initial weight, and the numerical bits include multiple groups of valid position sequences corresponding to the multiple target numerical values ​​and arranged in order, and the numerical value of each group of valid position sequences represents the bit position of the corresponding target numerical value in the first code.

3. A data processing method, comprising: Obtaining a target weight of the neural network model, wherein the target weight is obtained by quantizing an initial weight in the neural network model into a first code and converting the first code, wherein the number of target values ​​in the first code is less than a preset value, and the target weight is used to characterize a bit position of each target value in the first code; Based on the target weight, at least shift processing is performed on the data to be processed that is input into the neural network model to obtain a processing result corresponding to the data to be processed.

4. The method according to claim 3, wherein the target weight comprises a numerical sequence; wherein, The numerical sequence includes at least a sign bit; the first bit of the numerical sequence is a sign bit, which is used to represent the sign bit of the initial weight; the other bits are numerical bits, and the numerical bits include a plurality of groups of valid position sequences corresponding to the plurality of target values ​​and arranged in order, and the numerical value of each group of valid position sequences represents the bit position of the corresponding target value in the first code; the first bit of each bit of the first code is a sign bit, and the number of target values ​​in the remaining bits is less than a preset value, and the numerical value size corresponds to the numerical value size of the initial weight.

5. According to the method of claim 3, the step of performing at least a shift process on the data to be processed input into the neural network model based on the target weight, and obtaining a processing result corresponding to the data to be processed comprises: In the case where both the target weight and the data to be processed are not zero, determining at least one shift number of the data to be processed based on the target weight; wherein the value of each group of valid position sequences in the target weight corresponds to the number of shifts each time; Shifting the data to be processed respectively according to a plurality of shift numbers and then accumulating them to obtain a shift result; Calculating the sign bits of the data to be processed and the target weight to obtain a sign code; Based on the symbol code and the shift result, a processing result corresponding to the data to be processed is obtained.

6. The method according to claim 5, wherein the step of calculating the sign bits of the data to be processed and the target weight to obtain the sign code comprises: Inverting a target numerical sequence and then adding 1 to obtain a second code, wherein the target numerical sequence is composed of the numerical value of the sign bit of the data to be processed and the numerical sequence of the entire data to be processed; Perform an AND operation on the second code and the sign bit of the target weight to obtain a third code; The third code is padded so that the number of bits of the padded third code is consistent with the number of bits of the shift result, and the padded third code is a symbol code.

7. The method according to claim 5 or 6, wherein obtaining the processing result corresponding to the data to be processed based on the symbol encoding and the shift result comprises: A sum operation is performed on the symbol code and the shift result to obtain a processing result corresponding to the data to be processed.

8. A weight processing device, comprising: A quantization unit, used to quantize the initial weights of the neural network model into a first code, wherein the number of target values ​​in the first code is less than a preset value; A conversion unit is used to convert the first code into a target weight, where the target weight is used to represent the bit position of each target value in the first code.

9. A data processing device, comprising: An acquisition unit, used to obtain a target weight of the neural network model, wherein the target weight is obtained by quantizing an initial weight in the neural network model into a first code and converting the first code, wherein the number of target values ​​in the first code is less than a preset value, and the target weight is used to characterize a bit position of each target value in the first code; A processing unit is used to perform at least a shift process on the data to be processed input into the neural network model based on the target weight to obtain a processing result corresponding to the data to be processed.

10. The data processing device according to claim 9, wherein the processing unit comprises: At least one shift component, used to perform a shift operation on the data to be processed, the shift number corresponding to the shift operation is the value corresponding to each group of valid position sequences of the target weight corresponding to the data to be processed; wherein the first bit of the target weight is a sign bit, and the other bits are value bits, the value bits include multiple groups of valid position sequences corresponding to the multiple target values ​​and arranged in sequence, and the number of shift components is consistent with the number of groups of valid position sequences; A symbol calculation unit, used for processing the value of the sign bit of the data to be processed and the value of the sign bit in the target weight to obtain a symbol code; The accumulation unit is used to accumulate the shifted values ​​output by each shift component to obtain a shift result, and accumulate the shift result with the symbol code to obtain a processing result corresponding to the data to be processed after outputting the accumulation.