Model processing method and device based on key-value cache information, and task processing method and device
By adjusting the parameters of the forward connection layer network of a large language model, key-value cache information is converted into long-term memory information, which solves the storage pressure problem of large language models when the amount of data increases, and achieves optimization of storage resources and maintenance of performance.
Patent Information
- Application Number
- CN202411096132.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2044-08-09
AI Technical Summary
As large language models process increasing amounts of data, the storage space requirements for key-value cache information increase, leading to difficulties in deployment and application. Existing technical methods may result in performance degradation or additional costs.
By obtaining the key-value cache information of the attention layer of the target network module, adjusting the network parameters of the forward connection layer, converting short-term memory information into long-term memory information, storing it in the forward connection layer, and deleting the original key-value cache information.
This effectively reduces the amount of cached information in the model, alleviating the storage and bandwidth pressure on hardware devices, while maintaining model performance and avoiding performance degradation and additional costs.
Smart Images

Figure CN119003911B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a model processing method, task processing method, model processing device, task processing device, many-core system, electronic device, and computer-readable storage medium based on key-value cache information. Background Technology
[0002] The attention mechanism in deep learning is a method that mimics the human visual and cognitive system, allowing neural networks to focus their attention on relevant parts when processing input data. By introducing the attention mechanism, neural networks can automatically learn and selectively focus on important information in the input, improving the model's performance and generalization ability.
[0003] For large models (LMs), especially large language models (LLMs) such as Generative Pre-trained Transformer-3 (GPT-3) and Generative Language Model (GLM), as the amount of data they process increases (such as the increase in text length and text volume), the storage space required for storing key-value cache information during attention mechanism processing also increases accordingly. This brings great difficulties to the deployment and application of large models. Summary of the Invention
[0004] This disclosure provides a model processing method, a task processing method, a model processing device, a task processing device, a many-core system, an electronic device, and a computer-readable storage medium based on key-value cache information.
[0005] In a first aspect, this disclosure provides a model processing method based on key-value cache information, applied to a preset model. The preset model includes at least one target network module, which includes an attention layer and a forward connection layer. The model processing method includes: for any target network module among at least some target network modules, obtaining at least some key-value cache information corresponding to the attention layer of the target network module; adjusting the network parameters of the forward connection layer of the target network module based on the at least some key-value cache information to obtain an adjusted forward connection layer of the target network module, so as to convert the first memory information carried by the at least some key-value cache information into second memory information, and storing the second memory information in the adjusted forward connection layer, wherein the memory duration of the first memory information is less than the memory duration of the second memory information; and deleting the at least some key-value cache information.
[0006] Secondly, this disclosure provides a task processing method. The preset model includes at least one target network module, which includes an attention layer and a forward connection layer. The task processing method includes: inputting task data to be processed into the preset model to obtain a task processing result. The preset model is obtained based on the model processing method based on key-value caching information as described in any one of the embodiments of this disclosure. The attention layer of the target network module is used to perform a first data processing on the input hidden state vector to obtain a first processing result. The forward connection layer of the target network module is used to perform a second data processing on the input hidden state vector to obtain a second processing result. The first processing result and the second processing result are fused to obtain the output hidden state vector of the target network module, which is then used as the input hidden state vector of the next target network module. The input hidden state vector of the first target network module is determined based on the task data to be processed, and the task processing result is determined based on the output hidden state vectors of multiple target network modules.
[0007] Thirdly, this disclosure provides a model processing apparatus based on key-value cache information, applied to a preset model. The preset model includes at least one target network module, which includes an attention layer and a forward connection layer. The model processing apparatus includes: an acquisition module, configured to acquire at least some key-value cache information corresponding to the attention layer of any target network module among at least some target network modules; an adjustment module, configured to adjust the network parameters of the forward connection layer of the target network module based on the at least some key-value cache information, to obtain an adjusted forward connection layer of the target network module, so as to convert the first memory information carried by the at least some key-value cache information into second memory information, and store the second memory information in the adjusted forward connection layer, wherein the memory duration of the first memory information is less than the memory duration of the second memory information; and a deletion module, configured to delete the at least some key-value cache information.
[0008] Fourthly, this disclosure provides a task processing apparatus. The preset model includes at least one target network module, which includes an attention layer and a forward connection layer. The task processing apparatus includes a processing module for inputting task data to be processed into the preset model to obtain a task processing result. The preset model is obtained based on the model processing method based on key-value caching information according to any one of the embodiments of this disclosure. The attention layer of the target network module performs first data processing on the input hidden state vector to obtain a first processing result. The forward connection layer of the target network module performs second data processing on the input hidden state vector to obtain a second processing result. The first processing result and the second processing result are fused to obtain the output hidden state vector of the target network module, which is then used as the input hidden state vector of the next target network module. The input hidden state vector of the first target network module is determined based on the task data to be processed, and the task processing result is determined based on the output hidden state vectors of multiple target network modules.
[0009] Fifthly, this disclosure provides a many-core system, which includes multiple processing units, each processing unit corresponding to a processing core or a core group, and a target network module of a preset model is mapped to a processing unit of the many-core system; the many-core system is used to execute the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure.
[0010] In a sixth aspect, this 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, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform a model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or a task processing method as described in any one of the embodiments of this disclosure.
[0011] In a seventh aspect, this 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 model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure.
[0012] The embodiments provided in this disclosure, for any target network module among at least some target modules of a preset model, obtain at least some key-value cache information corresponding to the attention layer of the target network module; adjust the network parameters of the forward connection layer of the target network module based on the at least some key-value cache information to obtain the adjusted forward connection layer of the target network module; and delete at least some key-value cache information. Thus, it can be seen that the network parameters of the forward connection layer can be adjusted using key-value cache information carrying short-term memory information, thereby converting short-term memory information into long-term memory information, and storing this long-term memory information in the adjusted forward connection layer. This effectively preserves model information and allows for the deletion of corresponding key-value cache information, reducing the amount of cached information required by the model and alleviating the storage and bandwidth pressure on the hardware device carrying the model.
[0013] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0014] The accompanying drawings are provided to further illustrate the present disclosure and form part of the specification. They are used together with the embodiments of the present disclosure to explain the disclosure and do not constitute a limitation thereof. The above and other features and advantages will become more apparent to those skilled in the art from the detailed description of exemplary embodiments with reference to the accompanying drawings, in which:
[0015] Figure 1 A flowchart of a model processing method based on key-value caching information provided in this disclosure embodiment.
[0016] Figure 2 This is a schematic diagram of a target network module provided in Embodiment 1 of this disclosure.
[0017] Figure 3 This is a schematic diagram of a target network module provided in Embodiment 2 of this disclosure.
[0018] Figure 4 This is a flowchart illustrating a model processing method based on key-value caching information provided in an embodiment of this disclosure.
[0019] Figure 5 This is a flowchart of a task processing method provided in an embodiment of the present disclosure.
[0020] Figure 6 This is a block diagram of a model processing apparatus based on key-value cache information provided in an embodiment of the present disclosure.
[0021] Figure 7 This is a block diagram of a task processing apparatus provided in an embodiment of the present disclosure.
[0022] Figure 8 This is a block diagram of a many-core system provided in an embodiment of the present disclosure.
[0023] Figure 9 This is a block diagram of an electronic device provided in Embodiment 1 of this disclosure.
[0024] Figure 10 This is a block diagram of an electronic device provided in Embodiment 2 of this disclosure. Detailed Implementation
[0025] To enable those skilled in the art to better understand the technical solutions of this disclosure, exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments of this disclosure to aid understanding. These should be considered merely exemplary. Therefore, those skilled 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 this disclosure. Similarly, for clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0026] Where there is no conflict, the various embodiments of this disclosure and the features thereof in the embodiments may be combined with each other.
[0027] As used herein, the term “and / or” includes any and all combinations of one or more related enumerated entries.
[0028] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit this disclosure. As used herein, the singular forms “a” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that when the terms “comprising” and / or “made of” are used in this specification, the presence of the stated feature, integral, step, operation, element, and / or component is specified, but the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof is not excluded. Words such as “connected” or “linked” are not limited to physical or mechanical connections but can include electrical connections, whether direct or indirect.
[0029] Unless otherwise specified, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one 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 this disclosure, and will not be interpreted as having an idealized or overly formal meaning, unless expressly so defined herein.
[0030] Large models built on the transformer model architecture typically consist of many isomorphic network layers, each containing an attention layer and a feed forward network (FFN). When using these large models for forward inference (such as in text processing tasks), the output is often sequential and autoregressive. That is, the decoded output tokens are fed back to the input layer of the pre-defined model to participate in data processing, and then decoded again to generate the next token. This process repeats until a termination condition is met, yielding the final output.
[0031] During the decoding of a single token, the key and value vectors of previously processed tokens at each layer can be saved to avoid recalculation and reduce computational load. This portion of the key and value vectors is typically called the key-value cache (kv cache). Furthermore, this kv cache is the primary carrier of short-term memory, storing information about each token within a specific context. However, as the text length increases, the kv cache expands linearly, resulting in a significant storage and communication burden.
[0032] For example, personal assistant applications built on large models need to record information such as user conversations. These conversations are often long conversation sequences over a large time scale. The amount of key-value cache information required for these records is huge, which is not conducive to the promotion and flexible deployment of the model.
[0033] In related technologies, methods such as key-value cache quantization, sparse attention, and storing historical dialogue records are commonly used to reduce the amount of key-value cache information. Key-value cache quantization refers to storing key-value cache data in a lower precision format (e.g., int8, int4, int2). While this method reduces the precision of the key-value cache and thus the amount of data, it cannot reduce the cache length. Sparse attention refers to processing the attention of a single token to past tokens (i.e., calculating the linear comparison of the query vector of the current token with the key vectors of other tokens). Instead of participating with all tokens, only a subset of token key vectors are selected for data processing according to certain rules. However, this method usually causes a significant performance degradation. Storing historical dialogue records involves storing historical dialogue records in raw form, such as text, in a database and retrieving them when needed. This method requires the model to reprocess historical dialogue records, incurring additional costs, and also requires additional retrieval modules.
[0034] In summary, while these technologies reduce the storage pressure on key-value cache information, they may cause a significant drop in model performance and may also lead to additional costs.
[0035] In view of the above, embodiments of this disclosure provide a model processing method, a task processing method, a model processing apparatus, a task processing apparatus, a many-core system, an electronic device, and a computer-readable storage medium based on key-value cache information.
[0036] In this embodiment, for any target network module among at least some target modules of a preset model, at least some key-value cache information corresponding to the attention layer of the target network module is obtained; the network parameters of the forward connection layer of the target network module are adjusted based on the at least some key-value cache information to obtain the adjusted forward connection layer of the target network module; and at least some key-value cache information is deleted. Therefore, the network parameters of the forward connection layer can be adjusted using key-value cache information carrying short-term memory information, thereby converting short-term memory information into long-term memory information and storing this long-term memory information in the adjusted forward connection layer. This effectively preserves model information and allows for the deletion of corresponding key-value cache information, reducing the amount of cached information required by the model and alleviating the storage and bandwidth pressure on hardware devices.
[0037] The first aspect of this disclosure provides a model processing method based on key-value cache information.
[0038] Figure 1 This is a flowchart illustrating a model processing method based on key-value caching information, provided as an embodiment of the present disclosure. This method can be applied to a preset model, which includes at least one target network module. The target network module includes an attention layer and a forward connection layer. (Refer to...) Figure 1 The model processing method may include the following steps.
[0039] Step S11: For any target network module among at least some target network modules, obtain at least some key-value cache information corresponding to the attention layer of the target network module.
[0040] Step S12: Adjust the network parameters of the forward connection layer of the target network module based on at least part of the key-value cache information to obtain the adjusted forward connection layer of the target network module, so as to convert the first memory information carried by at least part of the key-value cache information into the second memory information, and store the second memory information in the adjusted forward connection layer, wherein the memory duration of the first memory information is less than the memory duration of the second memory information.
[0041] Step S13: Delete at least some of the key-value cache information.
[0042] In some optional implementations, the target network module is a module unit in a preset model, used to perform data processing related to the attention mechanism. Furthermore, a preset model may include one or more target network modules. When multiple target network modules exist, they can be connected in a serial and / or parallel manner. The attention mechanism includes self-attention, other-attention, global attention, local attention, etc., and this disclosure does not limit the specific mechanisms used.
[0043] In some alternative implementations, the target network module includes an attention layer and a forward connection layer (FFN).
[0044] The attention layer primarily handles the correlation between tokens (i.e., the time dimension). Since the input tokens have a certain degree of "temporariness," the attention layer can be considered to mainly involve short-term memory information. The forward connection layer primarily handles the correlation between individual tokens across various dimensions. Furthermore, the network parameters of the FFN layer mainly depend on the training set and are relatively fixed; therefore, the forward connection layer can be considered to mainly involve long-term memory information.
[0045] As mentioned earlier, with the processing of data from the preset model, a large amount of key-value cache information will accumulate. This key-value cache information will occupy a lot of storage and bandwidth resources. Therefore, in this embodiment of the present disclosure, for some target network modules, all or part of the key-value cache information corresponding to the attention layer of the target network module can be used to update the network parameters of the forward connection layer of the target network module. In this way, the short-term memory information carried by this part of the key-value cache information can be converted into long-term memory information, and the converted long-term memory information can be stored in the updated network parameters of the forward connection layer. Then, the converted part of the key-value cache information can be deleted, thereby releasing the storage resources occupied by this part of the key-value cache information and reducing the bandwidth overhead caused by transmitting this part of the key-value cache information.
[0046] In this embodiment, for any target network module among at least some target modules of a preset model, at least some key-value cache information corresponding to the attention layer of the target network module is obtained; the network parameters of the forward connection layer of the target network module are adjusted based on the at least some key-value cache information to obtain the adjusted forward connection layer of the target network module; and at least some key-value cache information is deleted. Therefore, the network parameters of the forward connection layer can be adjusted using the key-value cache information carrying short-term memory information, thereby converting short-term memory information into long-term memory information and storing this long-term memory information in the adjusted forward connection layer. This effectively preserves model information and allows for the deletion of corresponding key-value cache information, reducing the amount of cached information required by the model and alleviating the storage and bandwidth pressure on the hardware device carrying the model.
[0047] The model processing method based on key-value cache information according to the embodiments of this disclosure will be described in detail below.
[0048] In some optional implementations, the preset model may include one target network module or multiple isomorphic target network modules. Each target network module includes an attention layer and a forward connection layer. The attention layer is mainly used to mix tokens at different positions, while the forward connection layer is mainly used to mix the features of each token across different dimensions.
[0049] It should be noted that, in addition to the target network module, other network modules may exist in the preset model to implement other functions, and this disclosure does not limit this.
[0050] In some optional implementations, for any target network module among at least some target network modules, obtaining at least some key-value cache information corresponding to the attention layer of the target network module includes: selecting at least some target network modules from all target network modules of the preset model, and obtaining at least some key-value cache information of each selected target network module from a preset space; wherein, the preset space is a storage space used to store key-value cache information.
[0051] In some optional implementations, obtaining at least a portion of the key-value cache information corresponding to the attention layer of the target network module includes: selecting a portion of all key-value cache information corresponding to the attention layer as at least a portion of the key-value cache information; or, using all key-value cache information corresponding to the attention layer as at least a portion of the key-value cache information.
[0052] In other words, when selecting key-value cache information to be converted for a specific target network module, all key-value cache information of its attention layer can be selected for conversion, or a portion of the key-value cache information can be selected for conversion. This disclosure does not impose any restrictions on this.
[0053] It should be noted that the selected target network module is the target network module to be processed. When selecting the target network module to be processed from all target network modules in the preset model, the selection of which target network modules and how many target network modules to select can be determined based on the position, function, processing requirements, experience and statistical data of the target network module in the preset model. This embodiment does not limit this.
[0054] In some optional implementations, all key-value cache information corresponding to the attention layer constitutes a key-value cache sequence; correspondingly, a portion of the key-value cache information corresponding to the attention layer is selected as at least part of the key-value cache information, including: extracting a portion from the key-value cache sequence to obtain a key-value cache subsequence, and using the key-value cache information corresponding to the key-value cache subsequence as at least part of the key-value cache information.
[0055] For example, the first part of the key-value cache sequence is extracted to obtain a key-value cache subsequence, and this key-value cache subsequence is used as at least part of the key-value cache information.
[0056] For example, a key-value cache subsequence can be obtained by extracting a portion of the middle part of the key-value cache sequence, and this key-value cache subsequence can be used as at least part of the key-value cache information.
[0057] For example, the latter part of the key-value cache sequence is extracted to obtain a key-value cache subsequence, and this key-value cache subsequence is used as at least part of the key-value cache information.
[0058] It should be noted that when truncating a key-value cache subsequence, truncating parameters such as truncating length, truncating position, and truncating data volume can be predetermined, and the key-value cache subsequence can be determined based on these parameters. Specifically, the truncating length represents the length of the key-value cache subsequence to be truncated (including absolute length and relative length ratio (e.g., 20%)), the truncating position represents the position of the key-value cache subsequence to be truncated within the overall key-value cache sequence, and the truncating data volume represents the amount of data in the key-value cache subsequence to be truncated (including absolute data volume (e.g., 10 kilobytes, KB)) and relative data volume ratio (e.g., 10%).
[0059] In some optional implementations, a portion of the key-value cache information corresponding to the attention layer is selected as at least part of the key-value cache information, including: selecting a portion of the key-value cache information corresponding to the attention layer as at least part of the key-value cache information according to preset filtering conditions.
[0060] The filtering criteria are used to filter the key-value cache information to be converted (i.e., "at least some key-value cache information"). Key-value cache information that meets the filtering criteria is selected as the aforementioned "at least some key-value cache information", while key-value cache information that does not meet the filtering criteria remains unchanged.
[0061] In some alternative implementations, the filtering criteria are determined based on the information entropy of each key-value cache entry in at least a portion of the key-value cache information.
[0062] For example, for a target network module, the information entropy of the key-value cache information of each token processed in the past by the computational attention layer of the target network module is calculated, and the key-value cache information whose information entropy is less than or equal to the first entropy threshold is filtered out as the key-value cache information to be transformed, while the remaining key-value cache information is left unchanged.
[0063] For example, for a target network module, the information entropy of the key-value cache information of each token processed in the past by the computational attention layer of the target network module is calculated, and the key-value cache information whose information entropy is greater than or equal to the second entropy threshold is filtered out as the key-value cache information to be transformed, while the remaining key-value cache information is left unchanged.
[0064] It should be noted that the above screening criteria are merely illustrative examples, and this disclosure does not impose any limitations on them.
[0065] Furthermore, when the preset model includes multiple target network modules, for some or all of these target network modules, at least a portion of the key-value cache information of the corresponding attention layer (i.e., the attention layer in the same target network module as the forward connection layer) can be saved to the forward connection layer by adjusting the network parameters of the forward connection layer. When adjusting the network parameters of the forward connection layers of multiple target network modules, the processing of each target network module is independent, and the processing procedure is separate, which can be performed in parallel (or serially).
[0066] In some alternative implementations, after obtaining at least a portion of the key-value cache information corresponding to the attention layer of the target network module, the network parameters of the forward connection layer can be adjusted using this portion of key-value cache information, thereby converting the first memory information carried by this portion of key-value cache information into second memory information, and the forward connection layer "stores" the converted second memory information.
[0067] As mentioned earlier, the first memory information carried by the key-value cache information of the attention layer is essentially short-term memory information, and the second memory information carried by the forward connection layer is essentially long-term memory information. Therefore, the purpose of adjusting the network parameters is to convert short-term memory information into long-term memory information, and to store the converted long-term memory information in the forward connection layer with the help of the network parameters of the forward connection layer.
[0068] In some alternative implementations, the network parameters of the forward connection layer can be adjusted using an objective function.
[0069] In some optional implementations, adjusting the network parameters of the forward connection layer of the target network module based on at least some key-value cache information to obtain the adjusted forward connection layer of the target network module includes: determining the parameter adjustment amount of the forward connection layer of the target network module according to a preset objective function; wherein, the objective function is a function of at least some key-value cache information, the input data of the target network module, the network parameters of the attention layer, and the network parameters of the forward connection layer, and the input data conforms to a preset probability distribution; adjusting the network parameters of the forward connection layer of the target network module according to the parameter adjustment amount to obtain the adjusted network parameters of the forward connection layer of the target network module; and determining the adjusted forward connection layer based on the adjusted network parameters. The parameter adjustment amount is the amount by which the network parameters of the forward connection layer are adjusted, and it can be a positive number or a negative number; this disclosure does not limit this.
[0070] In some optional implementations, network parameters may include weight parameters, bias parameters, etc., and the embodiments disclosed herein do not impose any limitations on this.
[0071] In some alternative implementations, the objective function can be characterized by the following formula:
[0072]
[0073] Where E represents the statistical average, min represents the function for finding the minimum value, x represents the input data, x~N indicates that the input data follows a normal distribution, θ1 represents the network parameters of the attention layer, f1(x,θ1,s) represents the data processing of the attention layer, s represents the key-value cache information to be processed in the attention layer, f2(f1(x,θ1,s)+x,θ2) represents the data processing of the forward connection layer, f1(x,θ1,s)+x is the input of the forward connection layer, and θ2 represents the network parameters of the forward connection layer. This indicates the amount of parameter adjustment for the network parameters of the forward connection layer.
[0074] Furthermore, solving for this objective function aims to make the statistical average E of the objective function on the input data x. x~N The value of is minimized. The significance of this formula lies in constraining the output change of the target network module before and after adjustment, prompting the injection of key-value cache information from the attention layer into the network parameters (such as weight parameters) of the forward connection layer. Furthermore, during the above adjustment process, the network parameters of the attention layer remain unchanged; only the network parameters of the forward connection layer are adjusted.
[0075] In some alternative implementations, the objective function can be constructed using other functions and characterized by corresponding formulas. For example, the objective function can be constructed based on cross-entropy loss, maximum likelihood estimation, etc., and solved on preset input data. The updated network parameters of the forward connection layer are then determined based on the obtained objective solution. The above examples of objective functions are merely illustrative and do not limit the scope of this disclosure.
[0076] In some optional implementations, the objective function may also include constraint subfunctions; these constraint subfunctions are functions that define the constraints that need to be satisfied when solving the objective function. Furthermore, by setting constraint subfunctions, the impact of parameter updates on the original network parameters can be constrained, and the forgetting of other long-term memories in the forward connection layers can be avoided or mitigated.
[0077] In some optional implementations, the constraint subfunction includes at least one of the following: low-rank constraint subfunction, sparse constraint subfunction, and norm constraint subfunction; wherein, the low-rank constraint subfunction is used to constrain the rank corresponding to the parameter adjustment amount, the sparse constraint subfunction is used to constrain the sparsity of the parameter adjustment amount, and the norm constraint subfunction is used to constrain the magnitude of the parameter adjustment amount.
[0078] For example, the objective function can be characterized as:
[0079]
[0080] Among them, sb This represents a low-rank constraint sub-function, where r is a preset rank threshold. This represents the rank corresponding to the parameter adjustment amount. This constraint subfunction indicates that the rank corresponding to the parameter adjustment amount should be less than the preset rank threshold. The meanings of other parameters can be found in the aforementioned related content, and will not be described in detail here.
[0081] It should be noted that using low-rank constraint subfunctions can ensure the parameter adjustment amount It is low-rank, and this constraint can reduce the impact on the original network parameters of the forward connection layer, making the adjustment process of the network parameters of the forward connection layer similar to the low-rank adaptation (Lora) fine-tuning process, thereby effectively reducing the amount of data processing.
[0082] For example, the objective function can be characterized as:
[0083]
[0084] Among them, sb This represents a sparse constraint subfunction, where s is a preset sparsity threshold. This indicates the sparsity corresponding to the parameter adjustment amount. This constraint subfunction indicates that the sparsity corresponding to the parameter adjustment amount should be greater than the preset sparsity threshold. The meanings of other parameters can be found in the aforementioned related content, and will not be described in detail here.
[0085] The sparsity constraint subfunction can constrain the sparsity of the parameter adjustment amounts in the forward connection layer, making the parameter adjustment amounts sparse, that is, only a portion of the parameter adjustment amounts are non-zero, and most of the parameter adjustment amounts are zero.
[0086] For example, the objective function can be characterized as:
[0087]
[0088] Among them, sb This represents a norm constraint subfunction, where n is a preset norm threshold. This represents the norm corresponding to the parameter adjustment amount. This constraint subfunction indicates that the norm corresponding to the parameter adjustment amount should be less than the preset norm threshold. The meanings of other parameters can be found in the aforementioned related content, and will not be described in detail here.
[0089] The norm constraint subfunction can constrain the norm of the parameter adjustment of the forward connection layer, thereby making the update magnitude of the network parameters of the forward connection layer smaller.
[0090] It should be noted that in some optional implementations, multiple constraints can be combined when solving the objective function, i.e., multiple constraint sub-functions can be used as constraints for solving the objective function. The purpose is to constrain the parameter updates of the forward connection layer from different perspectives and alleviate information forgetting.
[0091] It should also be noted that the objective function can be solved using gradient descent methods (such as batch gradient descent, stochastic gradient descent, etc.), and the embodiments disclosed herein do not limit the solution method.
[0092] As can be seen from the above, at least part of the key-value cache information of the attention layer can be used to adjust the network parameters of the corresponding forward connection layer. In this way, the first memory information carried by this part of the key-value cache information can be converted into second memory information, and by adjusting the network parameters of the forward connection layer, this part of the second memory information can be "stored" in the forward connection layer, thereby realizing the conversion of short-term memory information into long-term memory information.
[0093] Furthermore, for a target network module, its attention layer and forward connection layer can be connected in parallel or in sequence. Moreover, in a preset model, the connection method between the attention layer and the forward connection layer in different target network modules can be the same or different; this disclosure does not impose any restrictions on this.
[0094] In some optional implementations, before adjusting the network parameters of the forward connection layer of the target network module based on at least some key-value cache information to obtain the adjusted forward connection layer of the target network module, the method may further include: adjusting the attention layer and the forward connection layer to be connected in parallel when the attention layer and the forward connection layer are connected in series, to obtain the adjusted preset model; fine-tuning the adjusted preset model based on a preset calibration dataset to obtain the fine-tuned preset model, so as to perform data processing on at least some of the target network modules in the fine-tuned preset model.
[0095] In other words, when the attention layer and forward connection layer of the target network module are connected serially, the connection method between the attention layer and the forward connection layer can be changed from serial to parallel before adjusting the network parameters of the forward connection layer. Furthermore, because of this change in connection method, to ensure that the preset model still possesses the corresponding data processing functions and accurate data processing capabilities, some fine-tuning can be performed on the adjusted preset model so that the network parameters of the fine-tuned preset model are compatible with the aforementioned parallel connection method.
[0096] It should be noted that in some optional implementations, residual connections may also exist in the target network module. These residual connections allow the input and output to be added together, which helps deeper network layers learn effective feature representations and simplifies gradient propagation, effectively mitigating problems such as vanishing and exploding gradients in deep networks. Furthermore, normalization and other processing can be performed after the residual connections; this disclosure does not limit the scope of such processing.
[0097] It should be noted that when a parallel connection is used between the attention layer and the forward connection layer, the input of the forward connection layer may not include the output of the corresponding attention layer. Therefore, the mutual influence between the attention layer and the forward connection layer can be reduced, which is beneficial for the conversion of key-value cache information.
[0098] Furthermore, after adjusting the network parameters of the forward connection layer, since the short-term memory information carried by the key-value cache information has been converted into long-term memory information and stored in the forward connection layer, the converted key-value cache information can be deleted.
[0099] In some optional implementations, at least a portion of the key-value cache information is deleted, including: removing the key-value cache information to be converted from the preset space to release the storage resources occupied by this portion of the key-value cache information.
[0100] In summary, the model processing method based on key-value cache information in this embodiment updates the network parameters of the forward connection layer of at least a portion of the target network modules in the preset model, which is equivalent to fine-tuning or retraining the preset model. Through this fine-tuning or retraining, at least a portion of the key-value cache information is "transferred" to the updated forward connection layer. Therefore, the transferred key-value cache information can be deleted from the cache space, releasing some storage resources of the cache space. Furthermore, when performing forward inference using the fine-tuned or retrained preset model, it is not necessary to load the deleted key-value cache information. Instead, the updated forward connection layer can "replace" this portion of key-value cache information to perform the corresponding data processing function, thus reducing the bandwidth overhead caused by loading key-value cache information.
[0101] It should be noted that after processing the preset model using the model processing method based on key-value cache information in the embodiments of this disclosure, various tasks to be processed can be executed based on the adjusted preset model. The tasks to be processed may include text processing tasks, voice processing tasks, and video processing tasks, etc., and the embodiments of this disclosure do not limit them.
[0102] In some optional implementations, model processing for multiple target network modules can be performed in parallel. In other words, if it is necessary to process at least a portion of the key-value cache information of multiple target network modules of a preset model to adjust the network parameters of the corresponding forward connection layer, the corresponding data processing of each target network module can be performed independently and in parallel.
[0103] In some alternative implementations, the model processing method based on key-value cache information of this disclosure can be applied to many-core scenarios.
[0104] In some optional implementations, a target network module of a preset model is mapped to a processing unit of a many-core system, with each processing unit corresponding to a processing core or a group of cores; each processing unit executes the model processing of the mapped target network module in parallel. The parallel processing can include asynchronous parallel processing and synchronous parallel processing, and this disclosure does not limit this approach.
[0105] Figure 2 This is a schematic diagram of a target network module provided in Embodiment 1 of this disclosure. (Refer to...) Figure 2The target network module includes an attention layer and a forward connection layer, with the attention layer and the forward connection layer connected sequentially. Further, the input of the attention layer is fused with its output via a residual connection (e.g., addition), and the fused result is used as the input of the forward connection layer. Similarly, for the forward connection layer, its input and output are fused using a residual connection to obtain the output of the target network module.
[0106] Figure 3 This is a schematic diagram of a target network module provided in Embodiment 2 of this disclosure. (Refer to...) Figure 3 The target network module includes an attention layer and a forward connection layer, which are connected in parallel. Further, the attention layer and the forward connection layer process the input data separately to obtain their respective processing results. These results are then fused with the input of the target network module using residual connections to obtain the output of the target network module.
[0107] It should be noted that the above description of the target network module structure is merely an example, and the embodiments disclosed herein do not impose any limitations on it.
[0108] Figure 4 This is a flowchart illustrating a model processing method based on key-value caching information provided in an embodiment of this disclosure, referring to... Figure 4 The model processing method may include the following steps.
[0109] Step S401: Obtain a preset model, which includes at least one target network module, and each target network module includes an attention layer and a forward connection layer.
[0110] Step S402: Select at least a portion of the target network modules from at least one target network module of the preset model as the target network modules to be processed.
[0111] Step S403: Determine whether the attention layer and the forward connection layer in the target network module to be processed are connected in a serial manner.
[0112] If the attention layer and the forward connection layer use a serial connection method, then jump to step S404; otherwise, jump to step S406.
[0113] Step S404: Adjust the attention layer and forward connection layer in the target network module to be processed to be connected in parallel to obtain the adjusted preset model.
[0114] Step S405: Fine-tune the adjusted preset model based on the preset calibration dataset to obtain the fine-tuned preset model, so as to process the target network module to be processed in the fine-tuned preset model.
[0115] Step S406: For any target network module to be processed, obtain at least some key-value cache information corresponding to the attention layer of the target network module.
[0116] Step S407: Determine the parameter adjustment amount of the forward connection layer of the target network module according to the preset objective function; wherein, the objective function is a function of at least part of the key-value cache information of the target network module, the input data of the target network module, the network parameters of the attention layer, and the network parameters of the forward connection layer, and the input data conforms to the preset probability distribution.
[0117] Step S408: Adjust the network parameters of the forward connection layer of the target network module according to the parameter adjustment amount to obtain the adjusted network parameters of the forward connection layer of the target network module.
[0118] Step S409: Determine the adjusted forward connection layer based on the adjusted network parameters.
[0119] Step S410: After adjusting the forward connection layers of all target network modules to be processed, the adjusted preset model is obtained, and the task to be processed is executed based on the adjusted preset model.
[0120] A second aspect of this disclosure provides a task processing method.
[0121] Figure 5 This is a flowchart illustrating a task processing method provided in an embodiment of the present disclosure. The method can be applied to a preset model, which includes at least one target network module. The target network module includes an attention layer and a forward connection layer. (Refer to...) Figure 5 The task processing method may include the following steps.
[0122] Step S51: Input the task data to be processed into the preset model to obtain the task processing result.
[0123] The preset model is obtained based on the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure. The attention layer of the target network module is used to perform first data processing on the input hidden state vector to obtain a first processing result. The forward connection layer of the target network module is used to perform second data processing on the input hidden state vector to obtain a second processing result. The first processing result and the second processing result are fused to obtain the output hidden state vector of the target network module. The output hidden state vector is used as the input hidden state vector of the next target network module. The input hidden state vector of the first target network module is determined based on the task data to be processed. The task processing result is determined based on the output hidden state vectors of multiple target network modules.
[0124] In some alternative implementations, the task to be processed includes at least one of text processing tasks, audio processing tasks, and video processing tasks, and this disclosure does not limit this.
[0125] In some optional implementations, if the attention layer and the forward connection layer of the target network module are connected in a serial manner, the attention layer is used to perform a first data processing on the input hidden state vector to obtain a first processing result, and uses the first processing result as the input hidden state vector of the forward connection layer of the target network module. The forward connection layer then performs a second data processing to obtain a second processing result, and uses the second processing result as the input hidden state vector of the next target network module so that the next target network module can perform the corresponding data processing.
[0126] Furthermore, after obtaining the output hidden state vectors of multiple target network modules, the corresponding task processing results can be obtained after processing by subsequent linear layers, normalization layers (such as Softmax layers), and other network layers.
[0127] For example, a linear layer can be viewed as a simple fully connected neural network that maps the output hidden state vector of the decoder of the preset model to a longer vector, which can be called a logits vector. Each value in the logits vector corresponds to the score of each word in the output vocabulary of the preset model. The normalization layer converts these scores into probabilities and selects the word with the highest probability as the corresponding output result.
[0128] Therefore, it can be seen that after adjusting the network parameters of the forward connection layer based on the key-value cache information model processing method of this disclosure to obtain the adjusted preset model, various tasks to be processed can be executed using the adjusted preset model, and the corresponding task processing results can be obtained. Specifically, when executing the tasks to be processed, the key-value cache information that the preset model can use only includes the key-value cache information that has not been converted or deleted, and the network parameters of the forward connection layer used are also the adjusted network parameters.
[0129] In summary, in this embodiment, the network parameters of the forward connection layer in the target network module of the preset model have been adjusted based on at least a portion of the key-value cache information of the corresponding attention layer. This converts the first memory information carried by the key-value cache information into second memory information with a longer memory duration, and "stores" this second memory information in the adjusted network parameters of the forward connection layer. On the one hand, this alleviates the data storage and data transmission pressure of the preset model; on the other hand, because the memory information is preserved as much as possible through the conversion, important information is retained in the preset model, thus not significantly affecting the processing performance of the preset model. Based on this, when using the preset model to execute a task, the corresponding task data is input into the preset model, and after the corresponding data processing of the preset model, an accurate and reasonable task processing result can be obtained.
[0130] It is understood that the various embodiments mentioned above in this disclosure can be combined with each other to form combined embodiments without violating the principle and logic. Due to space limitations, this disclosure will not elaborate further. Those skilled in the art will understand that in the above methods of specific implementation, the specific execution order of each step and the setting of functional modules should be determined by their functions and possible internal logic.
[0131] The third aspect of this disclosure provides a model processing apparatus based on key-value cache information.
[0132] Figure 6 This is a block diagram of a model processing apparatus based on key-value caching information, provided in an embodiment of this disclosure. The apparatus can be applied to a preset model, which includes at least one target network module. The target network module includes an attention layer and a forward connection layer. (Refer to...) Figure 6 The model processing device 600 based on key-value cache information may include the following modules.
[0133] The acquisition module 601 is used to acquire at least some key-value cache information corresponding to the attention layer of any target network module among at least some target network modules.
[0134] The adjustment module 602 is used to adjust the network parameters of the forward connection layer of the target network module based on at least some key-value cache information to obtain the adjusted forward connection layer of the target network module, so as to convert the first memory information carried by at least some key-value cache information into second memory information, and store the second memory information in the adjusted forward connection layer, wherein the memory duration of the first memory information is less than the memory duration of the second memory information.
[0135] Module 603 is used to delete at least a portion of the key-value cache information.
[0136] The embodiments provided in this disclosure, for any target network module among at least some target modules of a preset model, acquire at least some key-value cache information corresponding to the attention layer of the target network module through an acquisition module; adjust the network parameters of the forward connection layer of the target network module based on the at least some key-value cache information through an adjustment module to obtain the adjusted forward connection layer of the target network module; and delete at least some key-value cache information through a deletion module. Therefore, it can be seen that the network parameters of the forward connection layer can be adjusted using the key-value cache information carrying short-term memory information, thereby converting short-term memory information into long-term memory information and storing this long-term memory information in the adjusted forward connection layer. This effectively preserves model information and allows for the deletion of corresponding key-value cache information, reducing the amount of cache information required by the model and alleviating the storage and bandwidth pressure on the hardware device carrying the model.
[0137] A fourth aspect of this disclosure provides a task processing apparatus.
[0138] Figure 7 This is a block diagram of a task processing apparatus provided in an embodiment of the present disclosure. The apparatus can be applied to a preset model, which includes at least one target network module. The target network module includes an attention layer and a forward connection layer. (Refer to...) Figure 7 The task processing device 700 may include the following modules.
[0139] The processing module 701 is used to input the task data to be processed into the preset model to obtain the task processing result. The preset model is obtained based on the model processing method based on key-value cache information according to any one of the embodiments of this disclosure.
[0140] In this process, the attention layer of the target network module performs first data processing on the input hidden state vector to obtain a first processing result. The forward connection layer of the target network module performs second data processing on the input hidden state vector to obtain a second processing result. The first and second processing results are fused to obtain the output hidden state vector of the target network module, and the output hidden state vector is used as the input hidden state vector of the next target network module. The input hidden state vector of the first target network module is determined based on the task data to be processed, and the task processing result is determined based on the output hidden state vectors of multiple target network modules.
[0141] In the embodiments provided in this disclosure, the network parameters of the forward connection layer in the target network module of the preset model have been adjusted based on at least a portion of the key-value cache information of the corresponding attention layer. This causes the first memory information carried by the key-value cache information to be converted into second memory information with a longer memory duration, and this second memory information is "stored" in the adjusted network parameters of the forward connection layer. On the one hand, this alleviates the data storage and data transmission pressure of the preset model; on the other hand, since the memory information is preserved as much as possible through the conversion of memory information, important information is retained in the preset model, thus not significantly affecting the processing performance of the preset model. Based on this, when using the preset model to execute a task, the corresponding task data is input into the preset model through the processing module, and after the corresponding data processing of the preset model, an accurate and reasonable task processing result can be obtained.
[0142] The fifth aspect of this disclosure provides a many-core system.
[0143] Figure 8 This is a block diagram of a many-core system provided in an embodiment of this disclosure. (Refer to...) Figure 8 The many-core system 800 may include: multiple processing units, each processing unit corresponding to a processing core or a core group, and a target network module of a preset model is mapped to a processing unit of the many-core system.
[0144] The many-core system is used to execute the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure.
[0145] In some optional implementations, when processing the model based on key-value cache information, the target network modules of the preset model can be mapped one by one to the processing units of the many-core system. This allows multiple processing units to execute the relevant processing of their respective mapped target network modules in asynchronous or synchronous parallel modes. The processing includes: obtaining at least a portion of the key-value cache information corresponding to the attention layer of the mapped target network module; adjusting the network parameters of the forward connection layer of the target network module based on the at least a portion of the key-value cache information to obtain the adjusted forward connection layer of the target network module; and converting the short-term memory information (i.e., the first memory information) carried by the at least a portion of the key-value cache information into long-term memory information (i.e., the second memory information), and storing the long-term memory information in the adjusted forward connection layer.
[0146] In some optional implementations, during task processing, the target network modules of the preset model can be mapped one by one to the processing units of the many-core system. This allows multiple processing units to execute the relevant processing of their respective mapped target network modules using asynchronous parallelism, synchronous parallelism, or serial methods. The processing includes: performing first data processing on the input hidden state vector through the attention layer of the target network module to obtain a first processing result; performing second data processing on the input hidden state vector through the forward connection layer of the target network module to obtain a second processing result; fusing the first and second processing results to obtain the output hidden state vector of the target network module; and using the output hidden state vector as the input hidden state vector of the next target network module.
[0147] The embodiments provided in this disclosure can make full use of the hardware structure features of the many-core system when adjusting the network parameters of the preset model and using the preset model to execute the task to be processed, thereby enabling the corresponding model processing to be executed in parallel, which is beneficial to shorten the data processing time and improve the data processing efficiency.
[0148] In addition, this disclosure also provides electronic devices and computer-readable storage media.
[0149] Figure 9 This is a block diagram of an electronic device provided in Embodiment 1 of this disclosure.
[0150] Reference Figure 9 This disclosure provides an electronic device comprising: at least one processor 901; at least one memory 902; and one or more I / O interfaces 903 connected between the processor 901 and the memory 902; wherein the memory 902 stores one or more computer programs executable by the at least one processor 901, the one or more computer programs being executed by the at least one processor 901 to enable the at least one processor 901 to execute the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure.
[0151] Figure 10 This is a block diagram of an electronic device provided in Embodiment 2 of this disclosure.
[0152] Reference Figure 10 Embodiment 2 of this disclosure provides an electronic device, which includes multiple processing cores 1001 and an on-chip network 1002, wherein the multiple processing cores 1001 are all connected to the on-chip network 1002, and the on-chip network 1002 is used to exchange data between the multiple processing cores and external data.
[0153] One or more processing cores 1001 store one or more instructions, and the one or more instructions are executed by one or more processing cores 1001 to enable one or more processing cores 1001 to execute the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure.
[0154] In some embodiments, the electronic device may be a neuromorphic chip. Since neuromorphic chips can employ vectorized computation and require external memory, such as Double Data Rate (DDR) synchronous dynamic random access memory, to load parameters such as weights of the neural network model, the batch processing method used in this embodiment offers higher computational efficiency.
[0155] This disclosure also provides a computer-readable storage medium storing a computer program thereon, wherein the computer program, when executed by a processor / processing core, implements the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure. The computer-readable storage medium may be a volatile or non-volatile computer-readable storage medium.
[0156] This disclosure also provides a computer program product, including computer-readable code, or a non-volatile computer-readable storage medium carrying computer-readable code. When the computer-readable code is run in a processor of an electronic device, the processor in the electronic device executes the model processing method based on key-value cache information as described in any one of the embodiments of this disclosure, or the task processing method as described in any one of the embodiments of this disclosure.
[0157] Those skilled in the art will understand that all or some of the steps, systems, and apparatuses disclosed above, and their functional modules / units, can be implemented as software, firmware, hardware, or suitable combinations thereof. In hardware implementations, the division between functional modules / units mentioned above 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 collaboratively by several physical components. Some or all physical components may be implemented as software executed by a processor, such as a central processing unit, digital signal processor, or microprocessor, or as hardware, or as an integrated circuit, such as an application-specific integrated circuit (ASIC). Such software can be distributed on a computer-readable storage medium, which may include computer storage media (or non-transitory media) and communication media (or transient media).
[0158] As is known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, 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 includes, but is 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 technologies, portable compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical disc storage, magnetic cartridges, magnetic tape, disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and is accessible to a computer. Furthermore, it is known to those skilled in the art that communication media typically contain computer-readable program instructions, data structures, program modules, or other data in modulated data signals such as carrier waves or other transmission mechanisms, and may include any information delivery medium.
[0159] The computer-readable program instructions described herein can be downloaded from computer-readable storage media to various computing / processing devices, or downloaded via a network, such as the Internet, local area network, wide area network, and / or wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards them to the computer-readable storage media in the respective computing / processing device.
[0160] Computer program instructions used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status 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 the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving 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., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing the status information of the computer-readable program instructions to implement various aspects of this disclosure.
[0161] The computer program product described herein can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0162] Various aspects of this disclosure are described herein with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this disclosure. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-readable program instructions.
[0163] 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 apparatus to produce a machine such that, when executed by the processor of the computer or other programmable data processing apparatus, they create means for implementing the functions / actions specified in one or more blocks of the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium that causes a computer, programmable data processing apparatus, and / or other device to operate in a particular manner; thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing aspects of the functions / actions specified in one or more blocks of the flowchart and / or block diagram.
[0164] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device to cause a series of operational steps to be 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 perform the functions / actions specified in one or more boxes of a flowchart and / or block diagram.
[0165] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of an instruction containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than those shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0166] Example embodiments have been disclosed herein, and while specific terminology has been used, it is for illustrative purposes only and should be construed as such, and is not intended to be limiting. In some instances, it will be apparent to those skilled in the art that features, characteristics, and / or elements described in connection with particular embodiments may be used alone, or in combination with features, characteristics, and / or elements described in connection with other embodiments, unless otherwise expressly indicated. Therefore, those skilled in the art will understand that various changes in form and detail may be made without departing from the scope of this disclosure as set forth by the appended claims.
Claims
1. A model processing method based on key-value caching information, characterized in that, Applied to a preset model, the preset model including at least one target network module, the target network module including an attention layer and a forward connection layer, the method includes: For any target network module among at least some target network modules, obtain at least some key-value cache information corresponding to the attention layer of the target network module; Based on the at least part of the key-value cache information, the network parameters of the forward connection layer of the target network module are adjusted to obtain the adjusted forward connection layer of the target network module, so as to convert the first memory information carried by the at least part of the key-value cache information into the second memory information, and store the second memory information in the adjusted forward connection layer, wherein the memory duration of the first memory information is less than the memory duration of the second memory information; Delete at least a portion of the key-value cache information; The step of adjusting the network parameters of the forward connection layer of the target network module based on the at least partial key-value cache information to obtain the adjusted forward connection layer of the target network module includes: The parameter adjustment amount of the forward connection layer of the target network module is determined according to a preset objective function; wherein, the objective function is a function of at least some key-value cache information, the input data of the target network module, the network parameters of the attention layer, and the network parameters of the forward connection layer, and the input data conforms to a preset probability distribution; The network parameters of the forward connection layer of the target network module are adjusted according to the parameter adjustment amount to obtain the adjusted network parameters of the forward connection layer of the target network module. The adjusted forward connection layer is determined based on the adjusted network parameters.
2. The method according to claim 1, characterized in that, The objective function also includes constraint sub-functions; The constraint sub-functions include at least one of the following: low-rank constraint sub-functions, sparse constraint sub-functions, and norm constraint sub-functions; The low-rank constraint subfunction is used to constrain the rank corresponding to the parameter adjustment amount, the sparse constraint subfunction is used to constrain the sparsity of the parameter adjustment amount, and the norm constraint subfunction is used to constrain the magnitude of the parameter adjustment amount.
3. The method according to claim 1 or 2, characterized in that, The objective function is characterized by the following formula: in, This represents the statistical average. This represents a function that finds the minimum value. Indicates input data, This indicates that the input data follows a normal distribution. This represents the network parameters of the attention layer. This represents the data processing of the attention layer. This represents the key-value cache information to be processed in the attention layer. This indicates the data processing of the forward connection layer. As input to the forward connection layer, This represents the network parameters of the forward connection layer. This indicates the amount of parameter adjustment for the network parameters of the forward connection layer.
4. The method according to claim 1, characterized in that, The step of obtaining at least a portion of the key-value cache information corresponding to the attention layer of the target network module includes: Select a portion of all key-value cache information corresponding to the attention layer as the at least partial key-value cache information; or, All key-value cache information corresponding to the attention layer is used as the at least part of the key-value cache information.
5. The method according to claim 4, characterized in that, All key-value cache information corresponding to the attention layer constitutes a key-value cache sequence; The step of selecting a portion of the key-value cache information corresponding to the attention layer as the at least part of the key-value cache information includes: A portion is extracted from the key-value cache sequence to obtain a key-value cache subsequence, and the key-value cache information corresponding to the key-value cache subsequence is used as the at least part of the key-value cache information.
6. The method according to claim 4, characterized in that, The step of selecting a portion of the key-value cache information corresponding to the attention layer as the at least part of the key-value cache information includes: Based on preset filtering conditions, a portion of the key-value cache information corresponding to the attention layer is selected as the at least part of the key-value cache information.
7. The method according to claim 6, characterized in that, The filtering criteria are determined based on the information entropy of each key-value cache information in the at least partial key-value cache information.
8. The method according to claim 1, characterized in that, The attention layer and the forward connection layer of the target network module are connected in parallel or in series. Before adjusting the network parameters of the forward connection layer of the target network module based on the at least partial key-value cache information to obtain the adjusted forward connection layer of the target network module, the method further includes: When the attention layer and the forward connection layer are connected in series, the attention layer and the forward connection layer are adjusted to be connected in parallel to obtain the adjusted preset model; The adjusted preset model is fine-tuned based on a preset calibration dataset to obtain a fine-tuned preset model, and at least some target network modules in the fine-tuned preset model are then processed for data processing.
9. The method according to any one of claims 1 and 2, 4-8, characterized in that, The model processing of multiple target network modules is performed in parallel.
10. The method according to any one of claims 1 and 2, 4-8, characterized in that, A target network module of the preset model is mapped to a processing unit of the many-core system, and each processing unit corresponds to a processing core or a core group. Each of the processing units performs the model processing of the mapped target network module in parallel.
11. A task processing method, characterized in that, Applied to a preset model, the preset model including at least one target network module, the target network module including an attention layer and a forward connection layer, the method includes: The task data to be processed is input into the preset model to obtain the task processing result. The preset model is obtained based on the model processing method based on key-value cache information as described in any one of claims 1-10. The attention layer of the target network module performs first data processing on the input hidden state vector to obtain a first processing result. The forward connection layer of the target network module performs second data processing on the input hidden state vector to obtain a second processing result. The first processing result and the second processing result are fused to obtain the output hidden state vector of the target network module, which is then used as the input hidden state vector of the next target network module. The input hidden state vector of the first target network module is determined based on the task data to be processed, and the task processing result is determined based on the output hidden state vectors of multiple target network modules.
12. A model processing device based on key-value cache information, characterized in that, Applied to a preset model, the preset model including at least one target network module, the target network module including an attention layer and a forward connection layer, the device includes: The acquisition module is used to acquire at least some key-value cache information corresponding to the attention layer of any target network module among at least some target network modules; An adjustment module is used to adjust the network parameters of the forward connection layer of the target network module based on the at least part of the key-value cache information to obtain the adjusted forward connection layer of the target network module, so as to convert the first memory information carried by the at least part of the key-value cache information into the second memory information, and store the second memory information in the adjusted forward connection layer, wherein the memory duration of the first memory information is less than the memory duration of the second memory information; The deletion module is used to delete at least a portion of the key-value cache information; The adjustment module is further configured to determine the parameter adjustment amount of the forward connection layer of the target network module according to a preset objective function; wherein, the objective function is a function of the at least part of the key-value cache information, the input data of the target network module, the network parameters of the attention layer, and the network parameters of the forward connection layer, and the input data conforms to a preset probability distribution; the network parameters of the forward connection layer of the target network module are adjusted according to the parameter adjustment amount to obtain the adjusted network parameters of the forward connection layer of the target network module; and the adjusted forward connection layer is determined based on the adjusted network parameters.
13. A task processing device, characterized in that, Applied to a preset model, the preset model including at least one target network module, the target network module including an attention layer and a forward connection layer, the device includes: The processing module is used to input the task data to be processed into the preset model and obtain the task processing result. The preset model is obtained based on the model processing method based on key-value cache information as described in any one of claims 1-10. The attention layer of the target network module performs first data processing on the input hidden state vector to obtain a first processing result. The forward connection layer of the target network module performs second data processing on the input hidden state vector to obtain a second processing result. The first processing result and the second processing result are fused to obtain the output hidden state vector of the target network module. The output hidden state vector is used as the input hidden state vector of the next target network module. The input hidden state vector of the first target network module is determined based on the task data to be processed. The task processing result is determined based on the output hidden state vectors of multiple target network modules.
14. A many-core system, characterized in that, The many-core system includes multiple processing units, each processing unit corresponding to a processing core or a core group, and a target network module of a preset model is mapped to a processing unit of the many-core system. The many-core system is used to execute the model processing method based on key-value cache information as described in any one of claims 1-10, or the task processing method as described in claim 11.
15. 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 that can be executed by the at least one processor, the one or more computer programs being executed by the at least one processor to enable the at least one processor to perform the model processing method based on key-value cache information as described in any one of claims 1-10, or the task processing method as described in claim 11.
16. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the model processing method based on key-value cache information as described in any one of claims 1-10, or the task processing method as described in claim 11.
Citation Information
Patent Citations
Large language model reasoning optimization method and device, computer equipment and storage medium
CN117194056A
