Method and apparatus for data format conversion and method and apparatus for matrix processing

By adopting the xfp16 data format in the artificial intelligence model and dynamically adjusting the numerical range to balance the numerical range and precision, the problems of high resource consumption and insufficient precision of computationally intensive operators are solved, and high computational efficiency and precision improvement are achieved.

CN115237991BActive Publication Date: 2026-01-02KUNLUNXIN TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210946144.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-08
Publication Date
2026-01-02
Estimated Expiration
2042-08-08

AI Technical Summary

Technical Problem

Existing technologies for artificial intelligence model computation suffer from high computational resource consumption and insufficient precision, especially when using single-precision and half-precision floating-point data types, making it difficult to balance numerical range and precision.

Method used

By determining the maximum value, offset, and numerical range of the target matrix, and using a 16-bit half-precision data format (xfp16), the numerical range is dynamically adjusted to balance the numerical range and precision, thereby reducing the computational load of data format conversion.

Benefits of technology

It improves computing efficiency, reduces hardware resource consumption, significantly enhances computing performance and accuracy, and shortens the time for training and inference calculations of artificial intelligence models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115237991B_ABST
    Figure CN115237991B_ABST
Patent Text Reader

Abstract

The present disclosure provides a data format conversion method and device, and a matrix processing method and device, and relates to the technical field of computers, in particular to the technical field of artificial intelligence, deep learning, chips and the like. The specific implementation scheme of the data format conversion method is as follows: determining a maximum value of a target matrix according to each element in the target matrix; determining an offset according to a numerical value distribution interval of each element; determining a plurality of continuous numerical value intervals according to a numerical digit width of an index bit of a target data format, the offset and the maximum value of the target matrix; and converting an original data format of the target matrix into the target data format according to a corresponding relationship between each element and the plurality of numerical value intervals and a corresponding relationship between the plurality of numerical value intervals and the target data format. According to the scheme of the present disclosure, the operation amount of data format conversion can be reduced, and the quantization precision of each element in the target matrix can be improved while considering the numerical value range that can be represented by each element.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of computer, and particularly relates to the technical field of artificial intelligence, deep learning, chip, etc. BACKGROUND

[0002] There are a large number of computation-intensive operators in an artificial intelligence model, mainly including matrix computation, convolution, pooling and activation operators. The computation of the artificial intelligence model has a lower precision requirement than traditional high-performance computation applications, and the traditional high-performance computation applications mainly use double-precision data types, while the artificial intelligence applications mainly use single-precision and half-precision floating-point data types, or fixed-point data types. SUMMARY

[0003] The present disclosure provides a data format conversion method and device and a matrix processing method and device.

[0004] According to an aspect of the present disclosure, a data format conversion method is provided, comprising:

[0005] determining a maximum value of a target matrix according to each element in the target matrix;

[0006] determining an offset according to a numerical value distribution interval of each element;

[0007] determining a plurality of continuous numerical value intervals according to a digit width of an index bit of a target data format, the offset and the maximum value of the target matrix; and

[0008] converting an original data format of the target matrix into the target data format according to a corresponding relationship between each element and the plurality of numerical value intervals, and a corresponding relationship between the plurality of numerical value intervals and the target data format.

[0009] According to another aspect of the present disclosure, a matrix processing method is provided, comprising:

[0010] performing a multiplication operation on a first target matrix and a second target matrix to obtain a third matrix; wherein the data format of the first target matrix and the second target matrix is a target data format, and the target data format is obtained according to the data format conversion method of any embodiment of the present disclosure; and

[0011] converting the data format of the third matrix into a preset standard data format according to the preset standard data format.

[0012] According to another aspect of the present disclosure, a data format conversion device is provided, comprising:

[0013] a first determining module configured to determine a maximum value of a target matrix according to each element in the target matrix;

[0014] The second determining module is configured to determine the offset according to the numerical value distribution interval of each element.

[0015] The third determining module is configured to determine a plurality of continuous numerical value intervals according to the numerical digit width of the index bit of the target data format, the offset, and the maximum value of the target matrix.

[0016] The first converting module is configured to convert the original data format of the target matrix into the target data format according to the correspondence between each element and the plurality of numerical value intervals and the correspondence between the plurality of numerical value intervals and the target data format.

[0017] According to another aspect of the present disclosure, a device for matrix processing is provided, comprising:

[0018] The operation module is configured to perform multiplication operation on the first target matrix and the second target matrix to obtain a third matrix; wherein the data format of the first target matrix and the second target matrix is the target data format, and the target data format is obtained according to the method for data format conversion of any one of the embodiments of the present disclosure; and

[0019] The second converting module is configured to convert the data format of the third matrix into a preset standard data format according to the preset standard data format.

[0020] According to another aspect of the present disclosure, an electronic device is provided, comprising:

[0021] at least one processor; and

[0022] a memory in communication with the at least one processor; wherein

[0023] 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 of any one of the embodiments of the present disclosure.

[0024] According to another aspect of the present disclosure, a non-transitory computer readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to perform the method according to any one of the embodiments of the present disclosure.

[0025] According to another aspect of the present disclosure, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the method according to any one of the embodiments of the present disclosure.

[0026] According to another aspect of the present disclosure, an artificial intelligence chip is provided, comprising an execution device which executes the method of any one of the embodiments of the present disclosure.

[0027] According to the scheme of the present disclosure, the operation amount of data format conversion can be reduced, and the quantization precision of each element in the target matrix is improved while considering the numerical range that can be represented by each element.

[0028] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present disclosure, nor to limit the scope of the present disclosure. Other features of the present disclosure will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS

[0029] The accompanying drawings are used to better understand the present scheme and do not limit the present disclosure. Among them:

[0030] Figure 1 is a flowchart of a data format conversion method according to an embodiment of the present disclosure;

[0031] Figure 2 is a schematic diagram of a target data format according to an embodiment of the present disclosure;

[0032] Figure 3 is a schematic diagram of a numerical line segment according to an embodiment of the present disclosure;

[0033] Figure 4 is a flowchart of a matrix processing method according to an embodiment of the present disclosure;

[0034] Figure 5 is an application schematic diagram of a matrix processing method according to an embodiment of the present disclosure;

[0035] Figure 6 is a structural schematic diagram of a data format conversion device according to an embodiment of the present disclosure;

[0036] Figure 7 is a structural schematic diagram of a matrix processing device according to an embodiment of the present disclosure;

[0037] Figure 8 is an application scenario schematic diagram of a data format conversion method and / or a matrix processing method according to an embodiment of the present disclosure;

[0038] Figure 9 is a structural schematic diagram of an artificial intelligence chip according to an embodiment of the present disclosure;

