Data processing method and related device
By providing multiple data format combinations and format selection bit marking technology in artificial intelligence scenarios, the lack of data transmission efficiency and accuracy in the memory wall problem is solved, and flexible compression and efficient storage of data are achieved, which is suitable for the training and development of AI models. reasoning scenario.
Patent Information
- Application Number
- CN202310310172.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-21
- Publication Date
- 2024-09-24
AI Technical Summary
In artificial intelligence scenarios, the memory wall problem causes data transmission speed to lag behind computing power. Existing technologies such as FP16 and INT8 compression methods suffer from loss of accuracy or insufficient compression efficiency, and cannot meet users' flexible format needs.
Provide a data processing method that allows different data in the same batch of data to select different compression formats. Through the combination of multiple format types such as FP8, FP16, INT16, INT8, etc., the compression accuracy and efficiency can be flexibly selected, including generating and using format selection bits. Tag and decompress.
It achieves flexible compression of data, takes into account compression accuracy and efficiency, covers user needs, improves storage and read and write speeds, and is suitable for AI model training and inference scenarios.
Smart Images

Figure 00000000_0000
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data processing method and related devices. Background Art
[0002] In artificial intelligence (AI) scenarios, the memory wall problem is a common bottleneck. For example, the size of the transformer model, which has been popular in recent years, has increased by thousands of times compared to when it was first developed. In contrast, the memory size of AI hardware is only doubling every two years. In addition, the memory wall problem is also related to memory access bandwidth. In the current AI scenario, the speed of data transmission also lags far behind the computing power of AI hardware.
[0003] For the memory wall problem, the training data is usually compressed during the training process to reduce the demand for memory capacity and memory access bandwidth. For example, half-precision or quantization methods are used to convert the training data from single-precision floating-point numbers (Full-precision floating-point, FP32) to half-precision floating-point numbers (Half-precision floating-point, FP16) or 8-bit integers (INT8). However, the compression effect of FP16 on training data is relatively general, while INT8 will cause a certain loss of precision. In view of this, a new data type 8-bit floating-point type (FP8) is proposed. Compressing data into FP8 can effectively improve compression efficiency and compression accuracy. However, FP8 currently only provides two data formats. Moreover, although two formats are provided, each batch of training data can only use the same format, which cannot meet the user's usage needs. Summary of the invention
[0004] The present application provides a data processing method and related devices, which provide multiple compression formats when compressing data, and different data in the same batch of data can choose different compression formats, so that compression accuracy and compression efficiency can be taken into account, covering the user's usage needs as much as possible.
[0005] In a first aspect, the present application provides a data processing method, which can be applied to a data processing device. The method includes: the data processing device receives target batch data, the target batch data includes first data and second data; the data processing device compresses the first data into a first format to obtain third data; the data processing device compresses the second data into a second format to obtain fourth data, wherein the first format and the second format are different format types.
[0006] The target batch data may be 8-bit data, 16-bit data, 32-bit data, 64-bit data or larger data, and the data processing device may compress the target batch data. The first data included in the target batch data may be multiple data or single data, and the same is true for the second data.
[0007] The data processing device provides multiple compression formats, such as 16-bit type, 8-bit type and 4-bit type, etc. Among them, the 16-bit type and the 8-bit type can be floating point type (FP16, FP8), integer type (INT16, INT8) or other format types, and the 4-bit type can be integer type (INT4) or other format types.
[0008] INT data, FP16 data, and FP32 data are all in fixed formats. The first bit in INT data is the sign bit, which is used to indicate the positive or negative of the data, and the remaining bits are used to store data, and the stored data is an integer. In FP16, the first bit is the sign bit, the following 5 bits are the exponent bits, and the remaining 10 bits are the mantissa bits. The sign bit indicates the positive or negative of the data, the exponent bits store integers, and the mantissa bits store decimals. In FP32, the first bit is the sign bit, the following 8 bits are the exponent bits, and the remaining 23 bits are the mantissa bits. FP8 does not limit the allocation of exponent bits and mantissa bits, so FP8 can have multiple formats. For example, the format of FP8 can be one sign bit, 2 exponent bits, and 5 mantissa bits, or one sign bit, 3 exponent bits, and 4 mantissa bits, or one sign bit, 4 exponent bits, and 3 mantissa bits. The more exponent bits there are, the fewer mantissa bits there are, and the larger the range of representation, but the accuracy will deteriorate. Conversely, the fewer exponent bits there are, the more mantissa bits there are, and the smaller the range of representation, but the accuracy will increase. The format type of FP8 is not limited in this application.
[0009] It should be noted that although both the first format and the second format can be compressed into 16-bit type or 8-bit type, the first format and the second format are different format types. Even if the first format and the second format are both FP8, the first format and the second format are different format types in FP8. That is, the first data and the second data in the same batch of data can be compressed into different formats, realizing flexible selection of compression formats.
[0010] In the first aspect of the present application, multiple compression formats are provided when compressing data to cover the user's usage requirements as much as possible. In addition, different data in the same batch of data can be compressed into different formats as needed, thereby achieving a balance between compression accuracy and compression efficiency.
[0011] In a possible implementation manner of the first aspect, the first format and the second format are two different formats in an 8-bit floating point number type (FP8).
[0012] The first format and the second format may both be of FP8 type, the FP8 type includes seven format types, and the first format and the second format are two different format types among the seven format types.
[0013] In this possible implementation, the types of the first format and the second format are limited, thereby improving the feasibility of the solution.
[0014] In a possible implementation of the first aspect, the method also includes: a data processing device generates a first format selection bit based on the first format, and the first format selection bit is used to indicate the first format; the data processing device uses the first format selection bit to mark the third data; the data processing device decompresses the third data based on the first format selection bit to obtain the first data.
[0015] The data processing device can generate a format selection bit for the provided compression format, and use the format selection bit to mark the format type of the compressed data, so that when the compressed data needs to be decompressed later, the format type of the compressed data can be obtained from the corresponding format selection bit, and then the compressed data can be decompressed to obtain the data in the original format.
[0016] In a possible implementation manner of the first aspect, the third data is stored in a first area, the first format selection bit is stored in a second area, and the first area and the second area are different storage areas.
[0017] In this possible implementation, the compressed data and the corresponding format selection bits can be stored in different areas, so that the data and the format selection bits can be written or read in parallel, thereby improving the storage rate and the reading rate.
[0018] In a possible implementation of the first aspect, the first data and the second data are continuous data, and the method further includes: a data processing device generates a second format selection bit based on the second format, and the second format selection bit is used to indicate the second format; the data processing device uses the second format selection bit to mark the fourth data, and the second format selection bit and the first format selection bit are located in the same byte.
[0019] When the first data and the second data are consecutive data in the target batch data, and the total number of bits of the first format selection bit corresponding to the first data and the second format selection bit corresponding to the second data does not exceed one byte (i.e., 8 bits), the first format selection bit and the second format selection bit can be spliced in the same byte for storage. n) format selection bits, where n is the number of compression formats provided by the data processing device. If the number of bits after concatenation is less than 8 bits, the remaining bits are padded with 0 to make up a full byte.
[0020] For the format selection bits in the same byte, the data are written in the order of the data. For example, if the first data is before the second data, the first data is written first, and then the second data.
[0021] In this possible implementation, format selection bits of multiple consecutive data may be concatenated in the same byte for storage, thereby saving storage space and improving read and write efficiency.
[0022] In a possible implementation of the first aspect, the method also includes: a data processing device receives a first instruction, the first instruction is used to determine a third format, and the third format includes the first format; the above step: the data processing device compresses the first data into the first format, includes: the data processing device compresses the first data into the first format in the third format.
[0023] The data processing device receives a first instruction, the first instruction carries format information selected by a user, and the data processing device determines a third format according to the format information carried by the first instruction, the format included in the third format is the format to be compressed by the first data (that is, including the first format), or the format included in the third format is the format of the third data. The data processing device then determines the first format from the third format, thereby compressing the first data into the first format to obtain the third data.
[0024] In this possible implementation, the user may pre-select one or more formats from the compression formats provided by the data processing device, and the data processing device determines the compression format from the formats pre-selected by the user, thereby improving the processing speed.
[0025] In a possible implementation of the first aspect, the above-mentioned step: the data processing device compresses the first data into a first format, includes: the data processing device receives a second instruction, the second instruction carries a format selection condition, and the format selection condition is used to determine whether to compress the first data into the first format; the data processing device compresses the first data into the first format based on the format selection condition.
[0026] In this possible implementation, the user can preset the format selection condition through the second instruction, and the data processing device determines the first format according to the format selection condition, thereby improving the feasibility of the solution.
[0027] In a possible implementation of the first aspect, the above-mentioned step: the data processing device compresses the first data into the first format, includes: the data processing device receives a third instruction, and the third instruction is used to instruct to compress the first data into the first format; the data processing device compresses the first data into the first format based on the third instruction.
[0028] In this possible implementation, the user can directly instruct the data processing device through the third instruction into which format to compress the first data, thereby improving the processing speed of the data processing device and expanding the application scenarios of the solution.
[0029] In a possible implementation of the first aspect, the method is applied to an inference scenario of an artificial intelligence AI model and / or a training scenario of an AI model, and the target batch data includes training samples and weight data.
[0030] In this possible implementation, the data processing method provided in the first aspect can be applied to the reasoning scenario and / or training scenario of the AI model, and the first data and the second data can be training samples and / or weight data, which improves the feasibility of the solution.
[0031] The second aspect of the present application provides a data processing device, including a receiving unit and a compression unit. The receiving unit is used to receive target batch data, the target batch data includes first data and second data; the compression unit is used to compress the first data into a first format to obtain third data; the compression unit is also used to compress the second data into a second format to obtain fourth data, wherein the first format and the second format are different format types.
[0032] In a possible implementation manner of the second aspect, the first format and the second format are two different formats of an 8-bit floating point number type.
[0033] In a possible implementation of the second aspect, the device also includes a generation unit, which is used to generate a first format selection bit based on the first format, and the first format selection bit is used to indicate the first format; a marking unit, which is used to mark the third data using the first format selection bit; and a decompression unit, which is used to decompress the third data based on the first format selection bit to obtain the first data.
[0034] In a possible implementation manner of the second aspect, the third data is stored in the first area, the first format selection bit is stored in the second area, and the first area and the second area are different storage areas.
[0035] In a possible implementation of the second aspect, the first data and the second data are continuous data, the generating unit is further used to generate a second format selection bit based on the second format, and the second format selection bit is used to indicate the second format; the marking unit is further used to mark the fourth data using the second format selection bit, and the second format selection bit and the first format selection bit are located in the same byte.
[0036] In a possible implementation manner of the second aspect, the receiving unit is further used to receive a first instruction, the first instruction is used to determine a third format, the third format includes the first format; the compression unit is specifically used to compress the first data into a first format in the third format.
[0037] In a possible implementation of the second aspect, the compression unit is specifically used to receive a second instruction, the second instruction carries a format selection condition, and the format selection condition is used to determine whether to compress the first data into a first format; and compress the first data into the first format based on the format selection condition.
[0038] In a possible implementation manner of the second aspect, the compression unit is specifically used to receive a third instruction, where the third instruction is used to instruct to compress the first data into the first format; and compress the first data into the first format based on the third instruction.
[0039] In a possible implementation of the second aspect, the device is applied to an inference scenario of an artificial intelligence AI model and / or a training scenario of an AI model, and the target batch data includes training samples and weight data.
[0040] The data processing device provided in the second aspect of the present application is used to execute the method described in the first aspect or any possible implementation manner of the first aspect.
[0041] The third aspect of the present application provides a data processing device, including a processor and a memory, wherein the memory is used to store instructions, and the processor is used to obtain the instructions stored in the memory to execute the method described in the first aspect or any possible implementation of the first aspect.
[0042] A fourth aspect of the present application provides a computer-readable storage medium, which includes instructions. When the instructions are executed on a computer, the computer executes the method described in the first aspect or any possible implementation of the first aspect.
[0043] A fifth aspect of the present application provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the method described in the first aspect or any possible implementation of the first aspect.
[0044] In a sixth aspect, the present application provides a chip system, which includes at least one processor and a communication interface, wherein the communication interface and the at least one processor are interconnected via lines, and the at least one processor is used to run computer programs or instructions to execute the method described in the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] Figure 1 A schematic diagram of an application scenario of the data processing method provided in an embodiment of the present application;
[0046] Figure 2 A schematic diagram of an embodiment of a data processing method provided in an embodiment of the present application;
[0047] Figure 3 A schematic diagram of a data format and a corresponding format selection bit in an embodiment of the present application;
[0048] Figure 4 A schematic diagram of splicing format selection bits in an embodiment of the present application;
[0049] Figure 5 A schematic diagram of another embodiment of the data processing method provided in the embodiment of the present application;
[0050] Figure 6 A schematic diagram of another embodiment of the data processing method provided in the embodiment of the present application;
[0051] Figure 7 A schematic diagram of another embodiment of the data processing method provided in the embodiment of the present application;
[0052] Figure 8 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application;
[0053] Fig. 9 Another structural schematic diagram of the data processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0054] The following describes the embodiments of the present application in conjunction with the accompanying drawings. Obviously, the described embodiments are only embodiments of a part of the present application, rather than all embodiments. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0055] The terms "system" and "network" in the specification and claims of the present application and the above-mentioned drawings can be used interchangeably. Unless otherwise specified, ordinal numbers such as "first" and "second" are used to distinguish multiple objects and are not used to limit the order, timing, priority or importance of multiple objects. It should be understood that the terms used in this way can be interchangeable where appropriate, so that the embodiments described here can be implemented in an order other than the content illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0056] The embodiment of the present application provides a data processing method, which provides multiple compression formats when compressing data, and different data in the same batch of data can choose different compression formats, so that compression accuracy and compression efficiency can be taken into account, and the user's usage needs can be covered as much as possible. The embodiment of the present application also provides corresponding devices, computer-readable storage media, and computer program products, etc., which are described below.
[0057] See below Figure 1 , Figure 1 A schematic diagram of an application scenario of the data processing method provided in an embodiment of the present application.
[0058] like Figure 1 As shown, the application scenario is an AI model training scenario, and the AI model includes a multi-layer forward network and a multi-layer reverse network. Among them, the forward network is used to calculate the input value in the training sample to obtain the corresponding output value. The total error, or loss, can be calculated based on the output value and the target value. The total error is used as the input of the reverse network, and the error of each layer of the reverse network is calculated by the back propagation algorithm. The weight update parameters of each layer are calculated based on the error of each layer of the reverse network, and the corresponding weight data of the forward network is updated according to the weight update parameters. In other words, the training of the AI model mainly includes three processes, namely the forward propagation process of calculating the output value, the back propagation process of calculating the error, and the process of updating the weight data according to the error.
[0059] The training process of an AI model is essentially a process of continuously correcting weight data so that the output value approaches the target value. This process usually requires a large amount of training samples and weight data to implement, which will cause a memory wall problem, that is, the memory size of the AI hardware limits the growth of the model. In addition, the memory wall problem is also related to memory access bandwidth. In the current AI scenario, the speed of data transmission lags far behind the computing power of AI hardware.
[0060] For the memory wall problem, the method usually adopted is to compress the data in the training process, thereby reducing the demand for memory capacity and memory access bandwidth. For example, half-precision or quantization methods are used to convert the data in the training process from FP32 to FP16 or INT8. However, the compression efficiency of FP16 for network parameters is relatively general, while INT8 will cause a certain loss of precision. In view of this, a new data type FP8 is proposed. Compressing data into FP8 can effectively improve compression efficiency and compression accuracy. However, for FP8, only two data formats are provided in the current solution, which cannot meet the user's usage needs. Moreover, although two formats are provided, each batch of training data can only use the same format, and dynamic format selection for each data cannot be achieved.
[0061] In view of the above problems, the embodiment of the present application provides a data processing method that can be applied to a data processing device. When compressing data, the data processing device provides multiple compression formats, and different data in the same batch of data can flexibly select different compression formats, so as to cover the user's usage needs as much as possible and achieve a balance between compression efficiency and compression accuracy.
[0062] It should be understood that the data processing method provided in the embodiment of the present application can be applied to Figure 1 In addition to the AI model training scenario shown, it can also be applied to various scenarios, such as AI model reasoning scenarios, computer simulation scenarios, and data transmission scenarios. The application scenarios are not specifically limited here.
[0063] See below Figure 2 , is a schematic diagram of an embodiment of the data processing method provided in the embodiment of the present application. Figure 2 As shown, this embodiment includes steps 201 to 205.
[0064] 201. Receive target batch data, where the target batch data includes first data and second data.
[0065] The data processing device receives target batch data, wherein the target batch data includes first data and second data, wherein the first data may be a plurality of data or a single data, and the same is true for the second data.
[0066] The target batch data may be 8-bit data, 16-bit data, 32-bit data, 64-bit data or larger data, and the data processing device may perform compression processing on the target batch data.
[0067] 202. Compress the first data into a first format to obtain third data.
[0068] The data processing device provides multiple compression formats, such as 16-bit type, 8-bit type and 4-bit type, etc. Among them, the 16-bit type and the 8-bit type can be floating point type (FP16, FP8), integer type (INT16, INT8) or other format types, and the 4-bit type can be integer type (INT4) or other format types.
[0069] Both INT data and FP16 data are in fixed formats. The first bit in INT data is the sign bit, which is used to indicate the positive or negative of the data, and the remaining bits are used to store data, and the stored data is an integer. Floating-point data includes a sign bit, an exponent bit, and a mantissa bit, where the sign bit indicates the positive or negative of the data, the exponent bit stores the integer, and the mantissa bit stores the decimal. The Institute of Electrical and Electronics Engineers (IEEE) standard defines FP16 as 1 sign bit, 5 exponent bits, and 10 mantissa bits. In FP32, the first bit is the sign bit, the subsequent 8 bits are the exponent bits, and the remaining 23 bits are the mantissa bits. For FP8, there is no limit on the allocation of the exponent bits and mantissa bits, so FP8 can have multiple formats. The format of FP8 can be combined with Figure 3 To understand, Figure 3 The first bit is fixed as the sign bit, the solid line frame after the first bit is the exponent bit, and the dotted line frame is the mantissa bit. Figure 3 As shown, the format of FP8 can be one sign bit, 2 exponent bits and 5 mantissa bits, or one sign bit, 3 exponent bits and 4 mantissa bits, or one sign bit, 4 exponent bits and 3 mantissa bits, etc. The more exponent bits, the fewer mantissa bits, the larger the range of representation, but the accuracy will deteriorate. Conversely, the fewer exponent bits, the more mantissa bits, the smaller the range of representation, but the accuracy will increase. The format type of FP8 is not limited in the embodiments of the present application.
[0070] The data processing device may compress the first data into a first format in the provided compression format, thereby obtaining the third data. The first format may be an 8-bit type, such as a format of the seven format types included in FP8. The first format may also be a 16-bit type, such as FP16 or INT16. Of course, the first format may also be other format types, such as FP32, which is not specifically limited here.
[0071] In one possible solution, a data processing device receives a second instruction, which carries a format selection condition set by a user, and the data processing device determines the first format according to the format selection condition. Exemplarily, when the format selection condition is to ensure compression accuracy, the first format is determined to be FP16, or a format with more mantissa bits in FP8. When the format selection condition is to improve performance and compression efficiency, the first format is determined to be INT8. For various formats of FP8, the format selection condition can be further limited. When more attention is paid to accuracy, the first format is determined to be a format with more mantissa bits, and when more attention is paid to range, the first format is determined to be a format with more exponent bits.
[0072] In addition, the data processing device can also determine which format to compress the first data into by itself without selecting the format according to the condition. For example, if the value of the first data is large, the data processing device determines that the first format needs to be a format type that can represent a larger range, and the data processing device determines that the first format is FP16.
[0073] In another possible solution, the data processing device receives a third instruction, the third instruction directly indicates the format type (i.e., the first format) of the first data to be compressed, and the data processing device compresses the first data into the first format according to the third instruction to obtain the third data. Exemplarily, the third instruction indicates that the first format is INT8, and the data processing device compresses the first data into the INT8 format according to the third instruction.
[0074] Further, the user may pre-select one or more formats from the compression formats provided by the data processing device, and the data processing device determines the first format from the formats pre-selected by the user, thereby improving the processing speed of the data processing device. Specifically, the data processing device receives a first instruction, and the first instruction carries the format information selected by the user. The data processing device determines the third format according to the format information carried by the first instruction, and the format included in the third format is the format to be compressed by the first data (that is, including the first format), or the format included in the third format is the format of the third data. The data processing device then determines the first format from the third format, thereby compressing the first data into the first format to obtain the third data. Exemplarily, the formats pre-selected by the user include FP16 and FP8, and the data processing device determines the third format to be FP16 and FP8, wherein FP8 includes seven formats. The data processing device further determines the first format from the third format, for example, according to the above-mentioned second instruction or third instruction, the first format is determined from the third format as the first target format in FP8. The data processing device determines the first format according to the second instruction or the third instruction in detail in the previous text, and will not be repeated here.
[0075] 203. Generate a format selection bit, and use the first format selection bit to mark the third data.
[0076] The data processing device may generate a format selection bit corresponding to each provided compression format, and the format selection bit is associated with the compression format. When the data processing device determines the compression format of the first data (i.e., the first format) and compresses the first data to obtain the third data, the third data is marked using the first format selection bit corresponding to the first format, and the first format selection bit indicates the first format, thereby indicating that the format type of the third data is the first format.
[0077] For different data in the same batch of data, such as the first data and the second data in the target batch of data, the data processing device may compress the first data and the second data into different format types. That is to say, there may be multiple compression formats in the same batch of data. In this case, the format types of different data can be distinguished by the format selection bits. For example, the format types of the third data and the fourth data are obtained by the corresponding format selection bits. When the third data needs to be decompressed later, the third data is decompressed according to the first format obtained by the first format selection bits to obtain the first data.
[0078] When the user pre-selects one or more compression formats (ie, the third format) through the first instruction, the data processing device may generate format selection bits only for the compression format selected by the user.
[0079] The data processing device usually generates the format selection bit before compressing the target batch data. After compressing the data, the corresponding format selection bit can be used to mark the compressed data. Of course, the format selection bit can also be generated after compressing the data, which is not limited here.
[0080] The format selection bits can be combined with Figure 3 Understand. Figure 3 As shown, the format selection bits can be represented in binary. For the first compression format, the format selection bits are 000, for the second compression format, the format selection bits are 001, for the third compression format, the format selection bits are 010, and for the fourth compression format, the format selection bits are 011. One compression format corresponds to one format selection bit. For n formats, log2 n bits are used to represent the
[0081] In a possible solution, the compressed data and the corresponding format selection bits can be regarded as a whole data, and the size of the whole data is the size of the compressed data plus the size of the format selection bits. Exemplarily, the first format is FP8, the first format selection bit occupies 3 bits, and the third data obtained by compressing the first data and the corresponding first format selection bits are regarded as a whole data, then the size of the whole data is 8 bits occupied by the third data plus 3 bits occupied by the first format selection bits, which is equal to 11 bits. In the case of 16-bit type and 8-bit type compression format, the format selection bits usually do not need to exceed 4 bytes (4 bytes can represent 16 format types), then the size of the whole data is between 8 bits and 20 bits.
[0082] In one possible solution, the compressed data and the corresponding format selection bit can be stored in different areas. For example, the third data is stored in the first area, and the first format selection bit is stored in the second area. The first area and the second area are two different storage areas, so that the third data and the first format selection bit can be written or read in parallel, thereby improving the storage rate and the reading rate.
[0083] It should be understood that step 203 in this embodiment is an optional step. When the third data does not need to be decompressed, or the third data are all in the same format, the first format selection bit may not be generated.
[0084] 204. Compress the second data into a second format to obtain fourth data.
[0085] The data processing device may compress the second data into a second format in the provided compression format, thereby obtaining fourth data. The second format may be an 8-bit type, such as one of the seven formats included in FP8. The second format may also be a 16-bit type, such as FP16 or INT16. Of course, the second format may also be other format types, such as FP32, which is not specifically limited here.
[0086] It should be noted that although both the first format and the second format can be compressed into 16-bit type or 8-bit type, the first format and the second format are different format types. Even if the first format and the second format are both FP8, the first format and the second format are different format types in FP8. For example, the first format is Figure 3 The first format is the FP8 format shown, and the second format is Figure 3 The second format in the FP8 format is shown. Alternatively, the first format is FP16 and the second format is INT8. That is, the first data and the second data in the same batch of data can be compressed into different formats, thereby achieving flexible selection of compression formats.
[0087] The method for compressing the second data by the data processing device is similar to the method for compressing the first data, and the details are not repeated here.
[0088] 205. Use the second format selection bit to mark the fourth data.
[0089] The relevant contents of the data processing device generating the format selection bit have been described in step 203, and will not be repeated here. After the data processing device determines the second format and compresses the second data to obtain the fourth data, the second format selection bit corresponding to the second format is used to mark the fourth data, and the second format selection bit indicates the second format, thereby indicating that the format type of the fourth data is the second format. When the fourth data needs to be decompressed later, the fourth data is decompressed according to the second format obtained by the second format selection bit to obtain the second data.
[0090] Likewise, the fourth data and the second format selection bit may also be stored in different areas to improve the reading and writing efficiency.
[0091] In a possible solution, the first data and the second data are continuous data in the target batch data. When the total number of bits occupied by the first format selection bit and the second format selection bit does not exceed one byte (i.e., 8 bits), the first format selection bit and the second format selection bit can be spliced in the same byte for storage. A maximum of (8 / log2 n ) format selection bits, where n is the number of compression formats provided by the data processing device, or the number of compression formats pre-selected by the user through the first instruction. If the number of bits after concatenation is less than 8 bits, the remaining bits are padded with 0 to make up a full byte.
[0092] For the format selection bits in the same byte, the data are written in the order of the data. For example, if the first data is before the second data, the first data is written first, and then the second data.
[0093] Format selection bit can be combined with Figure 4 Understand. Figure 4 As shown, the first format selection bit corresponding to the first data is represented by 3 bits, and 3 bits can represent 8 data formats in total. The first format selection bit is 010, which is 2 when converted to decimal. The second format selection bit corresponding to the second data is also represented by 3 bits, and the second format selection bit is 011, which is 3 when converted to decimal. Since the first format selection bit and the second format selection bit only use 6 bits in total, the first format selection bit and the second format selection bit can be spliced in the same byte, and the remaining 2 bits are filled with 0.
[0094] Similar to step 203, step 205 in this embodiment is also an optional step.
[0095] In this embodiment, multiple compression formats are provided when compressing data to cover the user's usage requirements as much as possible. In addition, different data in the same batch of data can be compressed into different formats as needed, so that compression accuracy and compression efficiency can be taken into account. Then, the compression format of each data is recorded using a format selection bit, so that the same batch of data can be decompressed. Furthermore, the data and the corresponding format selection bits are stored in different areas, respectively, so that efficient storage and reading can be achieved.
[0096] Combine the following Figure 5 Together with the contents of the above embodiments, the data processing method provided in the embodiments of the present application is described. Figure 5 The process of compressing FP16 data into FP8 data. FP16 data includes a sign bit, an exponent bit, and a mantissa bit. The scale parameter is extracted from the FP16 data so that the value is within the range that FP8 data can represent. For example, for some smaller numbers, FP8 cannot represent them. In this case, the scale parameter can be extracted and all numbers can be multiplied by the same number, so that the numbers that FP8 cannot represent can be represented.
[0097] After extracting the scale parameter, the first format is determined from the third format pre-selected by the user according to the format selection condition set by the user, and FP16 is compressed. The third format can be one sign bit, 3 exponent bits, 4 mantissa bits, one sign bit, 5 exponent bits, 2 mantissa bits, etc. (the solid line box after the first bit is the exponent bit, and the dotted line box is the mantissa bit).
[0098] After FP16 is compressed, the corresponding format selection bit is used to mark it to record the format type of FP16. The compressed data is stored in the first area, and the format selection bit is stored in the second area, thereby improving the reading and writing efficiency.
[0099] The data processing method provided in the embodiment of the present application can be applied to the reasoning scenario or training scenario of the AI model. The training of the AI model requires a large amount of data and computing power to provide support, and during the training process, it is necessary to continuously adjust the weight data of the AI model and perform repeated calculations to make the AI model have good robustness. The reasoning of the AI model is to input new data into the trained model, so as to make the most accurate judgment and guess about a certain thing. The following describes the application of the data processing method in the reasoning scenario and training scenario of the AI model.
[0100] Combine the following Figure 6 , the application of the data processing method provided in the embodiment of the present application in the reasoning scenario of the AI model is described. Figure 6As shown, the model structure and target batch data are prepared first, wherein the target batch data includes training samples and weight data, that is, the first data and the second data can be training samples and / or weight data. The training sample includes an input value and a target value (true label), and the AI model will derive an output value based on an input value. The AI model can include multiple layers of forward networks, and each layer of the forward network has corresponding weight data.
[0101] Then the target batch data is sent to the data processing device, and the data processing device compresses the target batch data. Different data can be compressed into different formats as needed, for example, the first data is compressed into the first format to obtain the third data, and the second data is compressed into the second format to obtain the fourth data.
[0102] After compressing the target batch data, the data processing device uses the corresponding format selection bits to mark the compressed data, for example, using the first format selection bit to mark the third data and using the second format selection bit to mark the second data, and stores the compressed data and the format selection bits in different areas.
[0103] The data processing device then sends the compressed data to the AI model, and the AI model performs forward calculations on the compressed input values according to the compressed weight data to obtain corresponding output values. It should be understood that the input values in the training sample are the first data and / or the second data, and the compressed input values are the third data and / or the fourth data.
[0104] In this embodiment, the application of the above data processing method in the AI reasoning scenario is explained, which improves the feasibility of the solution.
[0105] Combine the following Figure 7 , the application of the data processing method provided in the embodiment of the present application in the training scenario of the AI model is introduced. Figure 7 As shown, first prepare the model structure and target batch data. The target batch data is Figure 6 The embodiments shown are similar and will not be described here in detail. It should be noted that the AI model in the training scenario includes a forward network and a reverse network.
[0106] Then the target batch data is sent to the data processing device, which compresses the target batch data. Figure 6 The embodiments shown are similar and will not be described again here.
[0107] After compressing the target batch data, the data processing device marks it with the corresponding format selection bits and stores the data and the format selection bits in different areas.
[0108] The data processing device sends the compressed data to the AI model, and the AI model performs forward calculation on the compressed input value to obtain the output value. According to the output value and the target value, the error, or loss, can be obtained, and then the weight update parameters of each layer of the reverse network are calculated according to the loss. Since the weight update parameter is derived from the output value, and the output value is consistent with the data format of the compressed input value, the format of the weight update parameter can be obtained according to the format selection bit of the compressed input value. The data processing device then decompresses the weight update parameter according to the format of the weight update parameter to obtain the original format, and uses the weight update parameter in the original format to adjust the corresponding weight data in the forward network. It should be understood that the input value in the training sample is the first data and / or the second data, and the compressed input value is the third data and / or the fourth data.
[0109] In this embodiment, the application of the above data processing method in AI training scenarios is introduced, which expands the application scenarios of the solution.
[0110] The above describes the embodiments of the present application from the perspective of the method. The following describes the relevant devices in the embodiments of the present application from the perspective of specific device implementation.
[0111] See also Figure 8 , an embodiment of the present application provides a schematic diagram of a data processing device 800, wherein the data processing device 800 includes a receiving unit 801 and a compression unit 802.
[0112] The receiving unit 801 is used to receive target batch data, where the target batch data includes first data and second data.
[0113] The compression unit 802 is used to compress the first data into a first format to obtain third data.
[0114] The compression unit 802 is further configured to compress the second data into a second format to obtain fourth data, wherein the first format and the second format are different format types.
[0115] Optionally, the first format and the second format are two different formats of 8-bit floating point number type.
[0116] Optionally, the data processing device 800 also includes a generation unit 803, which is used to generate a first format selection bit based on the first format, and the first format selection bit is used to indicate the first format; a marking unit 804, which is used to mark the third data using the first format selection bit; and a decompression unit 805, which is used to decompress the third data based on the first format selection bit to obtain the first data.
[0117] Optionally, the third data is stored in the first area, the first format selection bit is stored in the second area, and the first area and the second area are different storage areas.
[0118] Optionally, the first data and the second data are continuous data, and the generation unit 803 is further used to generate a second format selection bit based on the second format, and the second format selection bit is used to indicate the second format; the marking unit 804 is also used to use the second format selection bit to mark the fourth data, and the second format selection bit and the first format selection bit are located in the same byte.
[0119] Optionally, the receiving unit 801 is further used to receive a first instruction, where the first instruction is used to determine a third format, where the third format includes the first format; and the compression unit 802 is specifically used to compress the first data into a first format in the third format.
[0120] Optionally, the compression unit 802 is specifically used to receive a second instruction, the second instruction carries a format selection condition, and the format selection condition is used to determine whether to compress the first data into the first format; and compress the first data into the first format based on the format selection condition.
[0121] Optionally, the compression unit 802 is specifically configured to receive a third instruction, where the third instruction is configured to instruct to compress the first data into a first format; and compress the first data into the first format based on the third instruction.
[0122] Optionally, the data processing device 800 is applied to an inference scenario of an artificial intelligence AI model and / or a training scenario of an AI model, and the target batch data includes training samples and weight data.
[0123] Each unit in the data processing device 800 performs the above Figure 2 , Figures 5 to 7 The operation of the data processing device in the illustrated embodiment will not be described in detail herein.
[0124] See below Fig. 9 , is a possible structural diagram of a data processing device 900 provided in an embodiment of the present application, including a processor 901, a communication interface 902, a memory 903 and a bus 904. The processor 901, the communication interface 902 and the memory 903 are interconnected via the bus 904. In an embodiment of the present application, the processor 901 is used to control and manage the actions of the data processing device. For example, the processor 901 is used to execute Figure 2 The steps performed by the data processing device in the method embodiment. The communication interface 902 is used to support the data processing device to communicate. The memory 903 is used to store the program code and data of the data processing device.
[0125] Among them, the processor 901 can be a central processing unit, a general-purpose processor, a digital signal processor, an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a transistor logic device, a hardware component or any combination thereof. It can implement or execute various exemplary logic blocks, modules and circuits described in conjunction with the contents disclosed in this application. The processor can also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a digital signal processor and a microprocessor, and so on. The bus 904 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0126] The embodiment of the present application also provides a computer-readable storage medium, wherein the computer-readable storage medium includes instructions, and when the instructions are executed on a computer, the computer executes the aforementioned Figure 2 , Figures 5 to 7 The method in the illustrated embodiment.
[0127] The present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the aforementioned Figure 2 , Figures 5 to 7 The method in the illustrated embodiment.
[0128] The embodiment of the present application also provides a chip system, the chip system includes at least one processor and a communication interface, the communication interface and the at least one processor are interconnected through a line, and the at least one processor is used to run a computer program or instruction to execute the aforementioned Figure 2 , Figures 5 to 7 The method in the illustrated embodiment.
[0129] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0130] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0131] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0132] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0133] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.
Claims
1. A data processing method, characterized in that: include: receiving target batch data, wherein the target batch data includes first data and second data; compressing the first data into a first format to obtain third data; The second data is compressed into a second format to obtain fourth data, wherein the first format and the second format are different format types.
2. The method according to claim 1, characterized in that: The first format and the second format are two different formats in the 8-bit floating point number type.
3. The method according to claim 1 or 2, characterized in that: The method further comprises: generating a first format selection bit based on the first format, wherein the first format selection bit is used to indicate the first format; Marking the third data using the first format selection bit; The third data is decompressed based on the first format selection bit to obtain the first data.
4. The method according to claim 3, characterized in that The third data is stored in a first area, the first format selection bit is stored in a second area, and the first area and the second area are different storage areas.
5. The method according to claim 3 or 4, characterized in that: The first data and the second data are continuous data, and the method further includes: generating a second format selection bit based on the second format, wherein the second format selection bit is used to indicate the second format; The fourth data is marked using the second format selection bit, and the second format selection bit and the first format selection bit are located in the same byte.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: receiving a first instruction, wherein the first instruction is used to determine a third format, wherein the third format includes the first format; The compressing the first data into a first format comprises: The first data is compressed into a first format among the third formats.
7. The method according to any one of claims 1 to 6, characterized in that: The compressing the first data into a first format comprises: receiving a second instruction, wherein the second instruction carries a format selection condition, and the format selection condition is used to determine the first format; The first data is compressed into a first format based on the format selection condition.
8. The method according to any one of claims 1 to 6, characterized in that: The compressing the first data into a first format comprises: receiving a third instruction, wherein the third instruction is used to instruct to compress the first data into a first format; The first data is compressed into a first format based on the third instruction.
9. The method according to any one of claims 1 to 8, characterized in that: The method is applied to an inference scenario of an artificial intelligence (AI) model and / or a training scenario of the AI model, and the target batch data includes training samples and weight data.
10. A data processing device, characterized in that: include: A receiving unit, configured to receive target batch data, wherein the target batch data includes first data and second data; A compression unit, used for compressing the first data into a first format to obtain third data; The compression unit is further used to compress the second data into a second format to obtain fourth data, wherein the first format and the second format are different format types.
11. The device according to claim 10, characterized in that The device also includes: a generating unit, configured to generate a first format selection bit based on the first format, wherein the first format selection bit is used to indicate the first format; a marking unit, configured to mark the third data using the first format selection bit; A decompression unit is used to decompress the third data based on the first format selection bit to obtain the first data.
12. The device according to claim 11, characterized in that The third data is stored in a first area, the first format selection bit is stored in a second area, and the first area and the second area are different storage areas.
13. The device according to claim 11 or 12, characterized in that The first data and the second data are continuous data, and the generating unit is further used to: generate a second format selection bit based on the second format, wherein the second format selection bit is used to indicate the second format; The marking unit is further used for marking the fourth data using the second format selection bit, where the second format selection bit and the first format selection bit are located in the same byte.
14. The device according to any one of claims 10 to 13, characterized in that The receiving unit is further used to receive a first instruction, where the first instruction is used to determine a third format, where the third format includes the first format; The compression unit is specifically used to compress the first data into a first format in the third format.
15. The device according to any one of claims 10 to 14, characterized in that The compression unit is specifically used for: receiving a second instruction, wherein the second instruction carries a format selection condition, and the format selection condition is used to determine the first format; The first data is compressed into a first format based on the format selection condition.
16. The device according to any one of claims 10 to 14, characterized in that The compression unit is specifically used for: receiving a third instruction, wherein the third instruction is used to instruct to compress the first data into a first format; The first data is compressed into a first format based on the third instruction.
17. A data processing device, characterized in that: include: Processor and memory; The memory is used to store instructions; The processor is configured to execute instructions stored in the memory to implement the method according to any one of claims 1 to 9.
18. A chip system, comprising at least one processor and a communication interface, wherein the communication interface and the at least one processor are interconnected via a line, and the at least one processor is used to run a computer program or instruction to execute the method described in any one of claims 1 to 9.
19. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by one or more processors, the method according to any one of claims 1 to 9 is implemented.
20. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 9.
