Tensor precision processing method, device, electronic device, medium, and program product

By packaging and dequantizing high-precision tensor data on the artificial intelligence chip, the problem of hardware not supporting low-bit precision storage and calculation is solved, and the performance optimization and precision control of large language models are achieved.

CN118409866BActive Publication Date: 2024-09-27北京壁仞科技开发有限公司 +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410806736.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-09-27
Estimated Expiration
2044-06-21

AI Technical Summary

Technical Problem

The existing artificial intelligence chip hardware architecture does not support low-bit precision data storage and calculation, resulting in insufficient optimization of intelligent human-machine dialogue performance of large language models and the lack of efficient quantification solutions.

Method used

By packaging high-precision tensor data into high-precision second elements for storage, and after adapting to the high-precision operations supported by artificial intelligence chips, inverse quantization into high-precision elements supports the storage of low-bit data precision such as INT 4 and calculation, using the loading component and the inverse quantization component to process first-precision and second-precision tensor data respectively.

Benefits of technology

It achieves efficient calculation and storage of low-bit-width data, optimizes the intelligent human-machine dialogue performance of large language models, and ensures controllability of accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409866B
    Figure CN118409866B
Patent Text Reader

Abstract

A tensor precision processing method, a tensor precision processing device, an electronic device, a non-temporary computer-readable storage medium, and a computer program product are provided. The method comprises: loading a plurality of first elements of a first precision in a first tensor into a memory to obtain a second element of a second precision to form a second tensor including a plurality of second elements, wherein the number of bits of the first precision is lower than the number of bits of the second precision; and dequantizing the second tensor in the memory to obtain a third tensor of a third precision, wherein the number of bits of the third precision is higher than the number of bits of the first precision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] Embodiments of the present application relate to the field of artificial intelligence technology, and more specifically to a tensor precision processing method, a tensor precision processing device, a non-temporary computer-readable storage medium, an electronic device, and a computer program product. Background Art

[0002] As the scale of machine learning models increases rapidly, the demand for memory and computing power of artificial intelligence chips on devices is increasing. Model quantization is a model compression technology that can reduce the storage size of the model and improve computing efficiency. Model quantization mainly quantizes the elements of weight tensors or activation tensors in high-precision formats (such as floating point (FP) 32, FP16, or brain floating point (BF) 16) into low-precision integer (INTeger, INT) 8, FP8, FP4 and other formats, while model dequantization converts low-precision formats into high-precision formats. Summary of the invention

[0003] According to one aspect of the present application, at least one embodiment provides a tensor precision processing method, comprising: obtaining a second element of second precision by respectively loading multiple first elements of first precision in a first tensor into a memory to form a second tensor including multiple second elements, wherein the number of bits of the first precision is lower than the number of bits of the second precision; dequantizing the second tensor in the memory to obtain a third tensor of third precision, wherein the number of bits of the third precision is higher than the number of bits of the first precision.

[0004] According to another aspect of the present application, at least one embodiment provides a tensor precision processing device, comprising: a loading component, configured to obtain a second element of second precision by respectively loading multiple first elements of first precision in a first tensor into a memory to form a second tensor including multiple second elements, wherein the number of bits of the first precision is lower than the number of bits of the second precision; and a dequantization component, configured to dequantize the second tensor in the memory to obtain a third tensor of third precision, wherein the number of bits of the third precision is higher than the number of bits of the first precision.

[0005] According to another aspect of the present application, at least one embodiment provides a tensor precision processing device, comprising: a storage unit for storing computer instructions; a processing unit for reading the computer instructions in the storage unit and executing a method according to at least one embodiment of the present application.

[0006] According to another aspect of the present application, at least one embodiment provides a non-transitory computer-readable storage medium on which computer instructions are stored, wherein when the computer instructions are executed by a processing unit, the processing unit performs a method according to at least one embodiment of the present application.

[0007] According to another aspect of the present application, at least one embodiment provides a computer program product, including computer instructions, wherein when the computer instructions are executed by a processing unit, the processing unit performs a method according to at least one embodiment of the present application.

[0008] According to another aspect of the present application, at least one embodiment provides an electronic device, including: a tensor precision processing device according to at least one embodiment of the present application and a memory. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present disclosure or related technologies, the drawings required for use in the embodiments or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0010] Figure 1 A block diagram of a computing system according to at least one embodiment of the present application is shown.

[0011] Figure 2 A flowchart of a tensor precision processing method according to at least one embodiment of the present application is shown.

[0012] Figure 3A and 3B A schematic diagram showing two different tensor operation schemes according to at least one embodiment of the present application.

[0013] Figure 4 A schematic diagram is shown of an example of obtaining a second element of second precision by loading multiple first elements of first precision in a first tensor into a memory respectively according to at least one embodiment of the present application.

[0014] Figure 5 A block diagram of a tensor precision processing device according to at least one embodiment of the present application is shown.

[0015] Figure 6 A block diagram of an exemplary tensor precision processing device suitable for implementing at least one embodiment of the present application is shown.

[0016] Figure 7 A schematic diagram of a non-transitory computer-readable storage medium according to at least one embodiment of the present application is shown.

