Floating-point number encoding method, processor chip, and computing device

By separating and encoding floating-point numbers according to their exponential importance, the problem of low compression ratio caused by inconsistent floating-point number lengths is solved, achieving efficient compression without alignment and improving encoding efficiency.

WO2026242974A1PCT designated stage Publication Date: 2026-11-26HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2026/097526
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2025-05-23
Filing Date
2026-05-18
Publication Date
2026-11-26

AI Technical Summary

Technical Problem

In existing technologies, the entropy encoding of floating-point numbers results in low compression rates when the lengths of the floating-point numbers to be encoded are inconsistent, and the encoded floating-point numbers need to be aligned, which increases hardware complexity.

Method used

Based on the importance of the exponent, floating-point numbers are divided into two parts: important and unimportant. Different encoding prefixes and mantissa lengths are used for each part. By understanding the relationship between the exponent and mantissa lengths, the encoded floating-point numbers can be read without alignment.

Benefits of technology

It improves the compression rate of floating-point numbers, reduces the complexity requirements of hardware, and improves coding efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2026097526_26112026_PF_FP_ABST
    Figure CN2026097526_26112026_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of computers, and provides a floating-point number encoding method, a processor chip, and a computing device. The method comprises: on the basis of the exponent significance of floating-point numbers to be encoded, performing encoding processing on each floating-point number among said floating-point numbers, so that a prefix of an exponent of a first part of encoded floating-point number is a first value, and a prefix of an exponent of a second part of encoded floating-point number is a second value. A prefix is used for indicating the exponent bit length of each encoded floating-point number, and a mantissa bit of each encoded floating-point number is related to an exponent of each floating-point number; therefore, the exponent of each encoded floating-point number can be read by means of the prefix, and the mantissa bit can be read by means of the exponent. In this way, after the floating-point numbers are encoded, alignment processing does not need to be performed on the encoded floating-point numbers, thereby improving compression rate.
Need to check novelty before this filing date? Find Prior Art

Description

Methods for encoding floating-point numbers, processor chips, and computing devices

[0001] This application claims priority to Chinese patent application filed on May 23, 2025, with application number 202510682935.0 and entitled "Method for Encoding Floating-Point Numbers, Processor Chip and Computing Device", the entire contents of which are incorporated herein by reference. Technical Field

[0002] This application relates to the field of computer technology, and in particular to a method for encoding floating-point numbers, a processor chip, and a computing device. Background Technology

[0003] Floating-point (FP) numbers are an important data format, consisting of a sign, exponent (E), and mantissa (M). In most scenarios, due to the large data volume of floating-point numbers, storage and transmission consume significant resources. Therefore, compression is necessary to reduce the data size of floating-point numbers.

[0004] In related technologies, entropy encoding is used to compress floating-point numbers. However, entropy encoding may not achieve the desired compression ratio. For example, when multiple floating-point numbers to be encoded have different lengths, entropy encoding will result in a low compression ratio. Summary of the Invention

[0005] This application provides a method for encoding floating-point numbers, a processor chip, and a computing device. Using this method for encoding floating-point numbers can improve the compression ratio. The technical solution adopted is as follows:

[0006] In a first aspect, this application provides a method for encoding floating-point numbers. The method includes: encoding each floating-point number in the floating-point number to be encoded according to the importance of the exponent of the floating-point number to be encoded, wherein the floating-point number to be encoded includes a first part of the floating-point number and a second part of the floating-point number, wherein the first part of the floating-point number contributes more to the accuracy of the calculation result than the second part of the floating-point number contributes more to the accuracy of the calculation result; the prefix of the exponent of the encoded first part of the floating-point number is a first value, the prefix of the exponent of the encoded second part of the floating-point number is a second value, the mantissa bits of each encoded floating-point number are related to the exponent of each floating-point number, and the prefix is ​​used to indicate the length of the exponent bits of the encoded floating-point number.

[0007] In the scheme shown in this application, after encoding the floating-point number to be encoded using the above scheme, the exponent of the first part of the encoded floating-point number can be read through the first value, and the exponent of the second part of the encoded floating-point number can be read through the second value. Moreover, since the length of the mantissa of each encoded floating-point number is related to the exponent of each floating-point number, the length of the mantissa can be obtained through the exponent of the encoded floating-point number, so that the mantissa of the corresponding length can be read according to the length of the mantissa. In this way, even if the encoded floating-point number is not aligned after encoding, the encoded floating-point number can still be read, thus improving the compression ratio.

[0008] In one alternative approach, when encoding the floating-point number according to the importance of its exponent, if the exponent of the first part of the floating-point number is greater than that of the second part, an exponent threshold is obtained. This exponent threshold is used to distinguish the importance of the floating-point number; it can also be understood as the minimum exponent required to retain full precision during encoding. Then, using this exponent threshold, the floating-point number is encoded to obtain the encoded floating-point number. The compression degree of the first part of the floating-point number is lower than that of the second part. Thus, encoding the floating-point number according to the exponent threshold results in lower compression of important floating-point numbers and higher compression of less important ones, reducing the impact of encoding on the overall precision of the floating-point number.

[0009] In one alternative approach, an exponent threshold is used, along with the standard mantissa length of the floating-point number to be encoded, to determine the exponent threshold value for the floating-point number that retains 1 bit after encoding. Based on this exponent threshold value, each floating-point number is encoded, thus enabling the exponent to be encoded to compress the floating-point number.

[0010] In one alternative approach, when determining the exponent threshold, the threshold is set to be equal to the exponent threshold minus a first product and a third value. The first product is equal to the product of the standard mantissa length and n, where n is an integer greater than or equal to 1, and the third value is an integer greater than or equal to 0. This ensures that the floating-point number is encoded into a 1-bit value as early as possible after all mantissa bits have been removed, thereby improving the compression ratio.

[0011] In one alternative approach, when encoding each floating-point number using an exponent threshold, for each floating-point number, if the exponent is greater than the exponent threshold, the exponent of the encoded floating-point number is determined based on the difference between the exponent and the exponent threshold. If the exponent is less than or equal to the exponent threshold, the exponent is encoded as the second value. The first part of the floating-point number includes floating-point numbers whose exponents are greater than the exponent threshold, and the second part includes floating-point numbers whose exponents are less than or equal to the exponent threshold. This results in less exponent reduction for floating-point numbers with larger exponents and allows the exponents of floating-point numbers with smaller exponents to be encoded as 1 bit, thereby improving the compression ratio.

[0012] In one alternative approach, when encoding each floating-point number according to the importance of its exponent, the exponent of that floating-point number is encoded using the encoding method of the exponent range to which it belongs. The importance of exponents differs across exponent ranges. This allows the exponent of floating-point numbers to be encoded according to a specified exponent range.

[0013] In one alternative approach, using an exponent threshold, when encoding floating-point numbers, the mantissa bits can be encoded. The mantissa encoding process is as follows: for each floating-point number to be encoded, if the exponent is greater than or equal to the exponent threshold, all mantissa bits are retained. If the exponent is less than the exponent threshold, the mantissa bits are encoded based on the exponent threshold, the exponent, and the mantissa length. After encoding, the mantissa length is greater than or equal to 0 and less than the original mantissa length. This allows for the retention of mantissa bits for important floating-point numbers and the reduction of mantissa bits for less important numbers, effectively compressing floating-point numbers while maintaining the precision of important floating-point numbers.

[0014] In one alternative approach, for each floating-point number to be encoded, if the exponent of the floating-point number is less than an exponent threshold, a fourth mantissa bit is retained starting from the most significant mantissa bit of the floating-point number. This ensures that the larger the exponent, the more mantissa bits are retained. The fourth mantissa bit is the difference between the length of the mantissa bit and the fifth mantissa bit. The fifth mantissa bit is determined based on the difference between the exponent threshold and the exponent of the floating-point number. In this way, for floating-point numbers with larger exponents, more mantissa bits are retained, which not only compresses the floating-point number but also ensures the precision of the more important floating-point number.

[0015] Optionally, for each floating-point number, the fifth value is the result of dividing the difference between the exponent threshold and the exponent of that floating-point number by n and then rounding down. This ensures that the length of the mantissa changes by 1 for every n change in the exponent.