[0039] Figure 10 is a block diagram of an electronic device for implementing a data format conversion method and / or a matrix processing method according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0040] Exemplary embodiments of the present disclosure are described herein with reference to the accompanying drawings, which are cited as illustrative examples. Various changes and modifications can be suggested to one ordinarily skilled in the art, and it is intended that the present disclosure encompass such changes and modifications as fall within the scope of the appended claims. Also, in the description of the present disclosure, descriptions of well-known functions and constructions are omitted for clarity and conciseness.

[0041] According to an embodiment of the present disclosure, as shown in Figure 1 A method for data format conversion is provided, comprising:

[0042] Step S100: determining a maximum value of the target matrix according to each element in the target matrix.

[0043] Step S101: determining an offset according to a numerical value distribution interval of each element.

[0044] Step S102: determining a plurality of continuous numerical value intervals according to a numerical digit width of an exponential bit of the target data format, the offset, and the maximum value of the target matrix.

[0045] Step S103: converting the original data format of the target matrix into the target data format according to a corresponding relationship between each element and the plurality of numerical value intervals, and a corresponding relationship between the plurality of numerical value intervals and the target data format.

[0046] According to the above-mentioned embodiments of the present disclosure, it should be noted that:

[0047] The target matrix can be a matrix of any dimension.

[0048] The element can be understood as a data or vector in the target matrix located at different rows and columns. For example, the target matrix is a 2x2 matrix, and the target matrix contains four elements.

[0049] The maximum value of the target data can be understood as the maximum value among the absolute value numerical values of each element.

[0050] The corresponding relationship between each element and the plurality of numerical value intervals can be understood as a mapping relationship of the absolute value numerical value of each element on the plurality of numerical value intervals, i.e., which numerical value interval the absolute value numerical value of each element is located in.

[0051] The corresponding relationship between the plurality of numerical value intervals and the target data format can be understood as a calculation method of the exponential bit and the mantissa bit of the target data format corresponding to each numerical value interval. The calculation method of the exponential bit and the mantissa bit of the target data format corresponding to different numerical value intervals can be different.

[0052] Converting the original data format of the target matrix into the target data format can be understood as converting the original data format of each element in the target matrix into the target data format, so as to realize the conversion of the original data format of the target matrix into the target data format.

[0053] According to the embodiments of the present disclosure, the operation amount of data format conversion can be reduced, the quantization precision of each element in the target matrix is improved, and the numerical range that can be represented by each element is taken into account. By introducing the offset, the numerical interval can be dynamically adjusted, and the numerical range and numerical precision are balanced.

[0054] The method of data format conversion in the embodiments of the present disclosure can be applied to a computationally intensive operator of an artificial intelligence model. The computationally intensive operator can convert the data format of the input target matrix by the method, thereby reducing the operation resource consumption of the operator. The computationally intensive operator described in the embodiments of the present disclosure can be an operator used in the model training process, or an operator used in the inference process of the trained model. That is, the method of data format conversion in the embodiments of the present disclosure can be applied to the model training process, or can be applied to the actual inference process of the model.

[0055] The method of data format conversion in the embodiments of the present disclosure can be applied to an artificial intelligence chip, and can improve the peak performance of the artificial intelligence chip. When the artificial intelligence chip is applied to artificial intelligence model training and artificial intelligence model inference calculation, the time of artificial intelligence model training and the time of inference calculation can be greatly shortened.

[0056] In one example, the target matrix is a matrix used by an operator in a deep learning framework. The operator in the deep learning framework can be a high-precision operator used in the model training process, or an operator used when the trained model is calculated.

[0057] According to the embodiments of the present disclosure, the calculation efficiency of the operator in the deep learning framework can be improved when the target matrix after data format conversion is used for calculation, and the calculation resources can be saved.

[0058] In one example, each element in the target matrix is data obtained by feature extraction on image information, voice information, or text information.

[0059] According to the embodiments of the present disclosure, the feature data extracted from the image information, voice information, or text information can be converted in data format, and the feature data after data format conversion can be used for post-processing, which can effectively improve the processing speed of the image information, voice information, or text information.

[0060] In one embodiment, as Figure 2As shown, the bit width of the target data format is 16 bits, including a sign bit with a bit width of 1 bit, an exponent bit with a bit width of 2 bits, and a mantissa bit with a bit width of 13 bits.

[0061] It should be noted that, for the convenience of the description of the embodiments of the present disclosure, the target data format of 16-bit half-precision of the embodiments of the present disclosure is referred to as xfp16.

[0062] The bit width used in the calculation formula of each embodiment of the present disclosure can be understood as a specific numerical value of the bit width. For example, a numerical value segment is divided into 2 N N is the bit width of the exponent bit (2 bits) of the target data format, that is, N is 2.

[0063] According to the embodiments of the present disclosure, the xfp16 of the embodiments of the present disclosure is more suitable for the process of matrix operation processing, and can significantly improve the operation performance and accuracy. The operation performance of the existing float (floating point data type) data format is 19.5T (Terabyte, TB), the operation performance of the existing tf32 (TensorFlow) data format is 156T, and the operation performance of the xfp16 of the embodiments of the present disclosure can reach 312T when performing matrix calculation, which is 16 times and 2 times faster than float and tf32 respectively, and the operation performance is significantly improved.

[0064] The traditional fp16 (floating point) and bfloat16 (brain floating point) have more exponent bits and fewer mantissa bits, so the range of values that can be represented is very wide. However, since the exponent bit calculation is complex, more hardware resources are consumed. The traditional int16 (integer) does not have an exponent, so the calculation process is simple and less hardware resources are consumed. However, since the range of values that can be represented is small, there is a problem of accuracy degradation in the calculation when applied to the matrix calculation of some artificial intelligence models. The xfp16 of the embodiments of the present disclosure adopts a different data type from the traditional fp16, bfloat16 and int16, has more mantissa bits and fewer exponent bits. Thus, for the AI scene, the range that can be represented is wider than int16, and fewer exponent bits make the hardware consume fewer resources (at least 30% less hardware resource consumption), and the same area (16 bits) has better performance than standard fp16 and bfloat16, and can better represent artificial intelligence models and matrix data.

[0065] In an embodiment, the method for data format conversion of the present disclosure comprises steps S100-S103, wherein step S100 comprises:

[0066] The absolute value of each element is determined according to the floating point number of each element in the target matrix.

[0067] The maximum value of the target matrix is determined according to the maximum absolute value of each element.

[0068] It should be noted that the absolute value of each element can be determined by converting the floating point number of each element.

[0069] According to the present disclosure, the maximum value of the target matrix can be accurately determined according to the floating point number of each element in the target matrix.

[0070] In an embodiment, the method for data format conversion of the present disclosure comprises steps S100-S103, wherein step S101 comprises:

[0071] A plurality of value distribution intervals of each element are determined according to the value of each element.

[0072] The offset is determined according to a first value distribution interval with the largest number of elements in the plurality of value distribution intervals.

