Data processing method and device, electronic equipment and storage medium

By dynamically selecting caching strategies and controlling data migration in a distributed inference system, the problem of balancing storage resource utilization and data transmission overhead in multi-turn dialogue scenarios is solved, thereby improving the system's resource utilization efficiency and inference service performance.

CN123178550APending Publication Date: 2026-11-27CHINA TELECOM CORP LTD TECHNOLOGY INNOVATION CENTER +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611329277.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-28
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

In multi-turn dialogue scenarios, existing distributed inference systems struggle to balance storage resource utilization with data transmission overhead between nodes, leading to resource waste or increased response latency. Furthermore, they lack fine-grained migration control mechanisms for data locality characteristics, impacting overall throughput and response time.

Method used

By extracting the historical context length and the length of new input from multi-turn dialogue requests, dynamically selecting differentiated caching strategies, and controlling the migration of historical inference state data across nodes, a dynamic balance between storage resource utilization and data transmission overhead is achieved.

Benefits of technology

In multi-turn dialogue scenarios, it improves the resource utilization efficiency and inference service performance of distributed inference systems, avoids redundant storage and unnecessary data transmission, and optimizes overall throughput and response time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178550A_ABST
    Figure CN123178550A_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a data processing method and device, electronic equipment and storage medium, relating to the technical field of artificial intelligence, the method comprising: a distributed inference system adaptively selects a differentiated cache processing strategy by extracting historical context length and newly added input length, and dynamically decides according to actual request characteristics, avoiding the resource mismatch problem of a fixed single strategy in a multi-round dialogue scene. The system schedules the request to the corresponding node according to the target strategy, and performs transmission of historical inference state data on demand when cross-node migration is involved, so that the system can flexibly select redundant storage, single-node exclusive or on-demand migration mode, thereby realizing dynamic balance of storage resource utilization and cross-node communication overhead in a multi-round dialogue scene, avoiding excessive occupation of video memory resources, reducing unnecessary full data transmission overhead in non-essential scenarios, and improving the overall resource utilization efficiency and inference service performance of the system.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to a data processing method, a data processing apparatus, an electronic device, and a computer-readable storage medium. Background Technology

[0002] With the continuous growth in the scale of language model parameters, the demand for computing and storage resources for inference services has increased significantly. In practical deployments, to meet the requirements of high concurrency and low latency, a distributed inference architecture with multi-node collaboration is typically adopted, distributing different stages of the inference process to different computing nodes for execution. In scenarios such as multi-turn dialogues that require the reuse of historical context, how to efficiently manage historical inference state data among multiple computing nodes has become one of the key factors affecting overall inference performance.

[0003] However, existing distributed inference resource scheduling methods are mainly designed for single-round requests or static load scenarios. Their resource allocation strategies are usually determined before service startup, making it difficult to dynamically adjust them based on the actual characteristics of requests during operation. When faced with multi-round dialogue scenarios where parameters such as the length of historical context and the scale of new inputs continuously change, fixed resource scheduling methods cannot balance the utilization of computing node storage resources with the data transmission overhead between nodes, leading to resource waste or increased response latency in some operating conditions.

[0004] Furthermore, in scenarios involving the reuse of historical inference state data across nodes, existing processing methods typically lack fine-grained migration control mechanisms that address data locality characteristics. When the historical context is long, the amount of data transmitted between nodes is substantial, easily consuming significant communication bandwidth and thus adversely affecting the overall throughput and response time of the inference service. Summary of the Invention

[0005] The present invention provides a data processing method, apparatus, electronic device, and computer-readable storage medium to solve or partially solve the problems of difficulty in balancing storage resource utilization and data transmission overhead between nodes in multi-turn dialogue scenarios, as well as excessive communication overhead when reusing historical state data across nodes.

[0006] This invention discloses a data processing method applied to a distributed inference system, wherein the distributed inference system includes at least a first inference computing node and a second inference computing node, and the method includes: Extract the length of the historical context and the length of the new input for the new context from the multi-turn dialogue request; Based on the historical context length and the new input length, a target processing strategy is determined from at least two differentiated caching processing strategies; According to the target processing strategy, the multi-turn dialogue request is scheduled to the first inference computing node and / or the second inference computing node to perform computing tasks; When the target processing strategy is a strategy involving cross-node cache migration, the migration of historical inference state data is controlled between the first inference computing node and the second inference computing node.

[0007] This invention also discloses a data processing apparatus applied to a distributed inference system, the distributed inference system including at least a first inference computing node and a second inference computing node, the apparatus comprising: The feature extraction module is used to extract the length of the historical context and the length of the new input for the new context from multi-turn dialogue requests; A dynamic decision-making module is used to determine a target processing strategy from at least two differentiated caching processing strategies based on the historical context length and the new input length. The request scheduling module is used to schedule the multi-turn dialogue request to the first inference computing node and / or the second inference computing node to perform computing tasks according to the target processing strategy. The cache migration control module is used to control the migration of historical inference state data between the first inference computing node and the second inference computing node when the target processing strategy is a strategy involving cross-node cache migration.

[0008] This invention also discloses an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes a program stored in the memory, it implements the method described in the embodiments of the present invention.

[0009] This invention also discloses a computer-readable storage medium storing instructions that, when executed by one or more processors, cause the processors to perform the methods described in this invention.

[0010] The embodiments of the present invention have the following advantages: In this embodiment of the invention, the distributed inference system extracts the historical context length and the new input length from multi-turn dialogue requests, and determines the target processing strategy from at least two differentiated caching processing strategies based on these two length parameters. This achieves adaptive selection of the matching caching processing method based on the actual characteristics of the request. This not only avoids the resource mismatch problem caused by dynamic changes in context length in multi-turn dialogue scenarios using a fixed single strategy, but also schedules requests to the corresponding inference computing nodes according to the target processing strategy, and controls the migration of historical inference state data between nodes when cross-node cache migration is involved. This allows the system to flexibly adapt to different processing strategies. The system determines whether historical inference state data should be redundantly stored, exclusively used by a single node, or migrated on demand. Through dual-dimensional perception of request characteristics and adaptive policy selection, it achieves a dynamic balance between storage resource utilization and cross-node data transmission. This avoids excessive GPU memory consumption caused by simple redundant storage and avoids the communication overhead caused by frequent cross-node full data transmission in unnecessary scenarios. At the same time, through the on-demand triggering mechanism for migration operations, it can handle requests in the most optimal way to match the current scenario under different dialogue contexts. As a result, it improves the resource utilization efficiency and inference service performance of the distributed inference system in multi-turn dialogue scenarios. Attached Figure Description

[0011] Figure 1 This is a flowchart of the steps of a data processing method provided in an embodiment of the present invention; Figure 2 This is an architecture diagram of the PD-separated KV Cache management system provided in this embodiment of the invention; Figure 3 This is a schematic diagram of the differentiated request processing mode provided in the embodiments of the present invention; Figure 4 This is a schematic diagram of the decision-making process of the dual-threshold dynamic decision-making module provided in this embodiment of the invention; Figure 5 This is a schematic diagram of differentiated scheduling provided in an embodiment of the present invention; Figure 6 This is a schematic diagram of the migration interaction process provided in the embodiments of the present invention; Figure 7 This is a structural block diagram of a data processing device provided in an embodiment of the present invention. Detailed Implementation

[0012] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0013] As examples, distributed inference systems can provide inference services for large language models in interactive application scenarios such as intelligent customer service and multi-turn dialogue assistants. In such scenarios, multi-turn dialogue requests typically contain long historical contexts, and the system needs to reuse inference state data already generated in historical dialogues (such as KV cache) to avoid repeated calculations of historical sequences and accelerate the inference process.

[0014] However, in related distributed inference systems, resource allocation strategies are usually determined before service startup, making it difficult to dynamically adjust them based on the actual characteristics of requests during operation. This leads to an imbalance between storage resource utilization and data transmission overhead between nodes in multi-turn dialogue scenarios. At the same time, when reusing historical inference state data across nodes, existing methods typically lack fine-grained migration control mechanisms for data locality characteristics. When the historical context is long, the amount of data transmission between nodes is large, which can easily consume a lot of communication bandwidth, thus adversely affecting the overall throughput and response time of the inference service.

[0015] In response, this invention employs a dual-dimensional perception and multi-mode dynamic decision-making mechanism based on request features. When the distributed inference system receives a multi-turn dialogue request, the system can extract parameters from the request, including the length of the historical context and the length of the new input. Based on these two parameters, the system adaptively determines the target processing strategy matching the current scenario from a variety of differentiated caching processing strategies. Then, the system schedules the request to the corresponding computing node according to the target processing strategy, thereby achieving a dynamic balance between storage resource consumption and inter-node communication overhead.

[0016] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, some technical features involved in the embodiments of the present invention are explained and described below: KV Cache: In the large language model of the Transformer architecture, it refers to the key and value matrix in the self-attention mechanism cached during the autoregressive inference process to avoid repeated calculation of historical sequences.

[0017] Prefill: refers to the initial stage of reasoning in a large language model, where the input prompts are computed in a one-time, parallel manner to generate an initial key-value cache.

[0018] Decoding: This refers to the subsequent stage of reasoning in a large language model. After pre-filling, the model generates new tokens one by one. Each token generated requires utilizing the key-value cache of all previously generated tokens (including the Prompt and already generated tokens).

[0019] PD Separation (Prefill-Decode Separation): A distributed inference architecture for large language models that schedules and deploys the prefill and decode stages, which have different computational characteristics, on independent computing nodes or instances to optimize the overall resource utilization and throughput of the system.

[0020] Prefix Cache: In multi-turn dialogue scenarios, this specifically refers to the key-value cache of historical dialogue data that is cached for reuse in subsequent turns.

[0021] Reference Figure 1 The diagram illustrates a flowchart of a data processing method provided in an embodiment of the present invention, applied to a distributed inference system. The distributed inference system includes at least a first inference computing node and a second inference computing node, and specifically includes the following steps: Step 101: Extract the length of the historical context and the length of the new input for the new context from the multi-turn dialogue request; In this embodiment of the invention, a distributed inference system is applied. This system can be deployed on cloud server clusters or edge computing nodes to provide inference services for various interactive applications based on Large Language Models (LLMs). These interactive applications include, but are not limited to, intelligent customer service systems, multi-turn dialogue assistants, virtual digital humans, code generation tools, and various SaaS (Software as a Service) applications built on LLMs. These applications share the common characteristic that users typically engage in multi-turn continuous dialogues with the system. The system needs to maintain all historical dialogue content (i.e., historical context) throughout the entire conversation and use it as input for model inference to ensure the model can understand the complete context of the dialogue. During the inference process, whenever a user submits a new question (i.e., new context), the system needs to concatenate the historical context and the new context to form a complete input sequence, which is then input into the LLM for inference to generate the response for the current turn.

[0022] In practical deployments, to meet the requirements of high concurrency and low latency Service Level Agreements (SLAs), distributed inference systems can adopt a multi-node collaborative distributed architecture. Specifically, the system includes at least a first inference computing node and a second inference computing node. The first inference computing node can be a prefill node, mainly responsible for prefilling the input sequence, i.e., processing all tokens in the input sequence in parallel to generate the corresponding KV Cache. The second inference computing node can be a decode node, mainly responsible for generating the output sequence token by token after the prefilling is completed.

[0023] It should be noted that in the embodiments of this invention, "first" and "second" are only used to distinguish computing nodes with different functions and do not limit their physical form or deployment method. In actual networking, the first inference computing node and the second inference computing node can be deployed on different GPUs (Graphics Processing Units) of the same physical server, or on different GPUs of different physical servers within the same data center, or even deployed across data centers. This invention does not impose specific limitations on these deployments. For ease of description, the first inference computing node will be referred to as a P-node (PrefillNode) and the second inference computing node as a D-node (Decode Node) in the following text. However, "P-node" and "D-node" themselves do not constitute any limitation on the nodes and are only used for the purpose of brevity.

[0024] Furthermore, in this embodiment of the invention, to accelerate the autoregressive inference process of the large language model, the system employs KV Cache technology during inference. Specifically, after the initial calculation of the key and value matrices in the self-attention mechanism, the calculated key and value matrices are cached in the compute node's video memory (such as the GPU's HBM (High Bandwidth Memory)) for reuse in subsequent decoding steps, thus avoiding repeated attention calculations on tokens already computed in the historical sequence. In multi-turn dialogue scenarios, after each turn of dialogue, the newly generated KVCache is appended to the total KV Cache for that session, forming historical inference state data for reuse in subsequent turns. Therefore, in multi-turn dialogue scenarios, as the number of dialogue turns increases, the length of the historical context and the corresponding amount of historical inference state data show a continuous growth trend.