[0016] In one alternative approach, when encoding each floating-point number according to the importance of its exponent, the mantissa of the floating-point number is encoded using the encoding method of the exponent range to which the exponent belongs. The importance of the exponent differs across exponent ranges. This allows the mantissa of the floating-point number to be encoded according to a specified exponent range.

[0017] In one alternative approach, since the exponent threshold is related to the exponent of the floating-point number to be encoded, the exponent threshold can be accurately determined by using the exponent distribution of the floating-point number to be encoded.

[0018] In one alternative approach, when the floating-point number to be encoded is weight data, since the weight data is related to the activation data and gradient data, the floating-point number to be encoded and the related data are calculated to obtain the result data, which includes at least one of the activation data and gradient data. Using the result data, the exponential threshold is determined, and the exponential threshold can be accurately determined.

[0019] In one alternative approach, when performing calculations on the floating-point number to be encoded and its related data, a multiplication operation can be performed to obtain the result data.

[0020] In one alternative approach, the first value is 1 and the second value is 0, which facilitates decoding.

[0021] Secondly, this application provides a method for decoding floating-point numbers, the method comprising: in response to the prefix of the exponent of the encoded floating-point number being a first value, reading the exponent of a length corresponding to the first value, and determining the mantissa of the encoded floating-point number and the exponent of the encoded floating-point number before encoding based on the exponent; in response to the prefix of the exponent of the encoded floating-point number being a second value, reading the value of a length corresponding to the second value, and determining it as the encoded floating-point number.

[0022] In one alternative approach, determining the mantissa of the encoded floating-point number and the exponent of the encoded floating-point number before encoding based on the exponent includes: obtaining an exponent threshold, and determining the exponent of the encoded floating-point number before encoding based on the exponent threshold;

[0023] Based on the exponent of the encoded floating-point number, the length of the mantissa of the encoded floating-point number is determined, and the mantissa of the encoded floating-point number is read based on the length of the mantissa.

[0024] For a description of the effects in the second aspect and the optional methods, please refer to the description in the first aspect or the optional methods of the first aspect.

[0025] Thirdly, this application provides an apparatus for encoding floating-point numbers, which has the functionality to implement the first aspect or any optional method of the first aspect described above. The apparatus includes at least one module for implementing the method provided by the first aspect or any optional method of the first aspect.

[0026] Fourthly, this application provides an apparatus for decoding floating-point numbers, which has the functionality to implement the second aspect or an optional method described above. The apparatus includes at least one module for implementing the method provided by the second aspect or an optional method described above.

[0027] Fifthly, this application provides a processor chip for performing the methods provided by the first aspect or any alternative method of the first aspect.

[0028] In a sixth aspect, this application provides a processor chip for performing the methods provided as in the second aspect or alternative methods of the second aspect.

[0029] In a seventh aspect, this application provides a computing device that includes a processor chip as provided in the fifth and sixth aspects.

[0030] Eighthly, this application provides a computing device, which includes a communication interface, a processor, and a memory;

[0031] The communication interface is used to communicate with other devices; the processor is used to execute program instructions in the memory to perform the method provided by the first aspect or any optional method of the first aspect, or the method provided by the second aspect or an optional method of the second aspect.

[0032] In a ninth aspect, this application provides a computer-readable storage medium including program instructions that, when executed by a computing device, perform the method provided by the first aspect, or any alternative method of the first aspect, or by the second aspect or an alternative method of the second aspect.

[0033] In a tenth aspect, this application provides a computer program product including program instructions stored in a computer-readable storage medium. A processor in a computing device reads the program instructions from the computer-readable storage medium and executes the program instructions, causing the computing device to perform the methods provided in the first aspect or any optional method of the first aspect, or as provided in the second aspect or an optional method of the second aspect.

[0034] It should be understood that the technical effects achieved by the technical solutions provided by the second to tenth aspects of this application and their corresponding possible implementations can be found in the above description of the technical effects achieved by the technical solutions provided by the first aspect and their corresponding possible implementations, and will not be repeated here. Attached Figure Description

[0035] Figure 1 is a schematic diagram of a floating-point number provided in an embodiment of this application;

[0036] Figure 2 is a schematic flowchart of a method for encoding floating-point numbers according to an embodiment of this application;

[0037] Figure 3 is a schematic diagram showing that the lengths of the quantized floating-point numbers vary according to an embodiment of this application;

[0038] Figure 4 is a schematic diagram of determining the exponential threshold provided in an embodiment of this application;

[0039] Figure 5 is a schematic diagram of the framework of an coded floating-point number provided in one embodiment of this application;

[0040] Figure 6 is a schematic diagram comparing the floating-point number before and after encoding according to an embodiment of this application;

[0041] Figure 7 is another comparative diagram of floating-point numbers before and after encoding provided in an embodiment of this application;

[0042] Figure 8 is a schematic diagram of a packaged and encoded floating-point number provided in an embodiment of this application;

[0043] Figure 9 is another schematic diagram of a packaged and encoded floating-point number provided in one embodiment of this application;

[0044] Figure 10 is a schematic diagram of a device for encoding floating-point numbers according to an embodiment of this application;

[0045] Figure 11 is a schematic diagram of a device for decoding floating-point numbers according to an embodiment of this application;

[0046] Figure 12 is a schematic diagram of the structure of a device provided in one embodiment of this application. Detailed Implementation

[0047] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0048] The following explains some terms and concepts involved in the embodiments of this application.

[0049] 1. A floating-point number includes a sign bit, an exponent (also called an exponent code), and a mantissa. It can also be understood as including a sign bit, an exponent bit, and a mantissa bit. A floating-point number can be viewed as a three-dimensional vector or a two-dimensional vector. In a three-dimensional vector, the sign, exponent, and mantissa are represented; in a two-dimensional vector, the exponent and mantissa are represented, ignoring the sign bit. Alternatively, they can be represented as a combined number and a combined number, where the sign bit is combined with the exponent. Floating-point numbers include half-precision floating-point (FP16), single-precision floating-point (FP32), double-precision floating-point (FP64), and so on. See Figure 1; FP16 is a floating-point number stored using 16 bits, including 1 bit for the sign, 5 bits for the exponent, and 10 bits for the mantissa. Half-precision floating-point numbers can represent numbers with an absolute value range of approximately [6.10 x 10^-5, 6.55 x 10^4]. FP32 is a floating-point number stored using 32 bits, including 1 bit for the sign, 8 bits for the exponent, and 23 bits for the mantissa. Single-precision floating-point numbers can represent numbers with an absolute value range of approximately [1.18 x 10^-38, 3.40 x 10^38]. FP64 is a floating-point number stored using 64 bits, including 1 bit for the sign, 11 bits for the exponent, and 52 bits for the mantissa. Double-precision floating-point numbers can represent 15 or 16 significant decimal digits, with an absolute value range of approximately [2.23 x 10^-308, 1.80 x 10^308]. FP128 is a floating-point number stored using 128 bits, including 1 bit for the sign, 15 bits for the exponent, and 112 bits for the mantissa. Quad-precision floating-point numbers can represent 33 to 36 significant digits in decimal, and the absolute value range of the numbers they can represent is approximately [3.40 x 10^-4932, 1.18 x 10^4932].

[0050] 2. Compression refers to the process of reducing data size through specific encoding mechanisms.

[0051] 3. Entropy coding involves creating and assigning a unique code (such as a prefix code) to each input symbol, and then replacing each fixed-length symbol with a corresponding variable-length, prefix-free output codeword, thereby compressing the data. The length of each codeword is approximately proportional to the negative logarithm of the probability. Therefore, the shortest code is used for the most common symbols. Huffman coding and arithmetic coding are two of the most common entropy coding techniques.

[0052] In the field of artificial intelligence (AI), training large models (including but not limited to large language models (LLMs)) is limited by computation and interconnect bandwidth, while inference is mainly limited by memory bandwidth and memory capacity. Therefore, data transmission and storage are the biggest challenges in training and inference scenarios. Data transmission and storage lead to idle computing power, creating a bottleneck in overall performance. Improving the performance of large model training and inference is key to competitiveness. One important key is the compression of large model weight data, which needs to be compressed into floating-point numbers.

