Data processing method and apparatus
Patent Information
- Application Number
- PCT/CN2025/079222
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-03-04
- Filing Date
- 2025-02-26
- Publication Date
- 2025-10-02
AI Technical Summary
Existing uniform quantization methods cannot effectively adapt to the non-uniform distribution characteristics of large language model outputs, resulting in large quantization errors, affecting processing accuracy, and as the input data size increases, storage requirements and inference speed slow down.
A non-uniform quantization method is used to perform finer-grained quantization based on the distribution characteristics of the data. Nonlinear transformation and preset mapping relationships are used to convert data units into corresponding quantized values. The intermediate results are processed through non-uniform quantization and nonlinear transformation to reduce quantization errors.
It improves model processing accuracy, reduces storage requirements and the speed of the inference process, reduces overall quantization errors, and improves data processing efficiency.
Abstract
Description
A data processing method and device thereof
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on March 4, 2024, with application number 202410245713.8 and application name “A data processing method and device thereof”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of artificial intelligence, and in particular to a data processing method and device thereof. Background Art
[0003] Artificial Intelligence (AI) is the theory, methods, techniques, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a branch of computer science that seeks to understand the essence of intelligence and develop new intelligent machines that can respond in a manner similar to human intelligence. AI studies the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.
[0004] When input data is processed by a machine learning model, the machine learning model may include an attention layer. The attention layer may perform attention calculations on the input data (e.g., the data is a token, which is described below for convenience). When the attention layer performs attention calculations on the token, it obtains an intermediate result that needs to be reused when performing attention calculations on the token. For example, the intermediate result may be KV (key-value) data, i.e., a KV cache.
[0005] In this process, when processing a new token, the intermediate results that can be reused can be stored in the memory, so that when they need to be reused for attention calculation of other tokens later, the intermediate results can be read from the memory and the attention calculation of the subsequent token can be performed based on the intermediate results.
[0006] However, as the input data size continues to grow, the amount of reusable intermediate results that need to be stored will rapidly increase as the inference progresses, resulting in a large storage demand. In addition, overly large intermediate results can also make the inference process extremely slow, so reusable intermediate results need to be compressed. Summary of the Invention
[0007] In a first aspect, the present application provides a data processing method, which includes: obtaining first data, wherein the first data is obtained through a machine learning model based on first input data; performing non-uniform quantization processing on the first data to obtain first compressed data, and storing the first compressed data in a memory; reading the first compressed data from the memory, and performing inverse quantization processing corresponding to the non-uniform quantization processing on the first compressed data to obtain second data, wherein the second data and second input data are used to be input into the machine learning model, and the second input data is data input into the machine learning model after the first input data.
[0008] It should be understood that after the non-uniform quantization processing is performed on the first data, other processing (such as entropy coding, etc.) can be performed to obtain the first compressed data, which is not limited in the embodiment of the present application. Similarly, after the inverse transform processing corresponding to the nonlinear transform and the inverse quantization processing corresponding to the uniform quantization processing are performed on the first compressed data, other processing can be performed to obtain the second data, which is not limited in the embodiment of the present application.
[0009] Among them, the second input data can be data input into the machine learning model after the first input data. For example, the second input data can be data input into the machine learning model after and adjacent to the first input data. For example, the second input data can be data input into the machine learning model after the first input data and separated by multiple input data.
[0010] Among them, the first data can be obtained by linearly transforming the input token of the machine learning model (the intermediate network layer, for example, the attention layer), for example, the first data can be K data and / or V data.
[0011] The quantization strategies used in the current cache compression methods are all uniform quantization. The distribution of data output by large language models generally presents a non-uniform distribution similar to a Gaussian distribution. Uniform quantization cannot adapt well to this non-uniform distribution characteristic of the data, which will result in a large overall quantization error and a greater impact on data with small values (the main reason is that the data units of the data will be concentrated in a certain small interval. If uniform quantization is used, the data units concentrated in a certain small interval will be converted into the same or a small number of quantization values, which will result in a large loss of accuracy). In the embodiment of the present application, based on the non-uniform distribution characteristics of the data, the data is non-uniformly quantized, which can be more in line with the distribution characteristics of the data, and a quantization result with a smaller overall error or average error is obtained, thereby improving the processing accuracy of the model.
[0012] Taking KV data as an example, the quantization strategies used in the current KV cache compression method are all uniform quantization. The distribution of KV data output by the large language model generally presents a non-uniform distribution similar to the Gaussian distribution. Uniform quantization cannot adapt well to this non-uniform distribution characteristic of KV data, which will result in a large overall quantization error and a greater impact on data with small values (the main reason is that the data units of KV data will be concentrated in a certain small interval. If uniform quantization is used, the data units concentrated in a certain small interval will be converted into the same or a small number of quantization values, which will result in a large loss of accuracy). In the embodiment of the present application, based on the non-uniform distribution characteristics of KV data, the KV data is non-uniformly quantized, which can be more in line with the distribution characteristics of KV data, and a quantization result with a smaller overall error or average error is obtained, thereby improving the processing accuracy of the model.
[0013] Specifically, in an embodiment of the present application, finer-grained quantization can be performed on the more densely distributed numerical intervals in the first data, that is, more quantization values and corresponding intervals are inserted (since there are more quantization values, the numerical width of the intervals will become lower), so that the quantization can be more in line with the distribution characteristics of the KV data, and a quantization result with smaller overall error or average error is obtained. For example, the first data includes multiple data units, the first compressed data includes the quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0014] In one possible implementation, the non-uniform quantization processing of the first data to obtain the first compressed data includes: converting the data units of the first data into corresponding quantization values based on a preset mapping relationship (for example, in the form of a table) to obtain the first compressed data; wherein the mapping relationship includes multiple numerical intervals and the quantization values corresponding to each numerical interval, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0015] In a possible implementation, performing non-uniform quantization processing on the first data to obtain first compressed data includes: performing nonlinear transformation on the first data to obtain transformed first data; and performing uniform quantization processing on the transformed first data.
[0016] The function type can be a power function, a logarithmic function, a gamma mapping function, an A-law curve, a μ-law curve, or a PWL curve.
[0017] About: Power Function
[0018] Definition: Expressed as x to the power of n
[0019] Mathematical expression: y = x n , where n is a real number
[0020] About: Logarithmic Function
[0021] Definition: The logarithmic function is the inverse of the exponential function
[0022] Mathematical expression: y = log b (x) where b is the base of the logarithm
[0023] About: Gamma Correction Function
[0024] Definition: Similar to the power function, usually mapped on normalized data
[0025] Mathematical expression: y = x γ Where x is the input pixel value, γ is the Gamma value, which is usually a real number greater than 0.
[0026] About: A-law Curve
[0027] Definition: The A-law curve is a nonlinear coding curve commonly used for audio signal compression.
[0028] Mathematical expression: y = ln(1+A*|x|) / ln(1+A) where x is the input signal and A is a constant
[0029] About: μ-law Curve
[0030] Definition: The μ-law curve is also a nonlinear coding curve, often used for audio signal compression.
[0031] Mathematical expression: y = sgn(x)*(ln(1+μ*|x|) / ln(1+μ)), where x is the input signal and μ is a constant.
[0032] About: PWL Curve (Piecewise Linear Curve)
[0033] Definition: The PWL curve is a piecewise linear function consisting of a series of line segments.
[0034] Mathematical expression:
[0035] where (x1,y1),(x2,y2)…(x n ,y n ) are control points on the curve, m1,m2,…m n is the slope between adjacent control points.
[0036] In a possible implementation, the method further includes: determining, according to the quantization accuracy of the first data, a category of a nonlinear function used when performing the nonlinear transformation or parameter values included therein.
[0037] Through the above approach, the non-uniform mapping relationship in non-uniform quantization can be adaptively determined according to the quantization accuracy, further reducing the quantization error. This can reduce the overall quantization error while maintaining the compression benefit brought by quantization.
[0038] In one possible implementation, the method further includes: determining the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included according to the position of the network layer where the attention layer is located in the machine learning model.
[0039] In one possible implementation, the first data is obtained based on the first input data through the target head in the attention layer of the machine learning model; the method also includes: determining the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included according to the position of the target head in the attention layer.
[0040] In one possible implementation, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included can be determined based on the generation interval between the first data and the latest data obtained by the machine learning model (that is, the number of generations, the generation order can be determined by the storage order in the memory, and this information can be called the sequence number).
[0041] In this way, the non-uniform mapping relationship in non-uniform quantization can be adaptively determined based on data grouping information (for example, at least one of the position of the network layer where the attention layer is located in the machine learning model, the position of the target head in the attention layer, and the generation order), further reducing the quantization error. This can reduce the overall quantization error while maintaining the compression benefits brought by quantization.
[0042] In a possible implementation, the method further includes: determining the category of the nonlinear function or the parameter values included when performing the nonlinear transformation based on the data distribution of the first data; the data distribution is indicated by the distribution statistical information of the first data, or by an identifier, wherein different identifiers correspond to data distributions with different characteristics.
[0043] The non-uniform mapping relationship in non-uniform quantization can be adaptively determined based on data distribution information, further reducing the quantization error. This can reduce the overall quantization error while maintaining the compression benefits brought by quantization.
[0044] In a second aspect, the present application provides a data processing method, the method comprising:
[0045] Obtaining first data, where the first data is calculated using a machine learning model based on first input data;
[0046] Performing a nonlinear transformation on the first data using a nonlinear function to obtain transformed first data;
[0047] The transformed first data is uniformly quantized to obtain first compressed data, and the first compressed data is stored in a memory, the first compressed data is read from the memory, and the first compressed data is subjected to inverse transformation processing corresponding to the nonlinear transformation and dequantization processing corresponding to the uniform quantization processing to obtain second data, the second data and the second input data are used to be input into the machine learning model, and the second input data is the data input into the machine learning model after the first input data.
[0048] In a possible implementation, the type of the nonlinear function or the parameter values included are determined based on at least one of the following:
[0049] Quantization accuracy of the first data; or
[0050] the position of the network that generated the first data in the machine learning model; or
[0051] The order in which the first data is generated in the machine learning model; or
[0052] Data distribution of the first data.
[0053] It should be understood that the above-mentioned method for determining the nonlinear function and the uniform quantization method combined with the nonlinear function can be applied to the compression and decompression process of other data besides KV data. "Other data" can be, but is not limited to, data that needs to be reused in the machine learning model inference process.
[0054] In one possible implementation, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0055] In a possible implementation, performing non-uniform quantization on the first data to obtain first compressed data includes:
[0056] Based on a preset mapping relationship, the data unit of the first data is converted into a corresponding quantization value to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0057] In a possible implementation, performing non-uniform quantization on the first data to obtain first compressed data includes:
[0058] performing a nonlinear transformation on the first data to obtain transformed first data;
[0059] Perform uniform quantization processing on the transformed first data.
[0060] In a third aspect, the present application provides a data processing device, comprising:
[0061] An acquisition module is configured to acquire first data, where the first data is obtained through a machine learning model based on first input data; and read first compressed data from the memory;
[0062] A processing module is used to perform non-uniform quantization processing on the first data to obtain the first compressed data, and store the first compressed data in a memory, and perform inverse quantization processing corresponding to the non-uniform quantization processing on the first compressed data to obtain second data, and the second data and second input data are used to be input into the machine learning model, and the second input data is data input into the machine learning model after the first input data.
[0063] Among them, the processing module can perform more fine-grained splitting. For example, the processing module may include a compression module and a decompression module. The compression module can perform non-uniform quantization processing on the first data to obtain the first compressed data. The decompression module can perform inverse transformation processing corresponding to the nonlinear transformation and dequantization processing corresponding to the uniform quantization processing on the first compressed data to obtain the second data.
[0064] In one possible implementation, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0065] In a possible implementation, the processing module is specifically configured to:
[0066] Based on a preset mapping relationship, the data unit of the first data is converted into a corresponding quantization value to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0067] In a possible implementation, the processing module is specifically configured to:
[0068] performing a nonlinear transformation on the first data to obtain transformed first data;
[0069] Perform uniform quantization processing on the transformed first data.
[0070] In a possible implementation, the processing module is further configured to:
[0071] According to the quantization accuracy of the first data, the type of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0072] In a possible implementation, the processing module is further configured to:
[0073] According to the position of the network layer where the attention layer is located in the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0074] In one possible implementation, the first data is obtained according to the first input data through a target head in an attention layer of a machine learning model; and the processing module is further configured to:
[0075] According to the position of the target head in the attention layer, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0076] In a possible implementation, the processing module is further configured to:
[0077] According to the generation interval between the first data and the latest data obtained by the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0078] In a possible implementation, the processing module is further configured to:
[0079] Based on the data distribution of the first data, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined; the data distribution is indicated by the distribution statistical information of the first data, or by an identifier, wherein different identifiers correspond to data distributions with different characteristics.
[0080] In a fourth aspect, the present application provides a data processing device, comprising:
[0081] an acquisition module, configured to acquire first data, where the first data is calculated based on the first input data through a machine learning model, and read the first compressed data from the memory;
[0082] A processing module is used to perform a nonlinear transformation on the first data through a nonlinear function to obtain the transformed first data; perform uniform quantization processing on the transformed first data to obtain the first compressed data, and store the first compressed data in a memory, and perform inverse transformation processing corresponding to the nonlinear transformation and dequantization processing corresponding to the uniform quantization processing on the first compressed data to obtain second data. The second data and second input data are used to be input into the machine learning model, and the second input data is the data input into the machine learning model after the first input data.
[0083] In a possible implementation, the type of the nonlinear function or the parameter values included are determined based on at least one of the following:
[0084] Quantization accuracy of the first data; or
[0085] the position of the network that generated the first data in the machine learning model; or
[0086] The order in which the first data is generated in the machine learning model; or
[0087] Data distribution of the first data.
[0088] In one possible implementation, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0089] In a possible implementation, the processing module is specifically configured to:
[0090] Based on a preset mapping relationship, the data unit of the first data is converted into a corresponding quantization value to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0091] In the fifth aspect, an embodiment of the present application provides a data processing device, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to execute the programs in the memory to perform the first aspect and any optional method thereof, or the second aspect and any optional method thereof.
[0092] In a sixth aspect, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. When the computer-readable storage medium is run on a computer, the computer executes the above-mentioned first aspect and any optional method thereof, or the above-mentioned second aspect and any optional method thereof.
[0093] In a seventh aspect, an embodiment of the present application provides a computer program which, when executed on a computer, enables the computer to execute the above-mentioned first aspect and any optional method thereof, or the above-mentioned second aspect and any optional method thereof.
[0094] In an eighth aspect, the present application provides a chip system comprising a processor configured to support the execution of a data processing device to implement the functions described in the aforementioned aspects, such as transmitting or processing the data or information described in the aforementioned methods. In one possible design, the chip system further comprises a memory configured to store program instructions and data necessary for executing the device or training the device. The chip system may consist of a single chip or may include a chip and other discrete components. BRIEF DESCRIPTION OF THE DRAWINGS
[0095] Figure 1 is a schematic diagram of the structure of the artificial intelligence main framework;
[0096] Figures 2 to 4 are schematic diagrams of the application system framework of the present invention;
[0097] FIG5 is a flowchart of a data processing method provided in an embodiment of the present application;
[0098] FIG6A and FIG6B are schematic diagrams of a network structure provided in an embodiment of the present application;
[0099] Figures 6C and 6D are schematic diagrams of data distribution;
[0100] FIG6E is a schematic diagram of a nonlinear function;
[0101] 7A to 7D are schematic diagrams of a data processing method provided in an embodiment of the present application;
[0102] FIG7E and FIG7F are schematic diagrams of an effect provided by an embodiment of the present application;
[0103] FIG8 is a schematic structural diagram of a data processing device provided in an embodiment of the present application;
[0104] FIG9 is a schematic diagram of a structure of an execution device provided in an embodiment of the present application;
[0105] FIG10 is a schematic diagram of a structure of a training device provided in an embodiment of the present application;
[0106] FIG11 is a schematic diagram of the structure of a chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0107] The following describes the embodiments of the present invention in conjunction with the accompanying drawings. The terms used in the embodiments of the present invention are only used to explain the specific embodiments of the present invention, and are not intended to limit the present invention.
[0108] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0109] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0110] As used herein, the terms "substantially," "about," and similar terms are used as terms of approximation, not as terms of degree, and are intended to take into account the inherent variations in measurements or calculations that one of ordinary skill in the art would recognize. Furthermore, the use of "may" when describing embodiments of the present invention refers to "one or more possible embodiments." As used herein, the terms "use," "using," and "used" may be considered synonymous with the terms "utilize," "utilizing," and "utilized," respectively. Additionally, the term "exemplary" is intended to refer to an example or illustration.
[0111] First, let's describe the overall workflow of an AI system. See Figure 1, which shows a schematic diagram of the AI framework. This framework will be explained from two perspectives: the "intelligent information chain" (horizontal axis) and the "IT value chain" (vertical axis). The "intelligent information chain" reflects the entire process from data acquisition to processing. For example, it could be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, and intelligent execution and output. Throughout this process, data undergoes a condensed journey from "data-information-knowledge-wisdom." The "IT value chain," spanning the underlying infrastructure of human intelligence, information (provided and processed by technology), and the system's industrial ecosystem, reflects the value that AI brings to the information technology industry.
[0112] (1) Infrastructure
[0113] Infrastructure provides computing power for AI systems, enabling communication with the outside world and supporting this through a foundational platform. External communication occurs through sensors; computing power is provided by intelligent chips (CPUs, NPUs, GPUs, ASICs, FPGAs, and other hardware accelerators). The foundational platform includes a distributed computing framework and network-related platform guarantees and support, including cloud storage and computing, and interconnected networks. For example, sensors communicate with the outside world to acquire data, which is then fed into the intelligent chips within the distributed computing system provided by the foundational platform for computation.
[0114] (2) Data
[0115] Data above the infrastructure layer represents data sources for AI. This data includes graphics, images, voice, and text, as well as IoT data from traditional devices. This includes business data from existing systems and sensor data such as force, displacement, liquid level, temperature, and humidity.
[0116] (3) Data processing
[0117] Data processing generally includes data training, machine learning, deep learning, search, reasoning, decision-making, etc.
[0118] Among them, machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, and training.
[0119] Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formalized information to perform machine thinking and solve problems based on reasoning control strategies. Typical functions are search and matching.
[0120] Decision-making refers to the process of making decisions after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
[0121] (4) General ability
[0122] After the data has undergone the data processing mentioned above, some general capabilities can be further formed based on the results of the data processing, such as algorithms or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.
[0123] (5) Smart products and industry applications
[0124] Smart products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of the overall artificial intelligence solution, which productizes intelligent information decision-making and realizes practical application. Its application areas mainly include: smart terminals, smart transportation, smart medical care, autonomous driving, smart cities, etc.
[0125] The following is a detailed introduction to the system architecture provided in the embodiment of the present application in conjunction with Figure 2.
[0126] FIG2 is a schematic diagram of the system architecture provided by an embodiment of the present application. As shown in FIG2 , the system architecture 500 includes an execution device 510 , a training device 520 , a database 530 , a client device 540 , a data storage system 550 , and a data acquisition system 560 .
[0127] The execution device 510 includes a calculation module 511, an I / O interface 512, a pre-processing module 513, and a post-processing module 514. The calculation module 511 may include the target model / rule 501, and the pre-processing module 513 and the post-processing module 514 are optional.
[0128] The data collection device 560 is used to collect training samples. After collecting the training samples, the data collection device 560 stores these training samples in the database 530.
[0129] The training device 520 can train the neural network to be trained (such as the machine learning model in the embodiment of the present application) based on the training samples maintained in the database 530 to obtain the target model / rule 501.
[0130] It should be understood that the training device 520 can perform a pre-training process on the neural network to be trained based on the training samples maintained in the database 530, or fine-tune the model based on the pre-training.
[0131] It should be noted that, in actual applications, the training samples maintained in the database 530 may not all be collected by the data acquisition device 560, but may also be received from other devices. It should also be noted that the training device 520 may not train the target model / rule 501 entirely based on the training samples maintained in the database 530, but may also obtain training samples from the cloud or other places for model training. The above description should not be used as a limitation on the embodiments of the present application.
[0132] The target model / rule 501 obtained through training with the training device 520 can be applied to different systems or devices, such as the execution device 510 shown in FIG2 . The execution device 510 can be a terminal, such as a mobile phone terminal, a tablet computer, a laptop computer, an augmented reality (AR) / virtual reality (VR) device, an in-vehicle terminal, etc., or a server, etc.
[0133] Specifically, the training device 520 may transfer the trained model to the execution device 510 .
[0134] In FIG. 2 , the execution device 510 is configured with an input / output (I / O) interface 512 for data interaction with an external device. A user can input data to the I / O interface 512 through a client device 540 .
[0135] Preprocessing module 513 and preprocessing module 514 are used to preprocess the input data received by I / O interface 512. It should be understood that preprocessing module 513 and preprocessing module 514 may be absent or only one preprocessing module may be present. If preprocessing module 513 and preprocessing module 514 are absent, computing module 511 may be used directly to process the input data.
[0136] When the execution device 510 preprocesses the input data, or when the computing module 511 of the execution device 510 performs calculations and other related processing, the execution device 510 can call the data, code, etc. in the data storage system 550 for corresponding processing, and can also store the data, instructions, etc. obtained from the corresponding processing in the data storage system 550.
[0137] Finally, the I / O interface 512 provides the processed results to the client device 540 and thus to the user.
[0138] In the scenario shown in FIG. 2 , the user can manually input data, and this "manual input data" can be operated through the interface provided by I / O interface 512. Alternatively, client device 540 can automatically send input data to I / O interface 512. If user authorization is required for client device 540 to automatically send input data, the user can set the corresponding permissions in client device 540. The user can view the output of execution device 510 on client device 540, which can be presented in a display, sound, action, or other specific form. Client device 540 can also serve as a data acquisition terminal, collecting input data and output results from I / O interface 512 as new sample data and storing them in database 530. Of course, collection can also be performed without client device 540, with I / O interface 512 directly storing the input data and output results from I / O interface 512 as new sample data in database 530.
[0139] It is worth noting that FIG2 is merely a schematic diagram of a system architecture provided by an embodiment of the present application, and the positional relationships between the devices, components, modules, etc. shown in the figure do not constitute any limitation. For example, in FIG2 , the data storage system 550 is an external memory relative to the execution device 510. In other cases, the data storage system 550 can also be placed in the execution device 510. It should be understood that the execution device 510 can be deployed in the client device 540.
[0140] From the inference side of the model:
[0141] In the embodiment of the present application, the computing module 511 of the above-mentioned execution device 510 can obtain the code stored in the data storage system 550 to implement the steps related to the model reasoning process in the embodiment of the present application.
[0142] In an embodiment of the present application, the computing module 511 of the execution device 510 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, etc.), or a combination of these hardware circuits. For example, the training device 520 may be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0143] Specifically, the computing module 511 of the execution device 510 can be a hardware system with an execution instruction function, and the steps related to the model reasoning process provided in the embodiment of the present application can be software codes stored in the memory. The computing module 511 of the execution device 510 can obtain the software code from the memory and execute the obtained software code to implement the steps related to the model reasoning process provided in the embodiment of the present application.
[0144] It should be understood that the computing module 511 of the execution device 510 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions. Some of the steps related to the model reasoning process provided in the embodiment of the present application can also be implemented by the hardware system that does not have the function of executing instructions in the computing module 511 of the execution device 510, which is not limited here.
[0145] From the training side of the model:
[0146] In an embodiment of the present application, the above-mentioned training device 520 can obtain the code stored in the memory (not shown in Figure 2, which can be integrated into the training device 520 or deployed separately from the training device 520) to implement the steps related to model training in the embodiment of the present application.
[0147] In an embodiment of the present application, the training device 520 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, etc.), or a combination of these hardware circuits. For example, the training device 520 may be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0148] It should be understood that the training device 520 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions. Some of the steps related to model training provided in the embodiments of the present application can also be implemented by the hardware system in the training device 520 that does not have the function of executing instructions, which is not limited here.
[0149] In the embodiments of the present application, the forward propagation process of the model is involved, which can be executed by the execution device 510 or the training device 520 introduced in the above embodiments.
[0150] In addition, the execution device 510 or the training device 520 can process the input data through a machine learning model, wherein the machine learning model can include an attention layer, which can perform attention calculations on the input tokens. When the attention layer performs attention calculations on the tokens, it can obtain intermediate results that need to be reused when performing attention calculations on the tokens later. For example, the intermediate results can be K data or V data, and the K data and V data stored in the memory are the KV cache. In this process, when processing a new token, the intermediate results that can be reused can be stored in the memory so that when they need to be reused when performing attention calculations on other tokens later, the intermediate results can be read from the memory and the attention calculations of subsequent tokens can be performed based on the intermediate results. However, as the size of the input data continues to increase, the amount of reusable intermediate results that need to be stored will rapidly increase as the reasoning proceeds, resulting in a large demand for storage. In addition, excessively large intermediate results can also make the reasoning process extremely slow, so compressing the reusable intermediate results is particularly important.
[0151] In one implementation, the compression process can be performed by a compression module, which can be centrally deployed with the above-mentioned execution device 510 or training device 520, for example, belonging to the same chip or computing unit of other granularity, or it can be deployed separately, for example, belonging to different chips. For example, the execution device 510 or training device 520 can be an AI chip, and the compression module can belong to the CPU.
[0152] For example, referring to Figures 3 and 4, Figures 3 and 4 are schematic diagrams of the architecture of the embodiments of the present application, wherein the model operation module can obtain an intermediate result by running a machine learning model, the compression module can compress the intermediate result and write the compressed data into a memory, the compression module can read the compressed data from the storage area and perform decompression, obtain the decompression result and pass it to the model operation module. The compression module and the model operation module in Figure 3 are separately deployed on different chips, while the compression module and the model operation module in Figure 4 are centrally deployed on the same chip.
[0153] Since the embodiments of the present application involve the application of a large number of neural networks, in order to facilitate understanding, the relevant terms and related concepts such as neural networks involved in the embodiments of the present application are first introduced below.
[0154] (1) Neural Network
[0155] A neural network can be composed of neural units. A neural unit can refer to an operation unit that takes xs (i.e., input data) and intercept 1 as input. The output of the operation unit can be:
[0156] Where s = 1, 2, ... n, n is a natural number greater than 1, Ws is the weight of xs, and b is the bias of the neural unit. f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal of the neural unit into the output signal. The output signal of the activation function can be used as the input of the next convolutional layer, and the activation function can be a sigmoid function. A neural network is a network formed by connecting multiple single neural units mentioned above, that is, the output of one neural unit can be the input of another neural unit. The input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field. The local receptive field can be an area composed of several neural units.
[0157] (2) Convolutional neural network (CNN) is a deep neural network with a convolutional structure. Convolutional neural network contains a feature extractor consisting of a convolution layer and a subsampling layer, which can be regarded as a filter. The convolution layer refers to the neuron layer in the convolutional neural network that performs convolution processing on the input signal. In the convolution layer of the convolutional neural network, a neuron can only be connected to some neurons in the adjacent layer. A convolution layer usually contains several feature planes, and each feature plane can be composed of some rectangularly arranged neural units. The neural units in the same feature plane share weights, and the shared weights here are convolution kernels. Shared weights can be understood as the way of extracting features is independent of position. The convolution kernel can be formalized as a matrix of random size, and the convolution kernel can obtain reasonable weights through learning during the training process of the convolutional neural network. In addition, the direct benefit of shared weights is to reduce the connections between the layers of the convolutional neural network, while reducing the risk of overfitting.
[0158] CNN is a very common neural network. Below is a detailed introduction to its structure. As mentioned in the previous basic concepts, a convolutional neural network is a deep neural network with a convolutional structure. It is a deep learning architecture, which uses machine learning algorithms to perform multiple levels of learning at different levels of abstraction. As a deep learning architecture, CNN is a feed-forward artificial neural network, in which individual neurons respond to input images.
[0159] (3) Deep Neural Networks
[0160] Deep Neural Network (DNN), also known as multi-layer neural network, can be understood as a neural network with many hidden layers. There is no special metric for "many" here. Based on the position of different layers in DNN, the neural network inside DNN can be divided into three categories: input layer, hidden layer, and output layer. Generally speaking, the first layer is the input layer, the last layer is the output layer, and the layers in between are all hidden layers. The layers are fully connected, that is, any neuron in the i-th layer must be connected to any neuron in the i+1-th layer. Although DNN looks complicated, the work of each layer is actually not complicated. Simply put, it is the following linear relationship expression: in, is the input vector, is the output vector, is the offset vector, W is the weight matrix (also called coefficient), and α() is the activation function. Each layer is just an input vector After such a simple operation, the output vector Since there are many DNN layers, the coefficient W and the offset vector The definition of these parameters in DNN is as follows: Take the coefficient W as an example: Assume that in a three-layer DNN, the linear coefficient from the 4th neuron in the second layer to the 2nd neuron in the third layer is defined as The superscript 3 represents the layer number of the coefficient W, while the subscript corresponds to the output of the third layer index 2 and the input of the second layer index 4. In summary, the coefficient from the kth neuron in the L-1th layer to the jth neuron in the Lth layer is defined as It's important to note that the input layer has no W parameter. In deep neural networks, more hidden layers allow the network to better capture complex real-world situations. Theoretically, a model with more parameters has higher complexity and greater "capacity," meaning it can handle more complex learning tasks. Training a deep neural network is essentially the process of learning the weight matrix, with the ultimate goal of obtaining the weight matrices for all layers of a trained deep neural network (a weight matrix formed by the vectors W across many layers).
[0161] (4) Loss function
[0162] During the training of a deep neural network, because we want the output of the deep neural network to be as close as possible to the desired predicted value, we can compare the current network's predicted value with the desired target value and then update the weight vector of each layer of the neural network based on the difference between the two. (Of course, before the first update, there is usually an initialization process, which pre-configures the parameters for each layer in the deep neural network.) For example, if the network's predicted value is too high, the weight vector is adjusted to make it predict a lower value. This adjustment is continued until the deep neural network can predict the desired target value or a value very close to the desired target value. Therefore, it is necessary to predefine "how to compare the difference between the predicted value and the target value." This is the loss function (or objective function), which is an important equation used to measure the difference between the predicted value and the target value. For example, the loss function output value (loss) indicates a greater difference, so training a deep neural network becomes a process of minimizing this loss.
[0163] (5) Backpropagation algorithm
[0164] The back propagation (BP) algorithm can be used to correct the size of the initial model parameters during training, reducing the model's error loss. Specifically, forward propagation of the input signal to the output generates error loss. This error loss information is then backpropagated to update the parameters in the initial model, thereby converging the error loss. The BP algorithm is a backward propagation movement driven by error loss, aiming to obtain optimal model parameters, such as the weight matrix.
[0165] (6) Large Language Model: Large language models refer to natural language processing models trained on large amounts of data, typically with billions or tens of billions of parameters. These models capture the general characteristics of language by learning from large amounts of text data during the pre-training phase, and can then be fine-tuned on downstream tasks to adapt to specific task requirements.
[0166] (7) Transformer: Transformer is a deep learning model architecture originally used for sequence-to-sequence tasks such as machine translation. It uses a self-attention mechanism to process input sequences and has achieved great success in the field of natural language processing. Most large language models, such as BERT, GPT, and T5, are based on the Transformer architecture.
[0167] (8) KV cache (key-value cache): KV cache refers to a cache structure that stores key-value pairs. In large language models, KV cache is often used to store intermediate results or other useful information when the model processes text to improve efficiency. By using KV cache, the model can avoid repeated calculations when processing text.
[0168] (9) Key-Value cache quantization: KV cache quantization refers to quantizing the values in the KV cache to reduce storage space and computational overhead. In some large language models, in order to adapt the model to limited resources, the values in the KV cache can be quantized to reduce the storage and computational costs of the model.
[0169] (10) Perplexity (PPL): PPL is a metric used to evaluate the performance of a language model, indicating the model's ability to predict a given text sequence. PPL is a positive real number that can be understood as the average difficulty of the model in predicting the observed data sequence. The lower the PPL, the better the model performance.
[0170] (11) Non-Uniform Quantization: Non-Uniform Quantization is a quantization method in which the value range is divided into intervals of different sizes to better adapt to the data distribution. Unlike uniform quantization, non-uniform quantization can assign a different number of value ranges to each interval based on the data distribution.
[0171] (12) Token: In natural language processing, a "token" is the basic unit of text string segmentation. This can be a word, a character, or a subword fragment. Large language models usually need to segment input text into tokens and then convert these tokens into numerical representations (such as word vectors) that the model can understand.
[0172] (13) Sequence: In the context of large language models, "sequence" refers to a sequence of elements with a certain order relationship, and multiple tokens constitute a sequence.
[0173] (14) Incremental Inference: Incremental inference allows the model to process only newly added portions of the input, rather than reprocessing the entire sequence each time. This is achieved by maintaining contextual information in the model's internal state, allowing the model to respond quickly when new input is received. Incremental inference is particularly useful in interactive applications, such as chatbots or real-time translation, as it can significantly reduce latency and computing resource usage.
[0174] The present invention provides a data processing method. The data processing method of the present invention is described in detail below with reference to the accompanying drawings.
[0175] Refer to Figure 5, which is a flow chart of a data processing method provided in an embodiment of the present application. As shown in Figure 5, a data processing method provided in an embodiment of the present application may include steps 501 to 503, and these steps are described in detail below.
[0176] 501. Obtain first data, where the first data is obtained through a machine learning model based on first input data;
[0177] In the above process, each time the latest input data is processed by the machine learning model, it is necessary to obtain the intermediate results that have been generated in the history (such as K data or V data) and input them into the machine learning model to perform attention operations on the latest input data (that is, operations based on the attention mechanism). In this process, intermediate results will still be obtained (that is, data that still needs to be reused when processing subsequent input data). The newly generated intermediate results and the intermediate results that have been generated in the history can be spliced and the attention weight calculation can be performed.
[0178] For example, referring to FIG6B , K cache and V cache are intermediate results that have been generated historically. After calculating the token of the latest input data (for example, by linearly transforming the Wd matrix, the Wk matrix, and the Wv matrix), the Q data, K data, and V data of the latest input data can be obtained. The K data and K cache of the latest input data can then be concatenated and transposed, and the V data and V cache of the latest input data can be concatenated. The subsequent operations can be obtained by referring to the relevant introduction of the attention operation in the prior art, which will not be repeated here. The K data and V data of the latest input data can be stored in the memory, and can then be obtained from the memory when the machine learning model operates on the subsequent input data.
[0179] The machine learning model may be a language model.
[0180] Among them, the attention layer can perform self-attention calculation on the input data.
[0181] Take, for example, a transformer-based machine learning model using an attention mechanism. For example, referring to Figure 6A , the machine learning model can be a language model. The transformer is a model architecture using an attention mechanism, with the self-attention structure as its core component. Each transformer layer consists of two main components: a multi-head self-attention layer and a feedforward neural network (FNN). The self-attention structure allows the model to dynamically focus on information at different positions when processing sequential data. It consists of three main components: query data, key data, and value data. For an input sequence, a linear transformation of Q, K, and V is calculated, followed by a softmax operation. This distribution of attention at each position with respect to other positions is then weighted to produce the output for the current position. The self-attention structure is used to process information at different positions in the input data. In self-attention, the representation of each position is a weighted average of all other positions in the sequence, with the weights determined by calculating the relationship between the query, key, and value at the current position. This enables the model to dynamically focus on different parts of the input sequence.
[0182] During inference, the self-attention architecture generates a key-value (KV) pair for each position. These KV pairs are used by the attention mechanism to calculate weights for different positions. The KV cache is a collection of KV pairs generated at a specific time step. Storing historical KVs avoids repeated computations and accelerates model inference.
[0183] In one possible implementation, the first data may be data that needs to be reused by the machine learning model introduced above during the operation of subsequent input data.
[0184] In a possible implementation, the first data may be K data or V data. That is, the first data may be K data, the first data may be V data, or the first data may be K data and V data.
[0185] As the size of input data continues to grow, the amount of reusable intermediate results that need to be stored will increase rapidly as reasoning progresses, resulting in a large demand for storage. In addition, excessively large intermediate results will also make the reasoning process extremely slow, so compressing the reusable intermediate results is particularly important. Therefore, before storing the intermediate results (that is, the first data) that need to be reused when performing attention calculations, it is necessary to compress the data and store the compressed data to reduce storage overhead. When using the compressed data, it is necessary to read the compressed data and decompress it to ensure that the accuracy of the model is maintained when calculating the attention distribution.
[0186] In a possible implementation, the first data may be obtained by compressing the intermediate result.
[0187] In a possible implementation, the first data is specifically obtained by compressing and decompressing the intermediate result.
[0188] Specifically, in a possible implementation, the first data can be obtained through a machine learning model based on the latest input data (first input data), or it can be the result obtained by compressing and decompressing the intermediate result obtained through a machine learning model based on the latest input data.
[0189] Specifically, in a possible implementation, the first data may be obtained through a machine learning model based on the latest input data, or may be a result obtained by compressing and decompressing an intermediate result obtained through a machine learning model based on the latest input data.
[0190] Specifically, in a possible implementation, the first data may not be obtained through the latest input data (first input data), but may be compressed data obtained from the memory, or may be obtained by decompressing the compressed data obtained from the memory. It should be understood that the process of compression-decompression-recompression can only occur when the non-uniform quantization correspondence (or the type and parameters of the nonlinear mapping function) is determined according to the sequence number. That is, the K or V generated by the same token needs to be quantized differently at different times. If the quantization parameter changes at a certain moment, decompression-requantization is required.
[0191] When the first data is obtained based on the latest input data, it is necessary to compress it and store it in the memory.
[0192] When the first data is not obtained based on the latest input data but is acquired from a memory, it may be necessary to perform compression of other strengths (ie, compression with different precision losses) on the first data and store it in the memory.
[0193] 502. Perform non-uniform quantization processing on the first data to obtain first compressed data, and store the first compressed data in a memory;
[0194] In an embodiment of the present application, after the first data is acquired, the first data may be compressed to obtain first compressed data, and the first compressed data may be stored in a memory, for example, the memory is a memory cache.
[0195] The quantization strategies used in current KV cache compression methods are all uniform quantization. However, the distribution of KV data output by large language models generally presents a non-uniform distribution similar to the Gaussian distribution. As shown in Figures 6C and 6D, the Key cache data and Value cache data output by a certain layer of the large language model Llama-7B present a non-uniform distribution. Uniform quantization cannot adapt well to this non-uniform distribution characteristic of KV data, which will result in a large overall quantization error and a greater impact on data with small values (the main reason is that the data units of KV data will be concentrated in a small interval. If uniform quantization is used, the data units concentrated in a small interval will be converted into the same or a small number of quantization values, which will result in a large loss of accuracy).
[0196] In an embodiment of the present application, based on the non-uniform distribution characteristics of KV data, non-uniform quantization of KV data can be more consistent with the distribution characteristics of KV data, and a quantization result with smaller overall error or average error can be obtained, thereby improving the processing accuracy of the model.
[0197] Specifically, in an embodiment of the present application, finer-grained quantization can be performed on a more densely distributed numerical interval in the first data, that is, more quantization values and corresponding intervals are inserted (since there are more quantization values, the numerical width of the interval will become lower). For example, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0198] In a possible implementation, a nonlinear transformation may be performed on the first data to obtain transformed first data, and uniform quantization processing may be performed on the transformed first data. Specifically, reference may be made to the processing flow shown in FIG7A .
[0199] For example, the data is mapped and transformed according to a predetermined non-uniform mapping function (or it can be called a nonlinear transformation function). The non-uniform mapping function can be a power function, a logarithmic function, an A-law curve, a μ-law curve or a piecewise linear curve, etc. For example, reference can be made to FIG6E , which is a schematic diagram of a nonlinear function. The mapped data is then uniformly quantized. The quantization coefficient of the uniform quantization can be a preset value, or it can be adaptively determined by online statistical information of the mapped data.
[0200] Among them, the above-mentioned nonlinear transformation and uniform quantization steps can be combined. In this case, nonlinear mapping and uniform quantization can be combined into a table lookup step: according to the pre-set nonlinear transformation function and uniform quantization method, a corresponding table of floating-point value intervals and quantization values can be constructed. The quantization can be completed through the values and table of K data or V data to obtain the quantized K data or V data.
[0201] Specifically, in a possible implementation, the data unit of the first data can be converted into a corresponding quantization value based on a preset mapping relationship to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0202] In one possible implementation, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included can be determined based on the quantization accuracy of the first data. Different data to be quantized, such as KV cache data output by different layers of a large language model, KV cache data at different head dimensions, and KV cache data at different moments of model inference, may use different quantization accuracies. The quantization mapping relationship can be adaptively determined based on the quantization accuracy (e.g., the number of quantization bits), and quantization can be performed based on the determined quantization mapping relationship.
[0203] Exemplarily, the K data or V data to be cached and the quantization accuracy (number of quantization bits) of the current K data or V data can be obtained, and the type and parameters of the nonlinear transformation function can be determined according to the quantization accuracy. The numerical mapping relationship can be determined by the nonlinear transformation function type and parameters. The function type can be a power function, a logarithmic function, a gamma mapping function, an A-law curve, a μ-law curve or a PWL curve, etc. Nonlinear mapping is performed on the KV cache data to be quantized; uniform quantization is performed on the transformed KV cache data, and the quantized K data or V data is output.
[0204] Nonlinear mapping and uniform quantization can be combined into a table lookup step: based on the determined nonlinear transformation function and uniform quantization method, a corresponding table of floating-point value intervals and quantization values can be constructed. Quantization can be completed through the values of K data or V data and the table to obtain the quantized K data or V data.
[0205] Determining the type and parameters of the nonlinear transformation function based on the quantization precision can be achieved through a variety of methods: for example, it can be determined based on the correspondence between the preset quantization precision and the type and parameters of the nonlinear transformation function; or one quantization precision can correspond to multiple preset nonlinear transformation function types and parameters, and the types and parameters of the nonlinear transformation functions corresponding to different quantization precisions can be selected and determined by testing on a validation set. Specifically, the processing flow shown in FIG7A can be referred to.
[0206] Through the above approach, the non-uniform mapping relationship in non-uniform quantization can be adaptively determined based on the quantization accuracy, further reducing the quantization error. It is possible to reduce the overall quantization error while maintaining the compression benefit brought by quantization. Specifically, reference can be made to the processing flow shown in FIG7B .
[0207] In one possible implementation, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included can be determined based on the position of the network layer where the attention layer is located in the machine learning model.
[0208] In one possible implementation, the first data is K data and V data obtained by the target head in the attention layer of the machine learning model based on the first input data; the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included can be determined based on the position of the target head in the attention layer.
[0209] In one possible implementation, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included can be determined based on the generation interval between the first data and the latest data obtained by the machine learning model (that is, the number of generations, the generation order can be determined by the storage order in the memory, and this information can be called the sequence number).
[0210] In addition to changing with the quantization accuracy, the quantization mapping relationship also takes into account the grouping information of the data. For example, different quantization mapping relationships can be used for KV cache data output by different layers; different quantization mapping relationships can also be used for KV cache data of different head dimensions or sequence dimensions. Specifically, obtain the K data or V data that needs to be cached, the quantization accuracy (number of quantization bits) of the current K data or V data, and the grouping information. The grouping information can be the serial number of the layer that outputs the current K data or V data, the head dimension serial number of the current K data or V data, or the sequence serial number of the current K data or V data, or the group serial number of the current K data or V data, or the statistical information of the verification set in the current grouping.
[0211] The type and parameters of the nonlinear transformation function are determined based on the quantization accuracy and data grouping information. The nonlinear transformation function type and parameters can determine the numerical mapping relationship. The function type can be a power function, a logarithmic function, a gamma mapping function, an A-law curve, a μ-law curve, or a PWL curve. Nonlinear mapping is performed on the KV cache data to be quantized. Uniform quantization is performed on the transformed KV cache data, and quantized K data or V data is output. The nonlinear mapping and uniform quantization can be combined into a table lookup step: Based on the determined nonlinear transformation function and uniform quantization method, a corresponding table between floating-point value intervals and quantization values can be constructed. Quantization can be completed using the values of the K data or V data and the table to obtain the quantized K data or V data. The type and parameters of the nonlinear transformation function can be determined based on the quantization accuracy and data grouping information. This can be achieved through various methods: for example, based on the correspondence between the preset quantization accuracy, grouping information, and the type and parameters of the nonlinear transformation function; or one quantization accuracy + grouping information can correspond to multiple preset nonlinear transformation function types and parameters. The type and parameters of the nonlinear transformation function corresponding to different quantization accuracy and grouping information can be determined by testing on a validation set.
[0212] Through the above method, the non-uniform mapping relationship in the non-uniform quantization can be adaptively determined based on the data grouping information (for example, the position of the network layer where the attention layer is located in the machine learning model, the position of the target head in the attention layer, and at least one of the generation order), thereby further reducing the quantization error. It is possible to reduce the overall quantization error while maintaining the compression benefits brought by quantization. Specifically, reference can be made to the processing flow shown in Figure 7C.
[0213] In one possible implementation, the type of nonlinear function used or the parameter values included in the nonlinear transformation can be determined based on the data distribution of the first data; the data distribution is indicated by distribution statistics of the first data, or by an identifier, where different identifiers correspond to data distributions with different characteristics. For example, in addition to changing with quantization accuracy, the quantization mapping relationship also considers the distribution information of the current data to be quantized. For example, the quantization mapping relationship can be determined based on the quantization accuracy and the degree of dispersion of the current quantized data.
[0214] Specifically, the K data or V data that needs to be cached, the quantization accuracy (number of quantization bits) of the current K data or V data, and the distribution information of the current K data or V data can be obtained. The data distribution information is the statistical value from the current K data or V data, such as the mean, variance, maximum value, minimum value, value range and other information; the type and parameters of the nonlinear transformation function are determined according to the quantization accuracy and data distribution information, and the numerical mapping relationship can be determined by the nonlinear transformation function type and parameters. The function type can be a power function, a logarithmic function, a gamma mapping function, an A-law curve, a μ-law curve or a PWL curve, etc.; nonlinear mapping is performed on the KV cache data to be quantized; uniform quantization is performed on the transformed KV cache data, and the quantized K data or V data is output; the data distribution information is saved for use in the inverse quantization stage. Specifically, reference can be made to the processing flow shown in Figure 7D.
[0215] Nonlinear mapping and uniform quantization can be combined into a table lookup step: Based on the determined nonlinear transformation function and uniform quantization method, a corresponding table of floating-point value intervals and quantization values can be constructed. Quantization can be completed using the values of the K data or V data and the table, resulting in quantized K data or V data. The type and parameters of the nonlinear transformation function can be determined based on the quantization accuracy and data distribution information. This can be achieved through a variety of methods: for example, by testing on a validation set to obtain calibrated distribution information, and then, during the quantization and dequantization stages, the type and parameters of the nonlinear transformation function can be determined based on the difference between the current data distribution information and the calibrated distribution information and the quantization accuracy.
[0216] The non-uniform mapping relationship in non-uniform quantization can be adaptively determined based on data distribution information, further reducing quantization error. It can significantly reduce the overall quantization error while maintaining the compression benefits brought by quantization.
[0217] 503. Read the first compressed data from the memory, and perform inverse quantization processing corresponding to the non-uniform quantization processing on the first compressed data to obtain second data. The second data and second input data are used to be input into the machine learning model. The second input data is data input into the machine learning model after the first input data.
[0218] Depending on the way of determining the nonlinear function, the inverse quantization process may be performed in the following ways, but not limited to.
[0219] When KV Cache data is needed, it needs to be dequantized. The dequantization phase involves the following steps: obtaining quantized K or V data; uniformly dequantizing the quantized KV cache data using the same uniform quantization method as used in the quantization phase; inversely transforming the dequantized data using the nonlinear inverse transformation function corresponding to the nonlinear transformation used in the quantization phase; and finally obtaining decompressed KV Cache data for inference.
[0220] Among them, uniform inverse quantization and nonlinear inverse mapping can be combined into a table lookup step: according to the uniform inverse quantization method and the pre-set nonlinear inverse transformation function, a correspondence table between quantized values and floating-point values can be constructed. The inverse quantization can be completed through the numerical value and table of the quantized K data or V data to obtain the inverse quantized K data or V data.
[0221] When KV Cache data is needed, the quantized KV Cache data needs to be dequantized. The dequantization phase involves the following steps: obtaining the quantized K data or V data, determining its quantization precision, and uniformly dequantizing the quantized KV Cache data using the same uniform quantization method used in the quantization phase. The type and parameters of the nonlinear inverse transformation function are determined based on the quantization precision. The function is the inverse of the function used in the quantization phase. The dequantized data is inversely transformed using the nonlinear inverse transformation function. Finally, the decompressed KV Cache data is obtained for inference.
[0222] Nonlinear inverse mapping and uniform inverse quantization can be combined into a table lookup step: based on the uniform inverse quantization method and the determined nonlinear inverse transformation function, a corresponding table of quantized values and floating-point values can be constructed. Inverse quantization can be completed through the numerical value and table of the quantized K data or V data to obtain the inverse quantized K data or V data.
[0223] When KV Cache data is needed, the quantized KV Cache data needs to be dequantized. The specific steps of the dequantization stage are as follows: obtain the quantized K data or V data, obtain the quantization accuracy (number of quantization bits) of the current KV quantized data, and the grouping information. The grouping information can be the sequence number of the layer that outputs the current K data or V data, the head dimension sequence number of the current K data or V data, or the sequence number of the current K data or V data, or the group number of the current K data or V data; use the same uniform quantization method as the quantization stage to uniformly dequantize the quantized KV cache data; determine the type and parameters of the nonlinear inverse transformation function based on the quantization accuracy and data grouping information obtained in step 1, and the function is the inverse function of the function used in the quantization stage; use the nonlinear inverse transformation function to inversely transform the dequantized data; obtain the decompressed KV Cache data for reasoning.
[0224] Nonlinear inverse mapping and uniform inverse quantization can be combined into a table lookup step: based on the uniform inverse quantization method and the nonlinear inverse transformation function determined by step 3, a corresponding table of quantized values and floating-point values can be constructed. Inverse quantization can be completed through the numerical value and table of the quantized K data or V data to obtain the inverse quantized K data or V data.
[0225] When KV Cache data is needed, the quantized KV Cache data needs to be dequantized. The specific steps of the dequantization stage are as follows: obtain the quantized K data or V data, obtain the quantization accuracy (number of quantization bits) of the current KV quantized data, and the distribution information of the current K data or V data. The data distribution information is statistical values from the current K data or V data, such as the mean, variance, maximum value, minimum value, and range. The quantized KV cache data is uniformly dequantized using the same uniform quantization method as the quantization stage. The type and parameters of the nonlinear inverse transformation function are determined based on the obtained quantization accuracy and distribution information. The function is the inverse function of the function used in the quantization stage. The dequantized data is inversely transformed using the nonlinear inverse transformation function. The decompressed KV Cache data is obtained for inference.
[0226] Nonlinear inverse mapping and uniform inverse quantization can be combined into a table lookup step: based on the uniform inverse quantization method and the determined nonlinear inverse transformation function, a corresponding table of quantized values and floating-point values can be constructed. Inverse quantization can be completed through the numerical value and table of the quantized K data or V data to obtain the inverse quantized K data or V data.
[0227] Next, the beneficial effects of the embodiments of the present application are described in conjunction with experiments:
[0228] The wikitext2 validation set was tested on the Llama-7B model. The KV Cache data generated during inference was quantized using the non-uniform quantization method proposed in the present invention. Historically cached K or V data was dequantized when needed during inference. The compression rate and test perplexity (PPL) curves for a sequence length of 2048 are shown in Figure 7E. As can be seen from the figure, compared to uniform quantization, non-uniform quantization can achieve better inference performance while maintaining the same compression rate (lower PPL indicates better inference performance).
[0229] The wikitext2 validation set was tested on the Llama-7B model, and the KV Cache data generated during the inference process was quantized using the method of "quantization method for determining quantization mapping relationship according to quantization accuracy" proposed in the solution of the present invention. When the inference process needs to use historical cached K data or V data, it is dequantized. When the sequence length is 2048, the compression rate and test PPL curves are shown in Figure 7F. As can be seen from the figure, compared with using the preset non-uniform quantization, the quantization method for determining the quantization mapping relationship according to quantization accuracy can achieve better inference performance while maintaining the same compression rate (lower PPL means better inference performance).
[0230] It should be understood that the above-mentioned method for determining the nonlinear function and the uniform quantization method combined with the nonlinear function can be applied to the compression and decompression process of other data besides KV data. "Other data" can be, but is not limited to, data that needs to be reused in the machine learning model inference process.
[0231] Specifically, the present application provides a data processing method, which includes: obtaining first data, which is calculated by a machine learning model based on first input data; performing a nonlinear transformation on the first data through a nonlinear function to obtain the transformed first data; performing uniform quantization processing on the transformed first data to obtain first compressed data, and storing the first compressed data in a memory; reading the first compressed data from the memory, and performing an inverse transformation processing corresponding to the nonlinear transformation and an inverse quantization processing corresponding to the uniform quantization processing on the first compressed data to obtain second data, wherein the second data and the second input data are used to be input into the machine learning model, and the second input data is data input into the machine learning model after the first input data; wherein the category of the nonlinear function or the parameter values included are determined based on at least one of the following: the quantization accuracy of the first data; or the position of the network that generates the first data in the machine learning model; or the generation order of the first data in the machine learning model; or the data distribution of the first data.
[0232] In one possible implementation, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0233] In one possible implementation, the data unit of the first data can be converted into a corresponding quantization value based on a preset mapping relationship to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0234] In a possible implementation, when performing non-uniform quantization processing on the first data, a nonlinear transformation may be performed on the first data to obtain transformed first data; and uniform quantization processing may be performed on the transformed first data.
[0235] 8 , which is a schematic diagram of the structure of a data processing device provided in an embodiment of the present application. As shown in FIG8 , a data processing device provided in an embodiment of the present application, the device 800 includes:
[0236] An acquisition module 801 is configured to acquire first data, where the first data is obtained through a machine learning model based on first input data, and read first compressed data from the memory;
[0237] For a detailed description of the acquisition module 801 , reference may be made to the description of step 501 in the above embodiment, which will not be repeated here.
[0238] Processing module 802 is used to perform non-uniform quantization processing on the first data to obtain the first compressed data, store the first compressed data in a memory, and perform inverse quantization processing corresponding to the non-uniform quantization processing on the first compressed data to obtain second data. The second data and second input data are used to be input into the machine learning model, and the second input data is the data input into the machine learning model after the first input data.
[0239] For a detailed description of the acquisition module 801 , reference may be made to the description of steps 502 and 503 in the above embodiment, which will not be repeated here.
[0240] In one possible implementation, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0241] In a possible implementation, the processing module 802 is specifically configured to:
[0242] Based on a preset mapping relationship, the data unit of the first data is converted into a corresponding quantization value to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0243] In a possible implementation, the processing module 802 is specifically configured to:
[0244] performing a nonlinear transformation on the first data to obtain transformed first data;
[0245] Perform uniform quantization processing on the transformed first data.
[0246] In a possible implementation, the processing module 802 is further configured to:
[0247] According to the quantization accuracy of the first data, the type of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0248] In a possible implementation, the processing module 802 is further configured to:
[0249] According to the position of the network layer where the attention layer is located in the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0250] In one possible implementation, the first data is obtained according to the first input data by a target head in an attention layer of a machine learning model; and the processing module 802 is further configured to:
[0251] According to the position of the target head in the attention layer, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0252] In a possible implementation, the processing module 802 is further configured to:
[0253] According to the generation interval between the first data and the latest data obtained by the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
[0254] In a possible implementation, the processing module 802 is further configured to:
[0255] Based on the data distribution of the first data, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined; the data distribution is indicated by the distribution statistical information of the first data, or by an identifier, wherein different identifiers correspond to data distributions with different characteristics.
[0256] The present application also provides a data processing device, comprising:
[0257] an acquisition module, configured to acquire first data, where the first data is calculated based on the first input data through a machine learning model, and read the first compressed data from the memory;
[0258] A processing module is used to perform a nonlinear transformation on the first data through a nonlinear function to obtain the transformed first data; perform uniform quantization processing on the transformed first data to obtain first compressed data, and store the first compressed data in a memory, and perform inverse transformation processing corresponding to the nonlinear transformation and dequantization processing corresponding to the uniform quantization processing on the first compressed data to obtain second data, the second data and second input data are used to be input into the machine learning model, and the second input data is the data input into the machine learning model after the first input data.
[0259] In a possible implementation, the type of the nonlinear function or the parameter values included are determined based on at least one of the following:
[0260] Quantization accuracy of the first data; or
[0261] the position of the network that generated the first data in the machine learning model; or
[0262] The order in which the first data is generated in the machine learning model; or
[0263] Data distribution of the first data.
[0264] In one possible implementation, the first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0265] In a possible implementation, the processing module is specifically configured to:
[0266] Based on a preset mapping relationship, the data unit of the first data is converted into a corresponding quantization value to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
[0267] Next, a terminal device provided in an embodiment of the present application is introduced. Please refer to Figure 9. Figure 9 is a structural diagram of a terminal device provided in an embodiment of the present application. The terminal device 900 can be specifically manifested as a virtual reality VR device, a mobile phone, a tablet, a laptop computer, a smart wearable device, etc., which is not limited here. Specifically, the terminal device 900 includes: a receiver 901, a transmitter 902, a processor 903 and a memory 904 (wherein the number of processors 903 in the terminal device 900 can be one or more, and Figure 9 takes one processor as an example), wherein the processor 903 may include an application processor 9031 and a communication processor 9032. In some embodiments of the present application, the receiver 901, the transmitter 902, the processor 903 and the memory 904 may be connected via a bus or other means.
[0268] The memory 904 may include a read-only memory and a random access memory, and provides instructions and data to the processor 903. A portion of the memory 904 may also include non-volatile random access memory (NVRAM). The memory 904 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.
[0269] Processor 903 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.
[0270] The methods disclosed in the above embodiments of the present application can be applied to or implemented by the processor 903. The processor 903 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by hardware integrated logic circuits in the processor 903 or by software instructions. The above processor 903 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and can further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 903 can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of the present application can be directly implemented as being executed by a hardware decoding processor, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 904. Processor 903 reads information from memory 904 and, in conjunction with its hardware, completes the steps involved in the model training or model inference process in the above method.
[0271] Receiver 901 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 902 can be used to output digital or character information through the first interface. Transmitter 902 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 902 can also include a display device such as a display screen.
[0272] The embodiment of the present application also provides a server. Please refer to Figure 10. Figure 10 is a structural diagram of a server provided by an embodiment of the present application. The server 1000 may have relatively large differences due to different configurations or performances. It may include one or more central processing units (CPUs) 1010 (for example, one or more processors) and a memory 1032, and one or more storage media 1030 (for example, one or more mass storage devices) for storing application programs 1042 or data 1044. Among them, the memory 1032 and the storage medium 1030 can be temporary storage or permanent storage. The program stored in the storage medium 1030 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1010 can be configured to communicate with the storage medium 1030 to execute a series of instruction operations in the storage medium 1030 on the server 1000.
[0273] The server 1000 may also include one or more power supplies 1026, one or more wired or wireless network interfaces 1050, one or more input and output interfaces 1058; or one or more operating systems 1041, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0274] In an embodiment of the present application, the central processing unit 1010 is used to execute actions related to model training or model reasoning in the above embodiments.
[0275] An embodiment of the present application also provides a computer program product, which, when running on a computer, enables the computer to execute the steps executed by the aforementioned execution device, or enables the computer to execute the steps executed by the aforementioned training device.
[0276] A computer-readable storage medium is also provided in an embodiment of the present application, which stores a program for signal processing. When the computer-readable storage medium is run on a computer, it enables the computer to execute the steps executed by the aforementioned execution device, or enables the computer to execute the steps executed by the aforementioned training device.
[0277] The execution device, training device or terminal device provided in the embodiments of the present application can specifically be a chip, and the chip includes: a processing unit and a communication unit, the processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, a pin or a circuit, etc. The processing unit can execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the data processing method described in the above embodiment, or so that the chip in the training device executes the data processing method described in the above embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit can also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.
[0278] Specifically, see Figure 11, which is a schematic diagram of the structure of a chip provided in an embodiment of the present application. The chip can be represented as a neural network processor NPU 1100. NPU 1100 is mounted on the host CPU (host CPU) as a coprocessor and is assigned tasks by the host CPU. The core of the NPU is arithmetic circuit 1103, which is controlled by controller 1104 to extract matrix data from memory and perform multiplication operations.
[0279] In some implementations, the arithmetic circuit 1103 includes multiple processing units (PEs). In some implementations, the arithmetic circuit 1103 is a two-dimensional systolic array. The arithmetic circuit 1103 may also be a one-dimensional systolic array or other electronic circuitry capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit 1103 is a general-purpose matrix processor.
[0280] For example, assume there are input matrix A, weight matrix B, and output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from weight memory 1102 and caches it on each PE in the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from input memory 1101 and performs a matrix operation on matrix B. The partial or final matrix result is stored in accumulator 1108.
[0281] Unified memory 1106 is used to store input and output data. Weight data is directly transferred to weight memory 1102 through the Direct Memory Access Controller (DMAC) 1105. Input data is also transferred to unified memory 1106 through the DMAC.
[0282] BIU stands for Bus Interface Unit, i.e., bus interface unit 1110 , which is used for interaction between the AXI bus, DMAC, and instruction fetch buffer (IFB) 1109 .
[0283] The bus interface unit 1110 (BIU) is used for the instruction fetch memory 1109 to obtain instructions from the external memory, and is also used for the storage unit access controller 1105 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
[0284] DMAC is mainly used to move input data in the external memory DDR to the unified memory 1106 or to move weight data to the weight memory 1102 or to move input data to the input memory 1101.
[0285] The vector calculation unit 1107 includes multiple operation processing units. When necessary, it further processes the output of the operation circuit 1103, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for non-convolutional / fully connected layer network calculations in neural networks, such as batch normalization, pixel-level summation, and upsampling of feature planes.
[0286] In some implementations, the vector calculation unit 1107 can store the processed output vector in the unified memory 1106. For example, the vector calculation unit 1107 can apply a linear function or a nonlinear function to the output of the operation circuit 1103, such as linear interpolation of the feature plane extracted by the convolution layer, or accumulate a vector of values to generate an activation value. In some implementations, the vector calculation unit 1107 generates a normalized value, a pixel-level summed value, or both. In some implementations, the processed output vector can be used as an activation input to the operation circuit 1103, for example, for use in subsequent layers in a neural network.
[0287] An instruction fetch buffer 1109 connected to the controller 1104 is used to store instructions used by the controller 1104;
[0288] Unified memory 1106, input memory 1101, weight memory 1102, and instruction fetch memory 1109 are all on-chip memories. External memories are private to the NPU hardware architecture.
[0289] The processor mentioned in any of the above places can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the above program.
[0290] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.
[0291] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.
[0292] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0293] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website, a computer, a training device or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
Claims
1. A data processing method, characterized in that: The method comprises: Obtaining first data, where the first data is obtained through a machine learning model based on first input data; Performing non-uniform quantization processing on the first data to obtain first compressed data, and storing the first compressed data in a memory; The first compressed data is read from the memory, and the first compressed data is subjected to inverse quantization processing corresponding to the non-uniform quantization processing to obtain second data. The second data and the second input data are used to be input into the machine learning model. The second input data is the data input into the machine learning model after the first input data.
2. The method according to claim 1, characterized in that The first data is K data or V data.
3. The method according to claim 1 or 2, characterized in that The first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
4. The method according to any one of claims 1 to 3, characterized in that: The performing non-uniform quantization processing on the first data to obtain first compressed data includes: Based on a preset mapping relationship, the data unit of the first data is converted into a corresponding quantization value to obtain first compressed data; wherein, the mapping relationship includes multiple numerical intervals and the quantization value corresponding to each numerical interval, the data unit of the first data includes data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, the multiple numerical intervals include a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
5. The method according to any one of claims 1 to 4, characterized in that: The performing non-uniform quantization processing on the first data to obtain first compressed data includes: performing a nonlinear transformation on the first data to obtain transformed first data; Perform uniform quantization processing on the transformed first data.
6. The method according to claim 5, characterized in that The method further comprises: According to the quantization accuracy of the first data, the type of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
7. The method according to claim 5 or 6, characterized in that The first data is obtained by an attention layer of a machine learning model based on the first input data, and the method further includes: According to the position of the network layer where the attention layer is located in the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
8. The method according to any one of claims 5 to 7, characterized in that: The first data is obtained according to the first input data by a target head in an attention layer of a machine learning model; the method further includes: According to the position of the target head in the attention layer, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
9. The method according to any one of claims 5 to 8, characterized in that: The method further comprises: According to the generation interval between the first data and the latest data obtained by the machine learning model, the category of the nonlinear function used when performing a nonlinear transformation on the first data or the parameter values included are determined.
10. The method according to any one of claims 5 to 9, characterized in that: The method further comprises: According to the data distribution of the first data, the category of the nonlinear function used when performing a nonlinear transformation on the first data or the parameter values included are determined; the data distribution is indicated by the distribution statistical information of the first data, or by an identifier, wherein different identifiers correspond to data distributions with different characteristics.
11. A data processing method, characterized in that: The method comprises: Obtaining first data, where the first data is calculated using a machine learning model based on first input data; Performing a nonlinear transformation on the first data using a nonlinear function to obtain transformed first data; Performing uniform quantization processing on the transformed first data to obtain first compressed data, and storing the first compressed data in a memory; The first compressed data is read from the memory, and the first compressed data is subjected to inverse transformation processing corresponding to the nonlinear transformation and dequantization processing corresponding to the uniform quantization processing to obtain second data. The second data and the second input data are used to be input into the machine learning model. The second input data is the data input into the machine learning model after the first input data.
12. The method according to claim 11, characterized in that The type of the nonlinear function or the parameter values included are determined based on at least one of the following: Quantization accuracy of the first data; or the position of the network that generated the first data in the machine learning model; or The order in which the first data is generated in the machine learning model; or Data distribution of the first data.
13. A data processing device, characterized in that: The device comprises: an acquisition module, configured to acquire first data, where the first data is obtained through a machine learning model based on first input data, and read first compressed data from the memory; A processing module is used to perform non-uniform quantization processing on the first data to obtain the first compressed data, and store the first compressed data in a memory, and perform inverse quantization processing corresponding to the non-uniform quantization processing on the first compressed data to obtain second data, and the second data and second input data are used to be input into the machine learning model, and the second input data is data input into the machine learning model after the first input data.
14. The device according to claim 13, characterized in that The first data includes multiple data units, the first compressed data includes a quantization value corresponding to each of the data units, the data units of the first data include data in a first numerical range and data in a second numerical range, the data in the first numerical range is denser than the data in the second numerical range, and the quantization value corresponding to the data interval where each of the data units is located is used as the quantization value corresponding to the data unit, wherein the numerical interval includes a first numerical interval and a second numerical interval, the first numerical interval belongs to the first numerical range, the second numerical interval belongs to the second numerical range, and the numerical width of the first numerical interval is smaller than the numerical width of the second numerical interval.
15. The device according to claim 13 or 14, characterized in that The processing module is specifically used to: performing a nonlinear transformation on the first data to obtain transformed first data; Perform uniform quantization processing on the transformed first data.
16. The device according to claim 15, characterized in that The processing module is further configured to: According to the quantization accuracy of the first data, the type of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
17. The device according to claim 15 or 16, characterized in that The processing module is further configured to: According to the position of the network layer where the attention layer is located in the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
18. The device according to any one of claims 15 to 17, characterized in that The first data is K data and V data obtained by the target head in the attention layer of the machine learning model according to the first input data; the processing module is further used to: According to the position of the target head in the attention layer, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
19. The device according to any one of claims 15 to 18, characterized in that The processing module is further configured to: According to the generation interval between the first data and the latest data obtained by the machine learning model, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined.
20. The device according to any one of claims 15 to 19, characterized in that The processing module is further configured to: Based on the data distribution of the first data, the category of the nonlinear function used when performing the nonlinear transformation or the parameter values included are determined; the data distribution is indicated by the distribution statistical information of the first data, or by an identifier, wherein different identifiers correspond to data distributions with different characteristics.
21. A data processing device, characterized in that: The device comprises: an acquisition module, configured to acquire first data, where the first data is calculated based on the first input data through a machine learning model, and read the first compressed data from the memory; A processing module is used to perform a nonlinear transformation on the first data through a nonlinear function to obtain the transformed first data; perform uniform quantization processing on the transformed first data to obtain the first compressed data, and store the first compressed data in a memory, and perform inverse transformation processing corresponding to the nonlinear transformation and dequantization processing corresponding to the uniform quantization processing on the first compressed data to obtain second data. The second data and second input data are used to be input into the machine learning model, and the second input data is the data input into the machine learning model after the first input data.
22. The device according to claim 21, characterized in that The type of the nonlinear function or the parameter values included are determined based on at least one of the following: Quantization accuracy of the first data; or the position of the network that generated the first data in the machine learning model; or The order in which the first data is generated in the machine learning model; or Data distribution of the first data.
23. A computer storage medium, characterized in that The computer storage medium stores one or more instructions that, when executed by one or more computers, cause the one or more computers to perform the operations of the method of any one of claims 1 to 12.
24. A computer program product, characterized in that The method comprises computer-readable instructions, which, when executed on a computer device, cause the computer device to execute the method according to any one of claims 1 to 12.
25. A system comprising at least one processor and at least one memory; The at least one processor and the at least one memory are connected via a communication bus; The at least one memory is used to store code; The at least one processor is configured to execute the code to perform the method according to any one of claims 1 to 12.
26. A chip comprising a processor, characterized in that: The processor is configured to implement the method according to any one of claims 1 to 12.