[0025] In practical applications, when a user initiates a new dialogue request (i.e., a multi-turn dialogue request) to a distributed inference system through a client (such as a chat interface in a web browser, a dialogue page in a mobile app, or an SDK for API calls), this request typically carries a session identifier and a new context. The session identifier uniquely identifies the dialogue session; for example, it can be a session_id, conversation_id, or a session token issued by the system. The system can use this session identifier to index all historical contexts and historical inference state data for that session. The new context is the content actually input by the user in this turn. It can be natural language statements or instructions in text form, or, in a multimodal scenario, content in various forms such as images, voice, and document attachments, which has been feature-processed. This invention does not limit this. In this embodiment of the invention, for ease of understanding and explanation, the new context is mainly illustrated using text input as an example, but this does not mean that the invention is only applicable to text input scenarios.

[0026] In its implementation, after receiving a multi-turn dialogue request, the distributed inference system first parses the request, extracting two key parameters: the length of the historical context and the length of the new input for the new context. The length of the historical context represents the total length of all historical dialogue content accumulated before this request in the current dialogue session. This length can be represented in various ways, such as the number of tokens (i.e., the number of tokens after word segmentation or sub-word splitting; in English, this is usually done by spaces and punctuation combined with BPE (Byte Pair Encoding), while in Chinese, it is done by characters or words combined with BBPE (Byte-level BPE), the number of characters (i.e., the number of Unicode characters in the original text), or the number of bytes (i.e., the length of the byte array after UTF-8 encoding).

[0027] Accordingly, the newly added input length is used to characterize the length of the newly added context itself, and its unit of measurement should be consistent with the historical context length so that numerical comparisons can be made under the same measurement system later. In one example of this embodiment of the invention, the number of tokens is used as a unified unit of measurement because the length of the input sequence of large language models is usually limited in units of tokens (for example, the context window supported by the DeepSeek-V3 model is 128K tokens), and the computational complexity of the model is directly related to the number of tokens. Using tokens as the length measurement unit has a more direct technical relevance.

[0028] Optionally, the system may maintain a global session state index table, which may be stored in a distributed cache system (e.g., Redis) or shared storage (e.g., a distributed file system), with the session identifier as the primary key, to record metadata information related to each session. The metadata information may at least include: the historical context length of the session (counted in Tokens), the storage location of historical inference state data (i.e., which computing node the session's KV Cache is stored on, which may specifically include the node IP address, port number, tensor storage handle in the node's video memory, etc.), the data volume of historical inference state data (i.e., the number of video memory bytes occupied by the KV Cache), and the node identifier of the D node bound to the session, etc., which is not limited in the present invention.

[0029] Therefore, after receiving a multi-turn dialogue request, the system may extract the historical context length through the following steps: first parse the session identifier carried in the request, then use the session identifier as a key to query the session state index table, and read the value of the historical context length field corresponding to the session from the query result, so as to obtain the historical context length. Meanwhile, the system may extract the new input length through the following steps: first extract the original content of the new context (such as text strings or binary multimodal feature data) from the payload of the request, then call a tokenizer consistent with the model according to the adopted measurement unit (such as the number of Tokens) to perform tokenization processing on the new context, and count the number of Tokens obtained after tokenization, so as to obtain the new input length.

[0030] To illustrate the above process more clearly, the following descriptions are made through two specific examples.

[0031] In the first example, assume that the session identifier of a multi-turn dialogue request is "session_abc123", and the new context carried in the request payload is "Please help me summarize the core viewpoints discussed above". The system first parses to obtain the session identifier "session_abc123", then queries the session state index table with this identifier, and obtains that the accumulated historical context length of this session is 2048 Tokens (i.e., several rounds of dialogue have occurred before, and a total of 2048 Tokens of dialogue content have been generated). Then, the system inputs the new context "Please help me summarize the core viewpoints discussed above" into the tokenizer supporting the model for tokenization processing, and obtains 12 Tokens, that is, the new input length is 12. Then in the current round, the historical context length extracted by the system is 2048, and the new input length is 12.

[0032] In the second example, suppose a multi-turn dialogue request is the first request of the current session, i.e., the user's first dialogue with the system. At this time, the session state index table does not yet contain a record corresponding to the session identifier, or although a record exists, the value of the historical context length field is zero. After querying, the system will find that the historical context length is 0. At the same time, the newly added context (let's say "Hello, what are your company's main businesses?") is segmented into 14 tokens. Therefore, the historical context length extracted in this round is 0, and the newly added input length is 14.

[0033] Furthermore, when extracting the historical context length, the distributed inference system can further employ an asynchronous cache preloading mechanism. That is, while querying the session state index table to obtain the historical context length, it can asynchronously preload the storage location information of the historical inference state data of the session and cache this information in the local variables of the request processing context. This allows subsequent steps (such as the cache migration operation in step 104) to quickly obtain the network address of the data source node without querying the index table again, thereby reducing the end-to-end latency of request processing.

[0034] In some feasible implementations, before extracting the historical context length, the system can pre-parse the session identifier and the payload content of the new context from the multi-turn dialogue requests, and query the local cache index table based on the session identifier to obtain the storage location and metadata information of the historical inference state data of the session. Then, the historical context length is determined based on the metadata information, and the length of the new input is determined based on the payload content. Specifically, the system can set up a multi-level cache query mechanism: the first level is a local memory cache (such as an LRU (Least Recently Used) cache) to store the metadata information of the most recently active sessions, with access latency typically in the microsecond range; the second level is a distributed cache (such as Redis) to store the metadata information of all active sessions, with access latency typically in the millisecond range; and the third level is persistent storage (such as a relational database or a distributed file system) to store archived historical session data, with access latency typically in the tens of milliseconds range. When the system receives a multi-turn dialogue request, it first attempts to query the session's metadata information from the first-level local memory cache. If a match is found, the historical context length can be quickly obtained without accessing external storage. If a match is not found, the system continues to query the second-level distributed cache and populates the query results back into the first-level local memory cache to accelerate the processing of subsequent requests for the same session. If a match is still not found, the system loads the session's metadata information from the third-level persistent storage and populates the data back into each level of cache. Through this multi-level caching query mechanism, the system can maximize the metadata query hit rate and response speed while ensuring data consistency, thereby reducing the average latency of request processing.

[0035] When determining the length of a new input, in addition to using the aforementioned method of segmenting and statistically analyzing the new context using a tokenizer, some feasible implementations can pre-calculate the length of the new input during the request preprocessing stage (such as the gateway layer or load balancing layer) and append it as metadata to the request header. When the request reaches the inference node, the system can directly read this pre-calculated value from the request header without needing to call the tokenizer again for real-time segmentation calculation, thus saving CPU (Central Processing Unit) resources and time overhead consumed by segmentation calculation. This approach is particularly effective in scenarios with long new contexts (e.g., users pasting tens of thousands of words of document content at once), because real-time segmentation of long text can consume tens or even hundreds of milliseconds of processing time. Pre-calculation removes this overhead from the critical path, effectively reducing end-to-end latency in request processing.

[0036] Step 102: Determine the target processing strategy from at least two differentiated caching processing strategies based on the historical context length and the new input length; In this embodiment of the invention, the distributed inference system may further include a dual-threshold dynamic decision-making module. This module can be a standalone software service (such as a microservice process) or integrated into the scheduler or gateway of the distributed inference system as a functional sub-module. The dual-threshold dynamic decision-making module can select the most suitable approach from a variety of predefined differentiated caching strategies based on the historical context length and the length of the new input output by the request feature extraction module, using this as the target processing strategy for the current round.

[0037] The number of differentiated caching strategies can be configured according to actual application needs. In this embodiment of the invention, three differentiated caching strategies are preset, namely the first strategy, the second strategy and the third strategy. However, this does not exclude the possibility of configuring four or more strategies in more complex application scenarios. This invention does not limit this.

[0038] In this embodiment of the invention, different differentiated caching strategies correspond to different KV Cache management methods under the PD separation architecture. The PD separation architecture is a distributed inference architecture that splits the inference process of a large language model into a pre-filling stage and a decoding stage, and deploys them on different computing nodes for execution.

[0039] In this embodiment of the invention, to reduce memory usage, the system defaults to a single cache plus on-demand transmission management method. That is, for each session, only one complete set of historical inference state data (i.e., full KV Cache) is maintained on the D node bound to the session. When the P node needs to perform pre-filling computation, the P node retrieves the corresponding data from the D node on demand according to the selected target processing strategy. Based on this architecture, the "storage location of historical inference state data" recorded in the session state index table is the network address of the D node bound to that session. In the PD separation architecture, the first inference computation node (i.e., the P node) is responsible for performing the pre-filling stage computation, and the second inference computation node (i.e., the D node) is responsible for performing the decoding stage computation. In related technologies, managing the KV Cache between PD nodes in multi-turn dialogue scenarios often involves a trade-off between memory usage and communication overhead.

[0040] The first strategy corresponds to the "incremental fetch" mode. Under the first strategy, the pre-filling phase of the current request is executed by the P node. In one embodiment of the present invention, the system ensures that all requests in the same session are assigned to the same P node for processing through a scheduling strategy, thereby ensuring that the P node always stores the complete historical inference state data of the session up to the end of the previous round locally. Under this premise, the P node does not need to obtain the full historical inference state data from the D node, but only obtains the incremental state data output from the previous round (i.e., the KV Cache part newly generated in the previous decoding phase, which usually only corresponds to the KV data of a newly generated token), and then concatenates the incremental state data with the existing local historical inference state data and the newly added context for pre-filling calculation, and then sends the newly generated incremental state data of the current round back to the D node. In this process, the P node can restore the complete KV Cache state up to the end of the previous round by using the existing complete historical KV Cache locally plus the incremental KV from the previous round fetched from the D node, thereby completing the pre-filling calculation without the need for full transmission. It should be noted that, in another embodiment, if the system does not guarantee that the same session is always bound to the same P node, then before executing the first strategy, it is necessary to first determine whether the current P node has historical inference state data for the session locally. If it does, the first strategy is executed normally; if it does not, the system automatically switches the processing method to the third strategy described below, whereby the P node pulls the full historical inference state data from the D node before performing pre-filling calculation. Furthermore, it should be specifically noted that when the historical context length is zero, it indicates that the current request is the first round request of the session. At this time, the P node does not have any historical inference state data locally, and the first strategy does not meet the execution conditions. The dual-threshold dynamic decision module should allocate the first round request to the second or third strategy (depending on the comparison result between the newly added input length and the second preset threshold), rather than selecting the first strategy.

[0041] Correspondingly, the second strategy corresponds to the "D-node exclusive" mode. Under the second strategy, the P node does not participate in the processing of the current request at all, and the entire request (including the prefill phase and the decode phase) is completed on the D node. That is, when the second strategy is adopted, the D node not only acts as a decode node, but also temporarily takes on the role of a prefill node, independently completing all inference calculations during the processing of the current request. The advantage of this mode is that it effectively avoids any data transmission between the P node and the D node (since the P node is not involved at all), resulting in zero communication overhead. Correspondingly, the D node needs to perform both prefill calculations and decode calculations, and the computational workload of prefill calculations is usually much larger than that of decode calculations (since prefill requires parallel processing of all Tokens in the entire input sequence, while decode processes only one Token at a time during Token-by-Token generation), which may significantly increase the computational load of the D node and affect the original processing efficiency of the D node's decoding tasks. Therefore, the second strategy is applicable to scenarios where the historical context length is long but the new input length is short. In such scenarios, a long historical context means a large KV Cache, and the overhead of transmitting the full KV Cache across nodes is huge, but a short new input means that the prefill computational workload is not large, and the additional burden of the D node temporarily undertaking prefill calculations is within an acceptable range. In this case, choosing the D-node exclusive mode can avoid the communication overhead of transmitting the huge KV Cache across nodes, at the cost of the D node undertaking a small amount of additional calculations, which is the optimal choice overall. In addition, for the case of the first-round request with a short new input length (i.e., Lh=0 and Ln<T2), since there is no historical KV Cache that needs to be transmitted across nodes, and the D node has a small burden of undertaking prefill calculations for the short input, it also falls within the applicable scope of the second strategy.

[0042] In addition, the third strategy corresponds to the "P node executes prefill" mode. Under the third strategy, the prefill phase of the current request is executed by the P node, and the decode phase is executed by the D node. According to whether there is historical inference state data of the session local to the P node, the execution method of the third strategy is divided into two cases: Scenario 1 (No historical inference state data exists locally on the P node): For example, the previous round of this session was processed by another P node, or the session has never been allocated a P node before, or the P node has proactively released the historical cache of this session due to memory pressure. In this scenario, the P node first obtains the full historical state data (i.e., the complete KV Cache) from the D node, then performs pre-filling calculations based on the obtained full historical state data and the newly added context, and finally sends the newly generated incremental state data of this round back to the D node. In this mode, the P node obtains the complete full historical state data, so it can perform pre-filling calculations based on the complete historical context, and the inference quality is equivalent to the pre-filling quality under the redundant caching method. However, the cost is that it needs to pull the full historical state data from the D node across nodes. When the historical context is long, the data volume of the KV Cache may reach the GB level, and cross-node transmission will generate significant communication overhead and latency.