[0073] According to the present disclosure, the data format does not need to have such a large numerical range during the deep learning training process. A larger numerical range will result in poor numerical accuracy. The determined offset can adjust the numerical interval, so that the maximum endpoint value of each numerical interval is originally shifted to the left. By adjusting the offset, the numerical range and numerical accuracy can be balanced to achieve better model training results.

[0074] In an embodiment, the method for data format conversion of the present disclosure comprises steps S100-S103, wherein step S101 comprises:

[0075] In the case where the value of each element is normally distributed, the value of the element corresponding to the median of the normal distribution is taken as the center, and the second value distribution interval is determined according to a preset value rule.

[0076] The offset is determined according to the second value distribution interval.

[0077] According to embodiments of this disclosure, during deep learning training, the data format does not need such a large numerical range. A larger numerical range leads to poorer numerical accuracy. By using a defined offset, the numerical intervals can be adjusted so that the maximum endpoint values ​​of each interval are shifted to the left by the original default method. By adjusting the offset, a balance can be struck between numerical range and numerical accuracy, achieving better model training results.

[0078] In one embodiment, the data format conversion method of this disclosure includes steps S100 to S103, wherein step S102: determining a plurality of consecutive numerical intervals based on the bit width of the exponent of the target data format, the offset, and the maximum value of the target matrix, specifically including:

[0079] The numerical line segment is determined by using the maximum value of the target matrix as the maximum endpoint value and 0 as the minimum endpoint value.

[0080] Based on the digit width of the exponent in the target data format, the numerical line segment is divided into continuous 2... N A range of values.

[0081] Based on the digit width and offset of the mantissa in the target data format, use the formula Determine 2 respectively N The minimum endpoint value of each of the intervals.

[0082] Where N is the width of the exponent in the target data format, max0 is the maximum value of the target matrix, and max... a M is the minimum endpoint value for each numerical interval, P is the width of the mantissa in the target data format, A is the offset, and A is the order of the numerical intervals from largest to smallest.

[0083] According to embodiments of this disclosure, by utilizing the digit width of the exponent and the digit width of the mantissa of the target data format, numerical segments adapted to the target matrix can be defined. Furthermore, the maximum and minimum endpoint values ​​of each numerical interval within the numerical segments that best fits the values ​​of each element in the target matrix can be determined.

[0084] In a specific example, the target data format has a 16-bit (binary digit) width, including a 1-bit sign bit, a 2-bit exponent bit, and a 13-bit mantissa bit. The maximum value of the target matrix is ​​taken as the maximum endpoint value, max0. Based on the 2-bit width of the exponent bit in the target data format, without considering offset, the numerical segments are divided into four consecutive numerical intervals, specifically including:

[0085] [0, max3], [max3, max2], [max2, max1] and [max1, max0] four numerical intervals. Among them,

[0086] On the basis of the above numerical line segment is divided into four continuous numerical intervals, the introduction of offset, according to the numerical distribution of each element, the offset is determined as 4, as shown in Figure 3 Four new numerical intervals are formed: [0, max3], [max3, max2], [max2, max1] and [max1, max0].

[0087] Among them, the new The new The new

[0088] In an embodiment, the offset can take any value according to the numerical distribution interval of each element, but the value of the offset is not greater than the value of the mantissa bit of the target data format.

[0089] In an embodiment, the method for data format conversion of the present disclosure comprises steps S100 to S103, wherein step S103: converting the original data format of the target matrix into the target data format according to the correspondence between each element and the plurality of numerical intervals, and the correspondence between the plurality of numerical intervals and the target data format, which can specifically include:

[0090] Step S1031: determining the exponent bit of the target data format corresponding to each element according to the correspondence between the floating point number of each element and the plurality of numerical intervals, and the correspondence between the plurality of numerical intervals and the target data format.

[0091] Step S1032: determining the mantissa bit of the target data format corresponding to each element according to the correspondence between the floating point number of each element and the plurality of numerical intervals, and the correspondence between the plurality of numerical intervals and the target data format.

[0092] Step S1033: determining the sign bit of the target data format corresponding to each element according to the floating point number of each element.

[0093] Step S1034: converting the original data format of the target matrix into the target data format according to the sign bit, the exponent bit and the mantissa bit of the target data format corresponding to each element.

[0094] According to the present disclosure, by using the correspondence between the floating point number of each element and the plurality of numerical intervals, and the correspondence between the plurality of numerical intervals and the target data format, the mantissa bit and the exponent bit of the target data format corresponding to each element can be accurately calculated, so as to realize the conversion of the original data format of the target matrix into the target data format with high precision and wide numerical range.

[0095] In an embodiment, the method for data format conversion of the present disclosure comprises steps S100-S103, wherein step S1031: determining the exponent bit of the target data format corresponding to each element according to the correspondence between the floating point number of each element and the plurality of numerical intervals, and the correspondence between the plurality of numerical intervals and the target data format, which can specifically include:

[0096] Determining the absolute value of each element according to the floating point number of each element.

[0097] Determining the numerical interval corresponding to each element in the plurality of numerical intervals according to the absolute value of each element.

[0098] Determining the exponent bit of the target data format corresponding to each element according to the correspondence between the corresponding numerical interval and the exponent bit of the target data format.

[0099] In one example, the bit width of the target data format is 16 bits, including a sign bit with a bit width of 1 bit, an exponent bit with a bit width of 2 bits, and a mantissa bit with a bit width of 13 bits. The maximum value of the target matrix as the maximum endpoint value is max0, and according to the bit width of the exponent bit of the target data format 2 bits, the numerical line segment is divided into 4 continuous numerical intervals, as shown in Figure 3 , specifically including:

[0100] [0, max3], [max3, max2], [max2, max1], and [max1, max0] four numerical intervals. Among them,

[0101] When the numerical interval corresponding to the absolute value of the element is [0, max3], i.e., the absolute value < max3, it is determined that the exponent bit of the target data format corresponding to the element is 00.

[0102] When the numerical interval corresponding to the absolute value of the element is [max3, max2], i.e., max3 < absolute value ≤ max2, it is determined that the exponent bit of the target data format corresponding to the element is 01.

[0103] When the numerical interval corresponding to the absolute value of the element is [max2, max1], i.e., max2 < absolute value ≤ max1, it is determined that the exponent bit of the target data format corresponding to the element is 10.

[0104] When the numerical interval corresponding to the absolute value of the element is [max1, max0], i.e., max1 < absolute value ≤ max0, it is determined that the exponent bit of the target data format corresponding to the element is 11.

[0105] In an embodiment, the method for data format conversion of the present disclosure comprises steps S100-S103, wherein step S1032: determining the mantissa bits of the target data format corresponding to each element according to the correspondence between the floating point number of each element and the plurality of numerical intervals, and the correspondence between the plurality of numerical intervals and the target data format, which can specifically include:

[0106] Determining the absolute value of each element according to the floating point number of each element.