[0053] In one implementation, entropy coding is used to compress the floating-point numbers to be encoded. However, when the lengths of the multiple floating-point numbers to be encoded are inconsistent, entropy coding may result in a low compression ratio. This is because, after entropy coding, the lengths of the encoded floating-point numbers are inconsistent. Since the number of bits read during decoding is unknown, the length of the encoded floating-point numbers usually needs to be padded after entropy coding for alignment, resulting in a low compression ratio. If the encoded floating-point numbers are not aligned, the required hardware is more complex.

[0054] This application provides a method for encoding floating-point numbers. Each floating-point number is encoded according to the importance of its exponent. The important first part of the floating-point number is prefixed with a first value after encoding, and the less important second part is prefixed with a second value. Thus, the exponent of the encoded first part of the floating-point number can be read using the first value, and the exponent of the encoded second part can be read using the second value. Furthermore, since the length of the mantissa of each encoded floating-point number is related to its exponent, the length of the mantissa can be obtained from the exponent, allowing the mantissa of the corresponding length to be read. This ensures that even without alignment, the encoded floating-point number can be read, thereby improving the compression ratio.

[0055] The method for encoding floating-point numbers in this application can be applied to any scenario, as long as floating-point number encoding is required. For example, the applicable scenarios include, but are not limited to, encoding weight data in a large model where the weight data is a floating-point number, and the large model can be any large model containing weight data, such as a large language model.

[0056] The main body of the method can be a device for encoding floating-point numbers. Optionally, the device is a hardware device, such as a processor chip or a computing device. The processor chip includes, but is not limited to, a central processing unit (CPU) chip, an artificial intelligence (AI) chip, and a graphics processing unit (GPU) chip. Optionally, the device is a set of software programs deployed on the hardware device.

[0057] The following describes the method flow for encoding floating-point numbers in the embodiments of this application. Please refer to steps S101 to S102 in Figure 2. In Figure 2, a computing device is used as the execution subject for illustration.

[0058] Step S101: Determine the exponential importance of the floating-point number to be encoded.

[0059] In this embodiment, the floating-point numbers to be encoded include multiple floating-point numbers of the same type, such as all FP16, all FP8, or all FP32. Among these multiple floating-point numbers, some may have different bit lengths, or the multiple floating-point numbers may have the same bit length. The floating-point number to be encoded can be a quantized floating-point number or an unquantized floating-point number. When the floating-point number to be encoded is a quantized floating-point number, the quantization method can be any method. For example, referring to Figure 3, for an FP8 (E4M3) floating-point number, E4M3 means that the standard exponent length is 4 and the standard mantissa length is 3. The standard exponent length can also be understood as the maximum exponent length or the exponent length. The standard mantissa length can also be understood as the maximum mantissa length or the mantissa length. During quantization, all mantissa bits of floating-point numbers with exponents greater than +3 are retained, and the mantissa bits of floating-point numbers with exponents between -3 and +3 are retained. All mantissa bits of floating-point numbers with exponents less than -3 are deleted, and the exponent is quantized. The quantization method can be any method, and this application embodiment does not limit it.

[0060] The computing device uses the exponent length of the floating-point number to be encoded to determine the exponent importance of the floating-point number. This exponent importance reflects the degree of importance of the exponent, and thus the degree of importance of the floating-point number. The importance of the floating-point number can be measured by its contribution to the accuracy of the calculation result; the higher the importance, the greater the contribution to the accuracy of the calculation result, and vice versa. For example, if the floating-point number is weighted data, its importance can be measured by its contribution to the inference accuracy of the inference result.

[0061] In one alternative approach, a larger exponent for a floating-point number indicates greater importance of the floating-point number. This is because when using large models for inference, it ultimately boils down to mathematical operations, such as multiplication. After the operation is completed, a result is obtained. The larger the absolute value of the obtained value, the greater its contribution to the final result. Generally speaking, a larger exponent indicates a larger absolute value for the floating-point number, and thus a greater importance for the floating-point number. Therefore, using exponent importance can measure the importance of floating-point numbers.

[0062] In another alternative approach, the user divides the exponent of the floating-point number to be encoded into multiple exponent ranges based on simulation or experience, with different exponent ranges having different exponent importance.

[0063] Step S102: According to the importance of the exponent of the floating-point number to be encoded, each floating-point number in the floating-point number to be encoded is encoded. The floating-point number to be encoded includes a first part of the floating-point number and a second part of the floating-point number. The first part of the floating-point number contributes more to the accuracy of the calculation result than the second part of the floating-point number. The prefix of the exponent of the first part of the encoded floating-point number is a first value, and the prefix of the exponent of the second part of the encoded floating-point number is a second value. The mantissa of each of the encoded floating-point numbers is related to the exponent of each floating-point number. The prefix is ​​used to indicate the length of the exponent of the encoded floating-point number.

[0064] To reduce data storage requirements, the first value is 1 bit and the second value is 1 bit. For example, the first value is 1 and the second value is 0, or the first value is 0 and the second value is 1.

[0065] In this embodiment, the floating-point number to be encoded includes a first part of the floating-point number and a second part of the floating-point number. The first part of the floating-point number contributes more to the accuracy of the calculation result than the second part of the floating-point number. If the floating-point number to be encoded is weighted data, the first part of the floating-point number contributes more to the inference accuracy of the inference result than the second part of the floating-point number. This indicates that the first part of the floating-point number is more important than the second part of the floating-point number, and the inference result is obtained based on the first part of the floating-point number and the second part of the floating-point number. The computing device encodes each floating-point number in the unencoded floating-point number according to the importance of the exponent. The prefix of the exponent of the first part of the encoded floating-point number is a first value, and the prefix of the exponent of the second part is a second value. That is, the important first part of the floating-point number is mapped to a prefix of the first value after encoding, and the less important second part is mapped to a prefix of the second value. For each encoded floating-point number, the mantissa bits are related to the exponent of the encoded floating-point number, and this prefix indicates the length of the exponent bits. Thus, when reading the floating-point number, the exponent of the encoded floating-point number can be read according to the exponent bit length indicated by the prefix. Then, the mantissa bit length is determined using the exponent bit length, and the mantissa bit length is used to read the mantissa. Therefore, no alignment processing is required after encoding the floating-point number, which improves the compression ratio.

[0066] It should be noted that after encoding a floating-point number, when storing the encoded floating-point number, the exponent is placed first, followed by the sign bit, and finally the mantissa bit, or the exponent is placed first, followed by the mantissa bit, and finally the sign bit.

[0067] It should also be noted that the first part of the floating-point number and the second part of the floating-point number mentioned above may not have been pre-defined, but rather divided after encoding based on the different prefixes of the exponents.

[0068] In one alternative approach, the relationship between the mantissa bits of each encoded floating-point number and its exponent can be understood as follows: for each floating-point number, the length of the mantissa bits can be obtained using the exponent of the encoded floating-point number. In other words, the exponent of the encoded floating-point number directly or indirectly corresponds to the length of the mantissa bits. "Directly" means there is a correspondence between the exponent and the length of the mantissa bits, while "indirectly" means there is a correspondence between the exponent and the length of the encoded floating-point number. The length of the mantissa bits is then used to deduce the length of the mantissa. For example, if the first value is 1, for an FP8 (E4M3) floating-point number, and the exponent of the encoded floating-point number is 1001(+2), the encoded floating-point number is 6 bits, with the exponent occupying 4 bits, the sign bit occupying 1 bit, and the mantissa bit occupying 1 bit.

[0069] In an alternative approach, the exponential importance in step S102 can be measured by an exponential threshold, and the processing method in step S102 is as follows:

[0070] The computing device obtains an exponent threshold determined for the floating-point number to be encoded. This exponent threshold is used to distinguish the importance of floating-point numbers. Floating-point numbers with exponents higher than the exponent threshold are more important than those with exponents lower than the exponent threshold. The larger the exponent, the more important the floating-point number; the smaller the exponent, the less important the floating-point number. This exponent threshold can also be understood as the maximum exponent that distinguishes the importance of floating-point numbers, or as the minimum exponent that preserves full precision during encoding. Full precision means that the number of bits in the floating-point number is not reduced. Then, each floating-point number in the floating-point number to be encoded is encoded using this exponent threshold to obtain the encoded floating-point number. This exponent threshold allows the floating-point number to be encoded to be divided into a first part and a second part. The exponent of the first part is greater than the exponent of the second part, and the compression degree of the first part is lower than that of the second part.

