A key-value cache management method, device and related equipment
By dynamically calculating the semantic importance score of key-value cache pairs for the Large Language Model (LLM) and adjusting their storage location, the problem of increasing GPU memory usage in the KV Cache is solved, improving the deployment efficiency and inference throughput of the LLM, and reducing IO overhead and latency jitter.
Patent Information
- Application Number
- CN202611357304.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-02
- Publication Date
- 2026-11-27
AI Technical Summary
In existing technologies, as the context length increases, the memory usage of key-value cache (KV Cache) grows linearly or even superlinearly, becoming a bottleneck restricting the deployment efficiency and inference throughput of large language models (LLM). Furthermore, existing unloading strategies lack semantic awareness, leading to the erroneous unloading of core key-value cache pairs, resulting in significant IO overhead and inference latency jitter.
By obtaining feature scores of multiple dimensions of key-value cache pairs, their semantic importance scores are calculated, and the storage location is dynamically adjusted according to the scores. High semantic importance cache pairs are preferentially stored in high-bandwidth memory, while low semantic importance cache pairs are stored in low-speed storage media. The weights are dynamically adjusted to adapt to the needs of different inference stages.
It achieves more accurate cache unloading determination, reduces the probability of false unloading, reduces low-speed storage I/O pullback overhead, and improves LLM inference performance and storage resource utilization efficiency.
Smart Images