[0107] Determining the numerical interval corresponding to each element in the plurality of numerical intervals according to the absolute value of each element.

[0108] According to the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa bits of the target data format, and the absolute value of each element, the mantissa bits of the target data format corresponding to each element are determined by using the formula .

[0109] Wherein F is the value of the mantissa bits of the target data format corresponding to each element, V is the absolute value of each element, k is the digit width of the mantissa bits of the target data format, and max c is the maximum endpoint value of the corresponding numerical interval.

[0110] It should be noted that the floating point number of the original data format of each element of the target matrix is converted into the target data format, and the calculation logic of determining the mantissa bits of the target data format corresponding to each element is the calculation method of the mantissa bits of the present embodiment, but the mantissa bits of the target data format corresponding to each element are obtained by shifting the floating point number based on the calculation logic in actual operation, which effectively improves the calculation time of the target data format conversion.

[0111] According to the present disclosure, the maximum endpoint value of the numerical interval corresponding to each element, the digit width of the mantissa bits of the target data format, and the absolute value of each element can be accurately calculated to obtain the mantissa bits of the target data format corresponding to each element.

[0112] In an embodiment, the digit width of the target data format is 16 bits (Binary digit), including a sign bit with a digit width of 1 bit, an exponent bit with a digit width of 2 bits, and a mantissa bit with a digit width of 13 bits. The maximum value of the target matrix as the maximum endpoint value is max0, and according to the digit width of the exponent bit of the target data format 2 bits, the numerical line segment is divided into 4 continuous numerical intervals, as shown in Figure 3 .

[0113] [0, max3], [max3, max2], [max2, max1] and [max1, max0] four numerical intervals. Among them,

[0114] When the absolute value of the element corresponds to the numerical interval [0, max3], that is, the absolute value < max3, the mantissa bit of the target data format corresponding to the element is

[0115] When the absolute value of the element corresponds to the numerical interval [max3, max2], that is, max3 < absolute value ≤ max2, the mantissa bit of the target data format corresponding to the element is

[0116] When the absolute value of the element corresponds to the numerical interval [max2, max1], that is, max2 < absolute value ≤ max1, the mantissa bit of the target data format corresponding to the element is

[0117] When the absolute value of the element corresponds to the numerical interval [max1, max0], that is, max1 < absolute value ≤ max0, the mantissa bit of the target data format corresponding to the element is

[0118] In an embodiment, step S1033: according to the floating point number of each element, determining the sign bit of the target data format corresponding to each element, comprising:

[0119] According to the floating point number of the element, when the value of the element is greater than or equal to 0, the sign bit of the target data format corresponding to the element is recorded as 0. When the value of the element is less than 0, the sign bit of the target data format corresponding to the element is recorded as 1.

[0120] The embodiments of the present disclosure are only used for illustration, and vice versa. That is, when the value of the element is greater than or equal to 0, the sign bit of the target data format corresponding to the element is recorded as 1, and when the value of the element is less than 0, the sign bit of the target data format corresponding to the element is recorded as 0.

[0121] It should be noted that 1 and 0 of the sign bit are used to represent positive numbers or negative numbers, respectively, and whether the sign bit is 1 or 0 specifically represents a positive number or a negative number, which is selected and adjusted as needed.

[0122] According to the embodiments of the present disclosure, as shown in Figure 4 A matrix processing method is provided, comprising:

[0123] Step S400: performing multiplication operation on the first target matrix and the second target matrix to obtain a third matrix. The data format of the first target matrix and the second target matrix is the target data format, which is obtained according to the method for data format conversion of any of the embodiments of the present disclosure.

[0124] Step S401: converting the data format of the third matrix into the preset standard data format according to the preset standard data format.

[0125] According to the above embodiments of the present disclosure, it should be noted that:

[0126] The first target matrix and the second target matrix are matrices used by operators in a deep learning framework. Each first element and each second element is data obtained by performing feature extraction on image information, voice information or text information.

[0127] According to the embodiments of the present disclosure, the method for matrix processing can be performed by a multiplier, and the data format conversion process of the first target matrix and the second target matrix is performed inside the multiplier. The user cannot feel the data format conversion, and only pays attention to the input and output data of the multiplier. This way can realize the compatibility of different data, and the user does not need to change the data format of the input target matrix according to the multiplier. The format conversion process is automatically performed inside the multiplier.

[0128] The method for matrix processing of the embodiments of the present disclosure can be applied to a compute-intensive operator of an artificial intelligence model. The compute-intensive operator can realize the conversion of the data format of the input target matrix by the method, thereby reducing the operation resource consumption of the operator. The compute-intensive operator described in the embodiments of the present disclosure can be an operator used in the model training process, or an operator used in the inference process of the trained model. That is, the method for data format conversion of the embodiments of the present disclosure can be applied to the model training process, or can be applied to the actual inference process of the model.

[0129] The method for matrix processing of the embodiments of the present disclosure can be applied to an artificial intelligence chip, which can improve the peak performance of the artificial intelligence chip. When the artificial intelligence chip is applied to artificial intelligence model training and artificial intelligence model inference calculation, the time for artificial intelligence model training and the time for inference calculation can be greatly shortened.

[0130] In one example, the first target matrix and the second target matrix are matrices used by operators in a deep learning framework. The operator in the deep learning framework can be a high-precision operator used in the model training process, or an operator used when the trained model is calculated.

[0131] According to the embodiment of the present disclosure, the calculation efficiency of the operator in the deep learning framework can be improved by using the target matrix after data format conversion for calculation, and the calculation resources can be saved.

[0132] In one example, the first element and the second element can be data obtained by performing feature extraction on image information, voice information, or text information.

[0133] According to the embodiment of the present disclosure, the feature data extracted from the image information, voice information, or text information can be converted in data format, and the processing speed of the image information, voice information, or text information can be effectively improved by using the feature data after data format conversion for post-processing.

[0134] In one example, as shown in Figure 5 The method for data format conversion of any embodiment of the present disclosure is used to convert the matrix A in the fp16 data format, the bfloat16 data format, or the float data format into the first target matrix in the xfp16 data format. The method for data format conversion of any embodiment of the present disclosure is used to convert the matrix B in the fp16 data format, the bfloat16 data format, or the float data format into the second target matrix in the xfp16 data format. Then, the multiplication of the first target matrix and the second target matrix is performed by using steps S400 and S401 of the method for matrix processing, the matrix obtained by calculation is converted in data format according to the preset standard data format, and the matrix C (i.e., the third matrix) in the fp16 data format, the bfloat16 data format, or the float data format is obtained.

[0135] In one embodiment, the method for matrix processing of the embodiment of the present disclosure includes steps S400 and S401, wherein step S400 is multiplication of the first target matrix and the second target matrix to obtain the third matrix, and specifically can include:

[0136] According to the target data format corresponding to each first element in the first target matrix, the sign bit and the mantissa bit of the target data format corresponding to each first element are determined.

