Method, apparatus, device, medium and program product for precision conversion

By determining reserved bits and reference bits in the neural network, and performing rounding operations based on threshold comparisons, the problem of rounding errors when high-precision data is converted into low-precision data is solved, efficiency and accuracy are improved, and multiple precision formats are supported. Conversion reduces computing power costs.

CN118690797APending Publication Date: 2024-09-24HUAWEI TECH CO LTD

Patent Information

Application Number
CN202310354260.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

Technical Problem

In the field of artificial intelligence, in mixed-precision training and inference, due to rounding errors introduced when data is converted from high-precision format to low-precision format, the accuracy of the inference results of neural networks decreases, and it is difficult for existing technology to efficiently process high-precision data The conversion to low-precision data increases algorithm complexity and computational cost.

Method used

By determining the reserved bits and reference bits in the high-precision data, and based on comparing the threshold with the coded value of the reference bit with a bit width of 2, a rounding operation is performed to obtain the coded value of the low-precision data, and the threshold is generated using the predetermined padding value. , achieves efficient precision conversion and supports the conversion of high-precision data into low-bit tapered floating-point precision.

Benefits of technology

It improves the efficiency of converting high-precision data to low-precision data, reduces computing power costs, reduces the degradation of neural network reasoning performance, and supports conversion of multiple precision formats, including bit width changes in the exponent domain and mantissa domain.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690797A
    Figure CN118690797A
Patent Text Reader

Abstract

The embodiment of the invention provides a method, equipment and device for precision conversion, a medium and a program product, and relates to the technical field of chips. A method is provided for converting data in a first precision format comprising a first exponential domain and a first mantissa domain into a second precision format comprising a second exponential domain and a second mantissa domain. The precision of the first precision format is higher than that of the second precision format. The method includes determining reserved bits and reference bits in the first mantissa field based on a bit width of a second mantissa field for the data, the reserved bits including one or more bits starting from the highest bit and having the same bit width as the bit width of the second mantissa field, and the reference bits including two bits following the reserved bits. The method further includes rounding the coded values of the reserved bits based on a comparison of the coded values of the reference bits to a threshold to obtain coded values of a second mantissa field. In this manner, a mantissa can be efficiently rounded using a comparison of a reference bit with a bit width of 2 to a threshold, thereby improving the efficiency of precision conversion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present disclosure mainly relate to the field of chip technology. More specifically, the embodiments of the present disclosure relate to a method, an apparatus, a device, a computer-readable storage medium, and a computer program product for precision conversion. Background Art

[0002] At present, mixed-precision training and reasoning have been widely used in fields such as artificial intelligence. By converting part of the data in the neural network to a lower precision than other data, the computational efficiency can be improved and the computational time can be shortened during training and reasoning. However, due to the rounding error introduced when the data is converted from a high-precision format to a low-precision format, the accuracy of the reasoning results of the neural network may decrease. Therefore, a precision conversion scheme is needed to reduce the degradation of the reasoning performance of the neural network while improving the computational efficiency. Summary of the invention

[0003] The embodiments of the present disclosure provide a solution for precision conversion.

[0004] In a first aspect of the present disclosure, a precision conversion method is provided. The method is used to convert data from a first precision format to a second precision format, wherein the first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format. The method includes: based on the bit width of the second mantissa field for the data, determining the reserved bits and reference bits in the first mantissa field, the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include the two bits after the reserved bits in the first mantissa field. The method also includes: based on the comparison of the encoded value of the reference bit with a threshold, rounding the encoded value of the reserved bit to obtain the encoded value of the second mantissa field for the data.

[0005] In this way, based on the comparison between the threshold and the encoded value of the reference bit with a bit width of 2, the mantissa in the high-precision format can be efficiently rounded, thereby improving the efficiency of converting high-precision data to low-precision data and reducing computing power costs. In some embodiments, according to the scheme of the present disclosure, high-precision data can be converted to low-bit (e.g., 8-bit) tapered floating-point precision.

[0006] In some embodiments of the first aspect, the method further comprises: determining a comparison bit after the reference bit in the first mantissa field. Determining the threshold value based on the coded value of the comparison bit and a predetermined padding value. Alternatively, determining the threshold value based on the negation of the coded value of the comparison bit and the predetermined padding value. In some embodiments of the first aspect, the comparison bit is the least significant bit in the first mantissa field. In some embodiments of the first aspect, the predetermined padding value is 1.

[0007] In this way, based on the specific comparison bit in the mantissa of the high-precision data and the predetermined padding value, the threshold can be efficiently generated without using a random generator, thereby improving the efficiency of mantissa rounding. In addition, compared with the case where a threshold with more bits is generated for comparison with a multi-bit mantissa to be discarded, generating a threshold with two bits and comparing it with a reference bit with two bits can reduce the algorithm complexity and calculation cost.

[0008] In some embodiments of the first aspect, rounding the code value of the reserved bit to obtain the code value of the second mantissa field for the data includes: if the code value of the reference bit is greater than or equal to the threshold, performing a carry operation on the least significant bit of the code value of the reserved bit, and the code value of the reserved bit after the carry is determined as the code value of the second mantissa field; or, if the code value of the reference bit is less than the threshold, determining the code value of the reserved bit as the code value of the second mantissa field.

[0009] In some embodiments of the first aspect, the method further includes: selecting the bit width of the second exponent field from the bit width set of the second exponent field in the second precision format based on the encoded value of the first exponent field for the data; and determining the bit width of the second mantissa field based on the selected bit width of the second exponent field and the total bit width of the second precision format.

[0010] In some embodiments of the first aspect, the second precision format also includes a prefix code field, and the method further includes: determining an indication value of the prefix code field based on the encoding value of the first exponent field; and determining the bit width of the prefix code field and the encoding value of the prefix code field based on the indication value of the prefix code field and a mapping table, wherein the indication value of the prefix code field also indicates the bit width of the second exponent field.

[0011] In some embodiments of the first aspect, the second precision format is tapered floating point precision. In some embodiments of the first aspect, the second precision format includes HiFloat8. In some embodiments of the first aspect, the first precision format includes IEEE FP16 or IEEE BF16.

[0012] In this way, various types of precision formats can be converted, including precision formats where the bit width of the exponent field and / or the mantissa field is not fixed. For example, a high precision format can be converted to a tapered floating point precision. In particular, a high precision format can be converted to a HiFloat8 format with a prefix code field.

[0013] In a second aspect of the present disclosure, a device for precision conversion is provided. The device is used to convert data from a first precision format to a second precision format, wherein the first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format. The device includes: a bit determination unit, configured to determine the reserved bits and reference bits in the first mantissa field based on the bit width of the second mantissa field for the data, the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include two bits after the reserved bits in the first mantissa field. The device also includes a rounding unit, configured to round the encoded value of the reserved bits based on the comparison of the encoded value of the reference bit with a threshold value to obtain the encoded value of the second mantissa field for the data.

[0014] In some embodiments of the second aspect, the apparatus further comprises a threshold determination unit. The threshold determination unit is configured to: determine a comparison bit after the reference bit in the first mantissa field; and determine the threshold value based on the encoded value of the comparison bit and a predetermined padding value, or determine the threshold value based on the inversion of the encoded value of the comparison bit and the predetermined padding value. In some embodiments of the second aspect, the comparison bit is the least significant bit in the first mantissa field. In some embodiments of the second aspect, the predetermined padding value is 1.