Figure CN123178304A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a key-value cache management method, apparatus and related equipment. Background Technology
[0002] With the rapid development of Large Language Models (LLMs), their applications in scenarios such as long text generation, multi-turn dialogue, and code generation are becoming increasingly widespread. However, LLMs require maintaining a large key-value cache during the inference process to store the key and value vectors of historical tokens (semantic units), which is used to reuse the results of historical context attention calculations, significantly reducing inference latency and computational cost.
[0003] However, as the context length increases, the memory usage of the KV cache grows linearly or even superlinearly, becoming a key bottleneck restricting model deployment efficiency and inference throughput. The industry-standard KV cache offloading strategy is to offload some infrequently used KV cache from GPU memory to DDR, SSD, or remote storage to alleviate memory pressure. Summary of the Invention
[0004] This application provides a key-value cache management method, apparatus, and related equipment.
[0005] Firstly, this application provides a key-value cache management method, the method comprising: For each semantic unit Token, a key-value cache pair is generated, and the feature scores of the key-value cache pair in multiple dimensions are obtained. Among them, the feature scores of the key-value cache pair of a Token in each dimension are positively correlated with the semantic importance of the key-value cache pair of the Token. Based on the feature scores of multiple dimensions of each key-value cache pair and the weight values of multiple dimensions of preset features, the semantic importance score of each key-value cache pair is calculated. Based on the semantic importance score of each key-value cache pair, the storage location of each key-value cache pair is determined.
[0006] Optionally, the multiple dimensions of a key-value cache pair include: attention weight features, token type features, context position features, and historical session behavior features.
[0007] Optionally, a first weight value with multiple dimensions of features is preset for the pre-filling stage; a second weight value with multiple dimensions of features is preset for the decoding stage, wherein; The first weight of the Token type features and context position features preset for the pre-filling stage is higher than the second weight of the Token type features and context position features preset for the decoding stage. For the attention weight features preset in the decoding stage, the second weight of the historical conversation behavior features is higher than the first weight of the attention weight features preset in the pre-filling stage.
[0008] Optionally, in the pre-filling stage, the step of calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features includes: For each key-value cache pair, the first semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset first weights of each dimension of the features. The steps for determining the storage location of each key-value cache pair based on its semantic importance score include: If the first semantic importance score of a key-value cache pair is greater than or equal to the first preset value, the key-value cache pair is stored in high-bandwidth memory (HBM). If the first semantic importance score of a key-value cache pair is less than the first preset value but greater than the second preset value, the key-value cache pair is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR). If the first semantic importance score of a key-value cache pair is less than or equal to the second preset value, the key-value cache pair is stored in solid-state drive (SSD). The first preset value is greater than the second preset value.
[0009] Optionally, in the decoding stage, the step of calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features includes: During the decoding phase, if it is determined that the memory usage rate has reached the preset value, or if adding a key-value cache pair causes a memory overflow, for each key-value cache pair, the second semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset second weights of each dimension of the features. The steps for determining the storage location of each key-value cache pair based on its semantic importance score include: Key-value cache pairs with a second semantic importance score greater than or equal to the first preset value are stored in high-bandwidth memory (HBM). Key-value cache pairs with a second semantic importance score less than the first preset value but greater than the second preset value are stored in memory extension media (CXL) and synchronous dynamic random access memory (DDR). Key-value cache pairs with a second semantic importance score less than or equal to the second preset value are stored in solid-state drives (SSDs).
[0010] Optionally, the first preset value preset for the pre-filling stage and the first preset value preset for the decoding stage are the same or different; The second preset value for the pre-filling stage and the second preset value for the decoding stage are the same or different.
[0011] Secondly, embodiments of this application provide a key-value cache management device, the device comprising: The acquisition unit is used to acquire the feature scores of multiple dimensions of the key-value cache pair generated for each semantic unit Token. The feature scores of the key-value cache pair of a Token in each dimension are positively correlated with the semantic importance of the key-value cache pair of the Token. The calculation unit is used to calculate the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features. The determination unit is used to determine the storage location of each key-value cache pair based on the semantic importance score of each key-value cache pair.
[0012] Optionally, the multiple dimensions of a key-value cache pair include: attention weight features, token type features, context position features, and historical session behavior features.
[0013] Optionally, a first weight value with multiple dimensions of features is preset for the pre-filling stage; a second weight value with multiple dimensions of features is preset for the decoding stage, wherein; The first weight of the Token type features and context position features preset for the pre-filling stage is higher than the second weight of the Token type features and context position features preset for the decoding stage. For the attention weight features preset in the decoding stage, the second weight of the historical conversation behavior features is higher than the first weight of the attention weight features preset in the pre-filling stage.
[0014] Optionally, during the pre-filling stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, the calculation unit is specifically used for: For each key-value cache pair, the first semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset first weights of each dimension of the features. When determining the storage location of each key-value cache pair based on its semantic importance score, the determining unit is specifically used for: If the first semantic importance score of a key-value cache pair is greater than or equal to the first preset value, the key-value cache pair is stored in high-bandwidth memory (HBM). If the first semantic importance score of a key-value cache pair is less than the first preset value but greater than the second preset value, the key-value cache pair is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR). If the first semantic importance score of a key-value cache pair is less than or equal to the second preset value, the key-value cache pair is stored in solid-state drive (SSD). The first preset value is greater than the second preset value.
[0015] Optionally, during the decoding stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, the calculation unit is specifically used for: During the decoding phase, if it is determined that the memory usage rate has reached the preset value, or if adding a key-value cache pair causes a memory overflow, for each key-value cache pair, the second semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset second weights of each dimension of the features. When determining the storage location of each key-value cache pair based on its semantic importance score, the determining unit is specifically used for: Key-value cache pairs with a second semantic importance score greater than or equal to the first preset value are stored in high-bandwidth memory (HBM). Key-value cache pairs with a second semantic importance score less than the first preset value but greater than the second preset value are stored in memory extension media (CXL) and synchronous dynamic random access memory (DDR). Key-value cache pairs with a second semantic importance score less than or equal to the second preset value are stored in solid-state drives (SSDs).
[0016] Optionally, the first preset value preset for the pre-filling stage and the first preset value preset for the decoding stage are the same or different; The second preset value for the pre-filling stage and the second preset value for the decoding stage are the same or different.
[0017] Thirdly, embodiments of this application provide a key-value cache management device, which includes: Memory, used to store program instructions; A processor is configured to invoke program instructions stored in the memory and execute the steps of the method as described in any one of the first aspects above, according to the obtained program instructions.
[0018] Fourthly, embodiments of this application also provide a computer-readable storage medium storing computer-executable instructions for causing a computer to perform the steps of the method as described in any of the first aspects above.
[0019] In summary, the key-value cache management method provided in this application obtains feature scores of multiple dimensions of the key-value cache pair generated for each semantic unit Token. The feature scores of a Token's key-value cache pair in each dimension are positively correlated with the semantic importance of the Token's key-value cache pair. Based on the feature scores of each key-value cache pair in multiple dimensions and preset weight values of multiple dimensions, the semantic importance score of each key-value cache pair is calculated. Based on the semantic importance score of each key-value cache pair, the storage location of each key-value cache pair is determined.
[0020] The key-value cache management method provided in this application extracts the feature scores of multiple dimensions of key-value cache pairs corresponding to each semantic unit, calculates the semantic importance score of each key-value cache pair according to the preset weight values of each dimension feature, and determines the storage location of each key-value cache pair according to the semantic importance score of each key-value cache pair. This makes the unloading judgment more accurate, significantly reduces the probability of erroneous unloading of core key-value pairs, and reduces the overhead of low-speed storage IO pullback.
[0021] Furthermore, the weights of features in each dimension are dynamically adjusted for different inference stages to adapt to the inference features of the entire lifecycle of the large model, resulting in stronger strategy adaptability. Attached Figure Description
[0022] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments of this application or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings of the embodiments of this application.
[0023] Figure 1 A detailed flowchart of a key-value cache management method provided in this application embodiment; Figure 2 This is a schematic diagram of the structure of a key-value cache management device provided in an embodiment of this application; Figure 3 This is a schematic diagram of the hardware architecture of a key-value cache management device provided in an embodiment of this application. Detailed Implementation
[0024] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the application. The singular forms “a,” “the,” and “the” as used in this application and claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to any and all possible combinations comprising one or more of the associated listed items.
[0025] It should be understood that although the terms first, second, third, etc., may be used to describe various information in embodiments of this application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" may also be interpreted as "when," "when," or "in response to a determination."
[0026] Currently, to alleviate memory pressure, related technologies typically employ a KV Cache offloading strategy, migrating a portion of the KV Cache from high-speed memory (e.g., HBM) to lower-speed, high-capacity storage media (e.g., CPU memory, SSD, or CXL memory). Current mainstream methods mainly include: Elimination strategies based on time locality, such as LRU (Least Recently Used) and FIFO (First In First Out), determine the objects to be unloaded based on the order of access time.
[0027] However, relying solely on time sequence for unloading decisions results in a simplistic decision-making logic and a lack of semantic awareness. This can easily lead to the incorrect unloading of semantically critical, frequently accessed key-value caches to the SSD. Subsequent inference then requires frequent pull-backs from slow storage, generating significant I / O overhead and inference latency jitter.
[0028] This application provides a method that can sense the semantic importance of key-value cache and dynamically adjust the unloading strategy to achieve efficient utilization of video memory resources and synergistic optimization of inference performance.
[0029] For example, see Figure 1 The diagram shown is a detailed flowchart of a key-value cache management method provided in an embodiment of this application. The method includes the following steps: Step 100: For each semantic unit Token, generate a key-value cache pair and obtain the feature scores of the multiple dimensions of the key-value cache pair.
[0030] In this embodiment of the application, the feature scores of a key-value cache pair of a token in each dimension are positively correlated with the semantic importance of the key-value cache pair of the token.
[0031] In this embodiment of the application, the key-value cache multi-dimensional feature extraction module collects the semantic related features of each token's key-value cache pair in each dimension.
[0032] In this embodiment of the application, the multiple dimensional features of a key-value cache pair include: attention weight features, token type features, context position features, and historical session behavior features.
[0033] Specifically, attention weight features: For a target token, extract the proportion of global attention contribution and local window attention contribution of the key-value cache pair of the target token, and comprehensively determine the feature score of the attention weight feature based on the extracted global attention contribution and local window attention contribution. The higher the feature score of the attention weight feature of a key-value cache pair, the stronger the semantic importance of the key-value cache pair.
[0034] Token Type Characteristics: For a target token, the token type characteristics are determined according to preset rules. Specifically, the administrator pre-classifies tokens into system prompt tokens, user question tokens, assistant reply tokens, and redundant fill tokens. Different feature scores are preset for different types of token characteristics.
[0035] Contextual position features: Mark the position of the token in the context, which is divided into the key instruction area at the beginning of the context, the content-carrying area in the middle, and the continuation area at the end. Different feature scores are preset for different positions.
[0036] Historical session behavior characteristics: This involves statistically analyzing the number of historical accesses to key-value cache pairs corresponding to the same type of token within a preset historical timeframe, representing the degree of long-term inference dependency. "Same type of token" refers to tokens with the same or similar semantics; for example, instructions and commands are grouped into the same type of token.
[0037] Step 110: Calculate the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features.
[0038] The feature score of the attention weight feature of a key-value cache pair obtained below is... The feature weight is α; the feature score of the Token type feature. The feature weight is β; the feature score of the context location feature is... The feature weight is γ, and the feature score of the historical conversation behavior feature is γ. Taking a feature weight of δ as an example, the semantic importance score of this key-value cache pair can be calculated using the following formula: In this embodiment, a first weight value with multiple dimensions of features is preset for the pre-filling stage; a second weight value with multiple dimensions of features is preset for the decoding stage. The first weight of the Token type feature and context position feature preset for the pre-filling stage is higher than the second weight of the Token type feature and context position feature preset for the decoding stage; the second weight of the attention weight feature and historical session behavior feature preset for the decoding stage is higher than the first weight of the attention weight feature and historical session behavior feature preset for the pre-filling stage.
[0039] During the pre-filling stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, a preferred implementation method is as follows: For each key-value cache pair, the first semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset first weights of each dimension of the features.
[0040] For example, in the pre-filling stage, the preset weights for each dimension of features are: α1 for the attention weight feature; β1 for the token type feature; γ1 for the context position feature; and δ1 for the historical session behavior feature. Then, the semantic importance score of each key-value cache pair can be calculated using the following formula: In this embodiment of the application, during the decoding stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, a preferred implementation is as follows: During the decoding phase, if it is determined that the memory utilization rate has reached the preset value, or if the addition of a key-value cache pair causes a memory overflow, for each key-value cache pair, the second semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset second weights of each dimension of the features.
[0041] For example, in the decoding stage, the preset weights for each dimension of features are: α² for attention weight features; β² for token type features; γ² for context position features; and δ² for historical session behavior features. Then, the semantic importance score for each key-value cache pair can be calculated using the following formula: Step 120: Determine the storage location of each key-value cache pair based on the semantic importance score of each key-value cache pair.
[0042] In this embodiment of the application, the step of determining the storage location of each key-value cache pair based on the semantic importance score of each key-value cache pair during the pre-filling stage includes: If the first semantic importance score of a key-value cache pair is greater than or equal to the first preset value, the key-value cache pair is stored in high-bandwidth memory (HBM). If the first semantic importance score of a key-value cache pair is less than the first preset value but greater than the second preset value, the key-value cache pair is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR). If the first semantic importance score of a key-value cache pair is less than or equal to the second preset value, the key-value cache pair is stored in solid-state drive (SSD). The first preset value is greater than the second preset value.
[0043] For example, when the LLM model is reasoning about “text 1”, in the pre-filling stage, it obtains key-value cache pair 11 corresponding to Token1, key-value cache pair 12 corresponding to Token12, and key-value cache pair 13 corresponding to Token13. It extracts multi-dimensional features of key-value cache pair 11, key-value cache pair 12, and key-value cache pair 13, determines the feature score of each dimension feature, and calculates the semantic importance score of key-value cache pair 11, key-value cache pair 12, and key-value cache pair 13 based on the preset feature weights of each dimension feature (e.g., α1; β1; γ1, δ1). If the semantic importance score of key-value cache pair 11 is greater than or equal to the first preset value, then key-value cache pair 11 is stored in high-bandwidth memory (HBM); if the semantic importance score of key-value cache pair 12 is less than the first preset value but greater than the second preset value, then key-value cache pair 12 is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR); if the semantic importance score of key-value cache pair 13 is less than or equal to the second preset value, then key-value cache pair 13 is stored in solid-state drive (SSD).
[0044] Correspondingly, during the decoding phase, when determining the storage location of each key-value cache pair based on its semantic importance score, a preferred implementation is as follows: Key-value cache pairs with a second semantic importance score greater than or equal to the first preset value are stored in high-bandwidth memory (HBM). Key-value cache pairs with a second semantic importance score less than the first preset value but greater than the second preset value are stored in memory extension media (CXL) and synchronous dynamic random access memory (DDR). Key-value cache pairs with a second semantic importance score less than or equal to the second preset value are stored in solid-state drives (SSDs).
[0045] For example, when the LLM model infers "text 2", in the pre-filling stage, it obtains key-value cache pair 21 corresponding to Token21, key-value cache pair 22 corresponding to Token22, and key-value cache pair 23 corresponding to Token23. It extracts multi-dimensional features of key-value cache pair 21, key-value cache pair 22, and key-value cache pair 23, determines the feature score of each dimension feature, and calculates the semantic importance score of key-value cache pair 21, key-value cache pair 22, and key-value cache pair 23 based on the preset feature weights of each dimension feature (e.g., α2; β2; γ2, δ2). If the semantic importance score of key-value cache pair 21 is greater than or equal to the first preset value, then key-value cache pair 21 is stored in high-bandwidth memory (HBM); if the semantic importance score of key-value cache pair 22 is less than the first preset value but greater than the second preset value, then key-value cache pair 22 is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR); if the semantic importance score of key-value cache pair 23 is less than or equal to the second preset value, then key-value cache pair 23 is stored in solid-state drive (SSD).
[0046] In practical applications, if key-value cache pair 21 is already stored in HBM, there is no need to adjust its storage location; if key-value cache pair 21 is currently stored in CXL, then its storage location should be changed from CXL to HBM. Similarly, the storage locations of key-value cache pairs 22 and 23 should be adjusted using the same method as key-value cache pair 21.
[0047] It should be noted that the first preset value for the pre-filling stage is the same as or different from the first preset value for the decoding stage; similarly, the second preset value for the pre-filling stage is the same as or different from the second preset value for the decoding stage. Users can make presets according to their needs or actual application scenarios, and no specific limitations are made here in this embodiment.
[0048] For example, the first preset value for the pre-filling stage and the decoding stage is 80 points, and the second preset value is 60 points.
[0049] For example, the first preset value for the pre-filling stage is 80 points, and the second preset value is 60 points; the first preset value for the decoding stage is 75 points, and the second preset value is 65 points.
[0050] Based on the same inventive concept as the above-described method embodiments, see, for example, the following: Figure 2 The diagram shown is a structural schematic of a key-value cache management device provided in an embodiment of this application. The device includes: The acquisition unit 20 is used to acquire the feature scores of multiple dimensions of the key-value cache pair generated for each semantic unit Token, wherein the feature scores of the key-value cache pair of a Token in each dimension are positively correlated with the semantic importance of the key-value cache pair of the Token. The calculation unit 21 is used to calculate the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features. The determining unit 22 is used to determine the storage location of each key-value cache pair based on the semantic importance score of each key-value cache pair.
[0051] Optionally, the multiple dimensions of a key-value cache pair include: attention weight features, token type features, context position features, and historical session behavior features.
[0052] Optionally, a first weight value with multiple dimensions of features is preset for the pre-filling stage; a second weight value with multiple dimensions of features is preset for the decoding stage, wherein; The first weight of the Token type features and context position features preset for the pre-filling stage is higher than the second weight of the Token type features and context position features preset for the decoding stage. For the attention weight features preset in the decoding stage, the second weight of the historical conversation behavior features is higher than the first weight of the attention weight features preset in the pre-filling stage.
[0053] Optionally, during the pre-filling stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, the calculation unit 21 is specifically used for: For each key-value cache pair, the first semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset first weights of each dimension of the features. When determining the storage location of each key-value cache pair based on its semantic importance score, the determining unit 22 is specifically used for: If the first semantic importance score of a key-value cache pair is greater than or equal to the first preset value, the key-value cache pair is stored in high-bandwidth memory (HBM). If the first semantic importance score of a key-value cache pair is less than the first preset value but greater than the second preset value, the key-value cache pair is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR). If the first semantic importance score of a key-value cache pair is less than or equal to the second preset value, the key-value cache pair is stored in solid-state drive (SSD). The first preset value is greater than the second preset value.
[0054] Optionally, during the decoding stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, the calculation unit 21 is specifically used for: During the decoding phase, if it is determined that the memory usage rate has reached the preset value, or if adding a key-value cache pair causes a memory overflow, for each key-value cache pair, the second semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset second weights of each dimension of the features. When determining the storage location of each key-value cache pair based on its semantic importance score, the determining unit 22 is specifically used for: Key-value cache pairs with a second semantic importance score greater than or equal to the first preset value are stored in high-bandwidth memory (HBM). Key-value cache pairs with a second semantic importance score less than the first preset value but greater than the second preset value are stored in memory extension media (CXL) and synchronous dynamic random access memory (DDR). Key-value cache pairs with a second semantic importance score less than or equal to the second preset value are stored in solid-state drives (SSDs).
[0055] Optionally, the first preset value preset for the pre-filling stage and the first preset value preset for the decoding stage are the same or different; The second preset value for the pre-filling stage and the second preset value for the decoding stage are the same or different.
[0056] These units can be one or more integrated circuits configured to implement the above methods, such as one or more Application Specific Integrated Circuits (ASICs), one or more digital signal processors (DSPs), or one or more Field Programmable Gate Arrays (FPGAs). Alternatively, when one of these units is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. Furthermore, these units can be integrated together to form a system-on-a-chip (SOC).
[0057] Furthermore, regarding the key-value cache management device provided in this application embodiment, from a hardware perspective, the hardware architecture diagram of the key-value cache management device can be found in [reference needed]. Figure 3As shown, the key-value cache management device may include: a memory 30 and a processor 31. The memory 30 is used to store program instructions; the processor 31 calls the program instructions stored in the memory 30 and executes the above method embodiment according to the obtained program instructions. The specific implementation method and technical effect are similar, and will not be described again here.
[0058] Optionally, this application also provides a key-value cache management device, including at least one processing element (or chip) for performing the above method embodiments.
[0059] Optionally, this application also provides a program product, such as a computer-readable storage medium storing computer-executable instructions for causing the computer to perform the above-described method embodiments.
[0060] Here, a machine-readable storage medium can be any electronic, magnetic, optical, or other physical storage device that can contain or store information, such as executable instructions, data, etc. For example, a machine-readable storage medium can be: RAM (Random Access Memory), volatile memory, non-volatile memory, flash memory, storage drives (such as hard disk drives), solid-state drives, any type of storage disk (such as optical discs, DVDs, etc.), or similar storage media, or combinations thereof.
[0061] The systems, devices, modules, or units described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which can take the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email sending and receiving device, game console, tablet computer, wearable device, or any combination of these devices.
[0062] For ease of description, the above devices are described separately by function as various units. Of course, in implementing this application, the functions of each unit can be implemented in one or more software and / or hardware.
[0063] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, embodiments of this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0064] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will 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 program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0065] Furthermore, these computer program instructions can also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in the process. Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0066] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0067] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A key-value cache management method, characterized in that, The method includes: For each semantic unit Token, a key-value cache pair is generated, and the feature scores of the key-value cache pair in multiple dimensions are obtained. Among them, the feature scores of the key-value cache pair of a Token in each dimension are positively correlated with the semantic importance of the key-value cache pair of the Token. Based on the feature scores of multiple dimensions of each key-value cache pair and the weight values of multiple dimensions of preset features, the semantic importance score of each key-value cache pair is calculated. Based on the semantic importance score of each key-value cache pair, the storage location of each key-value cache pair is determined.
2. The method as described in claim 1, characterized in that, Multiple features of a key-value cache pair include: attention weight features, token type features, context position features, and historical session behavior features.
3. The method as described in claim 2, characterized in that, A first weight value with multiple dimensions of features is preset for the pre-filling stage; a second weight value with multiple dimensions of features is preset for the decoding stage, wherein; The first weight of the Token type features and context position features preset for the pre-filling stage is higher than the second weight of the Token type features and context position features preset for the decoding stage. For the attention weight features preset in the decoding stage, the second weight of the historical conversation behavior features is higher than the first weight of the attention weight features preset in the pre-filling stage.
4. The method as described in claim 3, characterized in that, In the pre-filling stage, the steps for calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features include: For each key-value cache pair, the first semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset first weights of each dimension of the features. The steps for determining the storage location of each key-value cache pair based on its semantic importance score include: If the first semantic importance score of a key-value cache pair is greater than or equal to the first preset value, the key-value cache pair is stored in high-bandwidth memory (HBM). If the first semantic importance score of a key-value cache pair is less than the first preset value but greater than the second preset value, the key-value cache pair is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR). If the first semantic importance score of a key-value cache pair is less than or equal to the second preset value, the key-value cache pair is stored in solid-state drive (SSD). The first preset value is greater than the second preset value.
5. The method as described in claim 4, characterized in that, During the decoding phase, the steps for calculating the semantic importance score of each key-value cache pair, based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, include: During the decoding phase, if it is determined that the memory utilization rate has reached the preset value, or if the addition of a key-value cache pair causes a memory overflow, for each key-value cache pair, the second semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset second weights of each dimension of the features. The steps for determining the storage location of each key-value cache pair based on its semantic importance score include: Key-value cache pairs with a second semantic importance score greater than or equal to the first preset value are stored in high-bandwidth memory (HBM). Key-value cache pairs with a second semantic importance score less than the first preset value but greater than the second preset value are stored in memory extension media (CXL) and synchronous dynamic random access memory (DDR). Key-value cache pairs with a second semantic importance score less than or equal to the second preset value are stored in solid-state drives (SSDs).
6. The method as described in claim 5, characterized in that, The first preset value for the pre-filling stage and the first preset value for the decoding stage are the same or different; The second preset value for the pre-filling stage and the second preset value for the decoding stage are the same or different.
7. A key-value cache management device, characterized in that, The device includes: The acquisition unit is used to acquire the feature scores of multiple dimensions of the key-value cache pair generated for each semantic unit Token. The feature scores of the key-value cache pair of a Token in each dimension are positively correlated with the semantic importance of the key-value cache pair of the Token. The calculation unit is used to calculate the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features. The determination unit is used to determine the storage location of each key-value cache pair based on the semantic importance score of each key-value cache pair.
8. The apparatus as claimed in claim 7, characterized in that, Multiple features of a key-value cache pair include: attention weight features, token type features, context position features, and historical session behavior features. A first weight value with multiple dimensions of features is preset for the pre-filling stage; a second weight value with multiple dimensions of features is preset for the decoding stage, wherein; The first weight of the Token type features and context position features preset for the pre-filling stage is higher than the second weight of the Token type features and context position features preset for the decoding stage. For the attention weight features preset in the decoding stage, the second weight of the historical conversation behavior features is higher than the first weight of the attention weight features preset in the pre-filling stage.
9. The apparatus as claimed in claim 8, characterized in that, During the pre-filling stage, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, the calculation unit is specifically used for: For each key-value cache pair, the first semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset first weights of each dimension of the features. When determining the storage location of each key-value cache pair based on its semantic importance score, the determining unit is specifically used for: If the first semantic importance score of a key-value cache pair is greater than or equal to the first preset value, the key-value cache pair is stored in high-bandwidth memory (HBM). If the first semantic importance score of a key-value cache pair is less than the first preset value but greater than the second preset value, the key-value cache pair is stored in memory extension media (CXL) or synchronous dynamic random access memory (DDR). If the first semantic importance score of a key-value cache pair is less than or equal to the second preset value, the key-value cache pair is stored in solid-state drive (SSD). The first preset value is greater than the second preset value.
10. The apparatus as claimed in claim 9, characterized in that, During the decoding phase, when calculating the semantic importance score of each key-value cache pair based on the feature scores of multiple dimensions of each key-value cache pair and the preset weight values of multiple dimensions of features, the calculation unit is specifically used for: During the decoding phase, if it is determined that the memory utilization rate has reached the preset value, or if the addition of a key-value cache pair causes a memory overflow, for each key-value cache pair, the second semantic importance score of the key-value cache pair is calculated by weighted summation based on the feature scores of each dimension of the key-value cache pair and the preset second weights of each dimension of the features. When determining the storage location of each key-value cache pair based on its semantic importance score, the determining unit is specifically used for: Key-value cache pairs with a second semantic importance score greater than or equal to the first preset value are stored in high-bandwidth memory (HBM). Key-value cache pairs with a second semantic importance score less than the first preset value but greater than the second preset value are stored in memory extension media (CXL) and synchronous dynamic random access memory (DDR). Key-value cache pairs with a second semantic importance score less than or equal to the second preset value are stored in solid-state drives (SSDs).
11. A key-value cache management device, characterized in that, The key-value cache management device includes: Memory, used to store program instructions; A processor is configured to invoke program instructions stored in the memory and execute the steps of the method as described in any one of claims 1-6 according to the obtained program instructions.
12. A computer-readable storage medium, characterized in that... The computer-readable storage medium stores computer-executable instructions for causing the computer to perform the steps of the method as described in any one of claims 1-6.