[0137] According to the target data format corresponding to each second element in the second target matrix, the sign bit and the mantissa bit of the target data format corresponding to each second element are determined.

[0138] According to the sign bit and the mantissa bit of the target data format corresponding to each first element and the sign bit and the mantissa bit of the target data format corresponding to each second element, the multiplication of the first target matrix and the second target matrix is performed to obtain the third matrix.

[0139] According to the embodiment of the present disclosure, since the calculation process does not involve the exponent bits, the resources consumed by the multiplication operation of the first target matrix and the second target matrix are saved, and meanwhile, since the mantissa bits are utilized, the data precision of the elements of the third matrix obtained can be ensured.

[0140] In one embodiment, the method for matrix processing of the present disclosure comprises steps S400 and S401, wherein in step S400, in the process of multiplication operation of the first target matrix and the second target matrix, the multiplication operation of the first element and the corresponding second element is performed by using the formula c=F1*F2*S1*S2.

[0141] Wherein, F1 is the value of the mantissa bits of the target data format corresponding to the first element, F2 is the value of the mantissa bits of the target data format corresponding to the corresponding second element, S1 is the fixed-to-floating point conversion scaling coefficient of the first element, and S2 is the fixed-to-floating point conversion scaling coefficient of the corresponding second element.

[0142] According to the embodiment of the present disclosure, the scaling coefficients can be used to convert the first element and the second element from fixed-point numbers to floating-point numbers, which is more convenient for data format conversion of the third matrix.

[0143] In one example, the fixed-to-floating point conversion scaling coefficients of the elements are determined according to the numerical value intervals corresponding to the absolute value numerical values of the elements in the target matrix. Specifically, the formula may be used to determine.

[0144] Wherein, S is the fixed-to-floating point conversion scaling coefficient corresponding to each element (S1, S2), k is the bit width of the mantissa bits of the target data format, and max c is the maximum endpoint value of the corresponding numerical value interval.

[0145] In one example, the bit width of the target data format is 16 bits (Binary digit), including a sign bit with a bit width of 1 bit, an exponent bit with a bit width of 2 bits, and a mantissa bit with a bit width of 13 bits. The maximum value of the target matrix as the maximum endpoint value is max0, and according to the bit width of the exponent bit of the target data format 2 bits, the numerical value interval is divided into four continuous numerical value intervals, as shown in Figure 3 , specifically including:

[0146] [0, max3], [max3, max2], [max2, max1], and [max1, max0] four numerical value intervals. Wherein,

[0147] When the numerical value interval corresponding to the absolute value numerical value of the element is [0, max3], i.e., the absolute value numerical value < max3, the mantissa bits of the target data format corresponding to the element Scaling factor of fixed-point conversion of element

[0148] When the absolute value of the element corresponds to the value interval [max3, max2], i.e., max3 < absolute value ≤ max2, the mantissa bit of the target data format corresponding to the element Scaling factor of fixed-point conversion of element

[0149] When the absolute value of the element corresponds to the value interval [max2, max1], i.e., max2 < absolute value ≤ max1, the mantissa bit of the target data format corresponding to the element Scaling factor of fixed-point conversion of element

[0150] When the absolute value of the element corresponds to the value interval [max1, max0], i.e., max1 < absolute value ≤ max0, the mantissa bit of the target data format corresponding to the element Scaling factor of fixed-point conversion of element

[0151] In an embodiment, the method for matrix processing of the present disclosure comprises steps S400 and S401, wherein in step S400, the operation result sign of the multiplication operation of the first element and the corresponding second element is determined according to the bitwise XOR of the sign bit of the target data format corresponding to the first element and the sign bit of the target data format corresponding to the corresponding second element.

[0152] In an embodiment, the method for data format conversion and the method for matrix processing of the present disclosure both comprise quantization process of converting floating-point number to fixed-point number and dequantization process of converting fixed-point number to floating-point number in the execution process. Wherein the original data format of the target matrix converted to the target data format is floating-point data. The data format of the third matrix converted to the preset standard data format is floating-point data.

[0153] According to the present disclosure, as shown in Figure 6 A data format conversion device is provided, comprising:

[0154] The first determining module 610 is configured to determine the maximum value of the target matrix according to each element in the target matrix.

[0155] The second determining module 620 is configured to determine the offset according to the value distribution interval of each element.

[0156] The third determining module 630 is configured to determine a plurality of continuous value intervals according to the digit width of the exponent bit of the target data format, the offset, and the maximum value of the target matrix. And

[0157] The first conversion module 640 is used to convert the original data format of the target matrix into the target data format according to the correspondence between each element and multiple numerical intervals, and the correspondence between multiple numerical intervals and the target data format.

[0158] In one implementation, the target data format has a bit width of 16 bits, including a sign bit with a bit width of 1 bit, an exponent bit with a bit width of 2 bits, and a mantissa bit with a bit width of 13 bits.

[0159] In one implementation, the first determining module 610 is used to:

[0160] Determine the absolute value of each element based on its floating-point number.

[0161] The largest absolute value among all elements is determined as the maximum value of the target matrix.

[0162] In one implementation, the second determining module 620 is used to:

[0163] Based on the values ​​of each element, determine multiple value distribution ranges for each element;

[0164] The offset is determined based on the first numerical distribution interval containing the largest number of elements among multiple numerical distribution intervals.

[0165] In one implementation, the second determining module 620 is used to:

[0166] When the values ​​of each element follow a normal distribution, the second value distribution interval is determined based on the value of the element corresponding to the median of the normal distribution, according to the preset value selection rules.

[0167] The offset is determined based on the second numerical distribution interval.

[0168] In one implementation, the third determining module 630 is used to:

[0169] The numerical line segment is determined by using the maximum value of the target matrix as the maximum endpoint value and 0 as the minimum endpoint value.

[0170] Based on the digit width of the exponent in the target data format, the numerical line segment is divided into continuous 2... N A range of values.

[0171] Based on the digit width and offset of the mantissa in the target data format, use the formula Determine 2 respectively N The minimum endpoint value of each of the intervals.

[0172] wherein N is the number of bit width of the exponent bit of the target data format, max0 is the maximum value of the target matrix, max a is the minimum endpoint value of each value interval, M is the number of bit width of the mantissa bit of the target data format, P is the offset, and A is the order of each value interval arranged from large to small.

[0173] In an embodiment, the first conversion module 640 comprises:

[0174] A first determining submodule is configured to determine the exponent bit of the target data format corresponding to each element according to the correspondence between the floating point number of each element and the plurality of value intervals, and the correspondence between the plurality of value intervals and the target data format.

[0175] A second determining submodule is configured to determine the mantissa bit of the target data format corresponding to each element according to the correspondence between the floating point number of each element and the plurality of value intervals, and the correspondence between the plurality of value intervals and the target data format.