[0017] Figure 8 A block diagram of an electronic device according to at least one embodiment of the present application is shown. DETAILED DESCRIPTION

[0018] The specific embodiments of the present application will now be described in detail, examples of which are illustrated in the accompanying drawings. Although the present application will be described in conjunction with the specific embodiments, it will be understood that it is not intended to limit the present application to the described embodiments. On the contrary, it is intended to cover the changes, modifications and equivalents included in the spirit and scope of the present application. It should be noted that the method steps described herein can be implemented by any functional block or functional arrangement, and any functional block or functional arrangement can be implemented as a physical entity or a logical entity, or a combination of the two.

[0019] The higher the precision, the larger the bit width of the data. A larger data bit width means more data to be moved. In the decoding stage such as large model inference, bandwidth and video memory are the biggest bottlenecks, so high-precision data is quantized to low-precision data as much as possible. However, since the native architecture of AI chip hardware does not support low-precision INT 4 and other data precisions, there is currently no efficient quantization system solution for computing and storing low-bitwidth data.

[0020] Multiple embodiments of the present application can achieve efficient calculation and storage of low-bit-width data, greatly optimize the performance of model reasoning, and ensure that the accuracy loss is controllable.

[0021] Figure 1 A block diagram of a computing system 100 is shown, in accordance with at least one embodiment of the present application.

[0022] The computing system 100 includes an artificial intelligence chip 110 and a central processing unit (CPU) 120. The central processing unit 120 is the computing core and control core of the computer, responsible for executing instructions, processing data and controlling multiple components of the computer. It has a wide range of general computing capabilities and is suitable for performing various types of general tasks; while the artificial intelligence chip 110 is dedicated to graphics processing and image rendering. It has large-scale parallel processing capabilities and dedicated computing cores, and can quickly process graphics computing tasks, especially for processing tensor operations and convolution tasks of machine learning. The artificial intelligence chip 110 may include a graphics processing unit (GPU), a general-purpose computing on graphics processing unit (GPGPU), a tensor processing unit (TPU), a data processing unit (DPU), an AI accelerator, etc., and the embodiments of the present disclosure are not limited to this.

[0023] The artificial intelligence chip 110 and the memory 1140 (also referred to as video memory) may be referred to as the device side, and the central processing unit 120 and the memory 1210 may be referred to as the host side. The memory 1140 may generally use a high bandwidth memory (HBM). The artificial intelligence chip 110 and the central processing unit 120 are connected to each other via a bus 130 to transfer code, data, address, control signal, etc.

[0024] The artificial intelligence chip 110 includes a command processor (CP) 1110 for receiving commands sent by the central processing unit 120. The artificial intelligence chip 110 also includes a plurality of computing units (CUs) 1120 for executing instructions sent by the central processing unit 120 to perform data calculations.

[0025] In the case of processing tensor operations and convolution tasks for machine learning, the computing unit 1120 pre-loads (referred to as loading) the data to be operated (e.g., matrices A and B to be matrix multiplied) into the HBM 1140, and reads the matrices A and B from the HBM 1140 to the register 1130 during the operation. The computing unit 1120 performs, for example, matrix multiplication operations on the matrices A and B in the register 1130, and stores the calculation results in the HBM 1140. The calculation results can be sent to the memory 1210 of the central processing unit 120 via the bus 130.

[0026] Artificial intelligence chips can work with the central processing unit to complete speech recognition, image recognition, text recognition, video recognition, intelligent human-computer dialogue with large language models, and so on.

[0027] The reasoning process of a large language model is divided into two stages: prefill and decode. In the decoding stage, the performance bottleneck of the reasoning of a large language model is the bandwidth bottleneck. The most effective way to speed up the reasoning speed of the decoding stage is to reduce the memory bandwidth usage by quantizing the low bits of tensor data, thereby accelerating model reasoning. However, the hardware architecture of current artificial intelligence chips does not natively support the storage and calculation of low-bit data precision tensors such as INT 4, and cannot enjoy the performance of efficient quantization. Therefore, the performance of intelligent human-computer dialogue of large language models is not optimized enough.

[0028] According to at least one embodiment of the present application, it is possible to utilize tensor precision processing methods, at least in the field of intelligent human-computer dialogue such as a large language model, to support the storage and calculation of low-bit data precision such as INT 4, enjoy efficient quantization performance, and optimize the performance of intelligent human-computer dialogue such as a large language model.

[0029] Figure 2 A flowchart of a tensor precision processing method according to at least one embodiment of the present application is shown.

[0030] like Figure 2 As shown, the tensor precision processing method includes step 110 and step 120.

[0031] In step 210, Figure 1 The execution unit CU 1120 shown obtains a second element of the second precision by loading a plurality of first elements of the first precision in the first tensor into the memory respectively, so as to form a second tensor including the plurality of second elements. The number of bits of the first precision is lower than the number of bits of the second precision. Here, the memory may be a high bandwidth memory (HBM).

[0032] In step 220, Figure 1 The execution unit CU 1120 shown dequantizes the second tensor in the memory to obtain a third tensor of third precision. The number of bits of the third precision is higher than the number of bits of the first precision.