[0043] Scenario 2 (P node has local historical inference state data): In this scenario, P node does not need to perform the "release local cache and then fetch full data" operation. Instead, it directly uses the existing complete historical inference state data and the newly added context to perform pre-filling calculations, and then sends the newly generated incremental state data back to D node. In this scenario, the actual execution method of the third strategy is the same as the first strategy at the data transmission level (both only send back incremental KV). The difference is that the third strategy is suitable for scenarios with longer new input lengths, where P node needs to handle a larger amount of computation, while the first strategy is suitable for scenarios with shorter new input lengths. Through the above distinction, the meaningless "release and then fetch" operation is avoided when P node already has a local historical cache, thus saving unnecessary communication overhead.

[0044] In summary, the third strategy is suitable for scenarios with longer new input lengths. In these scenarios, longer new inputs mean that if the second strategy (D node exclusively uses the input) is adopted, the D node would have to bear a large pre-padding computation load, which could seriously affect the normal execution of its decoding task; while adopting the third strategy, with the P node undertaking the complete pre-padding computation, is a more reasonable choice.

[0045] In the above process, the dual-threshold dynamic decision-making module compares the relationship between the historical context length and the first preset threshold, and the new input length and the second preset threshold, to automatically select among the three strategies, thereby achieving adaptation for different request scenarios.

[0046] In some feasible implementations, based on the above-mentioned multiple processing strategies, the dual-threshold dynamic decision module, when determining the target processing strategy from at least two differentiated caching processing strategies, may specifically include the following decision branches: If the length of the historical context is less than the first preset threshold and the length of the new input is less than the second preset threshold, then the first strategy is selected from at least two differentiated caching strategies. Under the first strategy, the first inference computing node obtains the incremental state data of the previous round output from the second inference computing node, processes the new context based on the incremental state data, and then sends the current round of incremental state data back to the second inference computing node. If the length of the historical context is greater than or equal to the first preset threshold and the length of the new input is less than the second preset threshold, then the second strategy is selected from at least two differentiated caching strategies. Under the second strategy, the second inference computing node performs the pre-filling stage and the decoding stage. If the length of the new input is greater than or equal to the second preset threshold, then a third strategy is selected from at least two differentiated caching strategies. Under the third strategy, the first inference computing node processes the new context based on the historical inference state data stored locally or the full historical state data obtained from the second inference computing node.

[0047] The aforementioned decision branches constitute the core decision logic of the dual-threshold dynamic decision module.

[0048] In its implementation, the dual-threshold dynamic decision-making module first obtains the first preset threshold (denoted as T1) and the second preset threshold (denoted as T2) pre-configured by the system. The specific values ​​of the two thresholds can be configured according to factors such as the hardware configuration, network environment, model size, and service quality requirements of the distributed inference system, and this invention does not impose any restrictions on them.

[0049] For example, in one embodiment, assume that the system adopts the XX model (671B parameters), P nodes and D nodes are respectively deployed in 8×A100 (80GB) GPU servers on different racks in the same data center, and the nodes are interconnected by a 100Gbps RoCE network, then the first preset threshold T1=4096 Tokens (corresponding to a historical context of about 4K length) and the second preset threshold T2=1024 Tokens (corresponding to a newly added input of about 1K length) can be set. The selection basis of these two thresholds is as follows: when the length of the historical context is less than 4096 Tokens and the length of the newly added input is less than 1024 Tokens, the data volume of the historical KV Cache is small (for this model, the KV Cache corresponding to 4K Tokens is about several hundred MB), the communication delay of transmitting the full KV Cache across nodes is within an acceptable range (hundreds of milliseconds), and the prefill computation amount of the P node is not large, so it is suitable to adopt the incremental pulling mode of the first strategy; when the length of the historical context exceeds 4096 Tokens and the length of the newly added input is less than 1024 Tokens, the KV Cache data volume is already large (more than 1GB), and the cost of full cross-node transmission is high, but the additional overhead of the D node temporarily undertaking the prefill computation of short inputs is small, so it is suitable to adopt the D node exclusive mode of the second strategy; when the length of the newly added input exceeds 1024 Tokens, regardless of the length of the historical context, the D node needs to process a long input sequence in the D node exclusive mode, and the prefill computation amount increases significantly, which may affect the decoding throughput of the D node. Therefore, the third strategy needs to be adopted, where the P node undertakes the prefill computation, and the P node executes according to the above-mentioned Case 1 or Case 2 respectively depending on whether there is a historical cache locally.

[0050] Further, after the dual-threshold dynamic decision module obtains T1 and T2, the historical context length (denoted as Lh) is compared with T1, and the newly added input length (denoted as Ln) is compared with T2. According to the comparison result, the following judgment logic is executed: First, it is judged whether the current request is the first round request of the session, that is, whether Lh is equal to 0. If Lh=0, the relationship between Ln and T2 is further judged: if Ln<T2, the second strategy is selected as the target processing strategy (the D node completes prefill and decoding independently, because there is no historical KV to transmit and the newly added input is short, the burden on the D node is acceptable); if Ln≥T2, the third strategy is selected as the target processing strategy (the newly added input is long, and the burden of the D node independently undertaking prefill is too large, so the P node needs to perform prefill, and the P node obtains historical state data from the D node. However, since Lh=0, the D node actually has no historical KV Cache to transmit, and the P node only needs to process the prefill computation of the newly added input and then return the incremental KV to the D node).

[0051] If Lh > 0 (i.e., it is not the first round request), the determination is performed according to the following three mutually exclusive logics: If Lh < T1 and Ln < T2, it is determined that the current request is suitable for the incremental pull mode, and thus the first strategy is selected as the target processing strategy. Under this condition, the historical context is short (the data volume of the full KV Cache is not large, and even the cost of cross-node full transmission is acceptable), and the new input is short (the prefill computation load on the P node is not large). By adopting the first strategy, only the incremental KV from the previous round is pulled and processed in combination with the historical KV already stored locally, which further reduces the transmission volume while ensuring the inference quality.

[0052] If Lh ≥ T1 and Ln < T2, it is determined that the current request is suitable for the D node exclusive mode, and thus the second strategy is selected as the target processing strategy. Under this condition, the historical context is already long (the cost of cross-node transmission of the full KV Cache is high), but the new input is short (the additional burden of the D node temporarily undertaking the prefill computation is small). Therefore, both prefill and decoding are executed on the D node, which can avoid cross-node communication overhead without affecting the overall throughput of the system.

[0053] If Ln ≥ T2, it is determined that the current request is suitable for the P node prefill mode, and thus the third strategy is selected as the target processing strategy. Under this condition, the new input is long, and the computation load on the D node would be excessively high if the D node exclusive mode is adopted, so the P node needs to undertake the prefill computation. The P node processes the request according to the execution manner of the above-mentioned case 1 or case 2 depending on whether historical inference state data exists locally. This determination condition covers two sub-cases: "Lh < T1 and Ln ≥ T2" (short history but long new input) and "Lh ≥ T1 and Ln ≥ T2" (long history and long new input), and the third strategy is selected in both sub-cases. Through the above three mutually exclusive determination logics, any multi-round dialogue request in the non-first round can be uniquely mapped to one of the first strategy, the second strategy, or the third strategy, without ambiguity in strategy selection.

[0054] It should be noted that, in the above determination logics, for boundary cases where Lh is equal to T1 or Ln is equal to T2, those skilled in the art can flexibly configure them according to actual requirements. For example, in one embodiment, the "equal to" case is included in the greater than or equal to set, that is, the comparison manner given in the above determination logics is adopted (Lh ≥ T1 and Ln < T2 are classified into the second strategy, and Ln ≥ T2 is classified into the third strategy); in another embodiment, the "equal to" case may also be included in the less than set, for example, modified to "if Lh < T1 and Ln ≤ T2, the first strategy is selected; if Lh ≥ T1 and Ln ≤ T2, the second strategy is selected; if Ln > T2, the third strategy is selected", etc. All these are equivalent substitutions and simple variations of the present invention, and all fall within the protection scope of the present invention.

[0055] Furthermore, to more clearly illustrate the working process of the dual-threshold dynamic decision-making module, the following detailed explanation uses a set of specific numerical examples. Assume the system is configured with a first preset threshold T1 = 2048 and a second preset threshold T2 = 512.

[0056] Example 1: If the historical context length of a multi-turn dialogue request is Lh=1024 (less than T1) and the new input length is Ln=256 (less than T2), then the system selects the first strategy.

[0057] Example 2: If the historical context length of a multi-turn dialogue request is Lh=3072 (greater than T1) and the new input length is Ln=128 (less than T2), then the system selects the second strategy.

[0058] Example 3: The historical context length of a multi-turn dialogue request is Lh=4096 (greater than T1), and the new input length is Ln=768 (greater than T2). Since Ln≥T2, the system selects the third strategy.

[0059] Example 4: In a multi-turn dialogue request, the historical context length Lh = 1536 (less than T1), and the new input length Ln = 640 (greater than T2). Since Ln ≥ T2, the system chooses the third strategy (instead of the first strategy). In this scenario, the historical context is relatively short, and the transmission cost of the full KV cache is acceptable. However, the new input is relatively long, and having the P node handle the pre-filling calculation can avoid overloading the D node.

[0060] Example 5: The historical context length of a multi-turn dialogue request is Lh=3072 (greater than T1), and the new input length is Ln=512 (equal to T2). According to the above judgment logic (classifying the equal case into greater than or equal to), since Ln≥T2, the system selects the third strategy.

[0061] Example 6: A multi-turn dialogue request is the first request of the current session (Lh=0). The length of the new input is Ln=256 (less than T2). According to the first-turn determination logic above, the system selects the second strategy. Under this strategy, node D performs pre-filling and decoding independently. Since there is no historical KV cache to be transmitted across nodes, and the new input is short, the additional computational burden on node D is within an acceptable range.

[0062] Example 7: A multi-turn dialogue request is the first-round request of the current session (Lh=0), and the new input length Ln=768 (greater than T2). According to the aforementioned first-round judgment logic, the system selects the third strategy. Under this strategy, the P node obtains full historical state data from the D node. However, since Lh=0, the D node actually has no historical KV Cache to transmit. The P node directly processes the prefill calculation of the new input, then returns the incremental KV to the D node, which continues to perform decoding generation.

[0063] It can be seen from the above seven examples that the trigger conditions of different strategies do not overlap with each other: the first strategy is only triggered when it is not the first round, Lh<T1 and Ln<T2; the second strategy is triggered when it is the first round and Ln<T2, or when it is not the first round, Lh≥T1 and Ln<T2; the third strategy is triggered when it is the first round and Ln≥T2, or when it is not the first round and Ln≥T2 (regardless of the relationship between Lh and T1). The trigger conditions of the above three strategies jointly form a complete coverage of all possible input parameter combinations, and any given request parameter combination can only hit one of the strategies, and there is no situation where multiple strategies are hit at the same time.

[0064] In addition, the aforementioned first preset threshold and second preset threshold can also be dynamically adjusted according to the real-time operating status of the distributed inference system. That is, the system does not use fixed thresholds, but can adaptively adjust the values of T1 and T2 according to the current resource utilization and network load conditions.

[0065] In a specific implementation, the monitoring module of the system can continuously collect the storage resource utilization rate of the distributed inference system (such as the video memory occupancy rate of each P node and D node) and the network bandwidth occupancy rate (such as the bandwidth usage rate of the communication link between nodes). Then the dual-threshold dynamic decision-making module dynamically adjusts the first preset threshold and the second preset threshold according to the obtained storage resource utilization rate and network bandwidth occupancy rate in accordance with a preset adjustment strategy.

[0066] In one example, the adjustment strategy may be as follows: when it is detected that the storage resource utilization rate of the current system exceeds the first resource warning line (e.g., the video memory occupancy rate exceeds 85%), the first preset threshold T1 is appropriately lowered. After T1 is lowered, a part of requests originally in the interval of "Lh < T1 and Ln < T2" (i.e., requests where Lh is between the lowered new T1 and the original T1, and Ln < T2) will be transferred to the second strategy (D node exclusive). Under the second strategy, the P node does not participate in the processing of the current request. At this time, the P node can selectively release the historical reasoning state data of this session to free up video memory space, thereby alleviating the overall storage resource pressure of the system. For some requests originally in the interval of "Lh < T1 and Ln ≥ T2" (i.e., requests where Lh is between the lowered new T1 and the original T1, and Ln ≥ T2), since the determination condition of the third strategy is Ln ≥ T2, which has nothing to do with Lh, lowering T1 will not change the strategy selection result of these requests (still the third strategy). However, whether the P node needs to pull the full historical cache from the D node when executing under the third strategy depends on whether the P node locally has the historical cache of this session, and has no direct relationship with the value of T1.

[0067] Conversely, when it is detected that the current storage resource utilization rate is low (e.g., the video memory occupancy rate is lower than 40%), the first preset threshold T1 can be appropriately increased, so that more requests fall into the applicable scope of the first strategy (condition is Lh < T1 and Ln < T2), thereby reducing the demand for releasing the cache due to the P node not participating in the processing, maintaining the hit rate of the P node local cache, and reducing the frequency of cross-node data transmission.