[0176] A third determining submodule is configured to determine the sign bit of the target data format corresponding to each element according to the floating point number of each element.

[0177] A conversion submodule is configured to convert the original data format of the target matrix into the target data format according to the sign bit, the exponent bit, and the mantissa bit of the target data format corresponding to each element.

[0178] In an embodiment, the first determining submodule is configured to:

[0179] determine the absolute value of each element according to the floating point number of each element.

[0180] determine the value interval corresponding to each element in the plurality of value intervals according to the absolute value of each element.

[0181] determine the exponent bit of the target data format corresponding to each element according to the correspondence between the corresponding value interval and the exponent bit of the target data format.

[0182] In an embodiment, the second determining submodule is configured to:

[0183] determine the absolute value of each element according to the floating point number of each element.

[0184] determine the value interval corresponding to each element in the plurality of value intervals according to the absolute value of each element.

[0185] determine the mantissa bit of the target data format corresponding to each element according to the maximum endpoint value of the corresponding value interval, the number of bit width of the mantissa bit of the target data format, and the absolute value of each element, using the formula determine the mantissa bit of the target data format corresponding to each element according to the maximum endpoint value of the corresponding value interval, the number of bit width of the mantissa bit of the target data format, and the absolute value of each element, using the formula

[0186] wherein F is a value of a mantissa bit of the target data format corresponding to each element, V is an absolute value of each element, k is a bit width of the mantissa bit of the target data format, max c is a maximum endpoint value of the corresponding numerical interval.

[0187] In an implementation, the target matrix is a matrix utilized by an operator in a deep learning framework. Each element in the target matrix is data obtained by performing feature extraction on image information, voice information, or text information.

[0188] The specific functions and examples of each module and sub-module of the apparatus according to the embodiments of the present disclosure are described above in the corresponding steps of the method embodiments, and will not be described here again.

[0189] According to the embodiments of the present disclosure, as shown in Figure 7 a matrix processing apparatus is provided, comprising:

[0190] The operation module 710 is configured to perform multiplication operation on the first target matrix and the second target matrix to obtain a third matrix. The data format of the first target matrix and the second target matrix is the target data format, and the target data format is obtained according to the data format conversion method in any one of claims 1 to 8.

[0191] and

[0192] The second conversion module 720 is configured to convert the data format of the third matrix into a preset standard data format according to the preset standard data format.

[0193] In an implementation, the operation module 710 is configured to:

[0194] According to the target data format corresponding to each first element in the first target matrix, determine the sign bit and the mantissa bit of the target data format corresponding to each first element.

[0195] According to the target data format corresponding to each second element in the second target matrix, determine the sign bit and the mantissa bit of the target data format corresponding to each second element.

[0196] According to the sign bit and the mantissa bit of the target data format corresponding to each first element, and the sign bit and the mantissa bit of the target data format corresponding to each second element, perform multiplication operation on the first target matrix and the second target matrix to obtain a third matrix.

[0197] In an implementation, in the process of performing multiplication operation on the first target matrix and the second target matrix, the multiplication operation of the first element and the corresponding second element utilizes the formula c=F1*F2*S1*S2.

[0198] F1 is a value of a mantissa bit of the target data format corresponding to the first element, F2 is a value of a mantissa bit of the target data format corresponding to the corresponding second element, S1 is a fixed floating point conversion scaling factor of the first element, and S2 is a fixed floating point conversion scaling factor of the corresponding second element.

[0199] In an embodiment, a result sign of the multiplication operation of the first element and the corresponding second element is determined according to a bitwise XOR operation of a sign bit of the target data format corresponding to the first element and a sign bit of the target data format corresponding to the corresponding second element.

[0200] In an embodiment, the first target matrix and the second target matrix are matrices used by an operator in a deep learning framework. The first element and the second element are data obtained by performing feature extraction on image information, voice information, or text information.

[0201] The specific functions and examples of the modules and sub-modules of the apparatuses of the embodiments of the present disclosure are described above in the corresponding steps of the method embodiments, and will not be described here.

[0202] In the technical solutions of the present disclosure, the acquisition, storage, and application of user personal information comply with relevant laws and regulations and do not violate public order and good customs.

[0203] According to the embodiments of the present disclosure, Figure 8 is a schematic diagram of a distributed cluster processing scenario according to an embodiment of the present disclosure. The distributed cluster system is an example of a cluster system. An example is described that the distributed cluster system can be used for model training. The deep learning framework of the model training can perform the data format conversion method of any one of the embodiments of the present disclosure and / or the matrix processing method of any one of the embodiments of the present disclosure through a compute-intensive operator. The present disclosure is not limited to model training on a single machine or multiple machines. The distributed processing can further improve the accuracy of model training. For example, Figure 8As shown, the distributed cluster system 800 includes multiple nodes (such as server cluster 801, server 802, server cluster 803, server 804, and server 805; server 805 can also connect to electronic devices, such as mobile phone 8051 and desktop computer 8052). Multiple nodes, as well as multiple nodes and connected electronic devices, can jointly execute one or more model training tasks. Optionally, the multiple nodes in this distributed cluster system can adopt a data-parallel model training method, in which case multiple nodes can execute model training tasks based on the same training method to better train the model; if the multiple nodes in this distributed cluster system adopt a model-parallel model training method, then multiple nodes can execute model training tasks based on different training methods to better train the model. Optionally, after each round of model training is completed, multiple nodes can exchange data (such as data synchronization).

[0204] According to embodiments of this disclosure, such as Figure 9 As shown, this disclosure also provides an artificial intelligence (AI) chip 900, including: an execution device for performing a data format conversion method and / or a matrix processing method of any of the above embodiments of this disclosure.

[0205] The AI ​​chip 900 can be any AI chip in the existing technology, without specific limitations. This includes, but is not limited to, GPUs (graphics processing units), FPGAs (field-programmable gate arrays), and ASICs (application-specific integrated circuits).

[0206] According to embodiments of this disclosure, the peak performance of an artificial intelligence chip can be improved by using the data format conversion method and / or the matrix processing method of any of the above embodiments of this disclosure. When the artificial intelligence chip is applied to artificial intelligence model training and inference calculations, the training time and inference calculation time of the artificial intelligence model can be significantly shortened.

[0207] According to embodiments of this disclosure, this disclosure also provides an electronic device, a readable storage medium, and a computer program product.

[0208] Figure 10A schematic block diagram of an example electronic device 1000 that can be used to implement embodiments 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 may also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0209] like Figure 10 As shown, device 1000 includes a computing unit 1001, which can perform various appropriate actions and processes according to a computer program stored in read-only memory (ROM) 1002 or a computer program loaded from storage unit 1008 into random access memory (RAM) 1003. The RAM 1003 may also store various programs and data required for the operation of device 1000. The computing unit 1001, ROM 1002, and RAM 1003 are interconnected via bus 1004. Input / output (I / O) interface 1005 is also connected to bus 1004.