[0015] In some embodiments of the second aspect, the rounding unit is further configured to: if the code value of the reference bit is greater than or equal to the threshold, perform a carry operation on the lowest bit of the code value of the reserved bit, and the code value of the reserved bit after the carry operation is determined as the code value of the second mantissa field. Alternatively, if the code value of the reference bit is less than the threshold, determine the code value of the reserved bit as the code value of the second mantissa field.

[0016] In some embodiments of the second aspect, the apparatus further comprises a bit width determination unit. The bit width determination unit is configured to: select a bit width of the second exponent field from a set of bit widths of the second exponent field of the second precision format based on an encoded value of the first exponent field of the data; and determine a bit width of the second mantissa field based on the selected bit width of the second exponent field and a total bit width of the second precision format.

[0017] In some embodiments of the second aspect, the second precision format also includes a prefix code field, and the device also includes a prefix code field determination unit, and the prefix code field determination unit is configured to: determine an indication value of the prefix code field based on the encoding value of the first exponent field; and determine the bit width of the prefix code field and the encoding value of the prefix code field based on the indication value of the prefix code field and a mapping table, wherein the indication value of the prefix code field also indicates the bit width of the second exponent field.

[0018] In some embodiments of the second aspect, the second precision format is tapered floating point precision. In some embodiments of the second aspect, the second precision format comprises HiFloat8. In some embodiments of the second aspect, the first precision format comprises IEEE FP16 or IEEE BF16.

[0019] In a third aspect of the present disclosure, a chip is provided. The chip includes a conversion circuit, which is used to convert data from a first precision format to a second precision format. The first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format. The conversion circuit is configured to: determine the reserved bits and reference bits in the first mantissa field based on the bit width of the second mantissa field for the data, the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include two bits after the reserved bits in the first mantissa field; and based on the comparison of the encoded value of the reference bit with a threshold, round the encoded value of the reserved bit to obtain the encoded value of the second mantissa field for the data.

[0020] In some embodiments of the third aspect, the conversion circuit is further configured to: determine the threshold based on the encoded value of the comparison bit after the reference bit in the first mantissa field and a predetermined padding value, or determine the threshold based on the inversion of the encoded value of the comparison bit after the reference bit in the first mantissa field and the predetermined padding value.

[0021] In a fourth aspect of the present disclosure, an electronic device is provided, comprising: at least one computing unit; and at least one memory, wherein the at least one memory is coupled to the at least one computing unit and stores instructions for execution by the at least one computing unit, and when the instructions are executed by the at least one computing unit, the device implements the method provided in the first aspect.

[0022] In a fifth aspect of the present disclosure, a computer-readable storage medium is provided, on which a computer program is stored, wherein the computer program is executed by a processor to implement the method provided in the first aspect.

[0023] In a sixth aspect of the present disclosure, a computer program product is provided, comprising computer executable instructions, which implement part or all of the steps of the method of the first aspect when the instructions are executed by a processor.

[0024] It can be understood that the chip of the third aspect, the electronic device of the fourth aspect, the computer storage medium of the fifth aspect, or the computer program product of the sixth aspect provided above is used to execute at least a portion of the method provided in the first aspect. Therefore, the explanation or description of the first aspect is also applicable to the third aspect, the fourth aspect, the fifth aspect, and the sixth aspect. In addition, the beneficial effects that can be achieved in the third aspect, the fourth aspect, the fifth aspect, and the sixth aspect can refer to the beneficial effects in the corresponding method, which will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements, wherein:

[0026] Figure 1 The distribution diagram of effective bits of HiF8 precision on the order code window is shown;

[0027] Figure 2 A schematic diagram showing an example process of precision conversion according to some embodiments of the present disclosure;

[0028] Figure 3 A schematic diagram showing an example of high-precision data in a first precision format and an example of low-precision data in a second precision format according to some embodiments of the present disclosure;

[0029] Figure 4 A schematic diagram showing an example process of converting FP16 data into HiF8 data according to some embodiments of the present disclosure;

[0030] Figure 5 A flowchart showing a process of an example method of precision conversion according to some embodiments of the present disclosure;

[0031] Figure 6 A schematic diagram showing an example process of applying a precision conversion scheme in a neural network training process according to some embodiments of the present disclosure;

[0032] Figure 7 A schematic block diagram of an apparatus for precision conversion according to some embodiments of the present disclosure is shown;

[0033] Figure 8 A schematic diagram showing an example chip according to some embodiments of the present disclosure; and

[0034] Fig. 9 A block diagram of a computing device capable of implementing various embodiments of the present disclosure is shown. DETAILED DESCRIPTION

[0035] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.

[0036] In the description of the embodiments of the present disclosure, the term "including" and similar terms should be understood as open inclusion, that is, "including but not limited to". The term "based on" should be understood as "based at least in part on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below. As used herein, a "neural network" is capable of processing inputs and providing corresponding outputs, and it typically includes multiple layers for determining outputs from inputs.

[0037] As briefly mentioned above, with the development of fields such as artificial intelligence, the scale of neural networks has also increased. A training process can be accelerated from the initial requirement of 10 17 The computing power demand has increased 10 million times from 100 PetaFLOPs to 1 billion PetaFLOPs (such as the Transformer model). The surge in computing power demand has led to huge chip cost overhead. At the same time, experiments have shown that low-bit data (that is, data in a low-precision format) can complete lossless training of large models such as Transformer. Combining the two, low-bit floating-point training is a trend for large model training in the future.

[0038] The neural network training process mainly includes forward calculation, reverse calculation, and weight update process. At the same time, according to the calculation mode, the neural network training process involves general matrix multiplication (GEMM) operations and non-general matrix multiplication operations. General matrix multiplication operations include but are not limited to convolution, convolution_transpose, matrix multiplication (matmul), batch matrix multiplication (batchmatmul), etc. Non-general matrix multiplication operations include but are not limited to various activation functions (sigmoid, tanh, relu, etc.), normalization functions (batch normalization, layer normalization, instance normalization, etc.), optimizer gradient update calculations, etc.

[0039] Generally, GEMM operations can be calculated using FP16 or BF16, and non-GEMM calculations require relatively high precision (such as FP32). FP32 and FP16 are floating-point data representation methods based on the Institute of Electrical and Electronics Engineers (IEEE) 754 standard. IEEE 754 floating-point data includes a sign field (bit sign, S), an exponent field (bits exponent, E), and a mantissa field (bits mantissa, M). The conversion formula between floating-point data represented by IEEE754 and a decimal value (Value) is: Value = (-1) sign *2 exponent-bias *(1+mantissa), where bias is a different constant for floating-point data such as FP32 and FP16.

[0040] The following briefly introduces the formats of FP32 and FP16 with reference to Tables 1 and 2. Table 1 shows the data format of FP32 data.

[0041] Table 1 Data format of FP32 data

[0042]