[0033] In this way, multiple low-precision first elements that the artificial intelligence chip does not support storage are packaged into high-precision second elements that the artificial intelligence chip supports storage for storage, and then dequantized into high-precision elements in order to adapt to the high-precision operations supported by the artificial intelligence chip in intelligent human-computer dialogues such as large language models. This enables the artificial intelligence chip to support the storage and calculation of low-bit data precision such as INT 4, enjoy the performance of efficient quantization, and optimize the performance of intelligent human-computer dialogues such as large language models.

[0034] Figure 3A and 3B A schematic diagram showing two different tensor operation schemes according to at least one embodiment of the present application.

[0035] like Figure 3A As shown in the A16W8 scheme, the activation tensor A is BF 16 precision (assuming it is two-dimensional and of size H×K), while the weight tensor B in the usual AI chip is quantized to INT 8 precision (assuming it is two-dimensional and of size K×W). Figure 1 The execution unit CU 1120 shown reads the activation tensor A and the weight tensor B stored in the HBM 1140 into the register 1130 to perform a matrix multiplication operation (MMA) to obtain an output with an accuracy of FP 32 (size is H×W) and stores it in the register 1130. Then, the execution unit CU 1120 uses the scaling factor Scale (size is 1×W) to perform a dot multiplication with the FP32 output from the register 1130 (that is, by multiplying each number in the scaling factor with each number in the corresponding column of the FP32 output) to quantize the output to obtain a quantized output with an accuracy of BF 16 (size is H×W), which is then stored in the HBM 1140 or elsewhere.

[0036] Generally, the lowest quantization precision supported by artificial intelligence chips is the storage and calculation of data with INT 8 precision, while there is no better solution for storing and calculating data in the lower precision INT 4 format.

[0037] As follows, taking the first precision as INT 4 and the second precision as INT 32 as an example, the description Figure 2 The number of bits of INT 4 is 4, which can be regarded as a low-precision data format, while the number of bits of INT 32 is 32, which can be regarded as a high-precision data format.

[0038] like Figure 3BAs shown in the A16W4 scheme, tensor A (which can be an activation tensor) is of BF 16 precision, and to store a tensor of INT4 precision (which can be a weight tensor of size K×W), in order to load and store efficiently, it is hoped that the elements of the INT 4 precision tensor are directly loaded into a tensor B of INT 32 precision (size is K / 8×W).

[0039] Then, as before, multiple INT 4 elements in the tensor are loaded into the memory respectively to obtain multiple INT 32 elements to form a tensor B of INT 32.

[0040] In one embodiment, Figure 2 In the illustrated embodiment, the number of bits of the second precision is N times the number of bits of the first precision, where N is a positive integer. Taking the above example, since the number of bits of INT 32 precision is 32, the number of bits of INT 4 precision is 4, and the number of bits of INT 32 precision is 8 times the number of bits of INT 4 precision (i.e., N=8), it is necessary to load 8 first elements of INT 4 precision as a second element of INT 32 precision.

[0041] In this way, according to multiple embodiments of the present application, it is possible to obtain the lower number of bits and reduced model size brought about by the quantization of the first precision (lower precision) of the tensor, and to support the storage and calculation of lower precision tensors to improve the performance of the artificial intelligence chip.

[0042] In one embodiment, Figure 2 In the illustrated embodiment, the execution unit CU 1120 may load N first elements of the first precision in the first tensor into the memory in a predetermined order to form a second element of the second precision, wherein the N first elements of the first precision form a second element of the second precision.

[0043] In one embodiment, Figure 2 In the illustrated embodiment, the predetermined order may be based on the original order of the multiple first elements of the first precision in the first tensor, and every N consecutive first elements of the first precision are stored in the memory as a second element of the second precision. Alternatively, the predetermined order may include not based on the original order of the multiple first elements of the first precision in the first tensor, and every N incompletely consecutive first elements of the first precision are stored in the memory as a second element of the second precision.

[0044] Taking the above example, assuming that the first tensor has 1024 elements of the first precision (e.g., INT 4), the first elements of the consecutive first precision are element W4[0], element W4[1], element W4[2], element W4[3], and so on, element W4

[1023] . The elements of the second precision (e.g., INT 32) are element W32[0], element W32[1], element W32[2], element W32[3], and so on, element W32

[127] (because every 8 elements of INT 4 form an element of INT 32, 1024 elements of INT 4 get 128 elements of INT 32 (1024 / 8=128)).

[0045] If every 8 consecutive first elements of INT 4 are stored in the memory as the second element of an INT 32 in the original order of multiple first elements of INT 4 in the first tensor, the second element of the 1st INT 32 precision (W32[0]) includes the first element of the 1st INT 4 precision (W4[0]), the first element of the 2nd INT 4 precision (W4[1]), the first element of the 3rd INT 4 precision (W4[2]), the first element of the 4th INT 4 precision (W4[3]), the first element of the 5th INT 4 precision (W4[4]), the first element of the 6th INT 4 precision (W4[5]), the first element of the 7th INT 4 precision (W4[6]), and the first element of the 8th INT 4 precision (W4[7]) in the first tensor.