[0210] Multiple components in device 1000 are connected to I / O interface 1005, including: input unit 1006, such as a keyboard, mouse, etc.; output unit 1007, such as various types of displays, speakers, etc.; storage unit 1008, such as a disk, optical disk, etc.; and communication unit 1009, such as a network card, modem, wireless transceiver, etc. Communication unit 1009 allows device 1000 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0211] The computing unit 1001 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the computing unit 1001 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, and the like. The computing unit 1001 performs various methods and processes described above, e.g., the method of data format conversion and / or the method of matrix processing. For example, in some embodiments, the method of data format conversion and / or the method of matrix processing can be implemented as a computer software program tangibly embodied in a machine-readable medium, e.g., the storage unit 1008. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device 1000 via the ROM 1002 and / or the communication unit 1009. When the computer program is loaded onto the RAM 1003 and executed by the computing unit 1001, one or more steps of the method of data format conversion and / or the method of matrix processing described above can be performed. Alternatively, in other embodiments, the computing unit 1001 can be configured to perform the method of data format conversion and / or the method of matrix processing by any other appropriate means, e.g., by means of firmware.

[0212] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a complex programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.

[0213] Program code for carrying out methods of the present disclosure can be written in any combination of one or more programming languages. The program code can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the program code, when executed by the processor or controller, produces the functions / operations specified in the flowcharts and / or block diagrams. The program code can be executed entirely on a machine, partially on a machine, partially on a machine as a standalone software package, or entirely on a remote machine or server.

[0214] In the context of the present disclosure, a machine-readable medium can be a tangible medium that contains or stores a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include but is not limited to an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0215] To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices can be used to provide for interaction with a user as well; for example, 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, speech, or tactile input.

[0216] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can 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.

[0217] The computer system can include clients and servers. This relationship can be. The servers are typically remote from the clients with the interactions between them occurring over a communication network. The relationship between client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The servers can be cloud servers, servers of a distributed system, or servers incorporating blockchain.

[0218] It should be understood that the various forms of flow shown above can be re-ordered, added to, or deleted from without departing from the scope of the present disclosure. For example, the steps recited in the present disclosure can be performed in parallel, in series, or in a different order, without departing from the desired results of the technology disclosed in the present disclosure, and are not limited herein.

[0219] The specific embodiments described above are not intended to be limiting. One of skill in the art will understand that various modifications, combinations, sub-combinations, and alternatives can be made to the specific embodiments without departing from the intended spirit and principles of the disclosure. Any modification, equivalent replacement, and improvement, etc. made within the spirit and principles of the present disclosure should be included in the scope of the present disclosure.

Claims

1. A method for data format conversion, comprising: The maximum value of the target matrix is ​​determined based on the elements of the target matrix used by the operators in the deep learning framework, wherein each element is data obtained by feature extraction of image information, speech information or text information; The offset is determined based on the numerical distribution range of each element; Using the maximum value of the target matrix as the maximum endpoint and 0 as the minimum endpoint, a numerical segment is determined; based on the digit width of the exponent in the target data format, the numerical segment is divided into two consecutive segments. N A numerical interval; based on the digit width of the mantissa of the target data format, the digit width of the exponent, the offset, and the maximum value of the target matrix, determine the 2... N The minimum endpoint value of each numerical interval in the given range; N is the digit width of the exponent in the target data format; and Based on the floating-point numbers of each element, determine the absolute value of each element and the sign bit of the target data format corresponding to each element; based on the absolute value of each element and the 2 N The minimum endpoint value of each of the 2 numerical intervals determines the element in the 2 N The numerical intervals are defined as follows: Based on the correspondence between the corresponding numerical intervals and the exponent bits of the target data format, the exponent bits of each element in the target data format are determined; based on the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa bits of the target data format, and the absolute value of each element, the mantissa bits of each element in the target data format are determined; based on the sign bit, exponent bit, and mantissa bits, the original data format of the target matrix is ​​converted to the target data format.

2. The method according to claim 1, wherein, The target data format has a bit width of 16 bits, including a sign bit with a bit width of 1 bit, an exponent bit with a bit width of 2 bits, and a mantissa bit with a bit width of 13 bits.

3. The method according to claim 1 or 2, wherein, Determining the maximum value of the target matrix based on each element in the target matrix includes: Determine the absolute value of each element based on the floating-point number of each element in the target matrix; The largest absolute value among the elements is determined as the maximum value of the target matrix.

4. The method according to claim 1 or 2, wherein, Determining the offset based on the numerical distribution range of each element includes: Based on the values ​​of each element, determine multiple value distribution ranges for each element; The offset is determined based on the first numerical distribution interval that contains the most elements among the plurality of numerical distribution intervals.

5. The method according to claim 1 or 2, wherein, Determining the offset based on the numerical distribution range of each element includes: When the values ​​of all elements are normally distributed, the second value distribution interval is determined based on the value of the element corresponding to the median of the normal distribution, according to a preset value selection rule. The offset is determined based on the second numerical distribution range.

6. The method according to claim 1 or 2, wherein, The 2 is determined based on the digit width of the mantissa, the digit width of the exponent, the offset, and the maximum value of the target matrix in the target data format. N The minimum endpoint value of each of the numerical intervals, including: Based on the digit width of the mantissa in the target data format and the offset, the formula is used. Determine the 2 respectively N The minimum endpoint value of each of the intervals of values; Where N is the bit width of the exponent in the target data format. The maximum value of the target matrix. M is the minimum endpoint value of each numerical interval, P is the width of the mantissa of the target data format, A is the offset, and A is the order of the numerical intervals from largest to smallest.

7. The method according to claim 1, wherein, The step of determining the mantissa of each element in the target data format based on the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa of the target data format, and the absolute value of each element includes: Based on the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa of the target data format, and the absolute value of each element, the formula is used... Determine the mantissa of the target data format corresponding to each element; Where F is the value of the mantissa of the target data format corresponding to each element. The absolute values ​​of each element are given. The width of the mantissa in the target data format. This is the maximum endpoint value of the corresponding numerical range.

8. A method for matrix processing, comprising: A third matrix is ​​obtained by multiplying the first target matrix and the second target matrix; wherein the data formats of the first target matrix and the second target matrix are both target data formats, and the target data formats are obtained by the data format conversion method according to any one of claims 1 to 7; and The data format of the third matrix is ​​converted into the preset standard data format according to the preset standard data format.

9. The method according to claim 8, wherein, The process of multiplying the first and second target matrices to obtain the third matrix includes: Based on the target data format corresponding to each first element in the first target matrix, determine the sign bit and mantissa bit of the target data format corresponding to each first element; Based on the target data format corresponding to each second element in the second target matrix, determine the sign bit and mantissa bit of the target data format corresponding to each second element; Based on the sign bit and mantissa bit of the target data format corresponding to each first element, and the sign bit and mantissa bit of the target data format corresponding to each second element, a multiplication operation is performed on the first target matrix and the second target matrix to obtain the third matrix.