[0043] For FP32 data, the sign field is 1 bit, the exponent field is 8 bits, and the mantissa field is 23 bits. The sign field of FP32 data determines whether the FP32 data is positive or negative, where 0 represents a positive number and 1 represents a negative number. The exponent field of FP32 data is a power of 2, so FP32 data can be weighted. The mantissa field of FP32 data is a binary decimal. The steps for converting FP32 data to decimal data are as follows: (1) If the sign field of FP32 data is 0, then the FP32 data is a positive number. (2) The encoding value of the exponent field of FP32 data is 01111100, which represents 124 in decimal. After removing the bias in the FP32 data (for FP32 data, bias = 127), the exponent field of the FP32 data is 2 to the power of -3. (3) The mantissa field of the FP32 data is 010000000000000000000000. Since the exponent field is not all "0" or all "1", the decimal data represented by the mantissa field is 1.25. Based on the conversion formula between floating-point data and decimal values, the decimal data corresponding to the FP32 data is 0.15625.

[0044] Table 2 shows the data format of FP16 data.

[0045] Table 2 FP16 data format table

[0046]

[0047] For FP16 data, the sign field is 1 bit, the exponent field is 5 bits, and the mantissa field is 10 bits.

[0048] BF16 is a precision format introduced for artificial intelligence accelerators. Table 3 shows the data format of BF16 data.

[0049] Table 3 Data format of BF16 data

[0050]

[0051] For BF16 data, the sign field is 1 bit, the exponent field is 8 bits, and the mantissa field is 7 bits. The bit width of the exponent field of BF16 is larger than that of the exponent field of FP16, and is the same as the bit width of the exponent field of FP32. Compared with FP16, BF16 obtains a larger dynamic range by further reducing the precision.

[0052] At present, some low-precision floating-point data formats with lower precision than FP16 or BF16 have been proposed, such as FP8 (E5M2), FP8 (E4M3), block floating point format, etc., to further reduce computing costs. By using these low-precision formats for GEMM operations and using FP32 or FP16 for non-GEMM operations, the required computing resources can be reduced.

[0053] However, the training process using the above low-precision format is different from the existing mixed precision (FP16 and FP32) training process. The conversion between different data formats requires the introduction of additional operations such as data scaling. In addition, block partitioning operations and additional operations involving data statistics, such as quantization and dequantization operations, may also be introduced, thereby increasing the algorithm complexity and computational cost.

[0054] In particular, when converting data from a high-precision format to a low-precision format, rounding errors will affect the performance of model training and reasoning. At present, some stochastic rounding (SR) schemes for converting FP32 to FP16 or BF16 data formats have been proposed. In these SR schemes, a random generator can be used to generate a threshold. Alternatively, the threshold can be generated using a specific bit of the FP32 data itself. By comparing the threshold with the encoded value of the bit to be discarded in the mantissa domain, it can be determined whether to perform a carry operation on the encoded value of the retained bit in the mantissa domain, thereby completing the rounding operation on the mantissa.

[0055] However, in these schemes, the generation of the threshold involves more bits in the mantissa field (the number of bits depends on the bit width of the bits to be discarded), the calculation is more complicated, and the hardware overhead is large. For example, when converting from FP32 data to FP16 data, it may be necessary to generate a 13-bit threshold for comparison with the mantissa to be discarded, so the calculation cost is high. In addition, these schemes only involve conversion of specific formats, such as conversion from FP32 to FP16 or BF16 data formats, and cannot meet the conversion of high-precision data in other formats to low-precision data, such as conversion of FP16 to low-bit conical floating-point precision format.

[0056] In order to at least partially solve the above problems and other potential problems, various embodiments of the present disclosure provide a solution for precision conversion. In general, according to various embodiments described herein, a method for converting data from a first precision format to a second precision format is provided, wherein the first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format. The method includes: based on the bit width of the second mantissa field for the data, determining the reserved bits and reference bits in the first mantissa field, the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include the two bits after the reserved bits in the first mantissa field. Based on the comparison of the encoded value of the reference bit with the threshold, the encoded value of the reserved bit is rounded to obtain the encoded value of the second mantissa field for the data.

[0057] In this way, based on the comparison between the threshold and the encoded value of the reference bit with a bit width of 2, the mantissa in the high-precision format can be efficiently rounded, thereby improving the efficiency of converting high-precision data to low-precision data and reducing computing power costs. In some embodiments, according to the scheme of the present disclosure, high-precision data can be converted to low-bit (e.g., 8-bit) tapered floating-point precision.

[0058] Conical floating-point precision is a universal floating-point encoding and decoding method and data expression method, and its bit width, data range and effective bits can be expanded and extended according to the scene requirements. Conical floating-point precision can be applied to various fields such as general computing, high-performance computing and artificial intelligence. Conical floating-point precision is a floating-point precision format with conical precision characteristics. In other words, the number of effective bits or mantissa bits of conical floating-point precision decreases as the absolute value of the exponent increases. Examples of conical floating-point precision may include POSIT precision and 8-bit conical floating-point precision HiFloat8 precision (also referred to as HiF8 precision). The following will briefly introduce the conical floating-point precision using HiF8 precision as an example. Table 4 shows the encoding method of HiF8 data.

[0059] Table 4 Encoding of HiF8 data

[0060]

[0061] The total bit width of HiF8 data is 8 bits. The sign field occupies one bit, 0 for positive, 1 for negative, or 1 for negative and 0 for positive. The prefix field occupies 2 or 3 bits, and the prefix field can express 5 different information. The value of D (also called indication value) can be 0, 1, 2, 3, 4. The bit width of the exponent field changes according to the value of D. The mantissa field occupies the remaining bit width.

[0062] The prefix code domain can be encoded using integers, in which case D is a fixed value. The prefix code domain can also be encoded using prefix codes, in which case D is a finite value set. In the prefix code encoding, 2 bits are used to encode values ​​2, 3, and 4, and 3 bits are used to encode values ​​0 and 1. The prefix code encoding method of the prefix code domain is shown in Table 5, which shows the encoding method of the prefix code domain.

[0063] Table 5 Prefix code encoding method of prefix code field

[0064]

[0065] In some embodiments, the conversion formula between HiF8 data and decimal value (X) is: X = (-1) * 2 Ei+Ec *(1+M). Ec is the symmetric center of the exponent, which is the bias in FP32 or FP16 data, Ei is the encoding value of the exponent domain, and Ev is the encoding value of the exponent domain corresponding to the decimal system, which can also be called the exponent.