[0068] In another example, the adjustment strategy may also be as follows: when it is detected that the network bandwidth occupancy rate of the current system exceeds the second resource warning line (e.g., the bandwidth occupancy rate exceeds 80%), the second preset threshold T2 is appropriately lowered. After T2 is lowered, some requests originally in the interval of "Ln < T2" will be transferred to the third strategy (executed by the P node for prefill) because of "Ln ≥ T2". Requests originally in the interval of "Lh < T1 and Ln < T2" are transferred to the third strategy (Lh < T1 and Ln ≥ T2), and requests originally in the interval of "Lh ≥ T1 and Ln < T2" are also transferred to the third strategy (Lh ≥ T1 and Ln ≥ T2). Since under the third strategy, if the P node locally has a historical cache, there is no need to pull the full amount of data across nodes, and only the incremental KV needs to be returned, with very small traffic; if the P node does not have a historical cache locally, it needs to pull the full amount of data across nodes, with large traffic. Therefore, the actual impact of lowering T2 on network bandwidth depends on the hit rate of the P node local cache. When the network bandwidth is tight, directing more requests to the P node for processing by lowering T2 can effectively reduce the computing load of the D node when the P node cache hit rate is high, without significantly increasing the network transmission overhead.

[0069] When it is detected that the network bandwidth occupancy is low, the second preset threshold T2 can be appropriately increased, so that more requests fall within the applicable scope of the first policy or the second policy (condition: Ln<T2), where the first policy only transmits incremental KV (small data volume), and the second policy does not transmit at all, thereby reducing the participation of P nodes when the D node has surplus computing capacity.

[0070] In addition, the system can also jointly consider two dimensions, storage resource utilization and network bandwidth occupancy, for joint adjustment. For example, when the video memory occupancy is high and the network bandwidth occupancy is also high, the system can simultaneously reduce T1 and T2 to prioritize alleviating the pressure on both resources; when the video memory occupancy is high but the network bandwidth occupancy is low, the system can reduce T1 but increase T2, so that more requests fall into the first policy (Lh<T1 and Ln<T2, using the P node local cache to avoid cross-node transmission) or the second policy (Lh≥T1 and Ln<T2, exclusive use of D node to avoid transmission), releasing video memory while utilizing idle network bandwidth for necessary full transmission. Through this dynamic threshold adjustment mechanism, the system can adaptively adjust the boundary conditions of policy selection under different operating conditions, thereby continuously maintaining an optimal balance between resource utilization and inference performance. The specific adjustment amplitudes in the above adjustment policies (such as the step size of each adjustment, the maximum single adjustment amount, etc.) can be configured according to the tuning experience of the actual system, and the present invention does not specifically limit this.

[0071] After the dual-threshold dynamic decision module completes the selection of the target processing policy, the selected target processing policy (i.e., one of the first policy, the second policy, or the third policy) is output as a decision result to the request scheduling module and the cache migration control module for use in subsequent steps. The decision result can be transmitted between modules in the form of a policy identifier (e.g., policy ID: 1 represents the first policy, 2 represents the second policy, 3 represents the third policy), or in the form of a policy configuration object (including the policy type and related execution parameters), and the present invention does not specifically limit this.

[0072] Step 103: According to the target processing policy, schedule the multi-round dialogue request to the first inference computing node and / or the second inference computing node to execute a computing task; In this embodiment of the invention, the distributed inference system may further include a request scheduling module, which is used to schedule the current multi-turn dialogue request to the corresponding inference computing node according to the target processing strategy determined in the foregoing embodiments. The request scheduling module maintains a node resource pool, used to record information such as the node identifier, IP address and port number, node type, current available video memory size, current number of concurrent requests, and node health status of each P node and D node. The monitoring module continuously collects the above-mentioned load information of each computing node as one of the data input sources for the dual-threshold dynamic decision-making module to perform dynamic threshold adjustment.

[0073] In some feasible implementations, when the target processing strategy is the first strategy or the third strategy, the multi-turn dialogue request is bound to the first inference computing node, and the newly added context is distributed to the first inference computing node to perform pre-filling calculation, and the second inference computing node bound to the current session is assigned as the decoding execution node; when the target processing strategy is the second strategy, the multi-turn dialogue request is distributed to the second inference computing node bound to the current session, and the second inference computing node is controlled to perform pre-filling calculation and decoding calculation to obtain the output result of the current round.

[0074] In its implementation, the request scheduling module can execute two differentiated scheduling logics based on the target processing strategy. Specifically, when the target processing strategy is the first or third strategy, both strategies require the P node to participate in the pre-filling calculation; therefore, the request scheduling module performs the "P node binding and request distribution" operation. When the target processing strategy is the second strategy, the P node does not participate in processing; therefore, the request scheduling module skips the P node binding and directly performs the "D node exclusive distribution" operation. The following sections elaborate on these two scheduling logics: Scheduling Logic 1: P-node binding and request distribution under the first or third strategy.

[0075] When the target processing strategy is the first or third strategy, the request scheduling module first obtains the session identifier of the current request, queries the session state index table, and confirms whether the session has been bound to a P node. In multi-turn dialogue scenarios, in order to maximize the advantage of data locality, the P node may still cache the historical inference state data of the previous turn of the session locally. In this case, the system prioritizes reusing the same P node to process consecutive requests of the same session.

[0076] If the session already has a bound P node, and that node is in a healthy state with sufficient available GPU memory, the scheduling module is requested to prioritize reusing that P node as the target P node to achieve local caching reuse of historical inference state data. In scenario two of the third strategy (where historical inference state data exists locally on the P node), this is a typical scenario: the already bound P node is directly reused without needing to reselect or pull the full historical data from the D node; only the incremental KV data needs to be returned to the D node after calculation.

[0077] If the session is not yet bound to a P-node, or the bound P-node is unhealthy or has insufficient available video memory, the request scheduling module selects a new P-node from the P-node resource pool for binding. One implementation approach is to use a strategy based on minimum video memory usage, selecting the P-node with the largest available video memory; another approach is to use a strategy based on minimum concurrent requests; or a weighted strategy considering both. After selection, the binding relationship between the current request and the target P-node (i.e., the mapping between the session identifier and the P-node identifier) ​​is written to the session state index table. For the first round of requests, since the D-node has no historical inference state data, the actual data volume when the P-node retrieves the full historical state data from the D-node is zero; only the pre-filling calculation for the newly added input needs to be processed.

[0078] After identifying the target P-node, the request scheduling module distributes the new context to that P-node for pre-filling computation. Simultaneously, it queries the session state index table to retrieve the D-node bound to that session and assigns it as a decoding execution node (i.e., used to receive incremental state data returned by the P-node and perform subsequent decoding computations). Optionally, before distribution, it can check whether the available GPU memory of the P-node is sufficient to accommodate this computation; if insufficient, a cache eviction mechanism can be triggered to release historical inference state data of other least recently used sessions on that P-node to free up space, and the session state index table is updated synchronously, setting the P-node binding field of the evicted session to null, so that subsequent requests from that session can reselect an available P-node.

[0079] Scheduling Logic 2: Exclusive distribution of D nodes under the second strategy.

[0080] When the target processing strategy is the second strategy, the request scheduling module skips the selection and binding operation of the P node and directly distributes the request to the D node bound to the current session. The request includes a strategy indication field (such as "strategy:decode_only"), instructing the D node to independently complete the pre-filling and decoding calculations. The D node uses its locally stored full historical KV cache, concatenates it with the new context, performs the pre-filling calculation, and immediately follows with the decoding calculation. After obtaining the output result, it directly returns it to the client, without any KV cache data transmission with the P node throughout the entire process.

[0081] After node D completes its calculation, it updates the historical context length field in the session state index table to the new value after this round of processing, and records the range information of the newly added KV Cache in this round, so that in subsequent rounds, node P can quickly locate the data when it pulls incremental state data on demand under the first strategy. The binding relationship of node P remains unchanged under the second strategy, and its local cache can be reused in subsequent rounds.

[0082] Optionally, if the current load on node D is too high, the request scheduling module can report the load status to the dual-threshold dynamic decision module to trigger a policy re-decision. The dual-threshold dynamic decision module will then redetermine the target processing policy based on the load status information, rather than the scheduling module unilaterally changing the policy.

[0083] Furthermore, a corresponding scheduling example can be: Example 1 (First Strategy): The session is already bound to P node "p-node-03" and D node "d-node-07". Request the scheduling module to reuse "p-node-03", distribute the new context to this node for pre-population, and after pre-population is complete, send the incremental KV back to "d-node-07" for decoding.

[0084] Example 2 (Second Strategy): The request scheduling module skips the P node selection, distributes the request to the bound "d-node-12", carries the strategy indication field, and the D node independently completes the pre-filling and decoding. After completion, it updates the historical context length in the session state index table and records the newly added KV Cache range.

[0085] Example 3 (Third Strategy): If the session is already bound to the P node "p-node-05", the scheduling module is requested to reuse this node. The P node directly processes the new context using its local historical cache (corresponding to Case 2 of the Third Strategy). If the session is not yet bound to a P node, the scheduling module is requested to select a new P node from the resource pool for binding. The P node pulls the full historical KV from the D node and performs pre-population (corresponding to Case 1 of the Third Strategy).

[0086] Through the aforementioned differentiated scheduling logic, the request scheduling module ensures that requests are correctly distributed to the corresponding nodes under different target processing strategies. It works closely with the dual-threshold dynamic decision-making module to achieve efficient reasoning in multi-turn dialogue scenarios.

[0087] Step 104: When the target processing strategy is a strategy involving cross-node cache migration, control the migration of historical inference state data between the first inference computing node and the second inference computing node.

[0088] In this embodiment of the invention, the distributed inference system may further include a cache migration control module. This module is a core component responsible for managing the transmission, storage, and release of historical inference state data (i.e., KV Cache) between P nodes and D nodes. It works in conjunction with the request scheduling module, which is responsible for distributing requests to the correct compute nodes, while the cache migration control module is responsible for ensuring that compute nodes have the necessary historical inference state data before performing pre-filled computations. The cache migration control module can run as a daemon on each P node and D node, or it can be deployed as an independent control plane service in the management plane of the distributed inference system, issuing migration instructions to each compute node via communication protocols such as RPC (Remote Procedure Call) or HTTP / 2. This invention does not impose any limitations on this approach.

[0089] In this embodiment of the invention, for ease of description, it is assumed that the functional logic of the cache migration control module is integrated into the scheduler of the distributed inference system and communicates with each computing node through the gRPC (Google Remote Procedure Call) framework, but this does not constitute any limitation on the scope of the invention.

[0090] It should be noted that not all target processing strategies involve cross-node cache migration. For the various strategies described in the preceding embodiments, the first and third strategies involve KV cache transfer between P nodes and D nodes, and therefore belong to the category of "strategies involving cross-node cache migration." However, under the second strategy, P nodes do not participate in processing; all calculations are completed on D nodes, and no cross-node data transfer is involved. Therefore, it does not belong to the category of "strategies involving cross-node cache migration" and does not require migration operations. Therefore, before performing the migration operation, the cache migration control module can first check the target processing strategy determined in the preceding embodiments: if the target processing strategy is the first or third strategy, then continue with the migration process in this step; if the target processing strategy is the second strategy, then skip this step, and D nodes directly perform pre-filling calculations and decoding calculations and return the results.

[0091] In practical implementation, historical inference state data can be collectively referred to as the Key Matrix and Value Matrix generated by the self-attention mechanism during the inference process of a large language model in a Transformer architecture; this is known as the KV Cache. In multi-turn dialogue scenarios, the KV Cache records the Key vector and Value vector corresponding to each Token in the historical context, and its data volume grows linearly with the increase in the length of the historical context. For a large language model with an N-layer Transformer decoder-only architecture, each layer needs to store the Key and Value of L Tokens, and the dimension of each Key / Value vector is d_k. Therefore, the total KV Cache data volume is approximately N×L×d_k×2×bytes (where 2 represents two sets of data, Key and Value, and the number of bytes depends on the precision, such as 2 bytes for FP16 and 1 byte for FP8).

[0092] Taking the XX model as an example (N=61 layers, d_k=128, using FP8 precision storage), the KVCache data size corresponding to each 1K tokens is approximately 61×1024×128×2×1≈16MB. When the historical context length reaches 128K, the total KVCache data size is approximately 2GB. Transmitting such a large amount of data across nodes will put significant pressure on network bandwidth. Therefore, the core design goal of the cache migration control module is to minimize the amount of KVCache data transmitted across nodes and reduce the impact of communication overhead on inference latency, while ensuring the correctness and quality of inference.

[0093] Specifically, the migration processes under the first and third strategies are described in detail below.

[0094] In some feasible implementations, controlling the migration of historical inference state data between the first inference computing node and the second inference computing node under the first strategy may specifically include the following steps: controlling the first inference computing node to send a request to the second inference computing node to obtain the incremental state data of the previous round; controlling the first inference computing node to receive the incremental state data of the previous round returned by the second inference computing node; controlling the first inference computing node to concatenate the incremental state data of the previous round with the newly added context and perform pre-filling calculation to generate the incremental state data of the current round; controlling the first inference computing node to transmit the incremental state data of the current round to the second inference computing node, wherein the incremental state data of the current round is used by the second inference computing node to generate the output of the current round.