10. The method according to claim 9, wherein, During the multiplication operation between the first target matrix and the second target matrix, the multiplication operation between the first element and the corresponding second element is performed using the formula c = F1. F2 S1 S2 proceeds; Wherein, F1 is the value of the mantissa of the target data format corresponding to the first element, F2 is the value of the mantissa of the target data format corresponding to the second element, S1 is the fixed-to-floating-point conversion scaling factor of the first element, and S2 is the fixed-to-floating-point conversion scaling factor of the second element.

11. The method according to claim 10, wherein, The sign of the result of the multiplication operation between the first element and the corresponding second element is determined by bitwise XORing the sign bit of the target data format corresponding to the first element and the sign bit of the target data format corresponding to the second element.

12. The method according to any one of claims 9 to 11, wherein the first target matrix and the second target matrix are matrices used by operators in a deep learning framework; and each first element and each second element are data obtained by feature extraction of image information, speech information or text information.

13. An apparatus for data format conversion, comprising: The first determining module is used to determine the maximum value of the target matrix based on each element of the target matrix used by the operator in the deep learning framework, wherein each element is data obtained by feature extraction of image information, speech information or text information; The second determining module is used to determine the offset based on the numerical distribution range of each element; The third determining module is used to determine numerical segments using the maximum value of the target matrix as the maximum endpoint value and 0 as the minimum endpoint value; and to divide the numerical segments into continuous 2^n segments according to the digit width of the exponent in the target data format. N A numerical interval; based on the digit width of the mantissa of the target data format, the digit width of the exponent of the target data format, the offset, and the maximum value of the target matrix, the 2... N The minimum endpoint value of each numerical interval in the given range; N is the digit width of the exponent in the target data format; and The first conversion module is used to determine the absolute value of each element and the sign bit of the target data format corresponding to each element based on the floating-point number of each element; based on the absolute value of each element and the 2 N The minimum endpoint value of each of the 2 numerical intervals determines the element in the 2 N The numerical intervals are defined as follows: Based on the correspondence between the corresponding numerical intervals and the exponent bits of the target data format, the exponent bits of each element in the target data format are determined; based on the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa bits of the target data format, and the absolute value of each element, the mantissa bits of each element in the target data format are determined; based on the sign bit, exponent bit, and mantissa bits, the original data format of the target matrix is ​​converted to the target data format.

14. The apparatus according to claim 13, wherein, The target data format has a bit width of 16 bits, including a sign bit with a bit width of 1 bit, an exponent bit with a bit width of 2 bits, and a mantissa bit with a bit width of 13 bits.

15. The apparatus according to claim 13 or 14, wherein, The first determining module is used for: Determine the absolute value of each element based on the floating-point number of each element in the target matrix; The largest absolute value among the elements is determined as the maximum value of the target matrix.

16. The apparatus according to claim 13 or 14, wherein, The second determining module is used for: Based on the values ​​of each element, determine multiple value distribution ranges for each element; The offset is determined based on the first numerical distribution interval containing the largest number of elements among the plurality of numerical distribution intervals; Alternatively, the second determining module is used to: When the values ​​of all elements are normally distributed, the second value distribution interval is determined based on the value of the element corresponding to the median of the normal distribution, according to a preset value selection rule. The offset is determined based on the second numerical distribution range.

17. The apparatus according to claim 13 or 14, wherein, The 2 is determined based on the digit width of the mantissa, the digit width of the exponent, the offset, and the maximum value of the target matrix in the target data format. N The minimum endpoint value of each of the numerical intervals, including: Based on the digit width of the mantissa in the target data format and the offset, the formula is used. Determine the 2 respectively N The minimum endpoint value of each of the intervals of values; Where N is the bit width of the exponent in the target data format. The maximum value of the target matrix. M is the minimum endpoint value of each numerical interval, P is the width of the mantissa of the target data format, A is the offset, and A is the order of the numerical intervals from largest to smallest.

18. The apparatus according to claim 13, wherein, The step of determining the mantissa of each element in the target data format based on the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa of the target data format, and the absolute value of each element includes: Based on the maximum endpoint value of the corresponding numerical interval, the digit width of the mantissa of the target data format, and the absolute value of each element, the formula is used... Determine the mantissa of the target data format corresponding to each element; Where F is the value of the mantissa of the target data format corresponding to each element. The absolute values ​​of each element are given. The width of the mantissa in the target data format. This is the maximum endpoint value of the corresponding numerical range.

19. A matrix processing apparatus, comprising: The computation module is used to perform multiplication operations on the first target matrix and the second target matrix to obtain a third matrix; wherein the data formats of the first target matrix and the second target matrix are both target data formats, and the target data formats are obtained by the data format conversion method according to any one of claims 1 to 7; and The second conversion module is used to convert the data format of the third matrix into the preset standard data format according to the preset standard data format.

20. The apparatus according to claim 19, wherein, The computing module is used for: Based on the target data format corresponding to each first element in the first target matrix, determine the sign bit and mantissa bit of the target data format corresponding to each first element; Based on the target data format corresponding to each second element in the second target matrix, determine the sign bit and mantissa bit of the target data format corresponding to each second element; Based on the sign bit and mantissa bit of the target data format corresponding to each first element, and the sign bit and mantissa bit of the target data format corresponding to each second element, a multiplication operation is performed on the first target matrix and the second target matrix to obtain the third matrix.

21. The apparatus according to claim 20, wherein, During the multiplication operation between the first target matrix and the second target matrix, the multiplication operation between the first element and the corresponding second element is performed using the formula c = F1. F2 S1 S2 proceeds; Wherein, F1 is the value of the mantissa of the target data format corresponding to the first element, F2 is the value of the mantissa of the target data format corresponding to the second element, S1 is the fixed-to-floating-point conversion scaling factor of the first element, and S2 is the fixed-to-floating-point conversion scaling factor of the second element.

22. The apparatus according to claim 20, wherein, The sign of the result of the multiplication operation between the first element and the corresponding second element is determined by bitwise XORing the sign bit of the target data format corresponding to the first element and the sign bit of the target data format corresponding to the second element.

23. The apparatus according to any one of claims 20 to 22, wherein, The first target matrix and the second target matrix are matrices used by operators in a deep learning framework; each first element and each second element is data obtained by feature extraction from image information, speech information, or text information.

24. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1 to 12.

25. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1 to 12.

26. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 12.

27. An artificial intelligence chip, comprising: An execution device for performing the method according to any one of claims 1 to 12.

Citation Information

Patent Citations

  • Matrix processor as well as instruction set and embedded system thereof

    CN102360344A

  • An improved floating point multiply-adder and a floating point multiply-add calculating method

    CN107168678A