[0066] When D is 0, it indicates that the value of the exponent field is 0. When D is not 0, the exponent field is encoded using signed magnitude, i.e. the sign bit follows the original code (True Form, TF). The encoding of the exponent field is Ei = {Se, 1'b1, TF[2:end]}, where Se is the exponent bit sign bit. The highest bit 1'b1 of TF is hidden and not stored, so the encoding value of the exponent field is Es = {Se, TF[2:end]}. The encoding value of the exponent field corresponding to the decimal system is Ev = Ei + Ec.

[0067] As an example, the encoded value distribution of HiFloat(8,5,0) is shown in Table 6. It should be understood that the cone floating point precision can be configured as HiFloat(8,5,0) or other situations.

[0068] Table 6 HiF8 encoding value distribution table

[0069] D 0 1 2 3 4 Es None Se Se,TF[2] Se,TF[2:3] Se,TF[2:4] E 0 Se,1 Se,1,TF[2] Se,1,TF[2:3] Se,1,TF[2:4] Ev 0 ±1 ±[2,3] ±[4,7] ±[8,15] M bit width 4 3 3 2 1

[0070] Figure 1 The figure shows the distribution of effective bits of HiF8 precision in the order code window. Figure 1 As shown in the figure, the effective digits of HiF8 precision are 2 to 5, and the number of effective digits decreases as the absolute value of the exponent increases. As a single Float8 data format, HiF8 precision has a wider dynamic range and higher calculation accuracy. The maximum and minimum positive numbers that HiF8 precision can represent, that is, the absolute value dynamic range, are as follows (1):

[0071] X max_pos =215 =32768

[0072] X min_pos =2 -15 ×1.5=0.000045776367 (1)

[0073] Various exemplary embodiments of the present disclosure are described below with reference to the accompanying drawings.

[0074] Figure 2 A schematic diagram of a process 200 for precision conversion according to some embodiments of the present disclosure is shown. Using process 200, data in a first precision format with higher precision (i.e., first precision data 201) can be converted into data in a second precision format with lower precision (i.e., second precision data 250). The first precision format includes a first exponent field and a first mantissa field, and the second precision format includes a second exponent field and a second mantissa field. The exponent field and the mantissa field can be the exponent field and the mantissa field as described above with reference to Tables 1 to 4.

[0075] In some embodiments, examples of the first precision format may include FP64, FP32, FP16, BF16, etc. Examples of the second precision format may include FP32, FP16, BF16, HiF8, etc. It should be understood that high precision and low precision are relative. For example, when the high-precision first precision format is FP16, the low-precision second precision format may be HiF8. In another example, when the high-precision first precision format is FP32, the low-precision second precision format may be BF16.

[0076] like Figure 2 As shown, for the first precision data 201, based on the bit width of the second mantissa field of the second precision format, the reserved bits in the first mantissa field of the first precision data 201 are determined in block 203. The reserved bits include one or more bits starting from the most significant bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field of the second precision format.

[0077] In some embodiments, the bit width of the second mantissa field of the second precision format is fixed, for example, when the second precision format is FP16. Alternatively, the bit width of the second mantissa field of the second precision format may be non-fixed, that is, the bit width of the second mantissa field may vary with different data. For example, when the second precision format is a tapered floating-point precision format, the bit width of the second mantissa field may depend on the exponent of the data.

[0078] In some embodiments, when the bit width of the second mantissa field of the second precision format is not fixed, the process 200 further includes selecting the bit width of the second exponent field in the bit width set of the second exponent field of the second precision format based on the encoded value of the first exponent field of the first precision data 201. For example, a suitable bit width may be selected from a predetermined bit width set of exponent fields of the tapered floating-point precision. Accordingly, based on the selected bit width of the second exponent field and the total bit width of the second precision format, the bit width of the second mantissa field may be determined. For example, the exponent of the tapered floating-point precision data may be determined based on the encoded value of the first exponent field of the first precision data 201. Based on the determined exponent, a suitable bit width may be determined in the bit width set of the second exponent field and the bit width of the second mantissa field may be thereby determined based on a mapping relationship between the exponent and the bit width of the second exponent field (e.g., as shown in Table 6).

[0079] In some embodiments, the second precision format may include a prefix code field, and the indication value of the prefix code field may indicate the bit width of the second exponent field. For example, in the example shown in Table 4, the indication value (D) of the prefix code field may indicate the bit width of the exponent field. In this case, the exponent of the data may be determined based on the encoding value of the first exponent field of the first precision data 201, thereby determining the indication value of the prefix code field of the second precision format. Based on the determined indication value of the prefix code field, the bit width of the prefix code field and the encoding value of the prefix code field may be determined with reference to a mapping table. The mapping table may indicate a mapping relationship between the indication value of the prefix code field and the bit width and encoding value of the prefix code field, such as Table 5.

[0080] For example, referring to Table 6, when it is determined that the exponent of the data is 2, the indication value (D) of the prefix code field can be determined to be 3. Accordingly, referring to Table 5, it can be determined that the bit width of the prefix code field is 2 and the encoding is 10. Based on the bit width of the prefix code field, the bit width of the exponent field, and the total bit width of the second precision format, the bit width of the second mantissa field of the second precision format can be determined.

[0081] Continue to refer Figure 2 , at block 205, a comparison bit in the first mantissa field of the first precision data 201 is determined. In some embodiments, the comparison bit may be a least significant bit (LSB) in the first mantissa field of the first precision data 201. Alternatively, the comparison bit may be a specific bit in the first mantissa field. For example, the bit before the least significant bit.

[0082] In process 200, a reference bit in the first mantissa field of first precision data 201 is determined at block 210. The reference bit is two bits after the reserved bit in the first mantissa field. In some embodiments, a predetermined bit after the reference bit in the first mantissa field can be used as a comparison bit.

[0083] In some embodiments, the process of determining the reserved bit, comparison bit and / or reference bit can be implemented by software. For example, the reserved bit, comparison bit and / or reference bit can be determined in the first mantissa field of the first precision data 201 by shift and mask operations. In this way, the appropriate bit can be determined as the reserved bit, comparison bit and / or reference bit in the first mantissa field of the first precision data 201 depending on the specific implementation. Alternatively, the process of determining the reserved bit, comparison bit and / or reference bit can be implemented by hardware. In other words, in the hardware circuit, a specific bit in the first precision format is predetermined as a reserved bit, comparison bit and / or reference bit.

[0084] At block 215, the determined coded value of the comparison bit may be negated. For example, if the coded value of the comparison bit is 1, the negated coded value is 0. If the coded value of the comparison bit is 0, the negated coded value is 1. It should be understood that the negation operation is optional.

[0085] At block 220, the coded value of the comparison bit or the inverted coded value is padded based on a predetermined padding value, thereby generating a threshold value at block 225. In some embodiments, the predetermined padding value is 1. Alternatively, the predetermined padding value is any suitable value. The padding value can be appended to the coded value of the comparison bit. At block 225, a threshold bit having the same bit width (i.e., 2 bits) as the reference bit can be generated by the padding operation, and its coded value can be referred to as a threshold value.

[0086] Alternatively, when the threshold value is generated in block 225, a threshold value generator may be used to generate the threshold value without being based on the comparison bit in the first mantissa field and a predetermined padding value. Alternatively, when the threshold value is generated in block 225, the threshold value may be generated based on a specific one or two bits in the first mantissa field for comparison with a reference bit having a bit width of 2.

[0087] In box 230, the threshold is compared with the encoded value of the reference bit, and in box 235, a rounding operation is performed on the encoded value of the reserved bit in the first mantissa field of the first precision data 201 based on the comparison result to obtain the second precision data 250. In some embodiments, if the encoded value of the reference bit is greater than or equal to the threshold, a carry operation is performed on the lowest bit of the encoded value of the reserved bit, and the encoded value of the reserved bit after the carry operation is determined as the encoded value of the second mantissa field of the second precision data 250.

[0088] On the contrary, if the code value of the reference bit is less than the threshold, the code value of the reserved bit can be determined as the code value of the second mantissa field of the second precision data 250, and the mantissa after the reserved bit is discarded. Based on the determined code value of the second mantissa field of the second precision data 250 and the determined code value of the second exponent field (and prefix code field), the second precision data 250 can be determined.

[0089] Additionally, an overflow check may be performed on the code value of the reserved bit after the carry operation. In some embodiments, if a carry operation is performed on the code value of the reserved bit, the code value may overflow. In one example, if the reserved code value is 3'b111, an overflow may occur after a carry operation is performed on the lowest bit of the code value of the reserved bit. In this case, the code value of the second exponent field of the second precision data 201 may be updated.

[0090] In some examples, if the code value of the reserved bit after the carry operation overflows, the least significant bit of the code value of the second exponent field may be added by 1 to obtain an updated code value of the second exponent field. For example, for the code value 8'b01111100 of the second exponent field, if there is an overflow, the least significant bit of the code value of the second exponent field may be added by 1 to obtain an updated code value 8'b01111101 of the second exponent field.

[0091] Figure 3 A schematic diagram showing an example 300 of high-precision data in a first precision format and an example 310 of low-precision data in a second precision format according to some embodiments of the present disclosure. Figure 3 As shown, the first precision format may include a sign field, a first exponent field, and a first mantissa field, and the second precision format may include a sign field, a second exponent field, and a second mantissa field. Figure 3 As shown in the example 300 of medium and high precision data, the reserved bits include one or more bits starting from the most significant bit in the first mantissa field. The reference bits include two bits after the reserved bits in the first mantissa field. Figure 3 In the illustrated example 300 , the comparison bit may be the least significant bit in the first mantissa field. Figure 3 Also shown is a threshold bit determined based on the comparison bit and a predetermined fill value. Figure 3 As shown, the threshold bit and the reference bit have the same bit width, that is, 2 bits.

[0092] In the first mantissa field, the remaining bits except the reserved bits are the mantissa to be rounded. Figure 2 As described above, based on the comparison between the encoding value of the threshold bit and the encoding value of the reference bit, the mantissa to be rounded can be discarded or the encoding value of the reserved bit can be carried forward. Figure 3As shown in the example 310 of medium and low precision data, the bit width of the second exponent field of the second precision format can be smaller than the bit width of the first exponent field. The bit width of the second mantissa field of the second precision format is the same as the bit width of the reserved bits of the first precision format.

[0093] Figure 4 A schematic diagram of an example process 400 for converting FP16 data to HiF8 data according to some embodiments of the present disclosure is shown. It should be understood that the process 400 can be modified accordingly to convert BF16 data or data in other precision formats to HiF8 data.

[0094] like Figure 4 As shown, FP16 data can be received in box 401, and the FP16 data includes a sign field S, an exponent field E[0:4], and a mantissa field M[0:9]. In box 402, the FP16 data can be judged to determine whether it is a special value. Examples of special values ​​include zero value, non-numeric value (Not a Number, NAN), positive infinity and negative infinity, etc. If the FP16 data is determined to be a special value, it can be encoded in box 421 according to the encoding rules of HiF8 for special values, so as to obtain a special value in HiF8 format. If the FP16 data is not a special value, the sign field of the FP16 data can be obtained in box 403, and the encoded value of the sign field can be used as the encoded value of the sign field of the HiF8 data.

[0095] In box 404, the exponent field of the FP16 data may be debiased, i.e., E=E+bias, to determine the exponent of the data. In box 405, the bit widths corresponding to the prefix code field, the exponent field, and the mantissa field in the HiF8 data may be determined, represented by db, eb, and mb, respectively. As described above, for example, the encoding and bit width of the prefix code field, the bit width of the exponent field, and the bit width of the mantissa field may be determined based on the exponent of the data by looking up a mapping table. In box 406, the encoding value e=E[0:k] of the exponent field of the HiF8 data may be determined based on the encoding value of the exponent field of the FP16 data and the bit width of the exponent field of the HiF8 data, where k is the value corresponding to the bit width of the exponent field of the HiF8 data.

[0096] At block 407, a reserved bit, a reference bit, and a comparison bit may be determined in the mantissa field of the FP16 data. At block 408, the comparison bit may be padded. For example, the padded may be performed with the coded value of the comparison bit or the negation of the coded value. At block 409, a threshold may be generated based on a predetermined padded value and the coded value of the comparison bit (or the negation of the coded value). At block 410, the coded value of the reference bit may be compared to the threshold.

[0097] In block 411, a rounding judgment may be made. If the code value of the reference bit is less than the threshold, a discard operation may be performed, that is, the mantissa to be rounded is discarded and only the code value of the reserved bit is retained as the code value of the mantissa field of HiF8. For example, the mantissa field 412 of the HiF8 data may be recorded as m=M[0:N-db-eb-1], where N is the total bit width of HiF8, 8.

[0098] On the contrary, if the code value of the reference bit is greater than or equal to the threshold, a carry operation can be performed. If a carry operation is performed, the code value of the reserved bit in the mantissa field of the FP16 data is added by 1, and the mantissa field 413 of the HiF8 data can be recorded as m=M[0:N-db-eb-1]+1.

[0099] In block 421 , encoding may be performed based on the determined bit widths and encoding values ​​of the sign field, prefix code field, exponent field, and mantissa field of HiF8, respectively, so as to determine HiF8 data converted from the received FP16 data in block 422 .

[0100] By using process 400, a threshold value can be efficiently generated based on a single comparison bit in the high-precision data without a random generator or a threshold value based on multiple bits in the high-precision data. In addition, by rounding the mantissa of the high-precision format based on the comparison of the threshold value with the encoded value of the reference bit with a bit width of 2, the efficiency of converting high-precision data to low-precision data is improved, thereby reducing the computing power cost.

[0101] Figure 5 A flowchart of a process 500 of an example method of precision conversion according to some embodiments of the present disclosure is shown. The process 500 can be implemented by any suitable computing device. The process 500 is used to convert data from a first precision format to a second precision format. The first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format.

[0102] In box 502, based on the bit width of the second mantissa field for the data, the reserved bits and reference bits in the first mantissa field are determined, the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include two bits after the reserved bits in the first mantissa field.

[0103] At block 504 , based on a comparison of the encoded value of the reference bit with a threshold, a rounding operation is performed on the encoded value of the reserved bit to obtain an encoded value for a second mantissa field of the data.

[0104] In some embodiments, the method further comprises: determining a comparison bit after the reference bit in the first mantissa field; and determining a threshold value based on the coded value of the comparison bit and a predetermined padding value, or determining the threshold value based on the negation of the coded value of the comparison bit and a predetermined padding value. In some embodiments, the comparison bit is the least significant bit in the first mantissa field. In some embodiments, the predetermined padding value is 1.

[0105] In some embodiments, rounding the code value of the reserved bit to obtain the code value of the second mantissa field for the data includes: if the code value of the reference bit is greater than or equal to the threshold, performing a carry operation on the lowest bit of the code value of the reserved bit, and the code value of the reserved bit after the carry operation is determined as the code value of the second mantissa field. Alternatively, if the code value of the reference bit is less than the threshold, the code value of the reserved bit is determined as the code value of the second mantissa field.

[0106] In some embodiments, the method further includes: selecting a bit width of the second exponent field from a set of bit widths of a second exponent field in a second precision format based on an encoded value of the first exponent field for the data; and determining a bit width of the second mantissa field based on the selected bit width of the second exponent field and a total bit width of the second precision format.

[0107] In some embodiments, the second precision format also includes a prefix code field, and the method also includes: determining an indication value of the prefix code field based on the encoded value of the first exponent field; and determining the bit width of the prefix code field and the encoded value of the prefix code field based on the indication value of the prefix code field and a mapping table, wherein the indication value of the prefix code field also indicates the bit width of the second exponent field.

[0108] In some embodiments, the second precision format is tapered floating point precision. In some embodiments, the second precision format comprises HiFloat8. In some embodiments, the first precision format comprises IEEE FP16 or IEEE BF16.

[0109] References Figures 1 to 5 The principles and details of precision conversion are described. It should be understood that the above processes 200, 400 and 500 are only exemplary and do not constitute a limitation on the scope of the present disclosure. The precision conversion scheme according to the embodiment of the present disclosure can be applied to various fields, such as image recognition, intelligent driving, speech recognition, etc. The scheme of the present disclosure can be applied to the training and reasoning process of neural networks in various fields, such as ResNet networks in the field of computer vision, Bert networks in the field of natural language processing, etc.

[0110] Figure 6 Schematic diagrams of example processes 610 and 620 of applying a precision conversion scheme in a neural network training process according to some embodiments of the present disclosure are shown. Figure 6As shown, in the example process 610, the precision conversion scheme (denoted as SR2) of the present disclosure can be applied in the backward calculation and gradient calculation and update (wgrad update) of the training process. Specifically, in the forward calculation of the training process, the activation value (A) of the L-1 layer in the neural network can be converted from a high-precision format (e.g., FP32 or FP16) to an FP8 format using a conventional rounding method (e.g., round half to away (TA)). Based on the matrix multiplication of the activation value in FP8 format and the weight (W) in FP8 format, a new activation value (A) of FP32 or FP16 can be obtained. Additionally, the new activation value is further updated through operations such as activation function (ReLu) and batch normalization (BN). At the Lth layer, the obtained activation value can be converted to FP8 format using TA, and matrix multiplied with the weight (W) in FP8 format of the Lth layer to obtain a new activation value. The obtained activation value can be processed similarly at the L+1th layer.

[0111] In the backward calculation of the training process, on the contrary, the error value (e.g., cross entropy E) can be converted from a high-precision format (e.g., FP32 or FP16) to an FP8 format using the precision conversion scheme (SR2) of the present disclosure. In the process of gradient (G) calculation and gradient update using the optimizer to obtain a new weight (Wnew), similarly, the activation value (A) can be converted from a high-precision format (e.g., FP32 or FP16) to an FP8 format using the precision conversion scheme of the present disclosure. In addition, the data in the local memory (local memory) for data exchange with the optimizer can be kept in a high-precision format, such as FP32. For example, the master weight (W_master), momentum (Momentum), and other state parameters (otherstates) can be kept in FP32 format.

[0112] In the example process 620, the precision conversion scheme (SR2) of the present disclosure can be applied in the forward and backward calculations and gradient calculation and update processes of the training process. Specifically, in the forward calculation of the training process, the precision conversion scheme of the present disclosure can be used to convert the activation value (A) of the L-1 layer in the neural network from a high-precision format (e.g., FP32 or FP16) to an FP8 format. Based on the matrix multiplication of the activation value in FP8 format and the weight (W) in FP8 format, a new activation value (A) of FP32 or FP16 can be obtained. Additionally, the new activation value is further updated through operations such as the activation function (ReLu) and batch normalization (BN). At the Lth layer, the obtained activation value can be converted to FP8 format using SR2 and matrix multiplied with the weight (W) in FP8 format of the Lth layer to obtain a new activation value. The obtained activation value can be processed similarly at the L+1th layer.

[0113] In the backward calculation of the training process, similarly, the error value (e.g., cross entropy E) can be converted from a high-precision format (e.g., FP32 or FP16) to an FP8 format using the precision conversion scheme disclosed in the present invention. In the process of gradient calculation and gradient update using an optimizer to obtain a new weight (Wnew), similarly, the activation value (A) can be converted from a high-precision format (e.g., FP32 or FP16) to an FP8 format using the precision conversion scheme disclosed in the present invention. In addition, the data in the local memory for data exchange with the optimizer can be kept in a high-precision format, such as FP32. For example, the master weight (W_master), momentum (Momentum), and other state parameters (other states) can be kept in FP32 format.

[0114] like Figure 6 As shown, the precision conversion scheme of the present disclosure can be applied to training and pre-training scenarios, and can be used together with other precision conversion schemes. It should be understood that in some training processes, the concepts of forward calculation and backward calculation may not be distinguished. Figure 6 The related description does not constitute a limitation on the scope of the present disclosure. In addition, although not shown, the precision conversion scheme of the present disclosure can also be applied to the reasoning process of the neural network.

[0115] Table 7 below shows a comparison of the effects of the precision conversion scheme according to an embodiment of the present disclosure and the common precision conversion scheme. The HiF8 data determined using the precision conversion scheme according to an embodiment of the present disclosure is recorded as HiF8-SR2. The HiF8 data determined using the common rounding (TA) rounding method is recorded as HiF8-TA. The performance of the model trained using FP16 data, HiF8-SR2 data, and HiF8-TA data is shown in Table 7 below.

[0116] Table 7 Comparison of precision conversion schemes

[0117] Model FP16 HiF8-TA HiF8-SR2 MobileNet-V2 77.28 71.50 71.70 Yolo-V3-Tiny 16.63 No convergence 16.78

[0118] As can be seen from Table 7, for the MobileNet-V2 model, the performance of the model trained with HiF8-SR2 data is similar to that of the model trained with FP16 data. For the Yolo-V3-Tiny model, the performance of the model trained with HiF8-SR2 data is similar to that of the model trained with FP16 data, and the problem of non-convergence of the model trained with HiF8-TA data can be solved.

[0119] By using the precision conversion scheme disclosed in the present invention, a specific bit can be extracted from the high-precision data itself to generate a threshold for random rounding, thereby applying a simplified random rounding method without using a random generator to round the mantissa of the high-precision data. In addition, when the threshold is {a n , 1} or {negate(a n ), 1} (a n is the comparison bit in the mantissa field of the high-precision data, and 1 is a predetermined padding value). The maximum error of a single data using the random rounding scheme of the present invention is 0.75 unit in the last place (ulp), which is less than the error of the standard random rounding of 1ulp.

[0120] Experiments also show that when the data is in a uniform distribution, the mean invariance of the output values ​​using the random rounding scheme of the present invention is better than that of standard random rounding. When the data is in a Gaussian distribution, the mean invariance of the output values ​​using the random rounding scheme of the present invention is comparable to that of standard random rounding.

[0121] In addition, in some networks, the precision conversion scheme disclosed in the present invention can improve rounding accuracy while achieving training stability. Specifically, in artificial intelligence network models such as convolutional neural networks and Transformer models, training accuracy consistent with FP32 or FP16 mixed precision can be achieved. At the same time, when the scheme disclosed in the present invention is deployed in an AI accelerator (such as an AI chip), since there is no need to read the threshold for random rounding from the random generator in the central processing unit (CPU), the data handling volume associated with the GEMM input data can be reduced to 50% of the original, while reducing the power consumption overhead of the GEMM operation.

[0122] Example devices and equipment

[0123] Figure 7 A block diagram of a device 700 for precision conversion according to an embodiment of the present disclosure is shown. The device 700 may include multiple modules for performing the following steps: Figure 2 and Figure 5 The device 700 is used to convert data from a first precision format to a second precision format. The first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format. The device 700 includes: a bit determination unit 710, which is configured to determine the reserved bits and reference bits in the first mantissa field based on the bit width of the second mantissa field for the data, the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include two bits after the reserved bits in the first mantissa field. The device 700 also includes a rounding unit 720, which is configured to round the encoded value of the reserved bits based on the comparison of the encoded value of the reference bits with a threshold value to obtain the encoded value of the second mantissa field for the data.

[0124] In some embodiments, the apparatus 700 further comprises a threshold determination unit. The threshold determination unit is configured to: determine a comparison bit after the reference bit in the first mantissa field; and determine the threshold value based on the coded value of the comparison bit and a predetermined padding value, or determine the threshold value based on the inversion of the coded value of the comparison bit and the predetermined padding value. In some embodiments, the comparison bit is the least significant bit in the first mantissa field. In some embodiments, the predetermined padding value is 1.

[0125] In some embodiments, the rounding unit 720 is further configured to: if the code value of the reference bit is greater than or equal to the threshold, perform a carry operation on the lowest bit of the code value of the reserved bit, and the code value of the reserved bit after the carry operation is determined as the code value of the second mantissa domain. Alternatively, if the code value of the reference bit is less than the threshold, determine the code value of the reserved bit as the code value of the second mantissa domain.

[0126] In some embodiments, the apparatus 700 further comprises a bit width determination unit. The bit width determination unit is configured to: select a bit width of the second exponent field from a set of bit widths of the second exponent field of the second precision format based on an encoded value of the first exponent field of the data; and determine a bit width of the second mantissa field based on the selected bit width of the second exponent field and a total bit width of the second precision format.

[0127] In some embodiments, the second precision format also includes a prefix code field, and the device also includes a prefix code field determination unit, and the prefix code field determination unit is configured to: determine an indication value of the prefix code field based on the encoding value of the first exponent field; and determine the bit width of the prefix code field and the encoding value of the prefix code field based on the indication value of the prefix code field and a mapping table, wherein the indication value of the prefix code field also indicates the bit width of the second exponent field.

[0128] In some embodiments, the second precision format is tapered floating point precision. In some embodiments, the second precision format comprises HiFloat8. In some embodiments, the first precision format comprises IEEE FP16 or IEEE BF16.

[0129] According to the solution of the present disclosure, a chip is also provided. The chip includes a conversion circuit for converting data from a first precision format to a second precision format. The first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, and the precision of the first precision format is higher than the precision of the second precision format.

[0130] Figure 8 FIG. 8 is a schematic diagram of an example chip 800 according to some embodiments of the present disclosure. The chip 800 may be, for example, a system-on-a-chip (SoC). Figure 8As shown, the chip 800 may include a processor 801, a memory 805, an I / O interface 810, etc. The processor 801 may include a conversion circuit 820. The conversion circuit 820 may load the data in the memory 805 to convert the data into a precision format. For example, the conversion circuit 820 may read the sign domain, the first exponent domain, and the first mantissa domain of the FP32 data in the memory 805, thereby determining the sign domain, the prefix code domain, the second exponent domain, and the second mantissa domain of the corresponding FP16 data, BF16 data, or HiF8 data.

[0131] According to an embodiment of the present disclosure, the conversion circuit 820 is configured to: determine the reserved bits and reference bits in the first mantissa field based on the bit width of the second mantissa field for the data, the reserved bits including one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include two bits after the reserved bits in the first mantissa field; and based on the comparison of the encoded value of the reference bit with a threshold, round the encoded value of the reserved bit to obtain the encoded value of the second mantissa field for the data.

[0132] In some embodiments, the conversion circuit 820 is further configured to: determine a comparison bit after the reference bit in the first mantissa field; and determine the threshold value based on the coded value of the comparison bit and a predetermined padding value, or determine the threshold value based on the inversion of the coded value of the comparison bit and the predetermined padding value. In some embodiments, the comparison bit is the least significant bit in the first mantissa field. In some embodiments, the predetermined padding value is 1.

[0133] In some embodiments, the conversion circuit 820 is further configured to: if the code value of the reference bit is greater than or equal to the threshold, perform a carry operation on the lowest bit of the code value of the reserved bit, and the code value of the reserved bit after the carry operation is determined as the code value of the second mantissa domain. Alternatively, if the code value of the reference bit is less than the threshold, determine the code value of the reserved bit as the code value of the second mantissa domain.

[0134] In some embodiments, the conversion circuit 820 is further configured to: select the bit width of the second exponent field from the set of bit widths of the second exponent field in the second precision format based on the encoded value of the first exponent field for the data; and determine the bit width of the second mantissa field based on the selected bit width of the second exponent field and the total bit width of the second precision format.

[0135] In some embodiments, the second precision format also includes a prefix code field, and the conversion circuit 820 is further configured to: determine an indication value of the prefix code field based on the encoding value of the first exponent field; and determine the bit width of the prefix code field and the encoding value of the prefix code field based on the indication value of the prefix code field and a mapping table, wherein the indication value of the prefix code field also indicates the bit width of the second exponent field.

[0136] In some embodiments, the second precision format is tapered floating point precision. In some embodiments, the second precision format comprises HiFloat8. In some embodiments, the first precision format comprises IEEE FP16 or IEEE BF16.

[0137] Fig. 9 A schematic block diagram of an example device 900 that can be used to implement an embodiment of the present disclosure is shown. As shown, the device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to computer program instructions stored in a random access memory (RAM) 903 and / or a read-only memory (ROM) 902 or computer program instructions loaded from a storage unit 908 into the RAM 903 and / or ROM 902. In the RAM 903 and / or ROM 902, various programs and data required for the operation of the device 900 can also be stored. The computing unit 901 and the RAM 903 and / or ROM 902 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0138] A number of components in the device 900 are connected to the I / O interface 905, including: an input unit 906, such as a keyboard, a mouse, etc.; an output unit 907, such as various types of displays, speakers, etc.; a storage unit 908, such as a disk, an optical disk, etc.; and a communication unit 909, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 909 allows the device 900 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0139] The computing unit 901 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 901 performs the various methods and processes described above, such as processes 200 and 500. For example, in some embodiments, processes 200 and 500 may be implemented as computer software programs that are tangibly included in machine-readable media, such as storage units 908. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 900 via RAM and / or ROM and / or communication unit 909. When the computer program is loaded into RAM and / or ROM and executed by the computing unit 901, one or more steps of processes 200 and 500 described above may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to perform processes 200 and 500 in any other appropriate manner (eg, by means of firmware).

