Data processing device and method, electronic equipment and storage medium
By using the quantization unit and the calculation unit in the data processing device to perform floating-point data quantization and operations, the problem of balancing performance and accuracy in large model matrix operations is solved, and efficient matrix calculations are achieved.
Patent Information
- Application Number
- CN202410890045.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2024-09-20
AI Technical Summary
In matrix operations of large models, it is difficult for the existing technology to take into account both performance and accuracy. Especially in general matrix multiplication operations, when floating-point data is quantized into fixed-point data, the computing power and storage capacity requirements will be too high, or the accuracy will be lost. Calculation accuracy decreases.
By introducing a quantization unit and a calculation unit into the data processing device, the quantization unit is used to quantize floating-point data into fixed-point data, and the calculation unit is used to perform related operations, thereby reducing the accuracy loss when converting floating-point data into fixed-point data while maintaining high bandwidth. and utilization of computing power to achieve efficient execution of matrix calculations.
It effectively reduces the accuracy loss when converting floating-point data to fixed-point data, maintains calculation accuracy, and makes full use of the bandwidth and computing power of the artificial intelligence chip to improve the performance of matrix calculations.
Smart Images

Figure CN118673263A
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of artificial intelligence technology, and in particular to the technical fields of chips, mixed precision computing, distributed computing platforms, etc. More specifically, the present disclosure provides a data processing device, method, electronic device, and storage medium. Background Art
[0002] With the development of artificial intelligence technology, the application scenarios of large models are increasing. When large models are running, matrix operations are difficult to balance performance and accuracy. Summary of the invention
[0003] The present disclosure provides a data processing device, method, electronic device and storage medium.
[0004] According to one aspect of the present disclosure, a data processing device is provided, the device comprising: a quantization unit, configured to: quantize the floating-point data to be processed into first fixed-point data according to a first maximum value corresponding to the floating-point data to be processed; quantize the second floating-point data into second fixed-point data according to a second maximum value corresponding to the floating-point data to be processed, wherein the second floating-point data is obtained according to the floating-point data to be processed and the first floating-point data, and the first floating-point data is obtained by dequantizing the first fixed-point data; a first calculation unit, configured to: obtain a first calculation result according to the fixed-point data to be processed and the first fixed-point data; obtain a second calculation result according to the fixed-point data to be processed and the second fixed-point data; and obtain a target calculation result according to the first calculation result and the second calculation result.
[0005] According to another aspect of the present disclosure, an electronic device is provided, comprising the device provided by the present disclosure.
[0006] According to another aspect of the present disclosure, a data processing method is provided, the method comprising: according to a first maximum value corresponding to the floating-point data to be processed, using a quantization unit to quantize the floating-point data to be processed into first fixed-point data; according to a second maximum value corresponding to the floating-point data to be processed, using the quantization unit to quantize the second floating-point data to second fixed-point data, wherein the second floating-point data is obtained according to the floating-point data to be processed and the first floating-point data, and the first floating-point data is obtained by inverse quantization of the first fixed-point data; according to the fixed-point data to be processed and the first fixed-point data, using a first calculation unit to obtain a first calculation result; according to the fixed-point data to be processed and the first fixed-point data, using the first calculation unit to obtain a second calculation result; according to the fixed-point data to be processed and the second fixed-point data, using the first calculation unit to obtain a target calculation result.
[0007] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method provided according to the present disclosure.
[0008] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided. The computer instructions are used to cause a computer to execute the method provided according to the present disclosure.
[0009] According to another aspect of the present disclosure, a computer program product is provided, including a computer program, wherein when the computer program is executed by a processor, the method provided according to the present disclosure is implemented.
[0010] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.
[0012] Figure 1A is a schematic diagram of a data processing method according to an example;
[0013] Figure 1B is a schematic diagram of a data processing method according to another example;
[0014] Figure 1C is a schematic diagram of a data processing method according to another example;
[0015] Figure 1D is a schematic diagram of a data processing method according to another example;
[0016] Figure 2 is a schematic block diagram of a data processing device according to an embodiment of the present disclosure;
[0017] Figure 3 is a diagram of data type conversion according to one embodiment of the present disclosure;
[0018] Figure 4A is a schematic block diagram of a data processing device according to another embodiment of the present disclosure;
[0019] Figure 4B is a schematic block diagram of a data processing device according to another embodiment of the present disclosure;
[0020] Figure 4Cis a schematic block diagram of a data processing device according to another embodiment of the present disclosure;
[0021] Figure 5 is a schematic block diagram of an electronic device according to an embodiment of the present disclosure;
[0022] Figure 6 is a flow chart of a data processing method according to an embodiment of the present disclosure;
[0023] Figure 7 is a block diagram of an electronic device to which a data processing method can be applied according to an embodiment of the present disclosure. DETAILED DESCRIPTION
[0024] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0025] General Matrix to Matrix Multiplication (GEMM) is one of the basic operations involved in neural networks and is also an important basic operation required for the operation of large models. General matrix multiplication is a calculation process that multiplies two matrices to obtain an output matrix. The matrices used as inputs for general matrix multiplication can be weight matrices and data matrices, respectively. After matrix multiplication, the output result matrix is obtained. The general calculation process of general matrix multiplication is as follows: Figure 1A shown.
[0026] Figure 1A is a schematic diagram of a general matrix multiplication operation according to an embodiment of the present disclosure.
[0027] In some embodiments, the functional components related to the general matrix multiplication operation may include a direct memory access (DMA) unit 111, a multiply accumulate (MAC) unit 120, and an element-wise processing unit (EW) 130. The direct memory access unit 111 may load or store data. When the direct memory access unit 111 executes a load instruction, the direct memory access unit 111 may, for example, load data from the global storage unit 112 to the local storage unit 113. When the direct memory access unit 111 executes a store instruction, the direct memory access unit 111 may, for example, store data from the local storage unit 113 to the global storage unit 112.
[0028] In the embodiments of the present disclosure, with the development of artificial intelligence technology, the number of parameters of deep neural networks has increased rapidly. If floating-point type storage and calculation continue to be used in general matrix multiplication operations, it will lead to excessive requirements on the computing power and storage capacity of the chip. Therefore, by quantizing floating-point data to fixed-point data, in order to achieve higher computing power and smaller storage space, it has become one of the mainstream means of accelerating model reasoning. The quantization unit can realize data type conversion. For example, the quantization unit can perform conversion (cast), quantization (quant), and dequantization (dequant) operations according to the data type.
[0029] In some embodiments, to ensure the accuracy of the operation, the data matrix of the general matrix multiplication operation may include multiple floating-point values. In order to reduce the storage resource usage, the weight matrix of the general matrix multiplication operation may include multiple fixed-point values. For example, the floating-point value may be a 16-bit floating-point value (FP16). The fixed-point value may be an 8-bit fixed-point value (int8). Figure 1A As shown, the input matrix A10 may be the above-mentioned data matrix. The input matrix B11 may be the above-mentioned weight matrix. After the multiplication and accumulation operation unit 120 performs a general matrix multiplication operation, an output result matrix C10 may be obtained. The element-by-element processing unit 130 may process the output result matrix C (for example, adding a bias or scaling), and then the direct memory access unit 111 may write the processed output result matrix C10 into the global storage unit 114.
[0030] In some embodiments, the general matrix multiplication operation performed by the multiplication-accumulation operation unit 112 can support inputs of the same data type. If a general matrix multiplication operation is to be performed on two matrices of different data types, the data types of the two matrices can be converted to the same type during the loading phase. In this case, the data matrix can be quantized from floating point numbers to fixed point numbers, or the weight matrix can be dequantized from fixed point numbers to floating point numbers. Next, the general matrix multiplication operation can be performed using the multiplication-accumulation operation unit 112. Figure 1B to Figure 1C Explain.
[0031] Figure 1B is a schematic diagram of a general matrix multiplication operation according to another embodiment of the present disclosure.
[0032] The input matrix A10 may include one or more 16-bit floating-point values. The input matrix B11 may include one or more 8-bit fixed-point values. In the loading stage, the 8-bit fixed-point values of the input matrix B may be dequantized into 16-bit floating-point values to obtain the dequantized input matrix dB11. The multiplication and accumulation operation unit 120 may perform calculations based on the input matrix A10 and the dequantized input matrix dB11 to obtain the output result matrix C10. The element-by-element processing unit 130 may process the output result matrix C10. The direct memory access unit 111 may store the processed output result matrix C10 in the global storage unit 112. However, for the input matrix B11, 8-bit fixed-point numbers are read from the global storage unit 112, and 16-bit floating-point numbers are written to the local storage unit 113. The amount of written data is about twice the amount of read data, which may cause the amount of written data to reach the bandwidth bottleneck, resulting in a slow loading process of the input matrix B11, which has a negative impact on chip performance.
[0033] Figure 1C is a schematic diagram of a general matrix multiplication operation according to another embodiment of the present disclosure.
[0034] In some embodiments, Figure 1B The embodiment shown is different in that, in the loading stage, the 16-bit floating-point value of the input matrix A10 can be quantized to an 8-bit fixed-point value. The multiplication and accumulation operation unit 120 can perform calculations based on the quantized input matrix qA10 and the input matrix B11. The element-by-element processing unit 130 can process the output result matrix C10. Next, the direct memory access unit 111 can store the processed output result matrix C in the global storage unit 114. In this case, the amount of written data is difficult to reach the bandwidth bottleneck, and the risk of performance problems is relatively small. However, quantizing the 16-bit floating-point value to an 8-bit fixed-point value in the loading stage will result in a loss of data precision, which in turn leads to a decrease in the calculation accuracy of the chip.
[0035] It can be understood that the above describes some methods of general matrix multiplication operations between input matrices of different precisions based on quantization and dequantization. In some embodiments, the multiplication and accumulation operation unit can be adjusted. Figure 1D Provide explanation.
[0036] Figure 1D is a schematic diagram of a general matrix multiplication operation according to another embodiment of the present disclosure.
[0037] In some embodiments, the multiplication and accumulation operation unit 120 can be modified so that the multiplication and accumulation operation unit 120 can support operations on input matrices of different precisions. For example, the modified multiplication and accumulation operation unit can directly multiply the input matrix A10 with the input matrix B11. In the loading stage, the direct memory access unit 111 can directly read the input matrix A10 or the input matrix B11. Next, the multiplication and accumulation operation unit 120 can perform a general matrix multiplication operation on the input matrix A10 and the input matrix B11 to obtain the output result matrix C10. Hardware modification of the multiplication and accumulation operation unit will increase the hardware complexity, the modification cost is very high, and the iteration cycle is long.
[0038] In order to improve the accuracy and performance of artificial intelligence chips, the present disclosure provides a data processing device, which will be described below.
[0039] Figure 2 is a schematic block diagram of a data processing device according to an embodiment of the present disclosure.
[0040] like Figure 2 As shown, the data processing device 200 may include a quantization unit 210 and a first calculation unit 220 .
[0041] The quantization unit 210 may be configured to quantize the floating-point data to be processed into first fixed-point data according to the first maximum value corresponding to the floating-point data to be processed. For example, the floating-point data to be processed may be the input matrix A10 described above. The input matrix A10 may include one or more 16-bit floating-point values. The first maximum value may be a preset value corresponding to the floating-point data to be processed, or may be determined based on the maximum value in the floating-point data to be processed. The first fixed-point data may include one or more 8-bit fixed-point values.
[0042] The quantization unit 210 may also be configured to quantize the second floating-point data into second fixed-point data according to a second maximum value corresponding to the floating-point data to be processed. For example, the second maximum value may be a preset value corresponding to the floating-point data to be processed, or may be determined based on a maximum value in the floating-point data to be processed. The second fixed-point data may include one or more 8-bit fixed-point values. For another example, the maximum value may be a maximum value, a minimum value, or a maximum value after taking an absolute value.
[0043] In an embodiment of the present disclosure, the second floating-point data is obtained according to the floating-point data to be processed and the first floating-point data, and the first floating-point data is obtained by dequantizing the first fixed-point data.
[0044] For example, when floating-point data is converted into fixed-point data, the precision of the data will be reduced. Therefore, when the floating-point data to be processed is quantized into the first fixed-point data, the precision of the first fixed-point data is less than that of the floating-point data to be processed. After the first fixed-point data is dequantized into floating-point data, there may be a difference between the first floating-point data obtained and the floating-point data to be processed. In this case, the first floating-point data can be used as the high-order floating-point component of the floating-point data to be processed. Based on the floating-point data to be processed and the first floating-point data, the second floating-point data can be obtained. The second floating-point data corresponds to the low-order floating-point component of the floating-point data to be processed. The second floating-point data is quantized to obtain the second fixed-point data.
[0045] The first calculation unit 220 may be configured to obtain a first calculation result according to the fixed-point data to be processed and the first fixed-point data, and to obtain a second calculation result according to the fixed-point data to be processed and the second fixed-point data.
[0046] For example, the fixed-point data to be processed may be the above-mentioned input matrix B11.
[0047] For example, the first calculation unit 220 may be the above-mentioned multiplication and accumulation unit. A first calculation result may be obtained by performing a matrix operation based on the fixed-point data to be processed and the first fixed-point data. A second calculation result may be obtained by performing a matrix operation based on the fixed-point data to be processed and the second fixed-point data. Matrix operations may include various matrix operations such as matrix multiplication operations, matrix addition operations, and matrix subtraction operations.
[0048] For another example, the first calculation unit 212 may also be configured to obtain a target calculation result according to the first calculation result and the second calculation result. For example, the first calculation result and the second calculation result may be added, subtracted, or multiplied to obtain the target calculation result.
[0049] According to the embodiments of the present disclosure, a floating-point input data is quantized into multiple fixed-point data using the quantization and dequantization methods supported by the chip. And the related operations are performed on the multiple fixed-point data obtained by quantization according to another fixed-point input data, which can reduce the precision loss caused by directly converting the floating-point data into fixed-point data, and at the same time, the fixed-point numbers are still used for calculation when performing matrix calculations, which can make full use of the bandwidth and computing power of the artificial intelligence chip, and maintain the calculation accuracy while maintaining the chip performance.
[0050] It can be understood that the above is a description of the data processing device disclosed in the present invention. Figure 3 The quantization unit of the present disclosure will be described.
[0051] Figure 3 is a schematic diagram of data precision conversion according to an embodiment of the present disclosure.
[0052] In some embodiments, the quantization unit can realize the conversion between floating-point values of different precisions and the conversion between floating-point values and fixed-point values. Figure 3 As shown, the quantization unit can convert (cast) a 32-bit floating point value (FP32) to a 16-bit floating point value, or convert a 16-bit floating point value to a 32-bit floating point value.
[0053] In the embodiment of the present disclosure, quantization can be performed based on the floating-point value to be quantized, the target maximum value corresponding to the fixed-point number obtained by quantization, and the maximum value corresponding to the floating-point number to be quantized to obtain a fixed-point value. For example, the floating-point value can be quantized to a fixed-point value by the following formula:
[0054] (Formula 1)
[0055] quant_value can be a fixed-point value obtained by quantization, and value_f can be a floating-point value to be quantized. int_max can be a target maximum value. The fixed-point value obtained by quantization can correspond to a target precision. The target maximum value can be the maximum value represented by the target precision. max_value_general can be the maximum value corresponding to the floating-point value to be quantized, which can be a preset value or determined based on the maximum value among multiple floating-point values to be quantized. Figure 3 As shown, the quantization unit can quantize (quantize) a 32-bit floating-point value to a 16-bit fixed-point value (int16) or an 8-bit fixed-point value (int8). The quantization unit can also quantize a 16-bit floating-point value to a 16-bit fixed-point value or an 8-bit fixed-point value. According to the above formula 1, a 16-bit floating-point value can be quantized to an 8-bit fixed-point value by the following formula:
[0056] (Formula 2)
[0057] quant_int8 can be the 8-bit fixed-point value obtained by quantization, max_value can be the maximum value corresponding to the 16-bit floating-point number, and int_max can be the target maximum value corresponding to the 8-bit fixed-point value, that is, 127.
[0058] In the disclosed embodiment, according to the fixed-point value obtained by quantization, the target maximum value corresponding to the fixed-point value, and the maximum value corresponding to the floating-point value used during quantization, inverse quantization can be performed to obtain a floating-point value. For example, the fixed-point value can be quantized to a floating-point value by the following formula:
[0059] (Formula 3)
[0060] dequant_value is the floating point value obtained by dequantization, and quant_value is the fixed point value obtained by quantization. Figure 3 As shown, the quantization unit can dequantize a 16-bit fixed-point value into a 32-bit floating-point value or a 16-bit floating-point value. The quantization unit can also dequantize an 8-bit fixed-point value into a 32-bit floating-point value or a 16-bit floating-point value.
[0061] It can be understood that the quantization and dequantization methods of the present disclosure are described above, and the device of the present disclosure will be further described below.
[0062] Figure 4A is a schematic block diagram of a data processing device according to another embodiment of the present disclosure.
[0063] like Figure 4A As shown, the data processing device may include a quantization unit 410, a first calculation unit 420, a second calculation unit 430, a global storage unit 412, and a local storage unit 413. It can be understood that the description of the quantization unit 210 and the first calculation unit 210 in the above text is also applicable to the quantization unit 410 and the first calculation unit 420, and the present disclosure will not repeat them here. The description of the element-by-element processing unit 130, the global storage unit 112, and the local storage unit 113 in the above text is also applicable to the second calculation unit 430, the global storage unit 412, and the local storage unit 413, and the present disclosure will not repeat them here.
[0064] In some embodiments, the quantization unit may be integrated with the data handling unit. For example, the data handling unit 410 may be a direct memory access unit in the chip. Through the embodiments of the present disclosure, the quantization unit is integrated with the data handling unit, so that quantization can be achieved when handling data, thereby improving the computing efficiency of the chip.
[0065] In some embodiments, the data transfer unit may be configured to transfer the floating-point data to be processed from the global storage unit to the local storage unit so that the quantization unit quantizes the floating-point data to be processed into the first fixed-point data. Figure 4A As shown, the data transport unit 411 can read the floating-point data F40 to be processed and the fixed-point data I41 to be processed from the global storage unit 412, respectively, and store the floating-point data F40 to be processed and the fixed-point data I41 to be processed in the local storage unit 413. Through the embodiment of the present disclosure, the efficiency of the quantization unit in processing floating-point data can be improved by transporting data to the local storage unit, and the storage resources of the chip can be fully utilized.
[0066] In an embodiment of the present disclosure, the floating-point data F40 to be processed may include at least one floating-point value to be processed. The quantization unit 410 may correspond to the target precision. The maximum value that the target precision can represent is the target maximum value. The target precision may be the precision of the quantized fixed-point value supported by the quantization unit 410. For example, if the target precision is the precision of an 8-bit fixed-point value, the target maximum value is the maximum value that the 8-bit fixed-point value can represent, i.e., 127.
[0067] In an embodiment of the present disclosure, as described above, the quantization unit can quantize a 16-bit floating-point value into an 8-bit fixed-point value, but this will result in a loss of data precision. If the 16-bit floating-point value is quantized into a higher-precision fixed-point value, the loss of precision can be reduced. In addition, the quantization unit can be used to quantize the floating-point value into multiple fixed-point values so as to achieve higher-precision quantization using a combination of multiple fixed-point values. For example, the sign bits of two 8-bit fixed-point values are the same. Two 8-bit fixed-point values can share a sign bit. Therefore, two 8-bit fixed-point values can be combined into a 15-bit fixed-point value (INT15). For another example, according to the above formula one, a 16-bit floating-point value can be quantized into a 15-bit fixed-point value by the following formula:
[0068] (Formula 4)
[0069] quant_int15 may be a 15-bit fixed-point value obtained by quantization, 16383 may be the maximum value that can be represented by the 15-bit fixed-point value, and max_value may be the maximum value corresponding to the floating-point data u to be processed.
[0070] It can be understood that the above quantization unit can quantize a 16-bit floating point value into an 8-bit fixed point value, and it is difficult to directly quantize a 16-bit floating point value into a 15-bit floating point value. In order to fully utilize the quantization capability of the quantization unit and reduce the modification of the hardware, the 16-bit floating point value can be quantized into two 8-bit fixed point values. Figure 4A As shown, based on the quantization unit 410 and the second calculation unit 430, the floating point data F40 to be processed can be quantized into the first fixed point data I401 and the second fixed point data I402. Figure 4B Provide explanation.
[0071] Figure 4B is a schematic diagram of a quantization unit and a second calculation unit according to an embodiment of the present disclosure.
[0072] In some embodiments, the quantization unit may be configured to: quantize the floating-point data to be processed into first fixed-point data according to a first maximum value corresponding to the floating-point data to be processed.
[0073] In the embodiment of the present disclosure, quantization may be performed based on the floating-point data to be processed, the target maximum value and the first maximum value to obtain the first fixed-point data.
[0074] In the embodiment of the present disclosure, the first fixed-point data may include at least one first fixed-point value.
[0075] In the embodiment of the present disclosure, the first maximum value may be determined by the following operation: multiplying the maximum value to be processed, the target maximum value and the effective parameter value to obtain a first product result. The first product result is divided by the preset maximum value to obtain the first maximum value. The maximum value to be processed may be a preset value or a maximum value of at least one floating-point value to be processed. The effective parameter value may be determined according to the number of effective bits corresponding to the target precision. For example, the target maximum value may be 127. The target precision may be the precision of an 8-bit fixed-point number. An 8-bit fixed-point number may include a sign bit and 7 effective bits. Thus, the effective parameter value may be 128. The preset maximum value may be the maximum value representable by the preset precision. In the case where the preset precision is the precision of a 15-bit fixed-point value, the preset maximum value may be 16383. It can be understood that the first fixed-point value may be an 8-bit fixed-point value, which may be used as the high-order fixed-point component of the above-mentioned 15-bit fixed-point value. A change of 1 in the high-order fixed-point component may cause a change of 2 in the 15-bit fixed-point value. 7 Thus, the effective parameter value can be related to the number of significant digits of the target precision.
[0076] In the embodiment of the present disclosure, the quantization unit is further configured to perform the following operations to quantize the floating-point data to be processed into the first fixed-point data according to the first maximum value corresponding to the floating-point data to be processed: multiplying the floating-point value to be processed by the target maximum value to obtain the first product result to be processed; dividing the first product result to be processed by the first maximum value to quantize the floating-point value to be processed into the first fixed-point value. For example, the floating-point value to be processed can be quantized into the first fixed-point value by the following formula:
[0077] (Formula 5)
[0078] quant_int15_high can be the first fixed-point value. Can be the first maximum value. = ... Figure 4B As shown, based on the above formula 5, the quantization unit 410 can quantize the to-be-processed floating-point value f400 of the to-be-processed floating-point data f40 into a first fixed-point value i401.
[0079] In some embodiments, the quantization unit may be further configured to: perform inverse quantization on the first fixed-point data to obtain first floating-point data. The first floating-point data may include at least one first floating-point value. Figure 4BAs shown, using the above formula 3, according to the first maximum value or the maximum value to be processed, the quantization unit 410 can dequantize the first fixed-point value i401 into the first floating-point value df400.
[0080] In some embodiments, the second calculation unit may be configured to: use the floating point data to be processed to subtract the first floating point data to obtain the second floating point data. The second floating point data may include at least one second floating point value. Figure 4B As shown, the second calculation unit 430 may subtract the first floating point value df400 from the floating point value f400 to be processed to obtain a second floating point value f400′.
[0081] In some embodiments, the second calculation unit may also be configured to provide the second floating point value to the quantization unit. Figure 4B As shown, the second calculation unit 420 can provide the second floating point value to the quantization unit 410.
[0082] In some embodiments, the quantization unit may be further configured to: quantize the second floating-point data into second fixed-point data according to a second maximum value corresponding to the floating-point data to be processed.
[0083] In the embodiment of the present disclosure, the second fixed-point data may include at least one second fixed-point value.
[0084] In the embodiment of the present disclosure, the second maximum value may be determined by the following operations: multiplying the maximum value to be processed and the target maximum value to obtain a second product result, and dividing the second product result by a preset maximum value to obtain the second maximum value.
[0085] In the embodiment of the present disclosure, the quantization unit may also be configured to: multiply the second floating-point value by the target maximum value to obtain a second to-be-processed product result. Divide the second to-be-processed product result by the second maximum value to quantize the to-be-processed floating-point value to the second fixed-point value. For example, the second floating-point value may be quantized to the second fixed-point value by the following formula:
[0086] (Formula 6)
[0087] quant_int15_low can be the second fixed-point value, which can be used as the low-order fixed-point component of the 15-bit floating-point value. value_f can be the floating-point value to be processed, value_f_high can be the first floating-point value, and (value_f-value_f_high) can be the second floating-point value. Can be the second maximum value. Figure 4B As shown, according to Formula 6, the quantization unit 410 can quantize the second floating-point value df400 into a second fixed-point value i402.
[0088] like Figure 4A As shown, after completing the quantization of one or more floating-point values to be processed of the floating-point data F40 to be processed, the first fixed-point data I401 and the second fixed-point data I402 can be obtained. The first fixed-point data I401 and the second fixed-point data I402 can be provided to the first calculation unit 420. The first calculation unit 420 can perform related operations according to the fixed-point data to be processed I41, the first fixed-point data I401 and the second fixed-point data I402. Figure 4C Provide explanation.
[0089] Figure 4C is a schematic diagram of a first computing unit according to an embodiment of the present disclosure.
[0090] In some embodiments, the first calculation unit may be configured to obtain a first calculation result according to the fixed-point data to be processed and the first fixed-point data. Figure 4C As shown, the first calculation unit 410 can multiply the fixed-point data to be processed I41 with the first fixed-point data I401 to obtain a first calculation result.
[0091] In some embodiments, the first calculation unit may be configured to obtain a second calculation result according to the fixed-point data to be processed and the second fixed-point data. Figure 4C As shown, the first calculation unit 410 can multiply the fixed-point data to be processed I41 with the second fixed-point data I402 to obtain a second calculation result.
[0092] In some embodiments, the first calculation unit may be configured to obtain a target calculation result according to the first calculation result and the second calculation result. Figure 4C As shown, the first calculation unit 410 can add the first calculation result and the second calculation result to obtain the target calculation result C40.
[0093] It can be understood that the above description of the present disclosure is based on the example that the floating-point value to be processed is a 16-bit floating-point value, but the present disclosure is not limited thereto, the floating-point value to be processed may also be a 32-bit floating-point value, and the corresponding first fixed-point value and second fixed-point value may be 16-bit fixed-point values.
[0094] It can be understood that the above describes the device of the present disclosure, and the following describes an electronic device including the device.
[0095] Figure 5 is a schematic block diagram of an electronic device according to an embodiment of the present disclosure.
[0096] like Figure 5As shown, the device 50 may include a data processing device 500. The data processing device 500 may be the data processing device 200 described above.
[0097] It will be appreciated that the apparatus and devices of the present disclosure are described above, and the method of the present disclosure will be described below.
[0098] Figure 6 is a flow chart of a data processing method according to an embodiment of the present disclosure.
[0099] like Figure 6 As shown, the data processing method 600 of the present disclosure may include operations S610 - S650 .
[0100] In operation S610, the floating-point data to be processed is quantized into first fixed-point data by using a quantization unit according to a first maximum value corresponding to the floating-point data to be processed.
[0101] In operation S620, the second floating point data is quantized into second fixed point data by a quantization unit according to the second maximum value corresponding to the floating point data to be processed. The second floating point data is obtained according to the floating point data to be processed and the first floating point data, and the first floating point data is obtained by dequantizing the first fixed point data.
[0102] In operation S630, a first calculation result is obtained by using a first calculation unit according to the fixed-point data to be processed and the first fixed-point data.
[0103] In operation S640, a second calculation result is obtained by using the first calculation unit according to the fixed-point data to be processed and the second fixed-point data.
[0104] In operation S650, a target calculation result is obtained by using a first calculation unit according to the first calculation result and the second calculation result.
[0105] For example, the method 600 may be executed by the above-mentioned data processing device 200 .
[0106] In an embodiment of the present disclosure, the method further includes: using a second calculation unit to subtract the first floating point data from the floating point data to be processed to obtain second floating point data, and using the second calculation unit to provide the second floating point data to the quantization unit.
[0107] In an embodiment of the present disclosure, the floating-point data to be processed includes at least one floating-point value to be processed, the quantization unit corresponds to the target precision, and the maximum value that can be represented by the target precision is the target maximum value.
[0108] In an embodiment of the present disclosure, the method further includes: multiplying the maximum value to be processed, the target maximum value and the effective parameter value to obtain a first product result. The maximum value to be processed is a preset value or a maximum value of at least one floating-point value to be processed, and the effective parameter value is determined according to the number of effective digits corresponding to the target precision. Dividing the first product result by the preset maximum value to obtain the first maximum value.
[0109] In an embodiment of the present disclosure, the first fixed-point data includes at least one first fixed-point value, and according to a first maximum value corresponding to the floating-point data to be processed, quantizing the floating-point data to be processed into the first fixed-point data using the quantization unit includes: multiplying the floating-point value to be processed by the target maximum value to obtain a first product result to be processed. Dividing the first product result to be processed by the first maximum value to quantize the floating-point value to be processed into the first fixed-point value.
[0110] In an embodiment of the present disclosure, the method further includes: multiplying the maximum value to be processed and the target maximum value to obtain a second product result. The maximum value to be processed is a preset value or a maximum value of at least one floating-point value to be processed. Dividing the second product result by the preset maximum value to obtain the second maximum value.
[0111] In an embodiment of the present disclosure, the first floating-point data includes at least one first floating-point value, the second floating-point data includes at least one second floating-point value, and the second fixed-point data includes at least one second fixed-point value. According to the second maximum value corresponding to the floating-point data to be processed, quantizing the second floating-point data into the second fixed-point data using the quantization unit includes: multiplying the second floating-point value by the target maximum value to obtain a second product result to be processed. Dividing the second product result to be processed by the second maximum value to quantize the floating-point value to be processed into the second fixed-point value.
[0112] In an embodiment of the present disclosure, the quantization unit is integrated with the data handling unit.
[0113] In an embodiment of the present disclosure, the method further includes: using a data transfer unit to transfer the floating-point data to be processed from the global storage unit to the local storage unit, so that the quantization unit quantizes the floating-point data to be processed into first fixed-point data.
[0114] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0115] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
[0116] Figure 7A schematic block diagram of an example electronic device 700 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0117] like Figure 7 As shown, the device 700 includes a computing unit 701, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 702 or a computer program loaded from a storage unit 708 to a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the device 700 can also be stored. The computing unit 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0118] A number of components in the device 700 are connected to the I / O interface 705, including: an input unit 706, such as a keyboard, a mouse, etc.; an output unit 707, such as various types of displays, speakers, etc.; a storage unit 708, such as a disk, an optical disk, etc.; and a communication unit 709, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 709 allows the device 700 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0119] The computing unit 701 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 701 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSP), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 701 performs the various methods and processes described above, such as data processing methods. For example, in some embodiments, the data processing method may be implemented as a computer software program, which is tangibly included in a machine-readable medium, such as a storage unit 708. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 700 via the ROM 702 and / or the communication unit 709. When the computer program is loaded into the RAM 703 and executed by the computing unit 701, one or more steps of the data processing method described above may be performed. Alternatively, in other embodiments, the computing unit 701 may be configured to execute the data processing method in any other appropriate manner (eg, by means of firmware).
[0120] Various embodiments of the systems and techniques described above herein may be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard parts (ASSPs), system on chip systems (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0121] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0122] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories, read-only memories, erasable programmable read-only memories (EPROM) or flash memories, optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0123] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a cathode ray tube (CRT) display or a liquid crystal display (LCD)) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0124] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a Local Area Network (LAN), a Wide Area Network (WAN), and the Internet.
[0125] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0126] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0127] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present disclosure shall be included in the protection scope of the present disclosure.
Claims
1. A data processing device, comprising: Quantization unit, configured as: quantizing the floating-point data to be processed into first fixed-point data according to a first maximum value corresponding to the floating-point data to be processed; quantizing the second floating-point data into second fixed-point data according to a second maximum value corresponding to the floating-point data to be processed, wherein the second floating-point data is obtained according to the floating-point data to be processed and first floating-point data, and the first floating-point data is obtained by inverse quantization of the first fixed-point data; The first computing unit is configured as follows: Obtaining a first calculation result according to the fixed-point data to be processed and the first fixed-point data; Obtaining a second calculation result according to the fixed-point data to be processed and the second fixed-point data; A target calculation result is obtained according to the first calculation result and the second calculation result.
2. The apparatus according to claim 1, further comprising a second computing unit configured to: Subtracting the first floating-point data from the floating-point data to be processed to obtain the second floating-point data; The second floating point data is provided to the quantization unit.
3. The device according to claim 1, wherein: The floating-point data to be processed includes at least one floating-point value to be processed, the quantization unit corresponds to a target precision, and the maximum value that can be represented by the target precision is a target maximum value.
4. The device according to claim 3, wherein: The first maximum value is determined by the following operation: Multiplying the maximum value to be processed, the target maximum value and the effective parameter value to obtain a first product result, wherein the maximum value to be processed is a preset value or a maximum value of at least one floating-point value to be processed, and the effective parameter value is determined according to the number of effective digits corresponding to the target precision; The first maximum value is obtained by dividing the first product result by a preset maximum value.
5. The device according to claim 4, wherein: The first fixed-point data includes at least one first fixed-point value, The quantization unit is further configured to perform the following operations to quantize the floating-point data to be processed into first fixed-point data according to a first maximum value corresponding to the floating-point data to be processed: Multiplying the floating-point value to be processed by the target maximum value to obtain a first product result to be processed; The first to-be-processed product result is divided by the first maximum value to quantize the to-be-processed floating-point value to the first fixed-point value.
6. The device according to claim 3, wherein: The second maximum value is determined by the following operation: Multiplying the maximum value to be processed and the target maximum value to obtain a second product result, wherein the maximum value to be processed is a preset value or a maximum value of at least one floating-point value to be processed; The second maximum value is obtained by dividing the second product result by a preset maximum value.
7. The device according to claim 6, wherein: The first floating-point data includes at least one first floating-point value, the second floating-point data includes at least one second floating-point value, and the second fixed-point data includes at least one second fixed-point value. The quantization unit is further configured to perform the following operations to quantize the second floating-point data into second fixed-point data according to a second maximum value corresponding to the floating-point data to be processed: multiplying the second floating-point value by the target maximum value to obtain a second product result to be processed; The second to-be-processed product result is divided by the second maximum value to quantize the second floating-point value to the second fixed-point value.
8. The device according to claim 1, wherein: The quantization unit is integrated with the data handling unit.
9. The device according to claim 8, wherein: The data handling unit is configured as follows: The floating-point data to be processed are transferred from the global storage unit to the local storage unit, so that the quantization unit quantizes the floating-point data to be processed into the first fixed-point data.
10. An electronic device comprising the device according to any one of claims 1 to 9.
11. A data processing method, comprising: quantizing the floating-point data to be processed into first fixed-point data using a quantization unit according to a first maximum value corresponding to the floating-point data to be processed; quantizing the second floating-point data into second fixed-point data using the quantization unit according to a second maximum value corresponding to the floating-point data to be processed, wherein the second floating-point data is obtained according to the floating-point data to be processed and first floating-point data, and the first floating-point data is obtained by inverse quantization of the first fixed-point data; Obtaining a first calculation result using a first calculation unit according to the fixed-point data to be processed and the first fixed-point data; Obtaining a second calculation result using the first calculation unit according to the fixed-point data to be processed and the second fixed-point data; According to the first calculation result and the second calculation result, a target calculation result is obtained by using the first calculation unit.
12. The method according to claim 11, further comprising: Using a second calculation unit, subtracting the first floating-point data from the floating-point data to be processed to obtain the second floating-point data; The second floating point data is provided to the quantization unit using the second calculation unit.
13. The method according to claim 11, wherein: The floating-point data to be processed includes at least one floating-point value to be processed, the quantization unit corresponds to a target precision, and the maximum value that can be represented by the target precision is a target maximum value.
14. The method according to claim 13, wherein: The first maximum value is determined by the following operation: Multiplying the maximum value to be processed, the target maximum value and the effective parameter value to obtain a first product result, wherein the maximum value to be processed is a preset value or a maximum value of at least one floating-point value to be processed, and the effective parameter value is determined according to the number of effective digits corresponding to the target precision; The first maximum value is obtained by dividing the first product result by a preset maximum value.
15. The method according to claim 14, wherein: The first fixed-point data includes at least one first fixed-point value, The step of quantizing the floating-point data to be processed into first fixed-point data by using a quantization unit according to the first maximum value corresponding to the floating-point data to be processed comprises: Multiplying the floating-point value to be processed by the target maximum value to obtain a first product result to be processed; The first to-be-processed product result is divided by the first maximum value to quantize the to-be-processed floating-point value to the first fixed-point value.
16. The method according to claim 13, wherein: The second maximum value is determined by the following operation: Multiplying the maximum value to be processed and the target maximum value to obtain a second product result, wherein the maximum value to be processed is a preset value or a maximum value of at least one floating-point value to be processed; The second maximum value is obtained by dividing the second product result by a preset maximum value.
17. The method according to claim 16, wherein: The first floating-point data includes at least one first floating-point value, the second floating-point data includes at least one second floating-point value, and the second fixed-point data includes at least one second fixed-point value. The step of quantizing the second floating-point data into second fixed-point data by using the quantization unit according to the second maximum value corresponding to the floating-point data to be processed comprises: multiplying the second floating-point value by the target maximum value to obtain a second product result to be processed; The second to-be-processed product result is divided by the second maximum value to quantize the to-be-processed floating-point value into the second fixed-point value.
18. The method according to claim 11, wherein: The quantization unit is integrated with the data handling unit.
19. The method according to claim 18, further comprising: The data transfer unit is used to transfer the floating-point data to be processed from the global storage unit to the local storage unit, so that the quantization unit quantizes the floating-point data to be processed into the first fixed-point data.
20. An electronic device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions 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 perform the method according to any one of claims 11 to 19.
21. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 11 to 19.
22. A computer program product comprising a computer program which, when executed by a processor, implements the method according to any one of claims 11 to 19.