[0071] Alternatively, there are several ways to obtain the exponential threshold; three feasible methods are provided below:

[0072] Method 1: The computing device determines the exponential distribution of the floating-point number to be encoded and uses this distribution to determine the exponential threshold. For example, the computing device obtains the desired compression ratio of the floating-point number to be encoded and sets the exponential threshold to x. Then, using the exponential distribution of the floating-point number to be encoded, the set encoding rules, and the compression ratio, an equation including x is constructed. Since there is only one unknown x, the exponential threshold used to achieve the compression ratio can be obtained by solving the equation. Here, one or more encoding rules can be set. If there are multiple encoding rules, each encoding rule can be used to calculate an exponential threshold, thus obtaining multiple exponential thresholds. One exponential threshold is then selected from these multiple exponential thresholds. For example, the selected exponential threshold ensures that the new exponent of the most frequently encoded floating-point number is still included within the range of the original data format exponent. Subsequent encoding is performed using the encoding rules that determined this exponential threshold.

[0073] Method Two: When the floating-point number to be encoded is weighted data, the computing device uses the floating-point number to be encoded and its related data to determine the exponential threshold. For example, the related data includes at least one of activation data and gradient data. The computing device performs calculations on the floating-point number to be encoded and the related data to obtain a result distribution, and then uses this result distribution to determine the exponential threshold.

[0074] Optionally, the computing device performs a multiplication operation between the floating-point number to be encoded and related data to obtain the result data. Then, the result data is used to determine the exponent threshold. For example, as shown in Figure 4, the operation between the floating-point number to be encoded and the related data is matrix multiplication. After the multiplication operation, a new result matrix is ​​obtained, which is the result data. A vector is generated using each column of data in the result matrix. For each column of data, the vector corresponding to that column is the mathematical statistical value of that column. This mathematical statistical value includes, but is not limited to, the average, maximum, minimum, or the most frequently occurring value. The mathematical statistical value of that column indicates the importance of that column of data. If the number of columns in the result data is i, i values ​​will be generated, denoted as R1 to Ri. R1 to Ri are sorted in descending order, and the largest K1 values ​​are selected, where K1 is an integer greater than 2. Then, for each of the K1 values, a column of floating-point numbers corresponding to that value is determined, and the exponent of that column of floating-point numbers is determined. In this way, the exponents of K columns of floating-point numbers can be obtained, and the exponents of these K columns of floating-point numbers are used to determine the exponent threshold. When determining the exponent threshold using the exponents of K columns of floating-point numbers, any function F can be used. For example, as shown in Figure 4, function F is a function that takes the minimum value among the K2 largest values. For K columns of floating-point numbers, determine the frequency of each exponent, sort the frequencies from largest to smallest, select the K2th frequency from largest to smallest, and determine the exponent corresponding to the K2th frequency as the exponent threshold. K2 is less than K1. The values ​​of K1 and K2 are related to the number of floating-point numbers in the floating-point number to be encoded. They can be set as empirical values ​​or substituted into a function to determine the threshold. Alternatively, for each column of floating-point numbers in the K1 floating-point numbers, determine the exponent with the highest frequency in that column. This will identify K1 exponents and their corresponding frequencies. Sort these K1 exponent frequencies in descending order, selecting the K3rd frequency. The exponent corresponding to this K3rd frequency is then determined as the exponent threshold, where K3 is less than K1. The values ​​of K1 and K3 are related to the number of floating-point numbers in the floating-point number to be encoded and can be set as empirical values ​​or determined by substituting them into a function. These are merely two possible examples; this application does not limit the method for determining the exponent threshold.

[0075] Optionally, since activation data has a greater impact on weight data, the relevant data includes activation data, while gradient data is optional.

[0076] Optionally, since gradient data also affects weight data, the relevant data includes activation data and gradient data.

[0077] Method 3: The computing device obtains the index threshold set by the technicians based on experience; that is, the index threshold is an empirical value.

[0078] It should be noted that when determining the exponent threshold, it is considered that after using the exponent threshold encoding, the new exponent of most floating-point numbers should still be included in the range of the original data format exponent. If the new exponent of most floating-point numbers is not included in this range, it indicates that the exponent threshold may be unreasonable and needs to be reset. Alternatively, the technician believes that floating-point numbers exceeding the range should be discarded or set to 0. Or, the exponent threshold exceeding the range should be set to the maximum exponent value.

[0079] Optionally, when encoding each floating-point number in the floating-point numbers to be encoded, an exponent threshold can be used, and the exponent and / or mantissa can be encoded.

[0080] Alternatively, the exponent can be encoded using an exponent threshold as follows:

[0081] Based on the exponent threshold and the standard mantissa length of the floating-point number to be encoded, the exponent threshold value for retaining 1 bit after encoding is determined. The standard mantissa length refers to the maximum mantissa length of the floating-point number, such as 3 for FP8 (E4M3). This exponent threshold value can also be called the zero threshold, which is the exponent boundary point of the least important exponent. It can be understood as the exponent boundary point where the exponent of the floating-point number is encoded as the second value. Then, using this exponent threshold value, the exponent of each floating-point number in the floating-point number to be encoded is encoded.

[0082] Alternatively, the exponential threshold value can be determined as follows:

[0083] The exponent threshold is determined to be equal to the exponent threshold minus the first product and the third value. The first product is equal to the product of the standard mantissa length and n, where n is the step size (1), an integer greater than or equal to 1. The third value is an integer greater than or equal to 0. The third value can also be understood as the step size (2). When the second value is 0, this step size (2) can be understood as how much further the exponent needs to be reduced to become 0 after all mantissas have been removed. Therefore, the exponent threshold = max exponent - (n * standard mantissa length + third value).

[0084] Optionally, n equals 1 and the third value equals 1. In this way, when all the mantissas are deleted, the exponent can be reduced by 1 to become 0. Then the exponent threshold value = max exponent - (standard mantissa length + 1).

[0085] It should be noted that the previous explanation used an integer as n. In practical applications, n can also be a fraction, but it needs to be rounded down to the standard mantissa length.

[0086] Alternatively, the exponent can be encoded using an exponent threshold value as follows:

[0087] For ease of description, the exponent before encoding is called the original exponent, and the exponent after encoding is called the new exponent. For each floating-point number to be encoded, if the original exponent is greater than the exponent threshold, the value obtained by subtracting the exponent threshold from the original exponent is determined as the new exponent after encoding. Here, if the value obtained by subtracting the exponent threshold from the original exponent exceeds the range of the exponent in the original data format, the new exponent after encoding is set to the maximum exponent within that range, or it is discarded. If the exponent is less than or equal to the exponent threshold, the exponent is encoded as a second value, and all mantissa bits and sign bits of the floating-point number are deleted. If the second value is bit 0, the floating-point number can be encoded as 1'b0, where 1'b0 represents 1 bit of binary data with a value of 0.

[0088] The process of encoding the index is expressed by the formula:

[0089] If the original exponent is greater than the exponent threshold, the new exponent = original exponent - exponent threshold. If the original exponent is less than or equal to the exponent threshold, the encoded floating-point number = the second value. Therefore, after encoding the second part of the floating-point number, the encoded second part of the floating-point number is encoded as a number prefixed with the second value.

[0090] Alternatively, the mantissa can be encoded using an exponential threshold as follows:

[0091] For ease of description, the length of the mantissa bits before encoding is called the original mantissa length, and the length of the mantissa bits after encoding is called the new mantissa length. For each floating-point number to be encoded, if the exponent of the floating-point number is greater than or equal to the exponent threshold, then all mantissa bits of the floating-point number are retained. That is, the new mantissa of the floating-point number is equal to the original mantissa. If the exponent of the floating-point number is less than the exponent threshold, then the mantissa bits of the floating-point number are encoded based on the exponent threshold, the exponent of the floating-point number, and the mantissa length. After encoding, the mantissa length of the floating-point number is greater than or equal to 0, and less than the mantissa length before encoding.

[0092] Optionally, the mantissa of the floating-point number is encoded according to the principle that the larger the exponent of the floating-point number, the longer the length of the mantissa is retained. The encoding process is as follows:

[0093] For each floating-point number to be encoded, retain a fourth mantissa starting from the most significant bit. This fourth mantissa is the difference between the length of the mantissa and a fifth mantissa, which is determined by the difference between the exponent threshold and the exponent of the floating-point number. If the fourth mantissa is less than or equal to 0, it indicates that all mantissa bits have been removed.

[0094] Optionally, for each floating-point number, the fifth value is equal to the difference between the exponent threshold and the exponent of that floating-point number.

[0095] Optionally, for each floating-point number, the fifth value is equal to the difference between the exponent threshold and the exponent of that floating-point number, divided by n and rounded down. This embodiment does not limit the rounding method, such as rounding up, rounding down, or rounding to the nearest integer. This ensures that for every n change in the exponent, the length of the mantissa changes by 1.

[0096] The process of encoding the mantissa can be expressed by the formula:

[0097] When the original exponent is greater than or equal to the exponent threshold, the new mantissa length equals the original mantissa length, and the new mantissa equals the original mantissa. When the original exponent is less than the exponent threshold, the new mantissa length equals the original mantissa length minus the integer part of [(exponent threshold - original exponent) / n]. If the new mantissa length is less than or equal to 0, it means that all mantissas have been removed. Specifically, when n equals 1, and the original exponent is less than the exponent threshold, the new mantissa length equals the original mantissa length minus (exponent threshold - original exponent). Floating-point numbers are lossy encoded.

[0098] To better illustrate the method of encoding the exponent and mantissa using the exponent threshold, this example uses the floating-point number to be encoded as FP8(E4M3). The format requirements for FP8(E4M3) floating-point numbers are shown in Table 1.

[0099] Table 1

[0100] In Table 1, NaN represents infinity, including positive infinity and negative infinity. The maximum normalized number (MNU) is the largest finite positive number that can be represented in the floating-point system, used to define the upper limit of the valid numerical range of floating-point numbers. The minimum normalized number (MNU) is the smallest finite positive number that can be represented in floating-point representations, used to define the lower limit of the legal range of normalized floating-point representations. The maximum denormalized number (MDO) is a special value in the floating-point system used to represent the smallest positive number close to zero, used to fill the numerical gap between the normalized number and zero, preventing direct underflow to zero during calculations due to excessively small values, thus maintaining numerical continuity. The minimum denormalized number (MON) is the non-zero positive number closest to zero in the floating-point system, used to fill the numerical gap between the normalized number and zero, preventing extremely small numbers from being completely lost in precision due to direct zeroing during calculations, thus maintaining numerical continuity.

[0101] For floating-point numbers corresponding to the format requirements shown in Table 1, assuming the exponent threshold is +3, n=1, k=1, and the zero threshold = max exponent – ​​(standard mantissa length + 1) = -1. When the original exponent of the floating-point number is greater than the zero threshold, the new exponent is equal to the original exponent - zero threshold = original exponent + 1. For example, if the original exponent is 0 (0111), the new exponent is +1 (1000). The mantissa length remains unchanged for an original exponent ≥ 3, decreases by 1 for an original exponent = 2, and becomes 0 for an original exponent = 0. Figure 5 shows a schematic diagram of the encoding principle for floating-point numbers, and Figure 6 shows a comparison diagram of floating-point numbers before and after encoding. In Figure 6, This indicates that all mantissa bits are removed, S represents the sign bit, M2, M1, and M0 are the mantissa bits from the most significant bit to the least significant bit, and E3, E2, E1, and E0 are the exponent bits from the most significant bit to the least significant bit. In Figure 6, when the exponent is +8, the new exponent exceeds the range of the original data format exponent, so there is no floating-point number encoded with an exponent of +8. In another example, after encoding, for floating-point numbers whose new exponent exceeds the range of the original data format exponent, the exponent of the encoded floating-point number is set to the maximum exponent of the original data format exponent range, and all mantissa bits are retained.

[0102] It should be noted that in the original exponent's four bits, the highest bit indicates the sign of the exponent; binary 0111 is designated as +0. In Figure 6, E3 represents the sign of the exponent. In Figure 6, the sign bit of the encoded floating-point number is located between the exponent and the mantissa bits. In another implementation, the mantissa bits of the encoded floating-point number are located between the exponent and the sign bit.

[0103] In another alternative approach, in step S102, the importance of an index can be measured by an index range. Different index ranges correspond to different levels of importance. Within the same index range, all indices are encoded in the same way. The processing method for step S102 is as follows:

[0104] The exponent range and its encoding method can be set based on empirical values ​​or simulation. For example, the number of exponent ranges can be set, and then the endpoint values ​​of the divided exponent ranges can be calculated using the desired compression ratio. The encoding method for each exponent range can then be determined, including exponent encoding and mantissa encoding. For each floating-point number to be encoded, the exponent range to which the floating-point number belongs is determined. The exponent of the floating-point number is encoded using the exponent range encoding method, and the mantissa of the floating-point number is also encoded using the same exponent range encoding method.

[0105] Alternatively, the exponent and mantissa can be encoded as follows:

[0106] Suppose we obtain two exponent ranges: a first exponent range and a second exponent range. The exponent in the first exponent range is more important than the exponent in the second exponent range. The highest bit of the exponent in the first exponent range is the first value, and its encoding method is to keep both the exponent and mantissa unchanged. The encoding method for the second exponent range is to retain part of the mantissa and the sign bit, and map the exponent according to rules so that its highest bit is mapped to the second value. Alternatively, the encoding method for the second exponent range is to map the exponent of the floating-point number to which the included exponent belongs to to the second value, while completely removing the mantissa and sign bits.

[0107] Assume there are three index ranges: a first index range, a second index range, and a third index range. The indexes in the first index range are more important than those in the second index range, and the indexes in the second index range are more important than those in the third index range. In the first index range, the highest bit of the index is the first value, and the encoding method for the first index range is to keep both the exponent and the mantissa unchanged. In the second index range, the encoding method is to retain a portion of the mantissa starting from the highest bit, and the exponent is mapped according to a rule so that the highest bit of the exponent is mapped to the first value. In the third index range, the encoding method is to map the floating-point number to which the included exponent belongs to the second value. For example, Figure 7 provides a comparison diagram of floating-point numbers before and after encoding. Referring to Figure 7, when the type of the floating-point number to be encoded is FP8 (E4M3), assuming the first exponent range is +8 to +5, the exponents included in +8 to +5 are the most important, and the corresponding floating-point numbers are also the most important. During encoding, the floating-point number will be completely preserved. The second exponent range is -3 to -6, the exponents included in -3 to -6 are the second most important, and the corresponding floating-point numbers are also the second most important. During encoding, one mantissa bit is retained, and when the highest bit of the exponent is not the first value, the exponent is mapped so that the highest bit of the exponent is the first value. The third exponent range is +4 to -2, the exponents included in +4 to -2 are the least important, and the corresponding floating-point numbers are also the least important. During encoding, the exponent is encoded as the second value, and the mantissa and sign bits are completely deleted. In this case, the complete code table shown in Figure 7 needs to be retained for use during decoding. In Figure 7, This indicates that all mantissa bits have been removed, S represents the sign bit, and X represents that the exponent bits have been removed.

[0108] Alternatively, the encoding method for the first exponent range is to keep the exponent unchanged and retain a mantissa of the first length starting from the most significant bit. The encoding method for the second exponent range is to map the exponent according to a rule so that the most significant bit of the exponent maps to the first value, and retain a mantissa of the second length starting from the most significant bit. The encoding method for the third exponent range is to map the exponent of the floating-point number to which the included exponent belongs to the second value, and to remove all mantissa bits and sign bits. In this case, the first length is greater than the second length.

[0109] It should be noted that when the first value is 1 and the second value is 0, the above exponents must be mapped according to the rules to ensure that the encoded non-zero floating-point numbers are prefixed with 1, the encoded zero floating-point numbers are prefixed with 0, the length of the mantissa of the encoded non-zero floating-point numbers can be arbitrarily specified, and the length of the mantissa of the encoded zero floating-point numbers is 0.

[0110] It should also be noted that the above explanation is based on dividing the index into two or three index ranges. In another implementation, M index ranges can be divided, where M is greater than or equal to 4. The value of M is determined based on empirical values ​​or neural network models, etc.