[0095] When the target processing strategy is the first strategy, the cache migration control module executes the "incremental migration" process. In this process, the P node already stores the historical KV cache of the current session locally (this premise is guaranteed by the session affinity mechanism of the request scheduling module). It only needs to obtain the incremental state data of the previous round of output from the D node to update the local KV cache to the latest state, and then process the new context.

[0096] Specifically, the cache migration control module first controls the P node to send a retrieval request to the D node to obtain the incremental state data from the previous round. This retrieval request carries at least the following information: a session identifier (used by the D node to locate the KV Cache storage area corresponding to the session), a request type identifier (indicating that this request is for incremental fetching), and a data range indicator (indicating that the KV Cache corresponding to the newly generated token in the previous decoding phase needs to be fetched).

[0097] In practice, the aforementioned data range indication can be represented as the start and end sequence positions. For example, if the previous decoding phase produced 8 tokens (from token 2048 to token 2056), then node P requests to retrieve KV Cache data from positions 2048 to 2056. Upon receiving this request, node D locates the KV Cache storage area for this session in its local memory, reads the corresponding KV Cache data according to the data range indication in the request, packages it into a response data packet, and returns it to node P.

[0098] It should be noted that since the incremental state data output from the previous round usually contains only a small number of tokens (for example, a large language model generates only 1 token each time during the decoding stage, but in some batch processing scenarios or speculative decoding scenarios, a forward propagation may generate multiple candidate tokens, but only one token is ultimately retained in the output, so the incremental data usually corresponds to a KV cache of 1 token), the amount of data transmitted is very small (for the XX model, the KV cache of a single token is about 16KB), so the communication latency is extremely low, usually in the range of microseconds to milliseconds.

[0099] After node P receives the incremental state data from the previous round returned by node D, the cache migration control module controls node P to concatenate this incremental state data with the existing local historical KV Cache to form a complete historical KV Cache (at this point, node P has been restored to the same historical state as node D). Then, the cache migration control module controls node P to concatenate the concatenated complete historical KV Cache with the newly added context (i.e., the current round of user input) to form a complete input sequence and perform pre-filling calculations.

[0100] It should be noted that during the pre-filling calculation, the P node not only calculates the Key and Value corresponding to the newly added context, but also needs to participate in the self-attention calculation using the complete historical KV Cache to generate a comprehensive attention output containing both historical and newly added context information. After the pre-filling calculation is completed, the P node generates the current round's incremental state data (i.e., the KV Cache corresponding to the newly added context, as well as all newly calculated Keys and Values ​​during this round's pre-filling calculation). The cache migration control module controls the P node to transmit this current round's incremental state data to the D node. After receiving the current round's incremental state data, the D node appends it to the end of its existing local full historical KV Cache, completing the update of the historical inference state data. Then, based on the updated full historical KV Cache, it performs subsequent decoding calculations, generating the current round's output result token by token.

[0101] Through the above process, the incremental migration process under the first strategy is fully realized. The amount of data transmitted across nodes in the whole process consists of only two parts: the incremental state data of the previous round and the incremental state data of the current round. The total amount of data is proportional to the number of output tokens and is much smaller than the amount of data in the full historical KV Cache, thereby significantly reducing the communication overhead between nodes.

[0102] In other feasible implementations, controlling the migration of historical inference state data between the first and second inference computing nodes under the third strategy may specifically include the following steps: releasing the historical inference state data stored in the first inference computing node; controlling the first inference computing node to send a request to the second inference computing node to obtain target historical state data; controlling the first inference computing node to receive the target historical state data returned by the second inference computing node; controlling the first inference computing node to perform pre-filling calculations based on the target historical state data and the new context to generate incremental state data; controlling the first inference computing node to transmit the incremental state data to the second inference computing node, wherein the incremental state data is used by the second inference computing node to generate output results by combining the target historical state data stored locally.

[0103] When the target processing strategy is the third strategy, the cache migration control module executes the "full pull and incremental return" process. In this process, since the length of the newly added input is relatively long (exceeding the second preset threshold), the P node is required to undertake the prefill computation to share the computational load of the D node. The P node may not store the historical KV Cache of the current session locally (for example, the session was not previously bound to the P node, the previously bound P node was reselected due to being unhealthy, or the P node previously released the historical cache of the session due to storage resource pressure). Therefore, the P node may need to obtain the full historical state data (i.e., the complete KV Cache) from the D node, then perform prefill computation based on the full historical state data and the newly added context, and finally return the incrementally generated state data of this round to the D node.

[0104] Specifically, the cache migration control module first controls the P node to release the historical inference state data stored locally (if any). The specific implementation of this release operation can be as follows: the P node locates the KV Cache storage area corresponding to the current session in the local video memory, calls the GPU's memory release API (such as the cudaFree function of CUDA) to release the video memory occupied by this area, and marks the corresponding storage location in the session state index table as "released". In actual implementation, since the video memory release operation may involve memory defragmentation, to reduce the impact on other requests being executed, the P node may adopt an asynchronous release mechanism, that is, the release operation is placed in a background thread for execution, and the main thread continues to process other tasks.

[0105] After confirming that the local historical inference state data has been released, the cache migration control module controls the P node to send an acquisition request to the D node for acquiring target historical state data. The acquisition request carries at least the following information: a session identifier, a request type identifier (indicating that this request is a full pull), and optional filtering conditions (such as window range, see subsequent variant embodiments for details). After receiving the acquisition request, the D node locates the full historical state data of the session in its local video memory, reads the corresponding KV Cache data, packages it into a response data packet, and returns it to the P node. For the first round of request (i.e., Lh=0), the D node does not yet have the historical inference state data of the session locally, and the acquisition request sent by the P node will return empty data (a response with zero data volume). The P node skips the loading step of the historical KV Cache and directly enters the prefill computation stage for the newly added input. For non-first-round requests, since the length of the newly added input is relatively long under the third strategy, but the value of the historical context length may be different (Lh<T1 or Lh≥T1). If the historical context is long, the data volume of the full historical state data may be large, and this pulling process may incur significant communication delay.

[0106] In addition, to reduce the impact of communication latency in the above process, the cache migration control module can adopt the following optimization measures: First, use RDMA technology to achieve zero-copy data transmission, bypassing the operating system kernel protocol stack, and directly copying data between the video memory of the two GPUs, reducing the transmission latency from milliseconds to sub-milliseconds; Second, use data compression technology, such as using LZ4 or Zstandard algorithms to compress the KV Cache data before transmission, and use it after decompression at the receiving end, sacrificing compression ratio for reduced bandwidth usage; Third, use pipelining transmission, transmitting the full KV Cache data in chunks, and the P node can start performing partial pre-filling calculations after receiving the first data block, achieving overlap between transmission and calculation, thereby hiding some transmission latency. This invention does not limit this.

[0107] After node P receives the target historical state data (i.e., the full KV Cache) returned by node D, the cache migration control module controls node P to load the target historical state data into its local video memory, concatenate it with the newly added context to form a complete input sequence, and then perform pre-filling calculation. After the pre-filling calculation is completed, node P generates incremental state data (i.e., the KV Cache corresponding to the newly added context). The cache migration control module controls node P to transmit this incremental state data to node D. After receiving the incremental state data, node D appends it to the end of its existing full historical state data (at this time, node D locally maintains the previously fetched full historical state data, plus the newly added incremental state data in this round, i.e., the updated full historical state data), and then performs subsequent decoding calculations based on the updated full historical state data to generate the output result of the current round.

[0108] Through the above steps, the migration process under the third strategy is fully realized. By undertaking all the pre-filling calculations, the P node effectively shares the computational load of the D node, ensuring the overall inference throughput of the system under high load conditions.

[0109] Furthermore, under the third strategy, before releasing the historical inference state data of the first inference computing node, the cache migration control module can first check whether the historical inference state data of the session actually exists in the local storage of the first inference computing node.

[0110] In the specific implementation, after receiving the migration instruction of the third strategy, the cache migration control module first queries the local cache index of the P node (which can be a hash table maintained in the memory of the P node, with the session identifier as the key and the KVCache storage address as the value) to confirm whether the local memory of the P node stores the historical KV Cache of the current session. If the query result shows that the historical KV Cache of the session exists locally, it means that the P node already has complete or partial historical context information. At this time, the release step and the subsequent full fetch step can be skipped, and the incremental migration process of the first strategy can be executed instead. That is, only the incremental state data output from the previous round is obtained from the D node, and the complete historical state can be restored based on the existing local historical KV Cache plus the fetched incremental state data, thereby avoiding the huge communication overhead caused by the full fetch.

[0111] In the above process, the pre-detection branch enables the system to skip the full fetch step and directly reuse the existing local historical cache (i.e., switch to incremental migration mode) while ensuring the correctness of inference, thus significantly reducing the amount of data transmitted. If the query result shows that the local historical KV cache for this session does not exist, the complete process of the third strategy is executed, namely, releasing (no-operation), fetching the full cache, processing, and sending back the incremental cache.

[0112] It should be noted that this switch does not affect the correctness of the inference, because regardless of whether the third strategy of full fetching or the degraded incremental fetching is used, the P node eventually obtains the complete historical KV Cache state (the former is obtained through full fetching, and the latter is obtained through local existing data plus incremental fetching). The only difference between the two is the amount of data transferred.

[0113] In some feasible implementations, under the third strategy, before releasing the historical inference state data stored in the first inference computing node, it is also possible to detect whether historical inference state data exists in the local storage of the first inference computing node. If the historical inference state data exists, the release step is skipped, and the first inference computing node is controlled to obtain the incremental state data of the previous round output from the second inference computing node. The new context is then processed based on the incremental state data. Thus, through this detection branch, the system can still intelligently determine whether it can be downgraded to an incremental migration mode with a smaller data volume under the triggering condition of the third strategy, thereby achieving further optimization of "strategy adaptation" and enhancing the system's adaptability in complex operating environments.

[0114] In some feasible implementations, during the full fetch process of the third strategy, in order to further reduce the amount of data transmitted across nodes, the cache migration control module can adopt a local attention mechanism based on a sliding window, which only fetches a portion of the historical KV Cache data that is most relevant to the current new context from the D node, instead of the full data.

[0115] Specifically, the cache migration control module first obtains the starting sequence position (denoted as S_start) of the new context. The starting sequence position refers to the starting index position of the new context within the complete input sequence (i.e., the complete sequence after concatenating the historical context and the new context). For example, if the historical context contains 1024 tokens, the new context starts from the 1025th token, and the starting sequence position S_start = 1025 (or index 1024 in 0-based indexing).

[0116] After determining the starting sequence position, the cache migration control module can control the P node to obtain the relative distance between each historical state data (i.e., the KVCache corresponding to each Token) and the starting sequence position from the full historical state data locally maintained by the D node bound to the current session. This relative distance can be determined by the difference (absolute value or signed difference) between the current Token's position index and the starting sequence position S_start. For example, if the position index of a historical Token is 800 and S_start is 1024, then the relative distance is |1024-800|=224.

[0117] Furthermore, the cache migration control module controls node P to identify target historical state data whose relative distance falls within a preset window range from the full historical state data. This preset window range can be a continuous interval that traces back a predetermined number of tokens from the starting sequence position (i.e., forward in the sequence). For example, the preset window range might be 512 tokens backward, covering all token positions from S_start-512 to S_start-1 (assuming S_start ≥ 512). Only the KV Cache corresponding to historical tokens within this window range is considered most relevant to the current new input and needs to be fetched from node D to node P. KV Caches corresponding to historical tokens outside the window range, being far from the starting position of the current new input, contribute less to the current round of pre-filling calculations and do not need to be migrated, thus significantly reducing the amount of data fetched.

[0118] Furthermore, the cache migration control module controls node P to send a request to node D to obtain target historical state data. This request carries the start and end position information of the aforementioned window range (e.g., start position S_start-window_size, end position S_start-1). Node D responds to this request by returning only the target historical state data within the stated window range to node P. After receiving the target historical state data, node P loads it into its local memory, thus obtaining the historical context information most relevant to the currently added input, for subsequent pre-filling calculations.