[0046] The second element of the 2nd INT 32 precision (W32[1]) includes the first element of the 9th INT 4 precision (W4[8]), the first element of the 10th INT 4 precision (W4[9]), the first element of the 11th INT 4 precision (W4

[10] ), the first element of the 12th INT 4 precision (W4

[11] ), the first element of the 13th INT 4 precision (W4

[12] ), the first element of the 14th INT 4 precision (W4

[13] ), the first element of the 15th INT 4 precision (W4

[14] ), and the first element of the 16th INT 4 precision (W4

[15] ) in the first tensor.

[0047] The second element of each subsequent INT 32 precision includes the first element of every 8 consecutive INT 4s in the original order of the first element of INT 4 precision. They are not listed here one by one.

[0048] Of course, in Figure 2In the illustrated embodiment, the predetermined order may also be other orders, for example, instead of following the original order of the multiple first elements of the first precision in the first tensor, every N incompletely consecutive first elements of the first precision are stored in the memory as a second element of the second precision. The purpose of doing so is to disperse the storage of the multiple first elements in the first tensor, thereby avoiding reading a large number of these elements in a continuous area somewhere in the memory when performing calculations, but dispersing them in multiple discontinuous locations in the memory, so as to reduce traffic accumulation, read conflicts and errors.

[0049] For example, in Figure 2 In the illustrated embodiment, the predetermined order is determined based on one or more of the following factors: the bit width of the register for storing the first element; the number of computing units for reading the first element in parallel. The computing unit reads data from the memory into the register to perform operations on the data, so the predetermined order is set in consideration of the bit width of the register and / or the number of computing units for reading the first element in parallel, so as to maximize the use of the register and the computing unit.

[0050] For example, in one embodiment, the bit width of the register is W, the number of computing units is U, where W and U are positive integers, and the predetermined sequence includes: loading consecutive W / U first precision first elements each time, with W first precision first elements spaced between two loadings, until the bit width W of the register is fully loaded to form the i-th second precision second element and the i+1-th second precision second element; loading consecutive W / U first precision first elements after the multiple first precision first elements loaded for the i+1-th second precision second element to form the i+2-th second precision second element and the i+3-th second precision second element, where i is a positive integer. The first precision first elements are taken in this way until all the first precision first elements are loaded and stored in the memory in the second precision format.

[0051] Thus, according to at least one embodiment of the present application, the execution unit CU can disperse and store the first elements of the first precision in the memory (at intervals of W), so that when the first elements are subsequently read by multiple computing units, they will not be read in large quantities in a certain area of ​​the memory, but will be dispersed in multiple locations in the memory, so as to reduce traffic accumulation, read conflicts and errors. At the same time, because in order to maximize the use of the bit width W of the register, it is most efficient for each of the U computing units to read W / U first elements of the first precision each time, so storing consecutive W / U first elements of the first precision in the memory continuously also helps each computing unit to read continuously faster.

[0052] Figure 4A schematic diagram is shown of an example of obtaining a second element of second precision by loading multiple first elements of first precision in a first tensor into a memory respectively according to at least one embodiment of the present application.

[0053] Taking the above example as an example, Figure 4 As shown, the first precision is INT 4 precision, the second precision is INT 32 precision, the bit width W of the register is 32 bits, the number of computing units U is 16, and the predetermined order includes the following order.

[0054] The second element of the 1st INT 32 precision (W32[0]) includes the first element of the 1st INT 4 precision (W4[0]), the first element of the 2nd INT 4 precision (W4[1]), the first element of the 33rd INT 4 precision (W4

[32] ), the first element of the 34th INT 4 precision (W4

[33] ), the first element of the 65th INT 4 precision (W4

[64] ), the first element of the 66th INT 4 precision (W4

[65] ), the first element of the 97th INT 4 precision (W4

[96] ), and the first element of the 98th INT 4 precision (W4

[97] ) in the first tensor.

[0055] The second element of the 2nd INT 32 precision (W32[1]) includes the 129th INT 4 precision first element (W4

[128] ), the 130th INT 4 precision first element (W4

[129] ), the 161st INT 4 precision first element (W4

[160] ), the 162nd INT 4 precision first element (W4

[161] ), the 193rd INT 4 precision first element (W4

[192] ), the 194th INT 4 precision first element (W4

[193] ), the 225th INT 4 precision first element (W4

[224] ), and the 226th INT 4 precision first element (W4

[225] ) in the first tensor.