[0111] This application also provides a method for decoding floating-point numbers. Floating-point decoding is the reverse process of floating-point encoding. During decoding, the first bit is read, which is the prefix of the exponent of the encoded floating-point number. If the value of the first bit is a first value, the exponent corresponding to the length of the first value is read. This exponent is used to determine the length of the mantissa bits of the encoded floating-point number and the exponent of the encoded floating-point number before encoding. The sign bit is then read using the first value. If the exponent and sign bits are adjacent, and the sign and mantissa bits are adjacent, the sign bit can be read after reading the exponent bit. Then, the mantissa bits are read according to the determined length. If the value of the first bit is a second value, the length of the second value is read, which is the floating-point number before encoding. This original value cannot be recovered during decoding. For example, if the second value indicates that the value of the encoded floating-point number is 0, 0 can be read directly; 0 is the value of the floating-point number. Here, the exponent is encoded with the first value as a prefix, the exponent of the floating-point number can be recovered, and the read mantissa is the mantissa of the encoded floating-point number.

[0112] Optionally, for schemes using exponent threshold encoding, the exponent before encoding is recovered using the read exponent and exponent threshold, according to the formula mentioned above. Then, the sum of the length of the mantissa bits and the length of the sign bit is determined using the exponent of the encoded floating-point number, with the sign bit length set to 1. The length of the mantissa bits is then calculated. If the sign bit is located between the exponent and the mantissa bits, 1 bit of the sign bit is read first, followed by bits of the same mantissa length to obtain the mantissa. If the mantissa bits are located between the exponent and the sign bit, bits of the same mantissa length are read first to obtain the mantissa, followed by 1 bit of the sign bit. In this way, the floating-point number can be read.

[0113] Optionally, for schemes using exponent range encoding, the exponent, exponent range, and code table (which mainly records the mapping rules of the exponent) are used to recover the exponent and determine the length of the mantissa bits to be read, and the mantissa of the corresponding mantissa bit length is read.

[0114] In this embodiment of the application, a packaging method for encoded floating-point numbers is also provided. Referring to Figure 8, the micro scaling (MX) FP8 of the open compute project (OCP) is used as an example for illustration. The packaging format requirements are shown in Table 2. Each floating-point number is 8 bits, including 1 bit sign (s), 4 bits exponent (E), and 3 bits mantissa (M). Each block includes 32 floating-point numbers, which is the scaling block size. The packaging method provided in this embodiment of the application can use any number of floating-point numbers and any number of blocks (called scaling blocks). The encapsulation format of the encoded floating-point numbers in this embodiment is shown in Figure 9. Figure 9 provides an example of eight floating-point numbers (floating-point numbers 1 to 8), with an exponent threshold of 3. Before encoding, each floating-point number is 8 bits, and each block also has an 8-bit shared scale, which is a coefficient used to compress and process the various floating-point numbers in the entire block, totaling 72 bits. After encoding, an additional 8-bit exponent threshold is added, zero-value floating-point numbers are 1 bit, and the remaining floating-point numbers are compressed to 5 to 8 bits, totaling 46 bits. Here, the 8-bit exponent threshold is optional; in other implementations, the exponent threshold can occupy fewer or more bits.

[0115] Table 2

[0116] In Table 2, the scaling data type refers to the type of the scaled floating-point number, and the scaling bits refer to the number of binary bits of the exponent after scaling the floating-point number.

[0117] It should be noted that the above explanation uses the example of each block including the exponential threshold when using exponential threshold encoding. In another implementation, multiple blocks can correspond to one exponential threshold. This eliminates the need to encode the exponential threshold in each block, reducing storage space usage. The number of blocks can be set based on empirical values.

[0118] In addition, when encoding floating-point numbers using an exponent range, each block can correspond to an endpoint value of the exponent range, or multiple blocks can correspond to endpoint values ​​of the exponent range.

[0119] In this embodiment, because the amount of floating-point data is reduced after encoding, the throughput of floating-point reading and storage can be improved under the same bandwidth, generally by several to tens of times. Moreover, in AI computing, within the tolerance range of precision error, the end-to-end computing performance can be improved by several to tens of times. In AI computing, end-to-end refers to the process from input to output.

[0120] The above encoding process can also be understood as quantization.

[0121] All of the above-mentioned optional technical solutions can be combined in any way to form the optional embodiments of this application, and will not be described in detail here.

[0122] Figure 10 is a structural diagram of an apparatus for encoding floating-point numbers provided in an embodiment of this application. The apparatus shown in Figure 10 can be implemented as part or all of the apparatus by software, hardware, or a combination of both. This apparatus is used to implement the method flow executed by the computing device in the embodiment of this application.

[0123] As shown in Figure 10, the device includes:

[0124] The encoding module 1010 is used to encode each floating-point number in the floating-point numbers to be encoded according to the exponential importance of the floating-point numbers to be encoded, wherein the floating-point numbers to be encoded include a first part of floating-point numbers and a second part of floating-point numbers, and the first part of floating-point numbers contributes more to the accuracy of the calculation result than the second part of floating-point numbers contributes more to the accuracy of the calculation result.

[0125] The prefix of the exponent of the first part of the encoded floating-point number is a first value, the prefix of the exponent of the second part of the encoded floating-point number is a second value, the mantissa of each encoded floating-point number is related to the exponent of each floating-point number, and the prefix is ​​used to indicate the length of the exponent of the encoded floating-point number.

[0126] In an alternative embodiment, the encoding module 1010 is used for:

[0127] Obtain the exponent threshold of the floating-point number to be encoded, wherein the exponent threshold is used to distinguish the importance of the floating-point number;

[0128] Based on the exponent threshold, each floating-point number in the floating-point numbers to be encoded is encoded, wherein the exponent of the first part of the floating-point numbers is greater than the exponent of the second part of the floating-point numbers, and the compression degree of the first part of the floating-point numbers is lower than the compression degree of the second part of the floating-point numbers.

[0129] In one alternative approach, the encoding module 1010 is used to: determine the exponent threshold value of the floating-point number that retains 1 bit after encoding, based on the exponent threshold and the standard mantissa length of the floating-point number to be encoded;

[0130] Based on the exponent threshold, the exponent of each floating-point number in the floating-point numbers to be encoded is encoded.

[0131] In an alternative embodiment, the encoding module 1010 is used for:

[0132] The exponential threshold value is determined to be equal to the exponential threshold minus a first product and a third value, wherein the first product is equal to the product of the standard mantissa length and n, where n is an integer greater than or equal to 1, and the third value is an integer greater than or equal to 0.

[0133] In an alternative embodiment, the encoding module 1010 is used for:

[0134] For each floating-point number in the floating-point numbers to be encoded, if the exponent of the floating-point number is greater than the exponent threshold, the exponent of the encoded floating-point number is determined based on the value of the exponent minus the exponent threshold. If the exponent of the floating-point number is less than or equal to the exponent threshold, the exponent of the floating-point number is encoded as the second value, which is 1 bit. The first part of the floating-point numbers includes the floating-point numbers in the floating-point numbers to be encoded whose exponents are greater than the exponent threshold, and the second part of the floating-point numbers includes the floating-point numbers in the floating-point numbers to be encoded whose exponents are less than or equal to the exponent threshold.

[0135] In one alternative approach, the encoding module 1010 is configured to: for each of the floating-point numbers to be encoded, encode the exponent of the floating-point number based on the encoding method of the exponent range to which the exponent of the floating-point number belongs, wherein the importance of the exponents in different exponent ranges is different.

[0136] In one optional embodiment, the encoding module 1010 is configured to: for each of the floating-point numbers to be encoded, if the exponent of the floating-point number is greater than or equal to the exponent threshold, retain all mantissa bits of the floating-point number; if the exponent of the floating-point number is less than the exponent threshold, encode the mantissa bits of the floating-point number based on the exponent threshold, the exponent of the floating-point number, and the length of the mantissa bits, wherein after the encoding process, the length of the mantissa bits of the floating-point number is greater than or equal to 0 and less than the length of the mantissa bits before the encoding process.

[0137] In one alternative approach, the encoding module 1010 is configured to: for each of the floating-point numbers to be encoded, retain a fourth number of mantissa bits starting from the most significant mantissa bit of the floating-point number, such that the larger the exponent, the more mantissa bits are retained, wherein the fourth number is the difference between the length of the mantissa bits of the floating-point number and a fifth number, and the fifth number is determined based on the difference between the exponent threshold and the exponent of the floating-point number.