[0140] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a server or terminal, the process or function described in the embodiment of the present application is generated in whole or in part. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a server or terminal or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (such as a floppy disk, a hard disk and a tape, etc.), an optical medium (such as a digital video disk (digital video disk, DVD), etc.), or a semiconductor medium (such as a solid-state hard disk, etc.).

[0141] In addition, although each operation is described in a specific order, this should be understood as requiring such operation to be performed in the specific order shown or in a sequential order, or requiring that all illustrated operations should be performed to obtain desired results. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single implementation in combination. On the contrary, the various features described in the context of a single implementation can also be implemented in multiple implementations individually or in any suitable sub-combination mode.

[0142] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.

Claims

1. A precision conversion method, for converting data from a first precision format to a second precision format, wherein the first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, the precision of the first precision format is higher than the precision of the second precision format, the method comprising: Determine, based on the bit width of the second mantissa field for the data, reserved bits and reference bits in the first mantissa field, wherein the reserved bits include one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits include two bits after the reserved bits in the first mantissa field; as well as Based on the comparison between the encoding value of the reference bit and a threshold, a rounding operation is performed on the encoding value of the reserved bit to obtain an encoding value of the second mantissa field for the data.

2. The method according to claim 1, further comprising: determining a comparison bit following the reference bit in the first mantissa field; as well as Determine the threshold based on the coded value of the comparison bit and a predetermined padding value, or The threshold is determined based on the inversion of the encoded value of the comparison bit and the predetermined padding value.