[0119] To more clearly illustrate the operation of the sliding window mechanism, a specific numerical example is provided below. Assume the historical context length of a multi-turn dialogue request is 2048 tokens (corresponding to position indices 0 to 2047), and the new context is located at position indices 2048 to 2560 (the new input length is 512 tokens), i.e., the starting sequence position S_start = 2048. The system's preset window range is to backtrack 512 tokens, so the window range for the target historical state data is position indices 1536 to 2047 (a total of 512 tokens corresponding to the KV Cache). The full historical state data stored locally on node D contains the KV Cache corresponding to 2048 tokens from position indices 0 to 2047, with a total data volume of 2048 × the KV size of each token. Without the sliding window mechanism, node P needs to pull the KV Cache of all 2048 tokens. Assuming the KV size of each token is 16KB (taking the XX model as an example), the total transmission volume is 2048 × 16KB = 32MB. After adopting the sliding window mechanism, the P node only needs to pull 512 tokens (location indices 1536 to 2047) from the KV cache, with a total transmission volume of 512 × 16KB = 8MB, reducing data transmission volume to one-quarter of the original. In actual deployment, the window size can be dynamically adjusted according to network bandwidth conditions and inference quality requirements. For example, when network bandwidth is sufficient, a larger window size can be used to obtain more complete historical context information; when network bandwidth is limited, a smaller window size can be used to reduce communication latency. The specific value of the window size (such as 256, 512, 1024, or 2048 tokens) can be configured and optimized by the system administrator according to the hardware configuration and service quality requirements of the actual deployment environment.

[0120] In some feasible implementations, the aforementioned sliding window-based local attention mechanism can be replaced with other equivalent sparse attention implementations to achieve the same effect of reducing communication overhead. For example, a strided attention mechanism can be used, which no longer filters using a continuous window range, but instead uniformly samples from the entire historical state data with a fixed step size (e.g., selecting 1 token every 4 tokens), using the sampled data range as the target historical state data. The advantage of this approach is that it can cover a wider historical range with the same number of sampling points, but the cost is that it may miss continuous contextual information.

[0121] For example, a global key-value compression mechanism can be used, in which a lightweight compression operation is performed on all historical state data at the D node in advance (such as compressing the high-dimensional key-value cache to a lower dimension through a single-layer linear transformation layer or a multilayer perceptron), and then the compressed data is transmitted to the P node as the target historical state data. After receiving the compressed data, the P node performs a decompression operation before pre-filling calculation, which can significantly reduce the amount of data transmitted.

[0122] In practical implementation, a global KV compression cache can also be set up on node D to share compressed data among multiple requests, thereby distributing the overhead of compression computation. Regardless of which alternative method is used, the core idea is to minimize the amount of KV cache data transmitted across nodes while ensuring the quality of pre-filled computation, thereby effectively alleviating network bandwidth bottlenecks and reducing end-to-end inference latency.

[0123] In the above process, the cache migration control module, through the differentiated migration procedures, can complete the migration of historical inference state data between nodes P and D in the most suitable way for the current scenario under each strategy involving cross-node cache migration. Under the first strategy, cross-node communication overhead is minimized by transmitting only incremental state data; under the third strategy, the combination of full fetching and incremental backhauling ensures inference quality while distributing the computational load of node D, and further optimizes communication efficiency through mechanisms such as sliding windows; in a variant of the third strategy, by pre-detecting the existence of local historical key-value pairs, it automatically degrades to incremental migration mode when conditions permit, further improving the system's adaptability.

[0124] It should be noted that the embodiments of the present invention include, but are not limited to, the examples described above. It is understood that those skilled in the art can make further settings according to actual needs under the guidance of the ideas in the embodiments of the present invention, and the present invention does not limit such settings.

[0125] In this embodiment of the invention, the distributed inference system extracts the historical context length and the new input length from multi-turn dialogue requests, and determines the target processing strategy from at least two differentiated caching processing strategies based on these two length parameters. This achieves adaptive selection of the matching caching processing method based on the actual characteristics of the request. This not only avoids the resource mismatch problem caused by dynamic changes in context length in multi-turn dialogue scenarios using a fixed single strategy, but also schedules requests to the corresponding inference computing nodes according to the target processing strategy, and controls the migration of historical inference state data between nodes when cross-node cache migration is involved. This allows the system to flexibly adapt to different processing strategies. The system determines whether historical inference state data should be redundantly stored, exclusively used by a single node, or migrated on demand. Through dual-dimensional perception of request characteristics and adaptive policy selection, it achieves a dynamic balance between storage resource utilization and cross-node data transmission. This avoids excessive GPU memory consumption caused by simple redundant storage and avoids the communication overhead caused by frequent cross-node full data transmission in unnecessary scenarios. At the same time, through the on-demand triggering mechanism for migration operations, it can handle requests in the most optimal way to match the current scenario under different dialogue contexts. As a result, it improves the resource utilization efficiency and inference service performance of the distributed inference system in multi-turn dialogue scenarios.

[0126] To enable those skilled in the art to better understand the technical solutions in the embodiments of the present invention, the following examples are provided for illustrative purposes: As some examples, see Figure 2 This diagram illustrates the architecture of a PD-separated KV Cache management system provided in an embodiment of the present invention. The PD-separated KV Cache management system may include a request feature extraction module, a dual-threshold dynamic decision-making module, a request scheduling module, and a cache migration control module, etc. Specifically: The request feature extraction module can be located at the very beginning of the system flow. It is responsible for extracting key length parameters from received multi-turn dialogue requests, including the historical context length (i.e., the number of tokens accumulated in all historical dialogue content before this request) and the new input length (i.e., the number of tokens for the new context content entered by the user in the current turn). The extraction method is as follows: parse the session identifier from the request, query the session state index table to obtain the historical context length; simultaneously, call the token segmenter to segment the new context, and count the number of tokens to obtain the new input length. These two length parameters serve as the input basis for the subsequent dual-threshold dynamic decision-making module to select strategies.

[0127] The dual-threshold dynamic decision-making module serves as the core decision-making unit. Its function is to determine the appropriate strategy for the current request from multiple differentiated caching strategies based on the historical context length and new input length output by the request feature extraction module, combined with the system's pre-configured first and second preset thresholds. Specifically, this module executes the following judgment logic: if the historical context length is less than the first preset threshold and the new input length is less than the second preset threshold, the first strategy (incremental fetch mode) is selected; if the historical context length is greater than or equal to the first preset threshold and the new input length is less than the second preset threshold, the second strategy (D-node exclusive mode) is selected; if the new input length is greater than or equal to the second preset threshold, the third strategy (P-node pre-filling mode) is selected. The first preset threshold measures the historical context length, and the second preset threshold measures the new input length. This module also supports dynamic adjustment of the two thresholds based on the system's real-time operating status (such as storage resource utilization and network bandwidth utilization).

[0128] The request scheduling module is responsible for executing differentiated request distribution operations based on the target processing strategy output by the dual-threshold dynamic decision-making module. When the target strategy is the first or third strategy, this module performs the "P-node binding and request distribution" operation, which specifically includes: checking the session state index table to confirm whether the session is already bound to a P-node (if it is already bound and healthy, it is reused; otherwise, a suitable P-node is selected from the P-node resource pool for binding), distributing the new context to the target P-node for pre-filling calculation, and assigning the D-node bound to the session as the decoding execution node. When the target strategy is the second strategy, this module skips the P-node selection and binding operation and directly distributes the request to the D-node bound to the current session, where the D-node independently completes the pre-filling calculation and decoding calculation.

[0129] The cache migration control module manages the migration, storage, and release of KV caches between PD nodes. It works in conjunction with the request scheduling module; the request scheduling module distributes requests to the correct compute nodes, while the cache migration control module ensures that compute nodes have the necessary historical inference state data before performing pre-filling computation. Specifically, under the first strategy, this module executes an "incremental migration" process: the P node retrieves the incremental state data from the previous round's output (only a small number of tokens corresponding to the KV cache) from the D node, performs pre-filling computation in conjunction with its existing local historical KV cache, and then sends back the current round's incremental state data, resulting in minimal cross-node communication. Under the third strategy, this module handles two scenarios based on whether the P node has local historical inference state data for the session: Scenario 1 (no local cache): the P node pulls the full historical KV cache from the D node, performs pre-filling, and then sends back the incremental state data; Scenario 2 (local cache): the P node directly reuses its local cache without needing to pull the full data across nodes. In addition, the module also supports optional optimization methods such as a sliding window-based local attention mechanism, which only pulls a portion of historical data that is most relevant to the current new input instead of the full amount of data, further reducing cross-node communication.

[0130] For the PD-separated KV Cache management system, four modules are connected end to end and work closely together to form a complete data processing pipeline from request feature extraction, strategy decision-making, request scheduling to cache migration.

[0131] Based on the aforementioned system architecture, referring to Figure 3 The diagram illustrates a differentiated request processing mode provided in an embodiment of the present invention, which corresponds to the first strategy, the second strategy, and the third strategy in the aforementioned embodiments.

[0132] like Figure 3As shown, the first mode (M1) corresponds to the incremental fetch mode of the aforementioned first strategy, i.e., dual-end KV Cache retention under the PD separation architecture. In this mode, the Prefill instance and the Decode instance each maintain a KV Cache, and both store the historical inference state data of the current session. When the user initiates a new round of dialogue request, the Prefill instance does not need to obtain the full historical KV Cache from the Decode instance, but only needs to fetch the newly generated incremental state data (i.e., IncrementalKV) from the previous decoding stage, concatenate it with the existing local historical KV Cache to restore the complete historical state, and then process the new context and perform prefill calculation. After prefilling is completed, the Prefill instance sends the newly generated incremental state data of this round back to the Decode instance, which updates its local KV Cache and performs subsequent decoding generation. The core feature of this mode is that both the Prefill instance and the Decode instance retain the complete KV Cache, only incremental data is transmitted across nodes, and the communication overhead is minimal. For the specific implementation process and data range indication method of this mode, please refer to the relevant description of the incremental migration process under the first strategy in step 104 above.

[0133] The second mode (M2) corresponds to the exclusive D-node mode of the second strategy mentioned above. In this mode, the Prefill instance does not participate in the processing of the current request at all; the entire prefilling and decoding phases of the request are completed independently on the Decode instance. That is, the Decode instance temporarily takes over the prefilling calculation task that should have been performed by the Prefill instance. It uses its locally stored full historical KV Cache and concatenates it with the new context to perform the complete prefilling calculation, and then directly enters the token-by-token decoding generation phase, obtains the output result, and returns it to the client. The communication overhead of this mode is zero—no KV Cache data transfer is required between the Prefill instance and the Decode instance throughout the entire process. This mode is suitable for scenarios with long historical contexts (high cost of transferring the full KV Cache across nodes) but short new inputs (small additional burden of the Decode instance temporarily taking on prefilling). For the applicable conditions and scheduling method of this mode, please refer to the relevant description of the exclusive D-node distribution logic under the second strategy in step 103 above.

[0134] The third mode (M3) corresponds to the P-node prefilling mode of the aforementioned third strategy, i.e., efficient migration of KV Cache under the PD separation architecture. In this mode, the Prefill instance is responsible for performing prefilling calculations, and the Decode instance is responsible for performing decoding calculations. Depending on whether the Prefill instance has historical inference state data for the session locally, this mode has two scenarios: If the Prefill instance does not have a historical KV Cache locally, it needs to pull the full historical state data from the Decode instance (i.e., the Pull operation of PrefixKV), then perform prefilling calculations based on the full historical data and the new context, and subsequently send the newly generated incremental state data back to the Decode instance (i.e., the Push operation of IncrementalKV); if the Prefill instance already has a historical KV Cache locally, it does not need to pull the full data across nodes, directly reuses the local cache to perform prefilling calculations, and only needs to send the incremental state data back to the Decode instance after the calculation is completed. In the first scenario, if the historical context is long, the amount of data in the full KV Cache may reach GB levels, and cross-node transmission will cause significant communication latency. To reduce this latency, the system can employ optimization measures such as RDMA technology, data compression technology, or pipelined transmission. Alternatively, it can use optional optimization methods such as a sliding window-based local attention mechanism to retrieve only the portion of historical data most relevant to the current new input. For details on the specific implementation process and optimization methods of this mode, please refer to the descriptions in step 104 above regarding the full retrieval and incremental data return process under the third strategy, the sliding window mechanism, and alternative implementation methods.

[0135] In summary, the three modes each have their own emphasis on KV Cache management and data transmission strategies. The system automatically selects the optimal mode based on the length of the historical context and the length of the new input through the dual-threshold dynamic decision-making module. Combined with the differentiated execution of the request scheduling module and the cache migration control module, it achieves a dynamic balance between memory usage and communication overhead in multi-turn dialogue scenarios.

[0136] Furthermore, based on the three models mentioned above, and referring to... Figure 4 This diagram illustrates the decision-making process of the dual-threshold dynamic decision-making module provided in this embodiment of the invention. The input parameters for the decision are two key length values ​​output by the request feature extraction module: the historical context length H and the new input length P. The system compares H with a first preset threshold L_h and P with a second preset threshold L_p. Based on the comparison results, it automatically guides the current request to the corresponding processing mode (i.e., selects the appropriate processing strategy to execute the corresponding complete inference service). When H < L_h, regardless of the size of the newly added input length P, the system selects the M1 mode under the PD separation architecture (corresponding to the first strategy mentioned above). The basis for this decision is that a shorter historical context means that the amount of full KV Cache data is not large, and the communication cost of cross-node transmission is within an acceptable range. Therefore, the PD separation method of division of labor and cooperation between Prefill instances and Decode instances is preferred, with Prefill instances performing prefill calculations and Decode instances performing decoding calculations.