[0056] The second element of the first INT 32 precision (composed of the first elements of the 8 INT 4 precision) and the second element of the second INT32 precision (composed of the first elements of the 8 INT 4 precision) are combined (i.e. Figure 4 The w0 shown in FIG. 1 is obtained by loading consecutive W / U=2 first precision first elements each time, with an interval of W=32 first precision first elements between two loaded elements (a total of 16 INT 4 precision first elements constitute w0).

[0057] The second element of the subsequent INT 32 precision includes the first elements of the consecutive 2 INT 4 precision that have not been loaded starting from the first element of the INT 4 precision that has been loaded (see w1, w2, w3, ...).

[0058] For example, the second element of the 3rd INT 32 precision (W32[2]) includes the first element of the 3rd INT 4 precision (W4[2]) in the first tensor, the first element of the 4th INT 4 precision (W4[3]) (i.e., the first elements of the 2 consecutive INT 4 precision that are not loaded starting with the first element of the 2nd INT 4 precision (W4[1])), the first element of the 35th INT 4 precision (W4

[34] ), the first element of the 36th INT 4 precision (W4

[35] ) (i.e., the first elements of the 2 consecutive INT 4 precision that are not loaded starting with the first element of the 34th INT 4 precision (W4[1])), the first element of the 67th INT 4 precision (W4

[66] ), the first element of the 68th INT 4 precision (W4

[67] ) (i.e., the first elements of the 2 consecutive INT 4 precision that are not loaded starting with the first element of the 66th INT 4 precision (W4

[65] )), the first element of the 99th INT 4 precision (W4

[69] ), The first element of 4 precision (W4

[98] ), the first element of the 100th INT4 precision (W4

[99] ) (that is, the first elements of the two consecutive INT4 precision that are not loaded starting with the first element of the 98th INT4 precision (W4

[97] )).

[0059] The second element of the 4th INT 32 precision (W32[3]) includes the first element of the 131st INT 4 precision (W4

[130] ) in the first tensor, the first element of the 132nd INT 4 precision (W4

[131] ) (i.e., the first elements of the 2 consecutive INT 4 precision that are not loaded starting with the first element of the 130th INT 4 precision (W4

[129] )), the first element of the 163rd INT 4 precision (W4

[162] ), the first element of the 164th INT 4 precision (W4

[163] ) (i.e., the first elements of the 2 consecutive INT 4 precision that are not loaded starting with the first element of the 162nd INT 4 precision (W4

[161] )), the first element of the 195th INT 4 precision (W4

[194] ), and the first element of the 196th INT 4 precision (W4

[195] ) (i.e., the first elements of the 2 consecutive INT 4 precision that are not loaded starting with the first element of the 194th INT 4 precision (W4

[193] ) 4 precision), the first element of the 227th INT 4 precision (W4

[226] ), the first element of the 228th INT 4 precision (W4

[227] ) (that is, the first elements of the two consecutive INT 4 precision that are not loaded starting with the first element of the 226th INT 4 precision (W4

[225] )).

[0060] The second element of the third INT 32 precision (composed of the first elements of the 8 INT 4 precision) and the second element of the fourth INT32 precision (composed of the first elements of the 8 INT 4 precision) are combined (i.e. Figure 4 The w1 shown in the figure is composed of consecutive W / U first precision first elements loaded after the multiple first elements of the first precision loaded for the 1st second precision second element and the multiple first elements of the first precision loaded for the 2nd second precision second element respectively (a total of 16 INT 4 precision first elements constitute w1).

[0061] And so on, I won’t list them all here.

[0062] If there are 1024 first elements of INT 4 precision in the first tensor, a total of 128 second elements of INT 32 precision are stored in the memory, where 128 is the first element of INT 4 precision of the first tensor 1024 divided by 8 (8 is the number of bits of INT 32 divided by the number of bits of INT 4), that is, 1024 first elements of INT 4 precision will get a total of 128 second elements of INT 32 precision. In short, in Figure 2 In the illustrated embodiment, the number of second elements of the second precision is equal to the number of first elements of the first precision in the first tensor divided by N (wherein, as before, the number of bits of the second precision is N times the number of bits of the first precision).

[0063] Thus, according to at least one embodiment of the present application, the first elements of the first precision can be dispersedly stored in the memory (at intervals of 32), so that when the 16 computing units read them later (each computing unit reads 2 consecutive first elements), they will not be read in large quantities in a certain area of ​​the memory, but will be dispersed in multiple locations in the memory, so as to reduce traffic accumulation, read conflicts and errors. At the same time, because in order to maximize the use of the bit width of the register 32, it is the most efficient for each of the 16 computing units to read 2 first elements of the first precision each time, so storing the consecutive 2 first elements of the first precision in the memory continuously also helps each computing unit to read continuously faster.

[0064] return Figure 3B For the A16W4 solution, after loading the tensor B with INT 32 precision, the execution unit CU 1120 continues to dequantize the first elements of INT 4 included in the tensor B in the memory (such as Figure 3B As shown, multiply by the scaling factor Scale, FP 32 format, size K / 128×W) to obtain a third tensor B' (size K×W) of a third precision (e.g., BF 16). The number of bits of the third precision is higher than the number of bits of the first precision. Here, the size of the scaling factor Scale K / 128×W is to enable each 128 elements of INT 4 stored in the above predetermined order to be multiplied by a corresponding scaling factor element. As such, since most AI chips use BF 16 precision in tensor operations (BF16 precision is a 16-bit half-precision floating point format, commonly used in deep learning and machine learning to save memory and accelerate calculations, BF16 numbers are represented as: 1 sign bit + 8 exponent bits + 7 mantissa bits (a total of 16 bits)), therefore, although the INT 32 precision used for efficient loading includes the first elements of 8 INT 4 precisions, in order to adapt to operations with other BF 16 precision tensors, here, the first element of INT 4 precision loaded in INT 32 format is also dequantized (scaled) to a tensor B' of BF16 precision. Dequantization to different precisions requires the use of different scaling factors, which are not described here one by one.

[0065] Then, the execution unit CU 1120 operates the fourth tensor of the third precision (e.g., the tensor A of BF16 precision as shown in FIG. 3, with a size of H×K) and the third tensor of the third precision (e.g., the tensor B' of BF16 precision as shown in FIG. 3, with a size of K×W) to output a tensor of the third precision (with a size of H×W). Of course, as shown in FIG. 3, a matrix multiplication operation can be performed, and of course other tensor operations, such as convolution, can also be performed. In this article, H, K, and W are positive integers.

[0066] In this way, according to multiple embodiments of the present application, low-precision (low-bit-width) tensors can be efficiently loaded and stored and quantized and calculated, which greatly optimizes the performance of large language model reasoning while reducing the amount of data transported, while ensuring that the accuracy loss is controllable.

[0067] Figure 5 A block diagram of a tensor precision processing device according to at least one embodiment of the present application is shown.

[0068] like Figure 5 As shown, the tensor precision processing device 500 includes a loading component 510 and a quantization component 520.

[0069] The loading unit 510 is configured to obtain a second element of second precision by loading a plurality of first elements of first precision in the first tensor into the memory respectively, so as to form a second tensor including a plurality of second elements. The number of bits of the first precision is lower than the number of bits of the second precision.

[0070] The dequantization component 520 is configured to dequantize the second tensor in the memory to obtain a third tensor of a third precision. The number of bits of the third precision is higher than the number of bits of the first precision.

[0071] In one embodiment, the tensor precision processing device 500 further includes a computing component configured to operate the fourth tensor of the third precision with the third tensor of the third precision.

[0072] In one embodiment, the number of bits of the second precision is N times the number of bits of the first precision, where N is a positive integer. The loading component 520 is configured to obtain a second element of the second precision by loading N first elements of the first precision in the first tensor into the memory in a predetermined order, wherein the N first elements of the first precision constitute a second element of the second precision.

[0073] In one embodiment, the predetermined order includes an original order of the plurality of first elements of the first precision in the first tensor, such that every N consecutive first elements of the first precision are stored in the memory as a second element of the second precision.

[0074] In one embodiment, the predetermined order includes not following the original order of the plurality of first elements of the first precision in the first tensor, so that every N incompletely consecutive first elements of the first precision are stored in the memory as a second element of the second precision.

[0075] In one embodiment, the predetermined order is determined based on one or more of the following factors: the bit width of the register used to store the first element; and the number of computing units used to read the first element in parallel.

[0076] In one embodiment, the bit width of the register is W, and the number of computing units is U, where W and U are positive integers, and the predetermined sequence includes: loading consecutive W / U first precision first elements each time, with W first precision first elements spaced between two loaded elements, until the bit width W of the register is fully loaded to form the i-th second precision second element and the i+1-th second precision second element; loading consecutive W / U first precision first elements after the multiple first precision first elements loaded for the i+1-th second precision second element to form the i+2-th second precision second element and the i+3-th second precision second element, where i is a positive integer, and the number of second precision second elements is equal to the number of first precision first elements in the first tensor divided by N.

[0077] In one embodiment, the first precision is INT 4 precision, the second precision is INT 32 precision, the bit width of the register is 32 bits, the number of computing units is 16, and the predetermined order includes: the second element of the 1st INT 32 precision includes the first element of the 1st INT 4 precision, the first element of the 2nd INT 4 precision, the first element of the 33rd INT 4 precision, the first element of the 34th INT 4 precision, the first element of the 65th INT 4 precision, the first element of the 66th INT 4 precision, the first element of the 97th INT 4 precision, and the first element of the 98th INT 4 precision in the first tensor; the second element of the 2nd INT 32 precision includes the first element of the 129th INT 4 precision, the first element of the 130th INT 4 precision, the first element of the 161st INT 4 precision, the first element of the 162nd INT 4 precision, the first element of the 193rd INT 4 precision, the first element of the 194th INT 4 precision, the first element of the 225th INT 4 precision, the first element of the 226th INT 4 precision in the first tensor. The first element of INT 4 precision; the subsequent second element of INT 32 precision includes the first elements of the two consecutive INT 4 precision that have not been loaded starting from the loaded first element of INT 4 precision.

[0078] In one embodiment, dequantizing the second tensor in the memory to obtain a third tensor of third precision includes: reading the first element from the memory into a register in a reading order, and multiplying the first element by a scaling factor to obtain the third tensor of third precision.

[0079] In this way, according to multiple embodiments of the present application, low-precision (low-bit-width) tensors can be efficiently loaded and stored and dequantized and calculated, which greatly optimizes the performance of large language model reasoning while reducing the amount of data transported, while ensuring that the accuracy loss is controllable.

[0080] Figure 6 A block diagram of an exemplary tensor precision processing device suitable for implementing at least one embodiment of the present application is shown.

[0081] The tensor precision processing device may include a processing unit 610 and a storage unit 620, wherein the storage unit 620 is coupled to the processing unit 610 and stores computer instructions therein for performing steps of multiple methods of at least one embodiment of the present application when executed by the processing unit.

[0082] The processing unit 610 may include, but is not limited to, one or more processing units or micro-processing units, etc.

[0083] The storage unit 620 may include, but is not limited to, for example, random access memory (RAM), read-only memory (ROM), flash memory, EPROM memory, EEPROM memory, registers, computer storage media (e.g., hard disk, floppy disk, solid state drive, removable disk, CD-ROM, DVD-ROM, Blu-ray disk, etc.).

[0084] In addition, the tensor precision processing device may also include (but not limited to) a data bus 630, an input / output (I / O) bus 640, a display 650, and an input / output device 660 (eg, a keyboard, a mouse, a speaker, etc.).

[0085] The processing unit 610 may communicate with an external display 650 and an input / output device 660 through an I / O bus 640 .

[0086] The storage unit 620 may also store at least one computer instruction for executing multiple functions and / or method steps in the embodiments described in the present technology when the processing unit 610 executes the instructions.

[0087] In one embodiment, the at least one computer instruction may also be compiled into or constitute a computer program product or software product, wherein when one or more computer instructions are executed by a processor, multiple functions and / or method steps in the embodiments described in the present technology are performed.

[0088] Figure 7 A schematic diagram of a non-transitory computer-readable storage medium according to at least one embodiment of the present application is shown.

[0089] like Figure 7As shown, the non-transitory computer-readable storage medium 720 stores instructions, such as computer instructions 710. When the computer instructions 710 are executed by the processing unit, multiple methods described above can be executed. Non-transitory computer-readable storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), flash memory, EPROM memory, EEPROM memory, registers, computer storage media (such as hard disk, floppy disk, solid state drive, removable disk, CD-ROM, DVD-ROM, Blu-ray disc, etc.), etc. For example, the non-transitory computer-readable storage medium 720 can be connected to a computing device such as a computer, and then, when the computing device executes the computer instructions 710 stored on the computer-readable storage medium 720, multiple methods described above can be performed.

[0090] Figure 8 A block diagram of an electronic device according to at least one embodiment of the present application is shown.

[0091] like Figure 8 As shown, the electronic device 800 includes: a tensor precision processing device 810 and a memory 820 according to at least one embodiment of the present application. For example, the electronic device 800 may be a general-purpose graphics processing unit, and the memory may be a video memory; for another example, the electronic device 800 may be a tensor processing unit, and the memory may be a global memory of the tensor processing unit, etc., and the embodiments of the present disclosure are not limited to this.

[0092] In one embodiment, the tensor precision processing device includes: a loading unit configured to obtain a second element of second precision by loading multiple first elements of first precision in the first tensor into the memory respectively, so as to form a second tensor including multiple second elements, wherein the number of bits of the first precision is lower than the number of bits of the second precision; and a dequantization unit configured to dequantize the second tensor in the memory to obtain a third tensor of third precision, wherein the number of bits of the third precision is higher than the number of bits of the first precision. In one embodiment, the tensor precision processing device can be a computing unit in an artificial intelligence chip.

[0093] In another embodiment, the tensor precision processing device includes: a storage unit for storing computer instructions; a processing unit for reading the computer instructions in the storage unit and executing the method according to at least one embodiment of the present application. Here, the tensor precision processing device can be a host computer, the processing unit is a central processing unit CPU, and the storage unit can be a memory.

[0094] Note that in this article, the meaning of "precision" can refer to the "data storage format" and / or the number of bits occupied by stored data. Because different data storage formats, such as INT 4 and INT32, occupy different numbers of bits for storing data, this article mainly focuses on the data storage format and the number of bits occupied by data storage of different data storage formats, and intends to use "precision" to refer to the "data storage format" and / or the number of bits occupied by stored data.

[0095] The block diagrams of the devices, apparatuses, equipment, and systems involved in this disclosure are only illustrative examples and are not intended to require or imply that they must be connected, arranged, and configured in the manner shown in the block diagrams. As will be appreciated by those skilled in the art, these devices, apparatuses, equipment, and systems can be connected, arranged, and configured in any manner. Words such as "including", "comprising", "having", etc. are open words, referring to "including but not limited to", and can be used interchangeably therewith. The words "such as / for example" used herein refer to the phrase "such as / for example but not limited to", and can be used interchangeably therewith.

[0096] The step flow charts and the above method descriptions in this disclosure are only illustrative examples and are not intended to require or imply that the steps of multiple embodiments must be performed in the order given. As will be appreciated by those skilled in the art, the order of the steps in the above embodiments can be performed in any order. Words such as "thereafter", "then", "next", etc. are not intended to limit the order of steps; these words are only used to guide the reader through the description of these methods. In addition, any reference to a singular element, such as using the article "one", "one", or "the" is not to be construed as limiting the element to the singular.

[0097] In addition, the steps and devices in the multiple embodiments of this document are not limited to be implemented in a certain embodiment. In fact, according to the concept of this application, relevant partial steps and partial devices in the multiple embodiments of this document can be combined to conceive new embodiments, and these new embodiments are also included in the scope of this application.

[0098] The above methods may be implemented in hardware, software, firmware or any combination thereof.

[0099] The present disclosure may also include a computer program product, wherein the computer program product can perform the methods, steps, and operations presented herein. For example, such a computer program product can be a computer software package, computer code instructions, a computer-readable tangible medium having computer instructions tangibly stored (and / or encoded) thereon, the instructions being executable by a processor to perform the operations described herein. The computer program product can include packaging materials.

[0100] In addition, modules and / or other appropriate means for performing the methods and techniques described herein can be downloaded from a server via wireless communication when appropriate. Alternatively, the various methods described herein can be provided via a storage component so that the various methods are available when coupled to the storage component. In addition, any other appropriate technology for providing the methods and techniques described herein to a device can be utilized.

[0101] The above description has been given for the purpose of illustration and description. In addition, this description is not intended to limit at least one embodiment of the present application to the form disclosed herein. Although multiple example aspects and embodiments have been discussed above, those skilled in the art will recognize certain variations, modifications, changes, additions and sub-combinations thereof.

Claims

1. A tensor precision processing method, comprising: A second tensor including a plurality of second elements is formed by loading a plurality of first elements of a first precision in the first tensor into a memory respectively to obtain a second element of a second precision, wherein the number of bits of the first precision is lower than the number of bits of the second precision; Dequantizing the second tensor in the memory to obtain a third tensor of third precision, wherein the number of bits of the third precision is higher than the number of bits of the first precision, The number of bits of the second precision is N times the number of bits of the first precision, where N is a positive integer greater than 1. The method of loading a plurality of first elements of the first precision in the first tensor into the memory to obtain a second element of the second precision to form a second tensor including the plurality of second elements comprises: A plurality of second elements of the second precision are obtained by loading N first elements of the first precision in the first tensor into a memory in a predetermined order, wherein the N first elements of the first precision constitute one second element of the second precision, The predetermined order includes not following the original order of the plurality of first elements of the first precision in the first tensor, so that every N incompletely consecutive first elements of the first precision are stored in the memory as a second element of the second precision, The predetermined order is determined based on one or more of the following factors: The bit width of the register used to store the first element; The number of computational units used for parallel reading of the first element.

2. The method according to claim 1, further comprising: The fourth tensor of the third precision is operated on the third tensor of the third precision.

3. The method according to claim 1, wherein: The predetermined order includes storing a plurality of first elements of the first precision in the first tensor in an original order such that every N consecutive first elements of the first precision are stored in the memory as a second element of the second precision.

4. The method according to claim 1, wherein: The bit width of the register is W, the number of the computing units is U, wherein W and U are positive integers, and the predetermined sequence includes: Each time, W / U consecutive first elements of the first precision are loaded, with W first elements of the first precision being spaced between two loadings, until the bit width W of the register is fully loaded to form the i-th second element of the second precision and the i+1-th second element of the second precision; respectively load consecutive W / U first precision first elements after the plurality of first precision first elements loaded for the i+1th second precision second element to form the i+2th second precision second element and the i+3th second precision second element, Wherein i is a positive integer, and the number of second elements of the second precision is equal to the number of first elements of the first precision in the first tensor divided by N.

5. The method according to claim 4, wherein: The first precision is INT 4 precision, the second precision is INT32 precision, the bit width of the register is 32 bits, the number of the computing units is 16, The predetermined sequence includes: The second element of the 1st INT 32 precision includes the first element of the 1st INT 4 precision, the first element of the 2nd INT 4 precision, the first element of the 33rd INT 4 precision, the first element of the 34th INT 4 precision, the first element of the 65th INT 4 precision, the first element of the 66th INT 4 precision, the first element of the 97th INT 4 precision, and the first element of the 98th INT 4 precision in the first tensor; The second element of the second INT 32 precision includes the first element of the 129th INT 4 precision, the first element of the 130th INT 4 precision, the first element of the 161th INT 4 precision, the first element of the 162th INT 4 precision, the first element of the 193rd INT 4 precision, the first element of the 194th INT 4 precision, the first element of the 225th INT 4 precision, and the first element of the 226th INT 4 precision in the first tensor; The subsequent second element of INT 32 precision includes the unloaded consecutive 2 first elements of INT 4 precision starting from the loaded first element of INT 4 precision.

6. The method according to claim 1, wherein: The dequantizing the second tensor in the memory to obtain a third tensor of a third precision includes: The first element is read from the memory into a register in a reading order and multiplied by a scaling factor to obtain a third tensor of the third precision, wherein the reading order corresponds to the predetermined order.

7. A tensor precision processing device, comprising: A memory unit for storing computer instructions; At least one processing unit, configured to read the computer instructions in the storage unit and execute the method according to any one of claims 1-6.

8. An electronic device, comprising: The tensor precision processing device according to claim 7; The memory.

9. A non-transitory computer-readable storage medium having computer instructions stored thereon, in, When the computer instructions are executed by a processing unit, the processing unit is caused to perform the method according to any one of claims 1 to 6.