3. The method of claim 2, wherein the comparison bit is the least significant bit in the first mantissa field.

4. The method according to any one of claims 2 to 3, wherein the predetermined padding value is 1.

5. The method according to any one of claims 1 to 4, wherein rounding the encoded value of the reserved bit to obtain the encoded value of the second mantissa field for the data comprises: If the code value of the reference bit is greater than or equal to the threshold, a carry operation is performed on the least significant bit of the code value of the reserved bit, and the code value of the reserved bit after the carry operation is determined as the code value of the second mantissa field, or If the encoding value of the reference bit is less than the threshold, the encoding value of the reserved bit is determined as the encoding value of the second mantissa field.

6. The method according to any one of claims 1 to 5, further comprising: selecting a bit width of the second exponent field from a set of bit widths of the second exponent field in the second precision format based on an encoded value of the first exponent field for the data; as well as The bit width of the second mantissa field is determined based on the selected bit width of the second exponent field and the total bit width of the second precision format.

7. The method according to any one of claims 1 to 6, wherein the second precision format further includes a prefix code field, and the method further includes: Determining an indication value of the prefix code field based on the encoding value of the first index field; as well as Determine the bit width of the prefix code field and the encoding value of the prefix code field based on the indication value of the prefix code field and the mapping table, The indication value of the prefix code field also indicates the bit width of the second exponent field.