[0137] When H ≥ L_h and P < L_p, the system selects mode M2 ​​(corresponding to the second strategy mentioned above), which means relying solely on the Decode instance to process the current request. The basis for this decision is that the historical context is already quite long (transferring the entire KV cache across nodes is costly), but the new input is short (the additional burden of pre-filling temporarily borne by the Decode instance is small). Therefore, having the Decode instance independently complete all the computations can avoid cross-node communication overhead, making it the optimal choice overall.

[0138] When P ≥ L_p, regardless of the relationship between the historical context length H and L_h, the system selects either the M1 mode or the M3 mode under the PD separation architecture (corresponding to the aforementioned first or third strategy). Specifically, when H < L_h and P ≥ L_p, the system selects the M1 mode; when H ≥ L_h and P ≥ L_p, the system selects the M3 mode. The basis for this decision logic is that when the newly added input is long, the Decode instance in exclusive mode needs to bear a large pre-filling computation load, which may affect the normal execution of its decoding task. Therefore, the Prefill instance needs to bear the pre-filling computation. Based on this, according to the comparison result of the historical context length H and the first preset threshold L_h, the incremental fetch (M1) or full fetch (M3) method is further distinguished.

[0139] In the above judgment logic, the handling method for boundary cases (such as H equals L_h or P equals L_p) can be referred to the relevant description of boundary cases in step 102 above; the specific execution flow of the three modes M1, M2 and M3 can be referred to the relevant description of the first strategy (incremental migration), the second strategy (D node exclusive) and the third strategy (full pull and incremental backhaul) in the second diagram above and step 104 respectively.

[0140] Furthermore, based on the target processing strategy determined in the aforementioned process, the request scheduling module can execute differentiated scheduling logic according to the three different target processing strategies, such as... Figure 5 This illustrates a schematic diagram of differentiated scheduling provided in an embodiment of the present invention. The input can be the target processing mode output by the aforementioned dual-threshold dynamic decision-making module, the newly added prompt, and the dialogue ID. Specifically: When the target processing mode is M1 (corresponding to the incremental fetch mode of the first strategy mentioned above), the process first determines whether the current dialogue ID is already bound to a PD instance (i.e., a combination of a Prefill instance and a Decode instance, where the P instance is responsible for performing prefill calculations and the D instance is responsible for performing decoding calculations). If it is already bound, the binding relationship is directly reused without reselecting a node; if it is not yet bound, based on the load of the Prefill cluster, the KV prefix matching situation, and the network topology, an optimal pair of PD instances is selected for binding, and the binding relationship is recorded in the session state index table. Subsequently, the new prompt is distributed to the specified Prefill instance for prefill calculation, and the original request is distributed to the Decode instance bound to the dialogue ID for decoding calculation, while setting the maximum number of generated tokens to 1 (i.e., each request only generates the output of the current round).

[0141] When the target processing mode is M2 (corresponding to the exclusive D-node mode of the second strategy mentioned above), since the Prefill instance does not participate in processing, the process first determines whether the current dialogue ID is already bound to a P instance (i.e., the Decode instance bound to the dialogue). If it is already bound, the Decode instance is directly reused to process the current request; if it is not yet bound, the most suitable P instance is selected for binding based on the Prefill cluster load and affinity with the bound D node, and the binding relationship is recorded in the session state index table. Subsequently, the original request is directly distributed to the D instance bound to the dialogue ID (i.e., the Decode instance associated with the same session), and the D instance independently completes the prefill calculation and decoding calculation. The entire process does not require the participation of the Prefill instance, nor does it require any cross-node KV Cache data transmission.

[0142] When the target processing mode is M3 (corresponding to the prefill mode executed by the P node in the aforementioned third strategy), the process first determines whether the current dialogue ID is already bound to a Prefill instance. If it is already bound, the Prefill instance is directly reused to perform prefill calculation; if it is not yet bound, the Prefill instance bound to the current dialogue ID is released (if an old binding relationship exists, it is released first to relieve resource occupation). Then, based on the Prefill cluster load and affinity with the bound D node, the most suitable P instance is reselected for binding, and the binding relationship is recorded in the session state index table. Subsequently, the request is distributed to the specified Prefill instance to perform prefill calculation, and the original request is distributed to the Decode instance bound to the dialogue ID to perform decoding calculation.

[0143] Among them, reference Figure 6This diagram illustrates the migration interaction process provided in this embodiment of the invention. It demonstrates the KV Cache migration interaction process between the Prefill instance and the Decode instance under the aforementioned third strategy (M3 mode), and is a specific implementation detail of the cache migration control module under the third strategy scenario one (the Prefill instance does not have historical inference state data locally). In the specific implementation, Figure 6 This describes a complete interaction between the Prefill instance and the Decode instance, involving request-response collaboration between the two core participants. Specifically: Steps to prefill the instance side: The Prefill instance first sends a request to the Decode instance to fetch the PrefixKV. This request carries at least the session ID of the current session, which is used by the Decode instance to locate the KV Cache storage area corresponding to the session in local video memory.

[0144] In response to the request, the Decode instance performs verification and retrieves the PrefixCache corresponding to the dialogue ID, and then returns two parts of response data to the Prefill instance: the number of tokens H in the history dialogue and the KV Cache within the preset window range (i.e., the target history state data filtered by the sliding window mechanism, which only includes the KV Cache corresponding to the part of the history tokens most relevant to the new input, rather than the full history data).

[0145] After receiving the response, the Prefill instance calculates the starting sequence position code of the new context based on the number of tokens H in the historical dialogue (that is, determines the position index of the new context in the complete input sequence, so as to ensure the accuracy of position information during attention calculation). Then, it concatenates the received KV Cache in the window with the new Prompt to form a complete input sequence, performs prefill calculation, and generates the KV Cache corresponding to the new Prompt.

[0146] After the prefill calculation is completed, the Prefill instance sends the newly generated incremental KV (i.e., the KVCache corresponding to the newly added Prompt) to the Decode instance.

[0147] Steps to decode the instance side: After receiving a fetch request from the Prefill instance, the Decode instance first verifies the validity of the request (such as verifying the validity of the session identifier and confirming the requester's permissions). Then, it retrieves the corresponding PrefixCache (i.e., the full historical KV Cache) stored in local video memory using the session ID as the key. After confirming a successful retrieval, the Decode instance reads the corresponding KV Cache data according to the filtering conditions (such as window range) carried in the Prefill instance's request, and packages the number of tokens H of the historical session and the KV Cache within the window into a response data packet and returns it to the Prefill instance.

[0148] In the subsequent stage, after receiving the incremental KV returned by the Prefill instance, the Decode instance appends it to the end of the existing full historical KV Cache to update the historical inference state data. Then, based on the updated full KV Cache, it performs token-by-token decoding calculations to generate the output result of the current round and returns it to the client.

[0149] Furthermore, based on the aforementioned system architecture and the functions of each module, to more clearly illustrate the overall process of this invention's embodiment, a complete application scenario is presented below. Assume an enterprise-level intelligent customer service system deploys the technical solution of this invention, using the XX model (671B parameters). The PD separation architecture is deployed in a GPU cluster within the same data center. The P node cluster contains 8 nodes (each node has 8×A100 80GB), and the D node cluster contains 16 nodes (each node has 8×A100 80GB). The nodes are interconnected via a 100Gbps RoCE network. The system is configured with a first preset threshold T1 = 4096 tokens and a second preset threshold T2 = 1024 tokens.

[0150] Scenario 1: User A opens the customer service dialogue interface for the first time and inputs "Hello, please introduce your company's product line". After receiving the request, in step 101, the system extracts the historical context length Lh=0 (first-round request), and the new input length Ln=18 (the input "Hello, please introduce your company's product line" is tokenized into 18 tokens). In step 102, the dual-threshold dynamic decision module compares Lh=0<T1=4096 and Ln=18<T2=1024, thus selecting the first strategy as the target processing strategy. In step 103, the request scheduling module queries the session state index table, confirms that the session has no bound P node, selects a P node with the largest available memory from the P node resource pool (assumed to be p-node-01), binds the session identifier "session_A" to p-node-01, and distributes the new context to p-node-01. In step 104, since the target processing strategy is the first strategy, the cache migration control module controls p-node-01 to send an incremental pull request to the D node d-node-03 bound to the session. As this is the first-round request, the previous round of incremental state data is empty, so the pull operation actually does not transmit any data. p-node-01 performs prefill calculation based on the empty historical KV Cache and the new context, generates the current round of incremental KV (corresponding to 18 tokens), and then sends it back to d-node-03. d-node-03 appends the received incremental KV to the local KV Cache (the total length is 18 tokens at this time), performs decoding calculation, generates the response "Our company mainly produces AI inference acceleration products..." and returns it to the user.

[0151] Scenario 2: User A immediately asks a follow-up question in the second round: "What are the specific product models?" After receiving this request, in step 101, the system extracts the historical context length Lh = 18 + the length of the previous round's response (assuming the previous response is 32 Tokens) = 50, and the new input length Ln = 11. In step 102, since Lh = 50 < T1 = 4096, the first strategy is still selected. In step 103, the request scheduling module queries the session state index table and finds that the session has already been bound to p-node-01, so it continues to use p-node-01 and distributes the new context "What are the specific product models?" to p-node-01. In step 104, the cache migration control module controls p-node-01 to send an incremental pull request to d-node-03, pulling the incremental state data of the previous round's output (i.e., the KV Cache of 32 Tokens corresponding to the previous response "Our company mainly produces AI inference acceleration products..."). p-node-01 concatenates the local existing historical KV Cache (18 Tokens from the first round) with the pulled incremental KV (32 Tokens) to obtain a complete historical KV Cache of 50 Tokens, then concatenates it with the new context "What are the specific product models?" to perform prefill calculation, generate the current round's incremental KV (11 Tokens), and send it back to d-node-03. d-node-03 appends the received incremental KV to the local KV Cache (the total length is 61 Tokens at this time), performs decoding calculation to generate a response and returns it. During the entire process, the data volume transmitted between nodes is only the first round's incremental KV (18×16KB=288KB), the second round's incremental pull (32×16KB=512KB), and the second round's incremental return (11×16KB=176KB), totaling about 1MB, with extremely low communication overhead.

[0152] Scenario 3: User A has dozens of consecutive dialogue rounds with the customer service bot, and the cumulative length of historical context reaches 5120 Tokens (exceeding T1=4096). At this point, User A asks: "Compared with competitor B, does our product have an advantage in latency?" The length of the new input is 28 Tokens (less than T2=1024). In step 102, Lh=5120≥T1=4096, and Ln=28<T2=1024, so the dual-threshold dynamic decision module selects the second strategy as the target processing strategy. In step 103, the request scheduling module skips P node binding, directly distributes the request to the D node d-node-03 bound to this session, and carries the strategy indication field "strategy:decode_only" in the request. In step 104, since the target processing strategy is the second strategy, which does not involve cross-node cache migration, the cache migration control module skips this step. After receiving the request, d-node-03 loads the full historical KV Cache of this session locally (5120 Tokens, approximately 82MB), concatenates it with the new context "Compared with competitor B, does our product have an advantage in latency?" (total length 5148 Tokens), executes prefill calculation, then performs decoding calculation, and returns the generated answer directly to the user. During the entire process, there is no KV Cache data transmission between nodes, and the communication overhead is zero. Although the D node undertakes one prefill calculation, since the length of the new input is only 28 Tokens, the prefill calculation amount is very small (only additional calculation for 28 Tokens is required), and its impact on the decoding throughput of the D node is negligible.

[0153] Scenario 4: Building upon Scenario 3, User A continues to ask questions, further accumulating the historical context length to 8192 tokens. User A also pastes a relatively long technical document as new context in this round, resulting in a new input length of 2048 tokens (exceeding T2=1024). In step 102, Lh=8192≥T1=4096, Ln=2048≥T2=1024, therefore the dual-threshold dynamic decision module selects the third strategy as the target processing strategy. In step 103, the request scheduling module queries the session state index table and finds that the session is already bound to p-node-01, and p-node-01 is currently in a healthy state. Therefore, p-node-01 continues to be used, and the new context (the 2048-token technical document) is distributed to p-node-01. In step 104, the cache migration control module first checks whether the historical KV cache of this session exists locally on p-node-01. Assuming that p-node-01 processed a large number of other session requests after Scenario 3, its local storage of the session's historical KV Cache has been released by the LRU eviction mechanism, so the detection result is that it does not exist. The cache migration control module executes the complete migration process of the third strategy: p-node-01 releases its local storage (at this time, there is no historical KV for this session locally, so the release operation is a null operation), and then sends a full pull request to d-node-03. To reduce the amount of data transmission, the pull operation adopts a sliding window-based local attention mechanism, with a preset window range of 1024 tokens backward (i.e., only the KV Cache corresponding to the last 1024 tokens in the historical context is pulled, instead of the full 8192 tokens). After receiving the target historical state data (KV Cache corresponding to 1024 tokens, about 16MB), the P node loads it into its local memory, concatenates it with the new context (2048 tokens), performs pre-filling calculation, generates incremental state data (KV Cache corresponding to the new context of 2048 tokens), and sends it back to d-node-03. d-node-03 appends the received incremental state data to the end of the full historical KV cache in local storage (at this point, the total length is 8192 + 2048 = 10240 tokens), performs decoding calculations to generate a response, and returns it. Throughout the process, the amount of data transmitted across nodes is only the 1024 tokens (16MB) fetched in full and the 2048 tokens (32MB) returned, totaling approximately 48MB. Compared to the 8192 tokens (128MB) that need to be transmitted without the sliding window mechanism, the data volume is reduced by approximately 62.5%. Simultaneously, due to the adoption of the third strategy, the pre-filling calculation is handled by the P node, avoiding the high load on the D node caused by processing long new inputs (2048 tokens), thus ensuring the stability of the D node's decoding service.

[0154] In summary, through the end-to-end collaborative design of four modules—request feature extraction, dual-threshold dynamic decision-making, request scheduling, and cache migration control—a dynamic balance between memory usage and communication overhead in multi-turn dialogue scenarios is achieved. Specifically, the dual-threshold dynamic decision-making mechanism enables the system to intelligently switch between three modes—incremental fetching, exclusive D-node access, and efficient migration—based on the length of historical context and the length of new input. Combined with customized request scheduling strategies for each mode, this ensures optimal allocation of computing, memory, and network resources. Furthermore, the efficient KV Cache migration algorithm based on the sliding window attention mechanism only transmits the most relevant historical data required for the current computation, rather than the entire cache, significantly reducing inter-node communication overhead and alleviating network bandwidth bottlenecks. Simultaneously, the incremental update mechanism of the D-node eliminates truncation errors, ensuring stable inference latency in long dialogue scenarios. This provides an efficient and feasible solution for deploying ultra-large-scale models under the PD separation architecture, comprehensively improving the overall performance and reliability of the distributed inference system.

[0155] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.

[0156] Reference Figure 7 The diagram illustrates a structural block diagram of a data processing device provided in an embodiment of the present invention, applied to a distributed inference system. The distributed inference system includes at least a first inference computing node and a second inference computing node, and may specifically include the following modules: The feature extraction module 701 is used to extract the length of the historical context and the length of the new input of the new context from the multi-turn dialogue request; The dynamic decision module 702 is used to determine a target processing strategy from at least two differentiated caching processing strategies based on the historical context length and the new input length. The request scheduling module 703 is used to schedule the multi-turn dialogue request to the first inference computing node and / or the second inference computing node to perform computing tasks according to the target processing strategy. The cache migration control module 704 is used to control the migration of historical inference state data between the first inference computing node and the second inference computing node when the target processing strategy is a strategy involving cross-node cache migration.

[0157] In some feasible implementations, the dynamic decision module 702 is specifically used for: If the length of the historical context is less than the first preset threshold and the length of the new input is less than the second preset threshold, then a first strategy is selected from at least two differentiated caching strategies. Under the first strategy, the first inference computing node obtains the incremental state data of the previous round output from the second inference computing node, processes the new context based on the incremental state data, and then sends the current round of incremental state data back to the second inference computing node. If the length of the historical context is greater than or equal to the first preset threshold and the length of the new input is less than the second preset threshold, then the second strategy is selected from at least two of the differentiated caching strategies, and the second inference computing node performs a pre-filling stage and a decoding stage under the second strategy; If the length of the newly added input is greater than or equal to the second preset threshold, then a third strategy is selected from at least two differentiated caching strategies. Under the third strategy, the first inference computing node processes the newly added context based on the historical inference state data stored locally or the full historical state data obtained from the second inference computing node.

[0158] In some feasible implementations, when the target processing strategy is the first strategy, the cache migration control module 704 is specifically used for: The first inference computing node is controlled to send a request to the second inference computing node to obtain the incremental state data of the previous round; Control the first inference computing node to receive the previous round of incremental state data returned by the second inference computing node; The first inference computing node is controlled to concatenate the previous round incremental state data with the newly added context and then perform pre-filling calculation to generate the current round incremental state data. The first inference computing node is controlled to transmit the current round incremental state data to the second inference computing node, and the current round incremental state data is used by the second inference computing node to generate the current round output.

[0159] In some feasible implementations, when the target processing strategy is the third strategy, the cache migration control module 704 is specifically used for: Release the historical inference state data stored in the first inference computing node; The first inference computing node is controlled to send a request to the second inference computing node to obtain target historical state data. Control the first inference computing node to receive the target historical state data returned by the second inference computing node; The first inference computing node is controlled to perform pre-filling calculations based on the target historical state data and the new context to generate incremental state data; The first inference computing node is controlled to transmit the incremental state data to the second inference computing node. The incremental state data is used by the second inference computing node to generate an output result by combining the target historical state data stored locally.

[0160] In some feasible implementations, the cache migration control module 704 is specifically used for: Obtain the starting sequence position of the newly added context; The first inference computing node is controlled to obtain the relative distance between each historical state data and the starting sequence position in the full historical state data locally maintained by the second inference computing node bound to the current session; The first inference computing node is controlled to determine the data in the full historical state data whose relative distance falls within a preset window range as the target historical state data; The first inference computing node is controlled to send a request to the second inference computing node to obtain the target historical state data. The first inference computing node is controlled to receive the target historical state data returned by the second inference computing node in response to the acquisition request.

[0161] In some feasible implementations, the request scheduling module 703 is specifically used for: When the target processing strategy is the first strategy or the third strategy, the multi-turn dialogue request is bound to the first inference computing node, the new context is distributed to the first inference computing node to perform pre-filling calculation, and the second inference computing node bound to the current session is assigned as the decoding execution node; When the target processing strategy is the second strategy, the multi-turn dialogue request is distributed to the second inference computing node bound to the current session, and the second inference computing node is controlled to perform pre-filling calculation and decoding calculation to obtain the output result of the current round.

[0162] In some feasible implementations, when the target processing strategy is the third strategy, the apparatus further includes: The detection module is used to detect whether historical inference state data exists in the local storage of the first inference computing node; The execution module is switched to skip the release step if the historical inference state data exists, and controls the first inference computing node to obtain the incremental state data of the previous round output from the second inference computing node, and process the new context based on the incremental state data.

[0163] Among some feasible implementation methods are: The monitoring module is used to obtain the storage resource utilization rate and network bandwidth utilization rate of the distributed inference system. The threshold adjustment module is used to adjust the first preset threshold and the second preset threshold using the storage resource utilization rate and the network bandwidth utilization rate.

[0164] As the device embodiment is basically similar to the method embodiment, the description is relatively simple, and relevant parts can be found in the description of the method embodiment.

[0165] In addition, this invention also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described data processing method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0166] This invention also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements the various processes of the above-described data processing method embodiments and achieves the same technical effects. To avoid repetition, it will not be described again here. The computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0167] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.