[0138] In one alternative approach, the encoding module 1010 is configured to: for each of the floating-point numbers to be encoded, encode the mantissa of the floating-point number based on the encoding method of the exponent range to which the exponent of the floating-point number belongs, wherein the importance of the exponent is different in different exponent ranges.

[0139] In one alternative approach, the encoding module 1010 is configured to: determine the exponent threshold of the floating-point number to be encoded based on the exponent distribution of the floating-point number to be encoded.

[0140] In one optional manner, the encoding module 1010 is configured to: perform calculations on the floating-point number to be encoded and its related data to obtain result data, wherein the related data includes at least one of gradient data and activation data;

[0141] Based on the result data, the exponent threshold of the floating-point number to be encoded is determined.

[0142] In one alternative approach, the encoding module 1010 is configured to: multiply the floating-point number to be encoded with its related data to obtain the result data.

[0143] In one alternative approach, the first value is 1 and the second value is 0.

[0144] Figure 11 is a structural diagram of an apparatus for encoding floating-point numbers provided in an embodiment of this application. The apparatus shown in Figure 11 can be implemented as part or all of the apparatus through software, hardware, or a combination of both. This apparatus is used to implement the method flow executed by the computing device in the embodiments of this application. As shown in Figure 11, the apparatus includes:

[0145] The reading module 1110 is used to read the exponent of the first value in response to the first value being a prefix of the exponent of the encoded floating-point number;

[0146] The determining module 1120 is used to determine the mantissa of the encoded floating-point number and the exponent of the encoded floating-point number before encoding based on the exponent;

[0147] The reading module 1110 is further configured to, in response to the prefix of the encoded floating-point exponent being a second value, read a value of length corresponding to the second value and determine it as the encoded floating-point number.

[0148] In one alternative approach, the determining module 1120 is configured to obtain an exponent threshold and, based on the exponent threshold, determine the exponent of the encoded floating-point number before encoding;

[0149] Based on the exponent of the encoded floating-point number, the length of the mantissa of the encoded floating-point number is determined, and the mantissa of the encoded floating-point number is read based on the length of the mantissa.

[0150] For a detailed explanation of the encoding process performed by the device shown in Figure 10, please refer to the descriptions in the preceding embodiments; they will not be repeated here. The device shown in Figure 10 can be a computing device or processor chip, as described above.

[0151] For a detailed description of the decoding process performed by the device shown in Figure 11, please refer to the descriptions in the preceding embodiments; they will not be repeated here. The device shown in Figure 11 can be a computing device or processor chip, as described above.

[0152] This application also provides a device 100. As shown in FIG12, device 100 includes: a bus 102, a processor 104, a memory 106, and a communication interface 108. The processor 104, the memory 106, and the communication interface 108 communicate with each other via the bus 102. Device 100 is the computing device mentioned above. It should be understood that this application does not limit the number of processors and memories in device 100.

[0153] Bus 102 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, only one line is used in Figure 12, but this does not imply that there is only one bus or one type of bus. Bus 102 can include pathways for transmitting information between various components of device 100 (e.g., memory 106, processor 104, communication interface 108).

[0154] Processor 104 may include any one or more processors such as CPU, GPU, microprocessor (MP), or digital signal processor (DSP).

[0155] The memory 106 may include volatile memory, such as random access memory (RAM). The memory 106 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).

[0156] The memory 106 stores executable program code, and the processor 104 executes the executable program code to perform the methods for encoding or decoding floating-point numbers. That is, the memory 106 stores program instructions for performing the methods for encoding or decoding floating-point numbers.

[0157] The communication interface 108 is used to enable communication between the device 100 and other devices or communication networks.

[0158] This application also provides a computing device, which includes a memory and the processor chip mentioned above. The memory may be the memory 106 mentioned above.

[0159] This application also provides a computer program product, which includes program instructions stored in a computer-readable storage medium. A processor of a computing device reads the program instructions from the computer-readable storage medium and executes the program instructions, causing the computing device to perform the method flow for encoding or decoding floating-point numbers described above.

[0160] This application provides a processor chip that includes logic circuitry for executing the methods of encoding and decoding floating-point numbers described above. In one possible implementation, the processor chip further includes a power supply circuit coupled to the logic circuitry, which supplies power to the logic circuitry to enable it to execute the methods of encoding and decoding floating-point numbers. Exemplarily, the logic circuitry may be a digital signal processor (DSP), a field-programmable gate array (FPGA), a programmable logic array (PLA), an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0161] Those skilled in the art will recognize that the method steps and units described in the embodiments disclosed in this application can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the steps and components of each embodiment have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0162] In the embodiments provided in this application, it should be understood that the disclosed system architecture, apparatus, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, or may be electrical, mechanical, or other forms of connection.

[0163] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of the embodiments of this application, depending on actual needs.

[0164] Furthermore, the modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or in software.

[0165] If the integrated module is implemented as a software functional module 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 this application, in essence, 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, ROM, RAM, magnetic disks, or optical disks.

[0166] In this application, the terms "first" and "second," etc., are used to distinguish identical or similar items that have substantially the same function and purpose. It should be understood that there is no logical or temporal dependency between "first" and "second," nor does it limit the quantity or order of execution. It should also be understood that although the following description uses the terms "first" and "second," etc., to describe various elements, these elements should not be limited by the terms. These terms are merely used to distinguish one element from another. For example, without departing from the scope of various examples, a first value can be referred to as a second value, and similarly, a second value can be referred to as a first value. Both the first and second values ​​can be numerical values, and in some cases, they can be separate and distinct values.

[0167] The phrase "at least one" in the preceding text can be understood as one or more.

[0168] The phrase "A and / or B" in the preceding text can be understood to include three cases: A, B, and A and B.

[0169] The above description is merely an exemplary embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and such modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A method for encoding floating-point numbers, characterized in that, The method includes: According to the exponential importance of the floating-point numbers to be encoded, each floating-point number to be encoded is encoded. The floating-point numbers to be encoded include a first part of floating-point numbers and a second part of floating-point numbers. The first part of floating-point numbers contributes more to the accuracy of the calculation result than the second part of floating-point numbers. The prefix of the exponent of the first part of the encoded floating-point number is a first value, the prefix of the exponent of the second part of the encoded floating-point number is a second value, the mantissa of each encoded floating-point number is related to the exponent of each floating-point number, and the prefix is ​​used to indicate the length of the exponent of the encoded floating-point number.

2. The method according to claim 1, characterized in that, The process of encoding each floating-point number in the floating-point numbers to be encoded according to its exponential importance includes: Obtain the exponent threshold of the floating-point number to be encoded, wherein the exponent threshold is used to distinguish the importance of the floating-point number; Based on the exponent threshold, each floating-point number in the floating-point numbers to be encoded is encoded, wherein the exponent of the first part of the floating-point numbers is greater than the exponent of the second part of the floating-point numbers, and the compression degree of the first part of the floating-point numbers is lower than the compression degree of the second part of the floating-point numbers.

3. The method according to claim 2, characterized in that, The encoding process for each floating-point number in the floating-point numbers to be encoded based on the exponential threshold includes: Based on the exponent threshold and the standard mantissa length of the floating-point number to be encoded, determine the exponent threshold value of the floating-point number that retains 1 bit after encoding; Based on the exponent threshold, the exponent of each floating-point number in the floating-point numbers to be encoded is encoded.

4. The method according to claim 3, characterized in that, The process of determining the exponent threshold value for retaining 1 bit in the encoded floating-point number based on the exponent threshold and the standard mantissa length of the floating-point number to be encoded includes: The exponential threshold value is determined to be equal to the exponential threshold minus a first product and a third value, wherein the first product is equal to the product of the standard mantissa length and n, where n is an integer greater than or equal to 1, and the third value is an integer greater than or equal to 0.