8. The method of any one of claims 1 to 7, wherein the second precision format is tapered floating point precision.

9. The method of claim 8, wherein the second precision format comprises HiFloat8.

10. The method according to any one of claims 1 to 9, wherein the first precision format comprises IEEE FP16 or IEEE BF16.

11. A device for precision conversion, for converting data from a first precision format to a second precision format, wherein the first precision format includes a first exponent field and a first mantissa field, the second precision format includes a second exponent field and a second mantissa field, the precision of the first precision format is higher than the precision of the second precision format, the device comprising: a bit determination unit configured to determine a reserved bit and a reference bit in the first mantissa field based on a bit width of the second mantissa field for the data, wherein the reserved bit includes one or more bits starting from a highest bit in the first mantissa field, and the bit width of the reserved bit is the same as the bit width of the second mantissa field, and the reference bit includes two bits after the reserved bit in the first mantissa field; as well as A rounding unit is configured to perform a rounding operation on the encoded value of the reserved bit based on a comparison between the encoded value of the reference bit and a threshold value to obtain an encoded value of the second mantissa field for the data.

12. The apparatus according to claim 11, further comprising a threshold determination unit, wherein the threshold determination unit is configured to: determining a comparison bit following the reference bit in the first mantissa field; and Determine the threshold based on the coded value of the comparison bit and a predetermined padding value, or The threshold is determined based on the inversion of the encoded value of the comparison bit and the predetermined padding value.