[0168] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, apparatus, or computer program products. Therefore, embodiments of the present invention can take the form of entirely hardware embodiments, entirely software embodiments, or embodiments combining software and hardware aspects. Furthermore, embodiments of the present invention can take the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, EEPROM, Flash, and eMMC, etc.) containing computer-usable program code.

[0169] Embodiments of the present invention are described with reference to flowchart illustrations and / or block diagrams of methods, terminal devices (systems), and computer program products according to embodiments of the invention. 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 terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0170] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal 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 a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0171] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal 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.

[0172] Although preferred embodiments of the present invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present invention.

[0173] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.

[0174] The above provides a detailed description of a data processing method and a data processing apparatus provided by the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A data processing method, characterized in that, The method is applied to a distributed inference system, wherein the distributed inference system includes at least a first inference computing node and a second inference computing node, and includes: Extract the length of the historical context and the length of the new input for the new context from the multi-turn dialogue request; Based on the historical context length and the new input length, a target processing strategy is determined from at least two differentiated caching processing strategies; According to the target processing strategy, the multi-turn dialogue request is scheduled to the first inference computing node and / or the second inference computing node to perform computing tasks; When the target processing strategy is a strategy involving cross-node cache migration, the migration of historical inference state data is controlled between the first inference computing node and the second inference computing node.

2. The method according to claim 1, characterized in that, The step of determining the target processing strategy from at least two differentiated caching strategies based on the historical context length and the new input length includes: If the length of the historical context is less than the first preset threshold and the length of the new input is less than the second preset threshold, then a first strategy is selected from at least two differentiated caching strategies. Under the first strategy, the first inference computing node obtains the incremental state data of the previous round output from the second inference computing node, processes the new context based on the incremental state data, and then sends the current round of incremental state data back to the second inference computing node. If the length of the historical context is greater than or equal to the first preset threshold and the length of the new input is less than the second preset threshold, then the second strategy is selected from at least two of the differentiated caching strategies, and the second inference computing node performs a pre-filling stage and a decoding stage under the second strategy; If the length of the newly added input is greater than or equal to the second preset threshold, then a third strategy is selected from at least two differentiated caching strategies. Under the third strategy, the first inference computing node processes the newly added context based on the historical inference state data stored locally or the full historical state data obtained from the second inference computing node.

3. The method according to claim 2, characterized in that, When the target processing strategy is the first strategy, controlling the migration of historical inference state data between the first inference computing node and the second inference computing node includes: The first inference computing node is controlled to send a request to the second inference computing node to obtain the incremental state data of the previous round; Control the first inference computing node to receive the previous round of incremental state data returned by the second inference computing node; The first inference computing node is controlled to concatenate the previous round incremental state data with the newly added context and then perform pre-filling calculation to generate the current round incremental state data. The first inference computing node is controlled to transmit the current round incremental state data to the second inference computing node, and the current round incremental state data is used by the second inference computing node to generate the current round output.

4. The method according to claim 2, characterized in that, When the target processing strategy is the third strategy, the step of controlling the migration of historical inference state data between the first inference computing node and the second inference computing node includes: Release the historical inference state data stored in the first inference computing node; The first inference computing node is controlled to send a request to the second inference computing node to obtain target historical state data. Control the first inference computing node to receive the target historical state data returned by the second inference computing node; The first inference computing node is controlled to perform pre-filling calculations based on the target historical state data and the new context to generate incremental state data; The first inference computing node is controlled to transmit the incremental state data to the second inference computing node. The incremental state data is used by the second inference computing node to generate an output result by combining the target historical state data stored locally.

5. The method according to claim 4, characterized in that, The control of the first inference computing node to receive the target historical state data returned by the second inference computing node includes: Obtain the starting sequence position of the newly added context; The first inference computing node is controlled to obtain the relative distance between each historical state data and the starting sequence position in the full historical state data locally maintained by the second inference computing node bound to the current session; The first inference computing node is controlled to determine the data in the full historical state data whose relative distance falls within a preset window range as the target historical state data; The first inference computing node is controlled to send a request to the second inference computing node to obtain the target historical state data. The first inference computing node is controlled to receive the target historical state data returned by the second inference computing node in response to the acquisition request.

6. The method according to claim 2, characterized in that, The step of scheduling the multi-turn dialogue request to the first inference computing node and / or the second inference computing node according to the target processing strategy includes: When the target processing strategy is the first strategy or the third strategy, the multi-turn dialogue request is bound to the first inference computing node, the new context is distributed to the first inference computing node to perform pre-filling calculation, and the second inference computing node bound to the current session is assigned as the decoding execution node; When the target processing strategy is the second strategy, the multi-turn dialogue request is distributed to the second inference computing node bound to the current session, and the second inference computing node is controlled to perform pre-filling calculation and decoding calculation to obtain the output result of the current round.

7. The method according to claim 4, characterized in that, When the target processing strategy is the third strategy, the method further includes the following steps before releasing the historical inference state data stored in the first inference computing node: Check whether historical inference state data exists in the local storage of the first inference computing node; If the historical inference state data exists, the release step is skipped, and the first inference computing node is controlled to obtain the incremental state data of the previous round output from the second inference computing node, and the new context is processed based on the incremental state data.

8. The method according to claim 2, characterized in that, Also includes: Obtain the storage resource utilization and network bandwidth utilization of the distributed inference system; The first preset threshold and the second preset threshold are adjusted based on the storage resource utilization rate and the network bandwidth utilization rate.

9. A data processing apparatus, characterized in that, The device is applied to a distributed inference system, wherein the distributed inference system includes at least a first inference computing node and a second inference computing node, and the device includes: The feature extraction module is used to extract the length of the historical context and the length of the new input for the new context from multi-turn dialogue requests; A dynamic decision-making module is used to determine a target processing strategy from at least two differentiated caching processing strategies based on the historical context length and the new input length. The request scheduling module is used to schedule the multi-turn dialogue request to the first inference computing node and / or the second inference computing node to perform computing tasks according to the target processing strategy. The cache migration control module is used to control the migration of historical inference state data between the first inference computing node and the second inference computing node when the target processing strategy is a strategy involving cross-node cache migration.

10. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes a program stored in the memory, it implements the method as described in any one of claims 1-8.

11. A computer-readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method as described in any one of claims 1-8.