Data processing method, data processing device, many-core system, equipment and medium
By compressing and storing the key-value information of the attention network module in the large language model, the major storage and bandwidth overhead caused by the growth of key-value cache information in the self-attention mechanism operation is solved, and data processing efficiency is improved.
Patent Information
- Application Number
- CN202411096832.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-11-22
AI Technical Summary
During the self-attention mechanism operation of the large language model, key-value cache information (KV-cache) continues to grow, resulting in large overhead of storage resources and bandwidth, and existing quantized processing methods cannot meet the needs.
During the data processing of the preset model, the attention network module in the current decoded state compresses and stores the key value information of the previous decoded state, loads and decompresses during the decoding process, and uses the target query vectors, key vectors and values to query vectors, key vectors and values. The vector is processed, generates incremental key-value information and stores it to reduce storage and bandwidth usage.
It effectively reduces storage resources and bandwidth usage, improves data processing efficiency, and performs loading, decompressing and computing of key-value cache compressed information in parallel.
Smart Images

Figure CN119003594A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a data processing method, a data processing device, a many-core system, an electronic device, and a computer-readable storage medium. Background Art
[0002] Large language models are important models in the field of natural language processing. Currently, the more mainstream large language models are based on the Transformer architecture, which mainly consists of an input part, an encoder, a decoder, and an output part. The self-attention mechanism (SA) is one of the keys to the Transformer architecture. The self-attention mechanism can capture the global dependencies of the input sequence and help to accurately process contextual information. When processing data based on the self-attention mechanism, certain computing resources, bandwidth resources, etc. are required as resource support. Summary of the invention
[0003] The present disclosure provides a data processing method, a data processing device, a many-core system, an electronic device, and a computer-readable storage medium.
[0004] In a first aspect, the present disclosure provides a data processing method, which is applied to a preset model, wherein the preset model includes at least one attention network module, and the data processing method includes: for any attention network module in a current decoding state, determining the target query vector, target key vector and target value vector of the attention network module according to the input hidden state sequence of the attention network module; obtaining the key value cache compression information of the attention network module in a previous decoding state from a preset space, and decompressing the key value cache compression information of the previous decoding state to obtain the key value cache information of the previous decoding state; processing according to the key value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module; obtaining incremental key value cache compression information according to the target key vector and the target value vector, and storing the incremental key value cache compression information in the preset space to obtain the key value cache compression information of the attention network module in the current decoding state.
[0005] In a second aspect, the present disclosure provides a data processing device, which is applied to a preset model, wherein the preset model includes at least one attention network module, and the data processing device includes: a determination module, which is used to determine the target query vector, target key vector and target value vector of the attention network module according to the input hidden state sequence of the attention network module for any attention network module in the current decoding state; a decompression module, which is used to obtain the key value cache compression information of the attention network module in the previous decoding state from the preset space, and decompress the key value cache compression information of the previous decoding state to obtain the key value cache information of the previous decoding state; a processing module, which is used to process according to the key value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module; a compression module, which is used to obtain the incremental key value cache compression information according to the target key vector and the target value vector; a storage module, which is used to store the incremental key value cache compression information in the preset space to obtain the key value cache compression information of the attention network module in the current decoding state.
[0006] In a third aspect, the present disclosure provides a many-core system, which includes: multiple processing cores; the many-core system is used to execute the data processing method as described in any one of the embodiments of the present disclosure.
[0007] In a fourth aspect, the present disclosure provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores one or more computer programs executable by the at least one processor, and one or more of the computer programs are executed by the at least one processor so that the at least one processor can execute the data processing method described in any one of the embodiments of the present disclosure.
[0008] In a fifth aspect, the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor / processing core, implements the data processing method described in any one of the embodiments of the present disclosure.
[0009] In a sixth aspect, the present disclosure provides a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying a computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the data processing method described in any one of the embodiments of the present disclosure.
[0010] The embodiments provided by the present disclosure can be applied to a preset module, which includes at least one attention network module. For any attention network module in the current decoding state, the target query vector, target key vector and target value vector of the attention network module are determined according to the input hidden state sequence of the attention network module; the key value cache compression information of the attention network module in the previous decoding state is obtained from the preset space, and the key value cache compression information of the previous decoding state is decompressed to obtain the key value cache information of the previous decoding state; the key value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector are processed to obtain the output hidden state sequence of the attention network module; the incremental key value cache compression information is obtained according to the target key vector and the target value vector, and the incremental key value cache compression information is stored in the preset space to obtain the key value cache compression information of the attention network module in the current decoding state.
[0011] It can be seen that in the embodiment of the present disclosure, in the data processing process of executing the preset model, for any attention network module in the current decoding state, the key value information generated in the previous processing process is compressed and stored in the preset space, and the key value cache compression information of the previous decoding state is obtained. Since the key value cache compression information of the previous decoding state is compressed information, the amount of data is effectively reduced, thereby reducing the occupation of storage resources; in addition, when the key value cache compression information of the previous decoding state is needed in the current decoding process, the key value cache compression information of the attention network module in the previous decoding state is loaded from the preset space. , decompress to obtain the decompressed key-value cache information, and calculate based on the decompressed key-value cache information and the corresponding target query vector, target key vector and target value vector to obtain the output hidden state sequence of the attention network module, and then obtain the incremental key-value cache compression information according to the target key vector and target value vector, and store the incremental key-value cache compression information in the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state, wherein, since the key-value cache compression information of the current iteration state transmitted to the preset space is still compressed information, the bandwidth requirement is also reduced accordingly, which can reduce the occupation of bandwidth resources. Furthermore, since the loading, decompression and corresponding calculation of the key-value cache compression information can be performed in parallel, the data processing efficiency can be effectively improved.
[0012] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the embodiments of the present disclosure, they are used to explain the present disclosure and do not constitute a limitation of the present disclosure. The above and other features and advantages will become more apparent to those skilled in the art by describing detailed example embodiments with reference to the accompanying drawings, in which:
[0014] Figure 1 A flowchart of a data processing method provided in an embodiment of the present disclosure.
[0015] Figure 2 A schematic diagram of loading and decompressing key-value cache compressed information provided in an embodiment of the present disclosure.
[0016] Figure 3 A schematic diagram of a data processing method based on incremental calculation provided in an embodiment of the present disclosure.
[0017] Figure 4 A schematic diagram of a data processing method based on block calculation method provided in an embodiment of the present disclosure.
[0018] Figure 5 A schematic diagram of a process for updating key-value cache compression information provided in an embodiment of the present disclosure.
[0019] Figure 6 A schematic diagram of a processing procedure of a data processing method provided in an embodiment of the present disclosure.
[0020] Figure 7 A schematic diagram of a data processing method based on a many-core system provided in an embodiment of the present disclosure.
[0021] Figure 8 A block diagram of a data processing device provided in an embodiment of the present disclosure.
[0022] Fig. 9 A block diagram of a many-core system provided in an embodiment of the present disclosure.
[0023] Fig.10 A block diagram of an electronic device based on a single processor provided in Embodiment 1 of the present disclosure.
[0024] Fig.11 A block diagram of an electronic device based on multiple processing cores provided in Embodiment 2 of the present disclosure. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, those of ordinary skill in the art should recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0026] In the absence of conflict, the various embodiments of the present disclosure and the various features therein may be combined with each other.
[0027] As used herein, the term "and / or" includes any and all combinations of one or more of the associated listed items.
[0028] The terms used herein are only used to describe specific embodiments and are not intended to limit the present disclosure. As used herein, the singular forms "a" and "the" are also intended to include plural forms, unless the context clearly indicates otherwise. It will also be understood that when the terms "including" and / or "made of" are used in this specification, the presence of the features, wholes, steps, operations, elements and / or components is specified, but the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or groups thereof is not excluded. "Connected" or "connected" and similar words are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect.
[0029] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as commonly understood by those of ordinary skill in the art. It will also be understood that terms such as those defined in commonly used dictionaries should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and will not be interpreted as having an idealized or overly formal meaning unless explicitly defined as such herein.
[0030] The current mainstream large language models are all built on the Transformer architecture (a model architecture that uses an attention mechanism to replace the traditional recurrent neural network structure). The attention mechanism (for example, the self-attention mechanism) is one of the keys to the Transformer. When performing self-attention mechanism operations, the input data includes the query vector (or query matrix) Q, the key vector (or key matrix) K, and the value vector (or value matrix) V. For incremental computing (incremental reasoning) scenarios, the key-value cache information (KV-cache) continues to grow during the decoding phase.
[0031] When using the incremental calculation method, all KV-caches need to be read each time to participate in the calculation, and the key-value data of the current iteration state needs to be generated. The newly generated key-value data needs to be merged into the KV-cache and stored together, so as to continuously update the KV-cache. When executing data processing for multiple users (large batch size) or long contexts, the KV-cache will also become larger. This is because each user has an independent KV-cache, so the total amount of KV-cache increases with the number of users; the longer the context, the KV-cache will also increase proportionally. Since the amount of KV-cache data is large, and each execution of the hidden state sequence of the attention network module requires reading the KV-cache from the external memory to the computing unit, the memory bandwidth overhead is very large. For example, the Double Data Rate (DDR) memory bandwidth is usually tens of GB / s (gigabytes per second), but the KV-cache can reach the TB / s level (terabytes per second), and the memory bandwidth pressure of DDR is relatively large.
[0032] To alleviate the above problems, the KV-cache can be quantized before storage (for example, converting 16-bit floating point numbers (fp16) into 8-bit integers (int8) or 4-bit integers (int4) data). However, this method has limited impact on the amount of KV-cache data and may still not meet usage requirements.
[0033] In view of this, embodiments of the present disclosure provide a data processing method, a data processing device, a many-core system, an electronic device, and a computer-readable storage medium.
[0034] In the embodiment of the present disclosure, during the data processing process of executing the preset model, for any attention network module in the current decoding state, the key value information generated in the previous processing process is compressed and stored in the preset space, and the key value cache compression information of the previous decoding state is obtained. Since the key value cache compression information of the previous decoding state is compressed information, the amount of data is effectively reduced, thereby reducing the occupation of storage resources; in addition, when the key value cache compression information of the previous decoding state is needed in the current decoding process, the key value cache compression information of the attention network module in the previous decoding state is loaded from the preset space, and the key value cache compression information of the previous decoding state is loaded from the preset space. Decompress the decompressed key-value cache information, and perform calculations based on the decompressed key-value cache information and the corresponding target query vector, target key vector, and target value vector to obtain the output hidden state sequence of the attention network module. Then, based on the target key vector and target value vector, obtain the incremental key-value cache compression information, and store the incremental key-value cache compression information in the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state, wherein, since the key-value cache compression information of the current iteration state transmitted to the preset space is still compressed information, the bandwidth requirement is also reduced accordingly, which can reduce the amount of bandwidth resources occupied. Furthermore, since the loading, decompression, and corresponding calculations of the key-value cache compression information can be performed in parallel, the data processing efficiency can be effectively improved.
[0035] A first aspect of an embodiment of the present disclosure provides a data processing method.
[0036] Figure 1 A flowchart of a data processing method provided in an embodiment of the present disclosure is applied to a preset model, wherein the preset model includes at least one attention network module. Figure 1 , the data processing method may include the following steps.
[0037] Step S11, for any attention network module in the current decoding state, determine the target query vector, target key vector and target value vector of the attention network module according to the input hidden state sequence of the attention network module.
[0038] Step S12, obtaining the key-value cache compression information of the attention network module in the previous decoding state from the preset space, and decompressing the key-value cache compression information of the previous decoding state to obtain the key-value cache information of the previous decoding state.
[0039] Step S13, processing is performed according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module.
[0040] Step S14, obtaining incremental key-value cache compression information according to the target key vector and the target value vector, and storing the incremental key-value cache compression information in a preset space to obtain the key-value cache compression information of the attention network module in the current decoding state.
[0041] It can be seen that for the preset model, it may include one or more attention network modules, and the process of each attention network module when performing attention processing is similar, and each attention network module may need to repeat multiple rounds of processing. The input and output of each round of processing are different, but the processing process is similar. Based on this, for each attention network module, in each round of iterative processing, the historically generated key-value cache information can be compressed and stored in the preset space for backup, and the new key-value cache information is also compressed after it is generated, and the newly generated part of the compressed information is merged with the previously stored key-value cache compressed information to obtain the updated key-value cache compressed information for backup. By compressing and storing the key-value cache information, the amount of storage resources and bandwidth resources occupied by this part of the data can be reduced, the corresponding resource overhead can be reduced, and the performance requirements for related hardware devices (for example, hardware devices that execute the data processing method of the embodiment of the present disclosure) can be reduced, so that some hardware devices that were originally unable to perform corresponding data processing have the ability to perform data processing.
[0042] That is, in the disclosed embodiment, for any attention network module, when performing the i-th (i>1) decoding process, on the one hand, it is necessary to determine the target query vector Q(i-1), target key vector K(i-1) and target value vector V(i-1) of the attention network module according to the i-th input hidden state sequence, and on the other hand, it is necessary to load the compressed KV-Cache(i-1) (i.e., the key value cache compression information of the attention network module in the previous decoding state) from the external storage space (such as the preset space), and decompress KV-Cache(i-1) to obtain KV-Cache(i-1)′ (i.e., the key value cache information of the previous decoding state), and then based on Q(i- 1), K(i-1), V(i-1) and KV-Cache(i-1)′ perform attention mechanism calculation, obtain △KV-Cache(i) (i.e., information obtained by compressing K(i-1) and V(i-1)) and the i-th output hidden state sequence of the attention network module, and use △KV-Cache(i) to update the original KV-Cache(i-1) to obtain KV-Cache(i) (i.e., the key value cache compression information of the attention network module in the current decoding state), and store KV-Cache(i) in the external storage space, so as to perform the i+1-th decoding process using KV-Cache(i) and the i+1-th input hidden state sequence. Among them, the i+1-th decoding process is similar to the i-th decoding process, and will not be described in detail here.
[0043] It should be noted that in some optional implementations, in step S12, obtaining the key-value cache compression information of the attention network module in the previous decoding state from the preset space and decompressing the key-value cache compression information of the previous decoding state can be performed in parallel, and the loading and decompression operations of the compressed data are performed in a pipeline execution manner. Among them, the data participating in the decompression or being decompressed is the key-value cache compression information of the previous decoding state that has been loaded, and during the decompression process, the key-value cache compression information of the previous decoding state that has not been loaded is continued to be obtained from the preset space.
[0044] Similarly, in some optional implementations, for step S12 and step S13, for any attention network module, the key-value cache compressed information of the previous decoding state can be decompressed while corresponding data processing is performed based on the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector, that is, the attention mechanism calculation of the decompressed data and the loading of compressed data is performed in a pipeline execution manner. Among them, the key-value cache information of the previous decoding state involved in data processing is the part of the key-value cache compressed information of the previous decoding state that has been decompressed, and, in the process of executing data processing, the key-value cache compressed information of the previous decoding state that has not been decompressed continues to be decompressed.
[0045] Furthermore, the loading of the key-value cache compressed information of the previous decoding state, the decompression of the key-value cache compressed information of the previous decoding state, and the data processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector can be performed in parallel, that is, the loading of compressed data, the decompression of compressed data and the attention mechanism calculation of the decompressed data are performed in a pipeline execution mode. Through the above parallel execution mode, the time consumption of data processing can be reduced, thereby improving the data processing efficiency.
[0046] The embodiments provided by the present disclosure are as follows: for any attention network module in a preset model that is in a current decoding state, a target query vector, a target key vector, and a target value vector are obtained according to the input hidden state sequence of the attention network module; the key value cache compression information of the attention network module in the previous decoding state is obtained from the preset space, and the key value cache compression information of the previous decoding state is decompressed to obtain the key value cache information of the previous decoding state; the key value cache information of the previous decoding state, the target query vector, the target key vector, and the target value vector are processed to obtain the output hidden state sequence of the attention network module; the incremental key value cache compression information is obtained according to the target key vector and the target value vector, and the incremental key value cache compression information is stored in the preset space to obtain the key value cache compression information of the attention network module in the current decoding state.
[0047] It can be seen that in the embodiment of the present disclosure, in the data processing process of executing the preset model, for any attention network module in the current decoding state, the key value information generated in the previous processing process is compressed and stored in the preset space, and the key value cache compression information of the previous decoding state is obtained. Since the key value cache compression information of the previous decoding state is compressed information, the amount of data is effectively reduced, thereby reducing the occupation of storage resources; in addition, when the key value cache compression information of the previous decoding state is needed in the current decoding process, the key value cache compression information of the attention network module in the previous decoding state is loaded from the preset space. , decompress to obtain the decompressed key-value cache information, and calculate based on the decompressed key-value cache information and the corresponding target query vector, target key vector and target value vector to obtain the output hidden state sequence of the attention network module, and then obtain the incremental key-value cache compression information according to the target key vector and target value vector, and store the incremental key-value cache compression information in the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state, wherein, since the key-value cache compression information of the current iteration state transmitted to the preset space is still compressed information, the bandwidth requirement is also reduced accordingly, which can reduce the occupation of bandwidth resources. Furthermore, since the loading, decompression and corresponding calculation of the key-value cache compression information can be performed in parallel, the data processing efficiency can be effectively improved.
[0048] The data processing method of the embodiment of the present disclosure is described below.
[0049] In some optional implementations, the preset model is a model that can be used to perform a preset task, and the preset model may include one or more attention network modules, each of which can be used to perform operations of a corresponding attention mechanism; exemplarily, the attention network module includes an attention processing layer and a forward feedback layer.
[0050] Furthermore, the preset task may be a translation task, a question-answering task, etc., which is mainly used to output text data that matches or corresponds to the input data. Accordingly, the preset model may include a translation model, a question-answering model, etc. Before outputting the text data, a decoding operation is usually required to determine the corresponding target word by decoding.
[0051] For example, the preset task is a question-answering task, and the input data is "What color is the sky?". Using the preset model and performing multiple decodings through the attention network model, the output answer is "The sky is blue."
[0052] In some optional implementations, in step S11, for any attention network module in the current decoding state, the target query vector, target key vector and target value vector of the attention network module are determined according to the input hidden state sequence of the attention network module, including: performing a linear transformation on the input hidden state sequence of the attention network module to obtain the target query vector, target key vector and target value vector of the attention network module.
[0053] Among them, considering that the processing process of the attention network module usually has iterative characteristics, the concept of decoding state is set, and the number of iterations in the decoding process is identified based on the decoding state, so as to more intuitively and conveniently understand and describe the specific processing process of the data processing method of the embodiment of the present disclosure. Exemplarily, the current decoding state represents the number of decoding iterations or decoding iteration process currently corresponding to the attention network module; the previous decoding state corresponds to the previous decoding iteration number of the attention network module relative to the current decoding iteration number, or the previous decoding iteration process of the attention network module relative to the current decoding iteration process; similarly, the next decoding state corresponds to the next decoding iteration number of the attention network module relative to the current decoding iteration number, or the next decoding iteration process of the attention network module relative to the current decoding iteration process.
[0054] For example, if the current decoding state corresponds to the i-th decoding iteration process (i>1), the previous decoding state corresponds to the i-1-th decoding iteration process, the next decoding state corresponds to the i+1-th decoding iteration process, and so on.
[0055] Furthermore, hidden state sequence is an important concept in neural networks, which can be used to store and transmit internal states of information, and can be updated based on time steps to capture information and contextual relationships in the input sequence. The input hidden state sequence refers to the hidden state sequence input to the attention network module, and correspondingly, the output hidden state sequence refers to the hidden sequence output by the attention network module. And, usually, the output hidden state sequence is the hidden state sequence obtained according to the attention processing result after the attention network module performs attention calculation and other processing on the input hidden state sequence. And, for any attention network module, its output hidden state sequence can capture information features and contextual relationships more accurately and deeply than its input hidden state sequence.
[0056] For example, the input hidden state sequence I(1) of the first attention network module in the preset model can be obtained by performing word segmentation, encoding and other processing according to the input text sequence. After the attention network model performs self-attention mechanism processing on the input hidden state sequence I(1), the output hidden state sequence O(1) generated by the first attention network module can be output to the outside; further, the second attention network module adjacent to the first attention network module can use the output hidden state sequence O(1) of the first attention network module as its input hidden state sequence I(2), and after the second attention network module performs self-attention mechanism processing on the input hidden state sequence I(2), the output hidden state sequence O(2) generated by the second attention network module is output to the outside, and so on.
[0057] Exemplarily, the input hidden state sequence of the previous decoding state is represented by I, and its corresponding target query vector Query, target key vector Key and target value vector Value can be represented as:
[0058] Query = I × W (Q)
[0059] Key=I×W(K)
[0060] Value = I × W (V)
[0061] Among them, W(Q) is the first linear transformation matrix, W(K) is the second linear transformation matrix, and W(V) is the third linear transformation matrix.
[0062] Furthermore, after or while executing step S11, the key-value cache compression information of the attention network module in the previous decoding state can be obtained from the preset space, and the key-value cache compression information of the previous decoding state can be decompressed to obtain the key-value cache information of the previous decoding state. Among them, the preset space belongs to the external space relative to the hardware device that performs the preset model data processing. If the hardware device that performs the preset model data processing is a multi-core chip, the preset space belongs to the off-chip storage space. In other words, the key-value cache compression information in the embodiment of the present disclosure is stored off-chip, and reading the key-value cache compression information is also read from off-chip to on-chip, the purpose of which is to save input / output IO bandwidth and improve the data loading speed on and off-chip.
[0063] For example, the preset space may be an off-chip double data rate synchronous dynamic random access memory (Double Data Rate, DDR), etc., and the embodiments of the present disclosure are not limited to this.
[0064] It should be noted that the key-value cache compression information KV-Cache is mainly information generated by compressing the key-value pair (Key: Value, KV). By pre-caching KV-Cache, it is possible to avoid recalculating all key-value vectors each time the attention mechanism is processed, thereby reducing the amount of calculation and improving data processing efficiency. In addition, in the disclosed embodiment, in order to minimize the storage space required to store the key-value cache information and the bandwidth resources required to transmit the key-value cache information, the key-value cache information will be compressed first, and then the compressed key-value cache information (i.e., key-value cache compression information) will be stored and transmitted.
[0065] In some optional implementations, key-value cache compression information of the attention network module in a previous decoding state is obtained from a preset space, and the key-value cache compression information of the previous decoding state is decompressed to obtain the key-value cache information of the previous decoding state, including: reading the key-value cache compression information of the attention network module in the previous decoding state from the preset space based on a streaming reading method; decompressing the key-value cache compression information that has been read based on a streaming decompression method to obtain at least part of the key-value cache information of the previous decoding state.
[0066] Streaming reading is a method of reading data gradually, which can divide the data into multiple blocks or segments for processing. Compared with reading all the data at once, streaming reading has higher efficiency and lower memory consumption. Streaming decompression is a technology for processing compressed data, which allows decompression of data while downloading compressed data, thereby reducing the time to wait for decompression after the download is completed.
[0067] In some optional implementations, the streaming reading method and the streaming decompression method can be executed in parallel. That is, while loading new key-value cache compression information, the already loaded key-value cache compression information can be decompressed. This parallel execution method can further improve data processing efficiency and shorten data processing time.
[0068] In some optional implementations, the key-value cache compression information includes at least one storage block, each storage block stores at least part of the key-value cache compression information; accordingly, the key-value cache compression information is read from the preset space based on the streaming reading method, including: based on the streaming reading method, reading the storage blocks corresponding to the key-value cache compression information from the preset space in sequence; based on the streaming decompression method, decompressing the key-value cache compression information that has been read to obtain at least part of the key-value cache information in the previous decoding state, including: based on the streaming decompression method, decompressing the storage block that has been read to obtain the key-value cache information corresponding to the storage block that has been read.
[0069] Figure 2 A schematic diagram of loading and decompressing key-value cache compressed information provided by an embodiment of the present disclosure. Figure 2 , the key-value cache compression information of the attention network module in the previous decoding state includes N storage blocks, namely storage block 1, storage block 2, ..., storage block N, where N is an integer greater than or equal to 1.
[0070] Exemplarily, N storage blocks are pre-stored in a preset space, and when the data processing device needs to load the key-value cache compression information of the attention network module in the previous decoding state from the preset space, the data processing device uses a streaming reading method to read the storage blocks from the preset space in sequence; wherein the data processing device is a device for executing the data processing method of the embodiment of the present disclosure. For example, the data processing device reads storage block 1, storage block 2, ..., storage block N from the preset space in sequence.
[0071] For a data processing device, after reading out a storage block, the storage block can be decompressed to obtain a corresponding decompressed storage block, so as to use the decompressed storage block to perform subsequent data processing. For example, after reading out storage block 1, the data processing device reads storage block 2 from the preset space while decompressing storage block 1 to obtain a decompressed storage block 1; ...; after reading out storage block i-1, the data processing device reads storage block i from the preset space while decompressing storage block i-1 to obtain a decompressed storage block i-1; ...; and so on, until the last storage block N is read out, and storage block N is decompressed to obtain a decompressed storage block N.
[0072] It should be noted that the key vector and the value vector in the key-value cache compression information may be stored independently or combined, and the embodiments of the present disclosure do not limit this.
[0073] In some optional implementations, the storage block includes a first storage block, the first storage block includes at least one compression history key vector and at least one compression history value vector; or, the storage block includes a second storage block and a third storage block, the second storage block includes at least one compression history key vector, and the third storage block includes at least one compression history value vector.
[0074] For example, each first storage block includes a compressed historical key-value pair, and a compressed historical key-value pair corresponds to a compressed historical key vector and a compressed historical value vector; for example, each first storage block includes multiple compressed historical key-value pairs.
[0075] In some optional implementations, considering that the data type and amount of data stored in each storage block may be different, and the data in each storage block is compressed data, this compression may cause the actual storage size of each storage block to be inconsistent. Therefore, the storage address of each storage block can be recorded through an address index information, thereby facilitating the reading of the storage block.
[0076] In some optional implementations, the key-value cache compression information includes multiple storage blocks, and the storage addresses of the multiple storage blocks are characterized based on the address index information; accordingly, based on the streaming reading method, the storage blocks corresponding to the key-value cache compression information are read from the preset space in sequence, including: according to the address index information, the storage blocks corresponding to the key-value cache compression information are read from the preset space in sequence using the streaming reading method. Among them, the multiple storage blocks can be decompressed in a parallel decompression method, thereby improving the decompression efficiency.
[0077] It should be noted that the data storage capacities corresponding to different storage blocks may be the same or different, and the embodiments of the present disclosure do not impose any limitation on this.
[0078] Exemplarily, if the subject executing the data processing method is a preset chip, and the address index information is an address list, the address list can be stored on the chip so that the preset chip can read the storage block based on the address list.
[0079] In some optional implementations, a buffer can also be used to implement streaming reading and streaming compression. The buffer is equivalent to a storage area of a fixed size, which is used to store data blocks or data segments read from a preset space; wherein each data block or data segment includes a portion of key-value cache compression information. The data processing device reads the data block or data segment from the buffer, and decompresses the read data block or data segment to obtain the corresponding partial key-value cache information.
[0080] It should be noted that the above method of executing the reading and decompression operations of key-value cache compressed information in parallel is only an example, and the embodiments of the present disclosure do not limit this.
[0081] Furthermore, when the key-value cache information of the attention network module in the previous decoding state is obtained, in step S13, relevant operations of the attention mechanism can be performed according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector, and the output hidden state sequence of the attention network module can be determined according to the operation results.
[0082] It should be noted that "obtaining the key-value cache information of the previous decoding state" can refer to obtaining the full key-value cache information of the previous decoding state, or it can refer to obtaining the key-value cache information of a part of the previous decoding state. In other words, when only the key-value cache information of a part of the previous decoding state of the attention network module is obtained, the attention mechanism calculation is performed based on this part of the key-value cache information of the previous decoding state and the corresponding target query vector, target key vector and target value vector. In this way, the decompression of the key-value cache compressed information and the calculation based on the key-value cache information can be performed in parallel, thereby improving data processing efficiency.
[0083] In some optional implementations, processing is performed based on the key-value cache information, target query vector, target key vector and target value vector of the previous decoding state to obtain the output hidden state sequence of the attention network module, including: in the process of decompressing the key-value cache compression information of the previous decoding state, processing is performed in parallel based on the key-value cache information, target query vector, target key vector and target value vector of the previous decoding state to determine the output hidden state sequence of the attention network module.
[0084] That is to say, the key-value cache compression information of the previous decoding state and the data processing based on the key-value cache information of the previous decoding state can be performed in parallel. Among them, the key-value cache information of the previous decoding state that can participate in the data processing in parallel is the key-value cache compression information of the previous decoding state that has been decompressed or a part of the key-value cache compression information of the previous decoding state that has been decompressed.
[0085] Exemplarily, the key-value cache compression information of the attention network module in the previous decoding state includes N storage blocks, namely storage block 1, storage block 2, ..., storage block N, where N is an integer greater than or equal to 1. If the decompression operation of the storage blocks is performed in the order of storage block 1 to storage block N, for storage block i (1 < i < N), while decompressing storage block i, the corresponding attention mechanism operation can be performed according to at least part of storage block 1 to storage block i-1.
[0086] In some optional implementations, obtaining the key-value cache compression information of the attention network module in the previous decoding state in step S12, decompressing the key-value cache compression information in the previous decoding state, and data processing in step S13 can be performed in parallel.
[0087] Exemplarily, the key-value cache compression information of the attention network module in the previous decoding state includes multiple storage blocks, and the storage blocks corresponding to the key-value cache compression information are read in sequence from the preset space based on the streaming reading method; at the same time, the storage blocks that have been read are decompressed based on the streaming decompression method to obtain the key-value cache information corresponding to the storage blocks that have been read; further, at the same time, the attention mechanism operation is performed according to the key-value cache information corresponding to the storage blocks that have been read, as well as the target query vector, the target key vector and the target value vector, to obtain the attention operation result, and the output hidden state sequence of the attention network module is determined according to the attention operation result. In other words, for step S12 and step S13, the acquisition of key-value cache compression information (i.e., loading data from the preset space), the decompression of key-value cache compression information, and data processing based on the decompressed key-value cache information and other related information can be performed in parallel.
[0088] In some optional implementations, the attention mechanism operation of the attention network module can be performed based on incremental calculation. When using the incremental calculation method, all KV-Cache' (i.e., the key value cache information of the attention network module in the previous decoding state) needs to be read and decompressed each time to participate in the calculation, and the key value information obtained in this calculation (i.e., the target key vector and target value vector determined based on the input hidden state sequence of the attention network module in the current decoding state) needs to be compressed, and the compression result is merged and stored with the previous key value cache compression information to obtain a new full KV-Cache (i.e., the key value cache compression information of the current decoding state) for backup.
[0089] In some optional implementations, the key-value cache information of the previous decoding state corresponds to the historical key matrix of the previous decoding state and the historical value matrix of the previous decoding state; accordingly, processing is performed based on the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module, including: obtaining the target key matrix based on the historical key matrix and the target key vector of the previous decoding state; obtaining the target similarity vector based on the target query vector and the target key matrix; obtaining the target value matrix based on the historical value matrix and the target value vector of the previous decoding state; obtaining the target attention vector based on the target similarity vector and the target value matrix; and determining the output hidden state sequence based on the target attention vector.
[0090] Figure 3 A schematic diagram of a data processing method based on incremental calculation provided by an embodiment of the present disclosure. Figure 3According to the input hidden state sequence of the attention network module, the target query vector Q(i-1), target key vector K(i-1) and target value vector V(i-1) can be determined, and the key-value cache compression information of the previous decoding state is KV-Cache(i-1). Based on the above information, the attention mechanism processing of the current decoding state (i.e., the i-th decoding process) is performed.
[0091] like Figure 3 As shown, since the KV-Cache (i-1) stored in the preset space is in a compressed state, after loading KV-Cache (i-1) from the preset space, KV-Cache (i-1) needs to be decompressed to obtain the key value cache information KV-Cache (i-1)′ of the previous decoding state. Furthermore, KV-Cache (i-1)′ includes two parts, one part is a number of key vectors or key matrices generated historically (referred to as historical key matrices), and the other part is a number of value vectors or value matrices generated historically (referred to as historical value matrices). In addition, the historical key matrix is concatenated and transposed with the target key vector K(i-1) to obtain the target key matrix Mk T (i-1), concatenate the historical value matrix with the target value vector V(i-1) to obtain the target value matrix Mv(i-1).
[0092] Then, the target query vector Q(i-1) is combined with the target key matrix Mk T (i-1) is multiplied to obtain the target similarity vector S(i-1), and then softmax[S(i-1) / sqrt(dk)] is calculated to obtain S(i-1)′, and the product of S(i-1)′ and the target value matrix Mv(i-1) is calculated to obtain the output hidden state sequence of the attention network module, where dk is the dimension of the target key matrix.
[0093] It should be noted that after obtaining the target key vector K(i-1) and the target value vector V(i-1), the KV-Cache(i-1) of the previous decoding state can also be updated based on K(i-1) and V(i-1), thereby obtaining the KV-Cache(i) of the current decoding state. Based on this, the corresponding attention mechanism calculation can be performed in the next decoding state (i.e., the i+1th decoding process) using KV-Cache(i) and the target query vector Q(i), the target key vector K(i), and the target value vector V(i), and the processing process is similar to the current decoding state, so it will not be described in detail here.
[0094] In some optional implementations, attention mechanism operations can also be performed based on FlashAttention. FlashAttention refers to performing corresponding calculations based on tiling calculations and tiling reading of query vectors, key vectors, and value vectors to reduce the read bandwidth requirements.
[0095] It should be noted that the block-based approach can reduce the amount of data involved in each operation, so that higher-level memories can be used to improve data processing efficiency. Among them, the capacity of the memory usually decreases with the increase of the level, but the reading and writing speed increases with the increase of the level.
[0096] In some optional implementations, the key-value cache compression information includes at least one storage block, the storage block includes at least one compressed historical key vector and / or at least one compressed historical value vector, the key-value cache information includes at least one decompressed historical key vector and / or at least one decompressed historical value vector, the key-value cache compression information is obtained based on a streaming reading method, and is decompressed based on a streaming decompression method; accordingly, the key-value cache information, the target query vector, the target key vector and the target value vector of the previous decoding state are processed to obtain an output hidden state sequence of the attention network module, including: when the historical key vector is obtained, a target similarity sub-vector is obtained based on the target query vector and the historical key vector; a value vector corresponding to the target similarity vector is determined, the target similarity vector includes multiple similarity sub-vectors, and the value vector corresponds to an element of a compressed historical value vector and a target value vector; when the historical compressed value vector corresponding to the value vector is decompressed, a target attention sub-vector is obtained based on the target similarity vector and the corresponding value vector; the multiple target attention sub-vectors obtained are spliced to obtain a target attention vector; according to the target attention vector, an output hidden state sequence is determined.
[0097] It should be noted that if the key-value cache compression information is information generated by compressing the quantized data, then after reading out the key-value cache compression information of the attention network module and decompressing it according to the corresponding decompression method to obtain the key-value cache information, the key-value cache information can also be first dequantized, and then the dequantized key-value cache information is used to perform attention mechanism calculations. For example, if the quantization method of the key-value cache compression information is to quantize the 16-bit floating point form into 4-bit integer data, then the decompressed key-value cache information of the attention network module is 4-bit integer data. After dequantization, the key-value cache information in the form of 16-bit floating point numbers is obtained, and the relevant operations of the attention mechanism are performed based on the key-value cache information in the form of 16-bit floating point numbers. That is, after reading out the data, it is first decompressed by the decompression module according to the corresponding compression method, and then converted back to floating point numbers through dequantization operations.
[0098] Figure 4 A schematic diagram of a data processing method based on a block calculation method provided by an embodiment of the present disclosure. Figure 4 , according to the input hidden state sequence of the attention network module in the current decoding state, the target query vector Q(i-1), the target key vector K(i-1) and the target value vector V(i-1) are determined; the key value cache compression information of the previous decoding state is KV-Cache(i-1), and KV-Cache(i-1) includes N storage blocks, namely storage block 1, storage block 2, ..., storage block N, wherein each storage block includes at least one compressed historical key vector and at least one compressed historical key vector. Based on the above information, the attention mechanism processing of the current decoding state (i.e., the i-th decoding process) is performed.
[0099] Since the KV-Cache (i-1) stored in the preset space is in a compressed state, after loading the KV-Cache (i-1) of the attention network module from the preset space, the KV-Cache (i-1) needs to be decompressed. Furthermore, the KV-Cache (i-1) of the attention network module can be read from the preset space in a streaming reading manner, that is, the storage blocks corresponding to the KV-Cache (i-1) are read one by one, and accordingly, the streaming decompression method can be used to perform decompression operations on the storage blocks that have been read.
[0100] like Figure 4 As shown, after loading storage block 1 from the preset space, storage block 1 can be decompressed based on the streaming decompression method to obtain the historical key vector Kh1 and the historical value vector Vh1. Furthermore, the target query vector Q(i-1) and Vh1 can be multiplied to obtain the target similarity subvector s1.
[0101] Similarly, after loading storage block 1, storage block 2 can be loaded, and storage block 2 can be decompressed based on the streaming decompression method to obtain the historical key vector Kh2 and the historical value vector Vh2. At this time, storage block 1 is a decompressed storage block, and the remaining storage blocks 3 to N are storage blocks waiting to be decompressed. Furthermore, multiplication operation can be performed based on the target query vector Q(i-1) and Vh2 to obtain the target similarity sub-vector s2. By analogy, the historical key vector and historical value vector corresponding to each storage block can be obtained, and multiple target similarity sub-vectors can be obtained based on the product of the target query vector and the historical key vector, and the multiple target similarity sub-vectors are spliced into the target similarity vector S(i-1).
[0102] Furthermore, the target similarity vector S(i-1) can be normalized to obtain the processed target similarity vector S(i-1)′, and then the processed target similarity vector S(i-1)′ and the corresponding value vector are calculated to obtain multiple target attention sub-vectors. Figure 4 As shown, the multiplication and addition values of S(i-1)′ and each column element of the target value matrix Mv(i-1) can be calculated in turn to obtain the corresponding target attention sub-vector, and then multiple target attention sub-vectors can be concatenated to obtain the target attention vector A(i-1), and then the output hidden state sequence of the attention network module is determined according to the target attention vector A(i-1).
[0103] Among them, when calculating the multiplication and addition values of each column element of S(i-1)′ and Mv(i-1), considering that each column element of V(i-1) is composed of a historical value vector and an element of a target value matrix, before calculating the corresponding multiplication and addition value, it is necessary to first determine whether the historical value vector in the column element involved in the calculation has been decompressed, and a parallel processing method of decompression and calculation can be adopted to improve data processing efficiency.
[0104] For example, the first column element Mv(i-1)_c1 of Mv(i-1) is concatenated by the historical value vector Vh1 and the first column element V(i-1)_c1 of the target value vector V(i-1). Therefore, before calculating the multiplication and addition value based on S(i-1)′ and Mv(i-1)_c1 to determine the target attention sub-vector a1, it is necessary to first determine that Vh1 has been decompressed; similarly, the second column element Mv(i-1)_c2 of Mv(i-1) is concatenated by the historical value vector Vh2 and the second column element V(i-1)_c2 of the target value vector V(i-1). Therefore, before calculating the multiplication and addition value based on S(i-1)′ and Mv(i-1)_c2 to determine the target attention sub-vector a2, it is necessary to first determine that Vh2 has been decompressed. Similarly, multiple target attention sub-vectors can be obtained, and multiple target attention sub-vectors can be concatenated to obtain the target attention vector A(i-1).
[0105] It should be noted that, similar to the incremental calculation attention mechanism, when the attention mechanism operation is performed based on FlashAttention, after obtaining the target key vector K(i-1) and the target value vector V(i-1), the KV-Cache(i-1) of the previous decoding state can also be updated based on K(i-1) and V(i-1), thereby obtaining the KV-Cache(i) of the current decoding state. The processing process is similar to the current decoding state and will not be described in detail here.
[0106] In some optional implementations, a sparse attention mechanism can also be used in the process of attention mechanism calculation. Sparse attention mechanism is a technology that can be applied to natural language processing models such as Transformer to reduce computational complexity. It reduces computational complexity by limiting each query vector to only calculate with some key vectors. In other words, the sparse attention mechanism does not calculate the similarity between the query vector and all key vectors, but only calculates the similarity between the query vector and some key vectors, thereby reducing the amount of calculation and memory consumption. Among them, the sparse attention mechanism can be implemented by introducing a mask matrix, which can select the key to be calculated with the query according to preset rules; for example, the L key vectors closest to the query vector are selected for calculation, and the remaining key vectors are masked, and L is an integer greater than 1.
[0107] In some optional implementations, before obtaining the target similarity subvector by performing calculations based on the target query vector and the historical key vector, the method may also include: when obtaining the historical key vector, determining whether the historical key vector belongs to a sparse key vector; when the historical key vector does not belong to the sparse key vector, performing calculations based on the target query vector and the historical key vector to obtain the target similarity subvector. Accordingly, when the historical key vector belongs to the sparse key vector, the calculation of the target query vector and the historical key vector is no longer calculated. Among them, most or all elements in the sparse key vector are shielded by the Mask matrix.
[0108] In some optional implementations, the attention mechanism calculation of the disclosed embodiment supports a multi-head attention mechanism. The multi-head attention mechanism is developed on the basis of the self-attention mechanism and is a variant of the self-attention mechanism, which aims to enhance the expressiveness and generalization capabilities of the model. It uses multiple independent attention heads to calculate the attention weights separately, and concatenates or weighted sums their results to obtain a richer representation.
[0109] In some optional implementations, the attention network module includes a module based on a single-head attention mechanism and a module based on a multi-head attention mechanism; processing is performed according to the key-value cache information, target query vector, target key vector and target value vector of the previous decoding state to obtain an output hidden state sequence of the attention network module, including: when the attention network module is based on the multi-head attention mechanism, the key-value cache information, target query vector, target key vector and target value vector of the previous decoding state are divided into feature information corresponding to each attention head; for each attention head, processing is performed according to the feature information corresponding to the attention head to obtain a target attention single-head vector of the attention head; based on the target attention single-head vectors of multiple attention heads, a target attention vector is obtained; based on the target attention vector, the output hidden state sequence is determined.
[0110] In some optional implementations, the multi-head attention mechanism can be applied to many-core computing scenarios.
[0111] Exemplarily, the data processing method can be applied to a many-core system, which includes multiple processing cores, each processing core corresponding to data processing of at least one attention head; accordingly, processing is performed according to feature information corresponding to the attention head to obtain a target attention single-head vector of the attention head, including: the processing core corresponding to the attention head processes according to the feature information corresponding to the attention head to obtain the target attention single-head vector of the attention head.
[0112] The above content describes the processing process of the attention mechanism. It should be noted that at the same time, the target key vector and target value vector of the target word can be further processed to update the key-value cache compression information of the previous decoding state.
[0113] In some optional implementations, in step S14, incremental key-value cache compression information may be obtained according to the target key vector and the target value vector.
[0114] In some optional implementations, incremental key-value cache compression information is obtained based on the target key vector and the target value vector, including: in the process of processing the key-value cache information, the target query vector, the target key vector and the target value vector according to the previous decoding state, compression of the target key vector and the target value vector is performed in parallel to obtain incremental key-value cache compression information.
[0115] From this, we can see that the attention mechanism calculation and the key-value information compression operation can be performed in parallel. This method can improve data processing efficiency and shorten data processing time.
[0116] In some optional implementations, when compressing the target key vector and the target value vector to update the key-value cache compression information of the previous decoding state, an incremental compression processing method can be used, that is, the current compression result is directly added after the old compression result.
[0117] That is to say, considering that the key-value cache compression information of the previous decoding state is already compressed information, only the newly generated key-value information (i.e., the target key vector and the target value vector) can be compressed to obtain the compressed key-value information (i.e., the compressed target key vector and the target value vector), and the compressed key-value information is added after the key-value cache compression information of the previous decoding state, so as to obtain the effect of updating the key-value cache compression information of the previous decoding state based on the compressed key-value information, thereby obtaining the key-value cache compression information of the current decoding state, and storing the key-value cache compression information of the current decoding state.
[0118] Furthermore, considering that KV-cache has a Gaussian distribution-like characteristic, the number of elements near zero is much greater than the number of elements with larger values. Therefore, in some optional implementations, entropy encoding and other methods can be used to perform KV-cache compression operations.
[0119] In some optional implementations, the compression encoding method for the target key vector and the target value vector includes an entropy encoding method, wherein the entropy encoding method includes Huffman encoding and the like, which is not limited in the embodiments of the present disclosure.
[0120] It should be noted that, considering the characteristics of Huffman coding and the different data calculated for each increment, the size of the compressed data (such as the incremental key-value cache compression information) may also be different accordingly. Therefore, it is necessary to apply for storage space of appropriate size from the storage unit. For example, memory allocation can be performed for each newly generated incremental key-value cache compression information through a memory application unit. The memory application unit determines the corresponding memory address according to the size requirement of the incremental key-value cache compression information, and writes the incremental key-value cache compression information to the corresponding position of the memory.
[0121] In some optional implementations, incremental key-value cache compression information is obtained based on the target key vector and the target value vector, including: compressing and encoding the target key vector and the target value vector based on a first code table to obtain incremental key-value cache compression information, wherein the first code table is determined based on preset encoding statistical information; or, determining a second code table based on the target key vector and the target value vector, and compressing and encoding the target key vector and the target value vector based on the second code table to obtain incremental key-value cache compression information.
[0122] It can be seen that a first code table can be determined based on preset coding statistics information, and the first code table can be shared during coding to perform compression coding; in addition, a new code table (such as a second code table) can be calculated on-site during compression coding, and compression coding can be performed based on the new code table. For example, the first code table can be used in some decoding states, and the corresponding second code table can be obtained by on-site calculation in other decoding states, and the compression coding operation in this decoding state can be performed based on the obtained second code table.
[0123] In some optional implementations, the key-value cache compression information includes at least one storage block; accordingly, incremental key-value cache compression information is obtained based on the target key vector and the target value vector, including: when the storage capacity of the last storage block of the key-value cache compression information does not meet the preset storage condition, compressing the target key vector and the target value vector to obtain the first incremental key-value cache compression information; when the storage capacity of the last storage block of the key-value cache compression information meets the preset storage condition, compressing the target key vector, the target value vector and the key-value cache compression information in the last storage block to obtain the second incremental key-value cache compression information; storing the incremental key-value cache compression information in the preset space, including: storing the first incremental key-value cache compression information in a new storage block in the preset space; or storing the second incremental key-value cache compression information in the last storage block in the preset space.
[0124] In some optional implementations, the storage capacity of the last storage block refers to the remaining storage capacity of the last storage block corresponding to the key-value cache compression information of the previous decoding state, which can be used to store data. The preset storage condition includes that the storage capacity of the last storage block is greater than or equal to the amount of data corresponding to the incremental key-value cache compression information. In other words, if the incremental key-value cache compression information can be stored in the last storage block, the incremental key-value cache compression information is stored in the last storage block; if the incremental key-value cache compression information cannot be stored in the last storage block, the incremental key-value cache compression information is stored in a new storage block.
[0125] In some optional implementations, the key-value cache compression information includes at least one storage block, the storage block includes multiple sub-blocks, and each sub-block is used to store the incremental key-value cache compression information of a target word; accordingly, the incremental key-value cache compression information is stored in a preset space, including: storing the incremental key-value storage compression information in any unoccupied sub-block in the storage block.
[0126] In some optional implementations, in order to more easily compress and merge the target key vector and target value vector generated by the current decoding state into the key-value cache compression information of the previous decoding state, a word-based alignment strategy can be adopted for the storage block, that is, a storage block is divided into sub-blocks corresponding to multiple words, and each sub-block is aligned by bytes. If there is redundant storage at the end of the sub-block, the redundant storage part is filled with preset information such as invalid values (for example, zero values) or specified values.
[0127] This alignment scheme can effectively reduce the complexity of bit shifting caused by alignment offset when merging compressed data, simplify the merging operation of compressed data, and reduce data processing time.
[0128] In some optional implementations, each sub-block has the same storage capacity; accordingly, after storing the incremental key-value storage compression information in any unoccupied sub-block in the storage block, the method may further include: when the incremental key-value storage compression information does not fully occupy the storage capacity of the sub-block, using preset information to fill the unoccupied storage capacity in the sub-block.
[0129] In some optional implementations, considering that the newly compressed incremental key-value cache compression information needs to be stored in an external storage space, it is necessary to apply for an external address before performing the storage to achieve smooth storage of the incremental cache key-value cache compression information. Furthermore, since the length of the compressed information may not be fixed, storage space can be dynamically applied to the external storage according to demand.
[0130] In some optional implementations, before storing the incremental key-value cache compression information in the preset space, the method may further include: applying for a storage address for storing the incremental key-value cache compression information from the preset space.
[0131] In some optional implementations, the storage addresses of multiple storage blocks corresponding to the key-value cache compression information are characterized based on the address index information; accordingly, after storing the incremental key-value cache compression information in the preset space, the method may also include: updating the address index information based on the storage address of the incremental key-value cache compression information.
[0132] For example, the address index information is an address index list including storage addresses of multiple storage blocks, and the address index list may be updated after the incremental key-value cache compression information is stored.
[0133] Figure 5 A schematic diagram of a key-value cache compression information update process provided by an embodiment of the present disclosure. Figure 5 After the i-1th decoding process is executed, the key-value cache compression information stored in the preset space is KV-Cache (i-1).
[0134] For the attention network module, when the i-th decoding process is executed, the corresponding target query vector, target key vector and target value vector are generated for the current input hidden state sequence. On the one hand, the key value cache compression information KV-Cache(i-1) of the previous decoding state is loaded from the preset space, and the loaded KV-Cache(i-1) is decompressed to obtain the key value cache information KV-Cache(i-1)′ of the previous decoding state; on the other hand, the attention mechanism is calculated according to KV-Cache(i-1)′, the target query vector, the target key vector and the target value vector, and the output hidden state sequence is determined according to the calculation result; on the other hand, the target key vector and the target value vector are compressed to obtain the incremental key value cache compression information, and the incremental key value cache compression information is stored in the preset space, so as to obtain the key value cache compression information KV-Cache(i) of the current iteration state based on KV-Cache(i-1) and the incremental key value cache compression information. By analogy, the data processing of the i+1-th decoding state can be performed, and the processing process is similar to it, which will not be described in detail here.
[0135] The following is a detailed description of the processes of data loading, data decompression, data calculation, data compression, etc. in a data processing method in an embodiment of the present disclosure.
[0136] Exemplarily, if the current decoding state of the attention network module corresponds to the first decoding, there is no previous decoding state. Therefore, it is necessary to perform the attention mechanism calculation based on the initial input hidden state sequence to obtain the initial query vector Q(0), initial key vector K(0) and initial value vector V(0), and then perform the attention mechanism calculation, and determine the output hidden state sequence of the first decoding state based on the calculation results. In addition, the initial key vector K(0) and the initial value vector V(0) can also be compressed to obtain the initial key-value cache compression information KV-Cache(1), and KV-Cache(1) is stored in the preset space for standby. Among them, the initial input hidden state sequence can be determined based on the filling result of the pre-filling stage. In the pre-filling stage, all word elements in the problem can be calculated in parallel, and the corresponding KV-Cache can be calculated.
[0137] If the current decoding state corresponds to the second decoding, the previous decoding state corresponds to the first decoding; accordingly, while determining the target query vector Q(1), the target key vector K(1) and the target value vector V(1) according to the current input hidden state sequence, the key-value cache compression information KV-Cache(1) of the previous decoding state can be loaded from the preset space, and KV-Cache(1) can be decompressed to obtain the key-value cache information KV-Cache(1)′ of the previous decoding state.
[0138] Furthermore, the attention mechanism calculation can be performed according to KV-Cache(1)′, Q(1), K(1) and V(1), and the output hidden state sequence of the current decoding state can be determined according to the calculation result. In addition, the incremental key-value cache compression information △KV-Cache(1) is obtained according to K(1) and V(1), and the KV-Cache(1) stored in the preset space is updated using △KV-Cache(1), so as to obtain the key-value cache compression information KV-Cache(2) of the current decoding state.
[0139] Similarly, if the current decoding state corresponds to the i-th decoding, the previous decoding state corresponds to the i-1-th decoding (i>2); accordingly, while determining the target query vector Q(i-1), the target key vector K(i-1) and the target value vector V(i-1) according to the current input hidden state sequence, the key value cache compression information KV-Cache(i-1) of the previous decoding state can be loaded from the preset space, and KV-Cache(i-1) is decompressed to obtain the key value cache information KV-Cache(i-1)′ of the previous decoding state; wherein KV-Cache(i-1) is the information obtained by compressing K(0), V(0), K(1), V(1), ..., K(i-2), V(i-2).
[0140] Furthermore, the attention mechanism calculation can be performed according to KV-Cache(i-1)′, Q(i-1), K(i-1) and V(i-1), and the output hidden state sequence of the current decoding state is determined according to the calculation result. In addition, the incremental key-value cache compression information △KV-Cache(i-1) is obtained according to K(i-1) and V(i-1), and △KV-Cache(i-1) is used to update KV-Cache(i-1) in the preset space, thereby obtaining the key-value cache compression information KV-Cache(i) of the current decoding state.
[0141] It can be seen that during the first decoding, the full amount of key vectors and value vectors need to be calculated. Starting from the second decoding, the key-value cache compression information generated last time can be reused, and only the target query vector, target key vector and target value vector need to be calculated for the target word in the previous decoding state, thereby effectively reducing the amount of calculation and improving data processing efficiency.
[0142] Figure 6 A schematic diagram of a processing process of a data processing method provided by an embodiment of the present disclosure. Figure 6, when executing the i-th decoding process of the attention network module, the key-value cache compression information KV-Cache(i-1) of the previous decoding state is loaded from the preset space, and KV-Cache(i-1) is decompressed by the decompressor to obtain the key-value cache information KV-Cache(i-1)′ of the previous decoding state. For the input hidden state sequence in the current decoding state, the corresponding target query vector Q(i-1), target key vector K(i-1) and target value vector V(i-1) are generated.
[0143] like Figure 6 As shown in the figure, when performing Attention calculation, only Q(i-1) is used. The historical query vector shown in the dotted box in the figure does not need to be actually involved in the calculation, nor does it need to be actually stored. Furthermore, the current target attention vector can be calculated based on Q(i-1), K(i-1), V(i-1) and KV-Cache(i-1)′, and the output hidden state sequence of this decoding state can be obtained based on the current target attention vector.
[0144] Furthermore, K(i-1) and V(i-1) generated for this decoding state can be compressed by a compressor, and the obtained compressed information can be stored in a preset space and directly added after KV-Cache(i-1), so as to obtain the key-value cache compression information KV-Cache(i) of the current decoding state based on KV-Cache(i-1) and the newly added compression information.
[0145] In some optional implementations, the data processing method may also include: for the current decoding state, when the output hidden state sequence of the last attention network module is obtained, determining the target word element of the current decoding state according to the output hidden state sequence of at least part of the attention network modules, so as to perform data processing of the next decoding state according to the key-value cache compression information of each attention network module in the current decoding state and the target word element of the current decoding state.
[0146] That is to say, after multiple rounds of iterative processing, the hit probability of each of the multiple candidate word-grams in the preset word-gram table can be determined according to the output hidden state sequence of the attention network module, and the candidate word-gram with the highest hit probability can be selected as the target word-gram.
[0147] Figure 7 A schematic diagram of a data processing method based on a many-core system provided by an embodiment of the present disclosure. Figure 7 The many-core system includes multiple processing cores, which are connected to a double data rate (DDR) memory through a communication interface.
[0148] In some optional implementations, the many-core system can be used to perform multi-head attention processing, during which each processing core is assigned a certain computing task. The data required for the calculation can be loaded from the DDR through the communication interface and transmitted to the corresponding processing core after decompression. The calculation results obtained by the computing core after data processing are first compressed and then written to the DDR through the communication interface.
[0149] It can be understood that the above-mentioned embodiments mentioned in the present disclosure can be combined with each other to form a combined embodiment without violating the principle logic. Due to space limitations, the present disclosure will not repeat them. Those skilled in the art can understand that in the above-mentioned method of the specific implementation method, the specific execution order of each step and the setting of the functional module should be determined by its function and possible internal logic.
[0150] A second aspect of an embodiment of the present disclosure provides a data processing device.
[0151] Figure 8 A block diagram of a data processing device provided in an embodiment of the present disclosure, the data processing device can be applied to a preset model, the preset model includes at least one attention network module. Figure 8 , the data processing device 800 may include the following modules.
[0152] The determination module 801 is used to determine the root target query vector, target key vector and target value vector of any attention network module in the current decoding state according to the input hidden state sequence of the attention network module.
[0153] The decompression module 802 is used to obtain the key-value cache compression information of the attention network module in the previous decoding state from the preset space, and decompress the key-value cache compression information of the previous decoding state to obtain the key-value cache information of the previous decoding state.
[0154] The processing module 803 is used to process the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module.
[0155] The compression module 804 is used to obtain incremental key-value cache compression information according to the target key vector and the target value vector.
[0156] The storage module 805 is used to store the incremental key-value cache compression information into a preset space to obtain the key-value cache compression information of the attention network module in the current decoding state.
[0157] In the embodiment of the present disclosure, during the data processing process of executing the preset model, for any attention network module in the current decoding state, the key value information generated in the previous processing process is compressed and stored in the preset space, and the key value cache compression information of the previous decoding state is obtained. Since the key value cache compression information of the previous decoding state is compressed information, the amount of data is effectively reduced, thereby reducing the occupation of storage resources; in addition, when the key value cache compression information of the previous decoding state is needed in the current decoding process, the key value cache compression information of the attention network module in the previous decoding state is loaded from the preset space, and the key value cache compression information of the previous decoding state is loaded from the preset space. Decompress the decompressed key-value cache information, and perform calculations based on the decompressed key-value cache information and the corresponding target query vector, target key vector, and target value vector to obtain the output hidden state sequence of the attention network module. Then, based on the target key vector and target value vector, obtain the incremental key-value cache compression information, and store the incremental key-value cache compression information in the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state, wherein, since the key-value cache compression information of the current iteration state transmitted to the preset space is still compressed information, the bandwidth requirement is also reduced accordingly, which can reduce the amount of bandwidth resources occupied. Furthermore, since the loading, decompression, and corresponding calculations of the key-value cache compression information can be performed in parallel, the data processing efficiency can be effectively improved.
[0158] A third aspect of the embodiments of the present disclosure provides a many-core system.
[0159] Fig. 9 A block diagram of a multi-core system provided by an embodiment of the present disclosure. Fig. 9 The many-core system 900 may include: a plurality of processing cores 910; wherein the many-core system 900 is used to execute any data processing method of the embodiments of the present disclosure.
[0160] In some optional implementations, the many-core system also includes: at least one decompressor, at least one compressor and a communication interface; wherein, for the current decoding state, at least some of the processing cores are used to determine the target query vector, target key vector and target value vector of the attention network module according to the input hidden state sequence of the attention network module; the communication interface is used to obtain the key-value cache compression information of the attention network module in the previous decoding state from a preset space; the decompressor is used to decompress the key-value cache compression information of the previous decoding state to obtain the key-value cache information of the previous decoding state; at least some of the processing cores are used to process the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to determine the output hidden state sequence of the attention network module; the compressor is used to obtain the incremental key-value cache compression information according to the target key vector and the target value vector; the communication interface is used to store the incremental key-value cache compression information to the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state.
[0161] In the embodiment of the present disclosure, during the data processing process of executing the preset model, for any attention network module in the current decoding state, the key value information generated in the previous processing process is compressed and stored in the preset space, and the key value cache compression information of the previous decoding state is obtained. Since the key value cache compression information of the previous decoding state is compressed information, the amount of data is effectively reduced, thereby reducing the occupation of storage resources; in addition, when the key value cache compression information of the previous decoding state is needed in the current decoding process, the key value cache compression information of the attention network module in the previous decoding state is loaded from the preset space, and the key value cache compression information of the previous decoding state is loaded from the preset space. Decompress the decompressed key-value cache information, and perform calculations based on the decompressed key-value cache information and the corresponding target query vector, target key vector, and target value vector to obtain the output hidden state sequence of the attention network module. Then, based on the target key vector and target value vector, obtain the incremental key-value cache compression information, and store the incremental key-value cache compression information in the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state, wherein, since the key-value cache compression information of the current iteration state transmitted to the preset space is still compressed information, the bandwidth requirement is also reduced accordingly, which can reduce the amount of bandwidth resources occupied. Furthermore, since the loading, decompression, and corresponding calculations of the key-value cache compression information can be performed in parallel, the data processing efficiency can be effectively improved.
[0162] In addition, the present disclosure also provides an electronic device and a computer-readable storage medium.
[0163] Fig.10 A block diagram of an electronic device based on a single processor provided in Embodiment 1 of the present disclosure.
[0164] Reference Fig.10 , an embodiment of the present disclosure provides an electronic device, which includes: at least one processor 1001; at least one memory 1002, and one or more I / O interfaces 1003, connected between the processor 1001 and the memory 1002; wherein the memory 1002 stores one or more computer programs that can be executed by the at least one processor 1001, and the one or more computer programs are executed by the at least one processor 1001, so that the at least one processor 1001 can execute the data processing method of the embodiment of the present disclosure.
[0165] Fig.11 A block diagram of an electronic device based on multiple processing cores provided in Embodiment 2 of the present disclosure.
[0166] Reference Fig.11 A second embodiment of the present disclosure provides an electronic device, which includes multiple processing cores 1101 and an on-chip network 1102, wherein the multiple processing cores 1101 are connected to the on-chip network 1102, and the on-chip network 1102 is used to exchange data between the multiple processing cores and external data.
[0167] One or more instructions are stored in one or more processing cores 1101, and the one or more instructions are executed by one or more processing cores 1101, so that one or more processing cores 1101 can execute the data processing method of the embodiment of the present disclosure.
[0168] In some embodiments, the electronic device may be a brain-like chip, which can use vectorized computing and needs to load the weight information and other parameters of the neural network model through an external memory such as a double data rate (DDR) synchronous dynamic random access memory. Therefore, the batch processing used in the embodiments of the present disclosure has a higher computing efficiency.
[0169] The present disclosure also provides a computer-readable storage medium on which a computer program is stored, wherein the computer program implements the data processing method of the present disclosure when executed by a processor / processing core. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.
[0170] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the data processing method of the embodiments of the present disclosure.
[0171] It will be appreciated by those skilled in the art that all or some of the steps, systems, and functional modules / units in the methods disclosed above may be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between the functional modules / units mentioned in the above description does not necessarily correspond to the division of physical components; for example, a physical component may have multiple functions, or a function or step may be performed by several physical components in cooperation. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application-specific integrated circuit. Such software may be distributed on a computer-readable storage medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium).
[0172] As is known to those of ordinary skill in the art, the term computer storage media includes volatile and nonvolatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable program instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), static random access memory (SRAM), flash memory or other memory technology, portable compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, it is known to those of ordinary skill in the art that communication media typically contain computer-readable program instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and may include any information delivery medium.
[0173] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0174] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0175] The computer program product described herein may be implemented in hardware, software, or a combination thereof. In one optional embodiment, the computer program product is embodied as a computer storage medium, and in another optional embodiment, the computer program product is embodied as a software product, such as a software development kit (SDK), etc.
[0176] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.
[0177] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0178] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.
[0179] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.
[0180] Example embodiments have been disclosed herein, and although specific terms are employed, they are used and should be interpreted only in a general illustrative sense and not for limiting purposes. In some instances, it will be apparent to those skilled in the art that, unless otherwise expressly noted, features, characteristics, and / or elements described in conjunction with a particular embodiment may be used alone or in combination with features, characteristics, and / or elements described in conjunction with other embodiments. Therefore, those skilled in the art will appreciate that various changes in form and detail may be made without departing from the scope of the present disclosure as set forth in the appended claims.
Claims
1. A data processing method, characterized in that: Applied to a preset model, the preset model includes at least one attention network module, the method includes: For any attention network module in the current decoding state, determine the target query vector, target key vector and target value vector of the attention network module according to the input hidden state sequence of the attention network module; Acquire the key-value cache compression information of the attention network module in the previous decoding state from the preset space, and decompress the key-value cache compression information of the previous decoding state to obtain the key-value cache information of the previous decoding state; Processing is performed according to the key-value cache information of the previous decoding state, the target query vector, the target key vector, and the target value vector to obtain an output hidden state sequence of the attention network module; According to the target key vector and the target value vector, incremental key-value cache compression information is obtained, and the incremental key-value cache compression information is stored in the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state.
2. The method according to claim 1, characterized in that The method further comprises: For the current decoding state, when the output hidden state sequence of the last attention network module is obtained, the target word of the current decoding state is determined according to the output hidden state sequence of at least part of the attention network module, so as to perform data processing of the next decoding state according to the key-value cache compression information of each attention network module in the current decoding state and the target word of the current decoding state.
3. The method according to claim 1, characterized in that: The step of obtaining the key-value cache compression information of the attention network module in the previous decoding state from the preset space, and decompressing the key-value cache compression information of the previous decoding state to obtain the key-value cache information of the previous decoding state includes: Reading the key-value cache compression information of the attention network module in the previous decoding state from the preset space based on a streaming reading method; The key-value cache compression information that has been read is decompressed based on a streaming decompression method to obtain the key-value cache information of at least part of the previous decoding state of the attention network module.
4. The method according to claim 3, characterized in that The streaming reading method and the streaming decompression method are executed in parallel.
5. The method according to claim 3, characterized in that: The key-value cache compression information includes at least one storage block; The method of reading the key-value cache compression information of the attention network module in the previous decoding state from the preset space based on the streaming reading method includes: Based on the streaming reading method, sequentially read the storage blocks corresponding to the key-value cache compression information from the preset space; The method of decompressing the read key-value cache compression information based on the streaming decompression method to obtain at least part of the key-value cache information of the previous decoding state of the attention network module includes: Based on the streaming decompression method, the storage block that has been read is decompressed to obtain the key-value cache information corresponding to the storage block that has been read.
6. The method according to claim 5, characterized in that The key-value cache compression information includes a plurality of the storage blocks, and storage addresses of the plurality of the storage blocks are characterized based on address index information; The step of sequentially reading the storage blocks corresponding to the key-value cache compression information from the preset space based on the streaming reading method includes: According to the address index information, the storage blocks corresponding to the key-value cache compression information are read from the preset space in sequence using the streaming reading method, and multiple storage blocks are decompressed using a parallel decompression method.
7. The method according to claim 5, characterized in that The storage block includes a first storage block, wherein the first storage block includes at least one compressed history key vector and at least one compressed history value vector; Or, the storage block includes a second storage block and a third storage block, the second storage block includes at least one compressed history key vector, and the third storage block includes at least one compressed history value vector.
8. The method according to claim 1, characterized in that The processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module includes: In the process of decompressing the key-value cache compression information of the previous decoding state, processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector is performed in parallel to determine the output hidden state sequence of the attention network module.
9. The method according to claim 1 or 8, characterized in that: The key value cache information of the previous decoding state corresponds to the history key matrix of the previous decoding state and the history value matrix of the previous decoding state; The processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module includes: Obtaining a target key matrix according to the history key matrix of the previous decoding state and the target key vector; Perform calculation based on the target query vector and the target key matrix to obtain a target similarity vector; Obtaining a target value matrix according to the historical value matrix of the previous decoding state and the target value vector; Calculating based on the target similarity vector and the target value matrix to obtain a target attention vector; The output hidden state sequence is determined according to the target attention vector.
10. The method according to claim 1 or 8, characterized in that: The key-value cache compression information includes at least one storage block, the storage block includes at least one compressed historical key vector and / or at least one compressed historical value vector, the key-value cache information includes at least one decompressed historical key vector and / or at least one decompressed historical value vector, the key-value cache compression information is obtained based on a streaming reading method, and is decompressed based on the streaming decompression method; The processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module includes: When the historical key vector is obtained, a target similarity subvector is obtained by performing calculation based on the target query vector and the historical key vector; Determining a value vector corresponding to a target similarity vector, the target similarity vector comprising a plurality of target similarity sub-vectors, the value vector corresponding to an element of a compression history value vector and a target value vector; When the historical compressed value vector corresponding to the value vector is decompressed, calculating based on the target similarity vector and the corresponding value vector to obtain a target attention sub-vector; Concatenate the multiple target attention sub-vectors obtained to obtain the target attention vector; The output hidden state sequence is determined according to the target attention vector.
11. The method according to claim 10, characterized in that Before calculating based on the target query vector and the history key vector to obtain a target similarity sub-vector, the method further includes: When the historical key vector is obtained, determining whether the historical key vector belongs to a sparse key vector; In the case where the historical key vector does not belong to a sparse key vector, performing the step of calculating based on the target query vector and the historical key vector to obtain a target similarity subvector; In the case where the historical key vector is a sparse key vector, the step of performing calculation based on the target query vector and the historical key vector to obtain a target similarity subvector is skipped.
12. The method according to claim 1 or 8, characterized in that: The attention network module includes a module based on a single-head attention mechanism and a module based on a multi-head attention mechanism; The processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain the output hidden state sequence of the attention network module includes: In the case where the attention network module is based on a multi-head attention mechanism, the key-value cache information of the previous decoding state, the target query vector, the target key vector, and the target value vector are divided into feature information corresponding to each attention head; For each attention head, processing is performed according to the feature information corresponding to the attention head to obtain the target attention single head vector of the attention head; According to the target attention single head vectors of multiple attention heads, the target attention vector is obtained; The output hidden state sequence is determined according to the target attention vector.
13. The method according to claim 12, characterized in that The method is applied to a many-core system, the many-core system comprising a plurality of processing cores, each processing core corresponding to data processing of at least one attention head; The processing according to the feature information corresponding to the attention head to obtain the target attention single head vector of the attention head includes: The processing core corresponding to the attention head processes the feature information corresponding to the attention head to obtain the target attention single head vector of the attention head.
14. The method according to claim 1, characterized in that The obtaining incremental key-value cache compression information according to the target key vector and the target value vector includes: In the process of processing according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector, compression of the target key vector and the target value vector is performed in parallel to obtain the incremental key-value cache compression information.
15. The method according to claim 1 or 14, characterized in that: The obtaining incremental key-value cache compression information according to the target key vector and the target value vector includes: compressing and encoding the target key vector and the target value vector based on a first code table to obtain the incremental key-value cache compression information, wherein the first code table is determined based on preset encoding statistical information; or, A second code table is determined according to the target key vector and the target value vector, and the target key vector and the target value vector are compressed and encoded based on the second code table to obtain the incremental key-value cache compression information.
16. The method according to claim 15, characterized in that The compression coding method includes an entropy coding method.
17. The method according to claim 1 or 14, characterized in that The key-value cache compression information includes at least one storage block; The obtaining incremental key-value cache compression information according to the target key vector and the target value vector includes: When the storage capacity of the last storage block of the key-value cache compression information does not meet the preset storage condition, compressing the target key vector and the target value vector to obtain first incremental key-value cache compression information; When the storage capacity of the last storage block of the key-value cache compression information meets the preset storage condition, compressing the target key vector, the target value vector, and the key-value cache compression information in the last storage block to obtain second incremental key-value cache compression information; The step of storing the incremental key-value cache compression information in the preset space includes: storing the first incremental key-value cache compression information in a new storage block in the preset space; or, The second incremental key-value cache compression information is stored in the last storage block in the preset space.
18. The method according to claim 1 or 14, characterized in that: The key-value cache compression information includes at least one storage block, the storage block includes a plurality of sub-blocks, and each sub-block is used to store incremental key-value cache compression information of a target word; The step of storing the incremental key-value cache compression information in the preset space includes: The incremental key-value storage compression information is stored in any unoccupied sub-block in the storage block.
19. The method according to claim 18, characterized in that Each sub-block has the same storage capacity; After storing the incremental key-value storage compression information in any unoccupied sub-block in the storage block, the method further includes: In the case that the incremental key-value storage compression information does not fully occupy the storage capacity of the sub-block, the preset information is used to fill the unoccupied storage capacity of the sub-block.
20. The method according to claim 1 or 14, characterized in that Before storing the incremental key-value cache compression information in the preset space, the method further includes: A storage address for storing the incremental key-value cache compression information is applied for from the preset space.
21. The method according to claim 20, characterized in that The storage addresses of the plurality of storage blocks corresponding to the key-value cache compression information are characterized based on the address index information; After storing the incremental key-value cache compression information in the preset space, the method further includes: The address index information is updated based on the storage address of the incremental key-value cache compression information.
22. A data processing device, characterized in that: Applied to a preset model, the preset model includes at least one attention network module, and the device includes: A determination module, for determining a target query vector, a target key vector, and a target value vector of any attention network module in a current decoding state according to an input hidden state sequence of the attention network module; A decompression module, used to obtain the key-value cache compression information of the attention network module in the previous decoding state from a preset space, and decompress the key-value cache compression information of the previous decoding state to obtain the key-value cache information of the previous decoding state; A processing module, configured to process the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to obtain an output hidden state sequence of the attention network module; A compression module, used for obtaining incremental key-value cache compression information according to the target key vector and the target value vector; A storage module is used to store the incremental key-value cache compression information into the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state.
23. A many-core system, characterized in that: include: Multiple processing cores; The many-core system is used to execute the data processing method according to any one of claims 1 to 21.
24. The many-core system according to claim 23, characterized in that: The many-core system further includes: at least one decompressor, at least one compressor and a communication interface; wherein, For a current decoding state, at least part of the processing cores are used to determine a target query vector, a target key vector, and a target value vector of the attention network module according to an input hidden state sequence of the attention network module; The communication interface is used to obtain the key-value cache compression information of the attention network module in the previous decoding state from the preset space; The decompressor is used to decompress the key-value cache compressed information of the previous decoding state to obtain the key-value cache information of the previous decoding state; At least some of the processing cores are used to process according to the key-value cache information of the previous decoding state, the target query vector, the target key vector and the target value vector to determine the output hidden state sequence of the attention network module; The compressor is used to obtain incremental key-value cache compression information according to the target key vector and the target value vector; The communication interface is used to store the incremental key-value cache compression information into the preset space to obtain the key-value cache compression information of the attention network module in the current decoding state.
25. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores one or more computer programs executable by the at least one processor, and the one or more computer programs are executed by the at least one processor to enable the at least one processor to perform the data processing method according to any one of claims 1 to 21.
26. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer program implements the data processing method according to any one of claims 1 to 21.
Citation Information
Patent Citations
Text generation method, device and model based on attention mechanism
CN118246413A
Layer compression key value caching method, system and equipment for large language model and medium
CN118246485A
Cited By
Sequence processing method based on MLA, related device, system and storage medium
CN120296366A
Data processing method, product, electronic equipment and computer readable storage medium
CN120950009A
Request processing method and device, equipment, medium and program product
CN121397087A
Graphics processor, key value cache read-write method, equipment and storage medium
CN122222803A
Method and apparatus for compressing key-value pair cache data
WO2026129690A1