13. The apparatus of claim 12, wherein the comparison bit is a least significant bit in the first mantissa field.

14. The apparatus according to any one of claims 12 to 13, wherein the predetermined padding value is 1.

15. The apparatus according to any one of claims 11 to 14, wherein the rounding unit is further configured to: If the code value of the reference bit is greater than or equal to the threshold, a carry operation is performed on the least significant bit of the code value of the reserved bit, and the code value of the reserved bit after the carry operation is determined as the code value of the second mantissa field, or If the encoding value of the reference bit is less than the threshold, the encoding value of the reserved bit is determined as the encoding value of the second mantissa field.

16. The apparatus according to any one of claims 11 to 15, further comprising a bit width determining unit, wherein the bit width determining unit is configured to: selecting a bit width of the second exponent field from a set of bit widths of the second exponent field in the second precision format based on an encoded value of the first exponent field for the data; and The bit width of the second mantissa field is determined based on the selected bit width of the second exponent field and the total bit width of the second precision format.

17. The apparatus according to any one of claims 11 to 16, wherein the second precision format further includes a prefix code field, the apparatus further includes a prefix code field determining unit, and the prefix code field determining unit is configured to: determining an indication value of the prefix code field based on the encoded value of the first index field; and Determine the bit width of the prefix code field and the encoding value of the prefix code field based on the indication value of the prefix code field and the mapping table, The indication value of the prefix code field also indicates the bit width of the second exponent field.

18. The apparatus of any one of claims 11 to 17, wherein the second precision format is tapered floating point precision.

19. The apparatus of claim 18, wherein the second precision format comprises HiFloat8.

20. The apparatus of any one of claims 11 to 19, wherein the first precision format comprises IEEE FP16 or IEEE BF16.

21. A chip, comprising a conversion circuit, the conversion circuit being used to convert data from a first precision format to a second precision format, wherein the first precision format comprises a first exponent field and a first mantissa field, the second precision format comprises a second exponent field and a second mantissa field, the precision of the first precision format is higher than the precision of the second precision format, the conversion circuit being configured as: Determining reserved bits and reference bits in the first mantissa field based on the bit width of the second mantissa field for the data, the reserved bits including one or more bits starting from the highest bit in the first mantissa field, and the bit width of the reserved bits is the same as the bit width of the second mantissa field, and the reference bits including two bits after the reserved bits in the first mantissa field; and Based on the comparison between the encoding value of the reference bit and a threshold, a rounding operation is performed on the encoding value of the reserved bit to obtain an encoding value of the second mantissa field for the data.

22. The chip according to claim 21, wherein the conversion circuit is further configured to: determining the threshold based on the encoded value of the comparison bit following the reference bit in the first mantissa field and a predetermined padding value, or The threshold is determined based on the inversion of the encoded value of the comparison bit following the reference bit in the first mantissa field and the predetermined padding value.

23. An electronic device, comprising: at least one computing unit; At least one memory, the at least one memory is coupled to the at least one computing unit and stores instructions for execution by the at least one computing unit, the instructions, when executed by the at least one computing unit, causing the electronic device to perform the method according to any one of claims 1-10.

24. A computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.

25. A computer program product comprising computer executable instructions, wherein the computer executable instructions, when executed by a processor, implement the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Floating-point number conversion method and device

    CN111340207A

  • Residual quantization for neural networks

    CN113168563A

  • Floating point data precision conversion method and device

    CN118585164A

  • Stochastic rounding of numerical values

    US20190377549A1

  • Converting floating point numbers to reduce the precision

    US20200201602A1

Cited By

  • Floating point data precision conversion method and device and computer equipment

    CN120353433A