5. The method according to claim 3 or 4, characterized in that, The process of encoding the exponent of each floating-point number in the floating-point numbers to be encoded based on the exponent threshold value includes: For each floating-point number in the floating-point numbers to be encoded, if the exponent of the floating-point number is greater than the exponent threshold, the exponent of the encoded floating-point number is determined based on the value of the exponent minus the exponent threshold. If the exponent of the floating-point number is less than or equal to the exponent threshold, the exponent of the floating-point number is encoded as the second value, which is 1 bit. The first part of the floating-point numbers includes the floating-point numbers in the floating-point numbers to be encoded whose exponents are greater than the exponent threshold, and the second part of the floating-point numbers includes the floating-point numbers in the floating-point numbers to be encoded whose exponents are less than or equal to the exponent threshold.

6. The method according to any one of claims 1 to 5, characterized in that, The process of encoding each floating-point number in the floating-point numbers to be encoded according to its exponential importance includes: For each floating-point number to be encoded, the exponent of the floating-point number is encoded based on the encoding method of the exponent range to which the exponent belongs, wherein the importance of the exponent in different exponent ranges is different.

7. The method according to any one of claims 2 to 5, characterized in that, The encoding process for each floating-point number in the floating-point numbers to be encoded based on the exponential threshold includes: For each floating-point number to be encoded, if the exponent of the floating-point number is greater than or equal to the exponent threshold, then all mantissa bits of the floating-point number are retained. If the exponent of the floating-point number is less than the exponent threshold, then the mantissa bits of the floating-point number are encoded based on the exponent threshold, the exponent of the floating-point number, and the length of the mantissa bits. After encoding, the length of the mantissa bits is greater than or equal to 0 and less than the length of the mantissa bits before encoding.

8. The method according to claim 7, characterized in that, The encoding process for the mantissa of the floating-point number based on the exponent threshold and the exponent and mantissa length of the floating-point number includes: For each floating-point number to be encoded, a fourth number of mantissa bits are retained starting from the most significant mantissa bit of the floating-point number, so that the larger the exponent, the more mantissa bits are retained. The fourth number is the difference between the length of the mantissa bits of the floating-point number and a fifth number, which is determined based on the difference between the exponent threshold and the exponent of the floating-point number.

9. The method according to claim 1, characterized in that, The process of encoding each floating-point number in the floating-point numbers to be encoded according to its exponential importance includes: For each floating-point number to be encoded, the mantissa of the floating-point number is encoded based on the encoding method of the exponent range to which the exponent belongs, wherein the importance of the exponent is different in different exponent ranges.

10. The method according to any one of claims 2 to 5 and 7 to 8, characterized in that, The step of obtaining the exponent threshold of the floating-point number to be encoded includes: Based on the exponential distribution of the floating-point number to be encoded, the exponential threshold of the floating-point number to be encoded is determined.

11. The method according to any one of claims 2 to 5 and 7 to 8, characterized in that, The floating-point number to be encoded is weighted data; obtaining the exponent threshold of the floating-point number to be encoded includes: The floating-point number to be encoded and its related data are processed to obtain result data, wherein the related data includes at least one of gradient data and activation data; Based on the result data, the exponent threshold of the floating-point number to be encoded is determined.

12. The method according to claim 11, characterized in that, The step of performing calculations on the floating-point number to be encoded and its related data to obtain the result data includes: The floating-point number to be encoded is multiplied by its related data to obtain the result data.

13. The method according to any one of claims 1 to 12, characterized in that, The first value is 1, and the second value is 0.

14. A method for decoding floating-point numbers, characterized in that, The method includes: In response to the first value being the prefix of the exponent of the encoded floating-point number, the exponent of the length corresponding to the first value is read, and the mantissa of the encoded floating-point number and the exponent of the encoded floating-point number before encoding are determined based on the exponent. In response to the fact that the prefix of the encoded floating-point exponent is a second value, the value of the length corresponding to the second value is read and determined to be the encoded floating-point number.

15. The method according to claim 14, characterized in that, The step of determining the mantissa of the encoded floating-point number and the exponent of the encoded floating-point number before encoding based on the exponent includes: Obtain the exponent threshold, and based on the exponent threshold, determine the exponent of the encoded floating-point number before encoding; Based on the exponent of the encoded floating-point number, the length of the mantissa of the encoded floating-point number is determined, and the mantissa of the encoded floating-point number is read based on the length of the mantissa.

16. A device for encoding floating-point numbers, characterized in that, The device includes: The encoding module is used to encode each floating-point number in the floating-point numbers to be encoded according to the exponential importance of the floating-point numbers to be encoded, wherein the floating-point numbers to be encoded include a first part of floating-point numbers and a second part of floating-point numbers, and the first part of floating-point numbers contributes more to the accuracy of the calculation result than the second part of floating-point numbers contributes more to the accuracy of the calculation result. The exponent of the first part of the encoded floating-point number is prefixed with a first value, the exponent of the second part of the encoded floating-point number is prefixed with a second value, the mantissa of each encoded floating-point number is related to the exponent of each floating-point number, and the prefix is ​​used to indicate the length of the exponent of the encoded floating-point number.

17. The apparatus according to claim 16, characterized in that, The encoding module is used for: Obtain the exponent threshold of the floating-point number to be encoded, wherein the exponent threshold is used to distinguish the importance of the floating-point number; Based on the exponent threshold, each floating-point number in the floating-point numbers to be encoded is encoded, wherein the exponent of the first part of the floating-point numbers is greater than the exponent of the second part of the floating-point numbers, and the compression degree of the first part of the floating-point numbers is lower than the compression degree of the second part of the floating-point numbers.

18. The apparatus according to claim 17, characterized in that, The encoding module is used for: Based on the exponent threshold and the standard mantissa length of the floating-point number to be encoded, determine the exponent threshold value of the floating-point number that retains 1 bit after encoding; Based on the exponent threshold, the exponent of each floating-point number in the floating-point numbers to be encoded is encoded.

19. The apparatus according to claim 18, characterized in that, The encoding module is used for: The exponential threshold value is determined to be equal to the exponential threshold minus a first product and a third value, wherein the first product is equal to the product of the standard mantissa length and n, where n is an integer greater than or equal to 1, and the third value is an integer greater than or equal to 0.

20. The apparatus according to claim 18 or 19, characterized in that, The encoding module is used for: For each floating-point number in the floating-point numbers to be encoded, if the exponent of the floating-point number is greater than the exponent threshold, the exponent of the encoded floating-point number is determined based on the value of the exponent minus the exponent threshold. If the exponent of the floating-point number is less than or equal to the exponent threshold, the exponent of the floating-point number is encoded as the second value, which is 1 bit. The first part of the floating-point numbers includes the floating-point numbers in the floating-point numbers to be encoded whose exponents are greater than the exponent threshold, and the second part of the floating-point numbers includes the floating-point numbers in the floating-point numbers to be encoded whose exponents are less than or equal to the exponent threshold.

21. The apparatus according to any one of claims 17 to 20, characterized in that, The encoding module is used for: For each floating-point number to be encoded, if the exponent of the floating-point number is greater than or equal to the exponent threshold, then all mantissa bits of the floating-point number are retained. If the exponent of the floating-point number is less than the exponent threshold, then the mantissa bits of the floating-point number are encoded based on the exponent threshold, the exponent of the floating-point number, and the length of the mantissa bits. After encoding, the length of the mantissa bits is greater than or equal to 0 and less than the length of the mantissa bits before encoding.

22. The apparatus according to claim 21, characterized in that, The encoding module is used for: For each floating-point number to be encoded, a fourth number of mantissa bits are retained starting from the most significant mantissa bit of the floating-point number, so that the larger the exponent, the more mantissa bits are retained. The fourth number is the difference between the length of the mantissa bits of the floating-point number and a fifth number, which is determined based on the difference between the exponent threshold and the exponent of the floating-point number.

23. An apparatus for decoding floating-point numbers, characterized in that, The device includes: The reading module is used to read the exponent of the encoded floating-point number with a prefix of a first value, and read the exponent of the length corresponding to the first value. The determining module is used to determine the mantissa of the encoded floating-point number and the exponent of the encoded floating-point number before encoding based on the exponent; The reading module is further configured to, in response to the prefix of the encoded floating-point exponent being a second value, read a value of length corresponding to the second value and determine it as the encoded floating-point number.

24. A processor chip, characterized in that, The processor chip is used to perform the method as described in any one of claims 1 to 15.

25. A computing device, characterized in that, The computing device includes the processor chip as described in claim 24.