A large model hybrid inference optimization method, device, equipment and medium

By acquiring task phases, contextual features, and latency constraints, the quantization configuration and resource preloading of large models are dynamically adjusted, solving the problems of resource waste and increased latency in existing technologies, and achieving more efficient resource utilization and inference stability.

CN123159541APending Publication Date: 2026-11-24BEIJING LINGCHENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611387328.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-08
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing large-scale model inference systems struggle to dynamically adjust to changes in task stage, context, and time limits when faced with escalating demands for computing and storage resources, leading to resource waste and increased inference latency.

Method used

By obtaining the task stage, context features, and latency constraints of the current inference request, the quantization configuration and key-value cache are determined, the batch processing waiting time is dynamically controlled, and the resources for the next task stage are preloaded, thus achieving the matching of model quantization configuration with the inference task.

Benefits of technology

It reduces redundant computation, shortens inference latency and resource consumption, improves the utilization of computing and storage resources, and enhances the stability of concurrent inference processes for large models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123159541A_ABST
    Figure CN123159541A_ABST
Patent Text Reader

Abstract

This application relates to a method, apparatus, device, and medium for optimizing large-scale model hybrid inference. The method includes determining the quantization configuration of the large model based on the task stage and the current inference resource status; obtaining cache lookup results based on context features and the running configuration of the large model; determining the batch processing wait time for the current inference request; forming an inference batch by combining the current inference request with other inference requests arriving within the batch processing wait time that match the running configuration of the large model; running the large model according to the quantization configuration; and when a matching key-value cache is found in the cache lookup result representation, performing inference processing on the inference batch using the matching key-value cache to obtain the current inference result; predicting the next task stage based on the task stage and the current inference result; determining the inference resources corresponding to the next task stage; and preloading the inference resources before receiving the inference request for the next task stage.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the technical field of artificial intelligence and large model inference optimization, and in particular to a method, apparatus, device and medium for large model hybrid inference optimization. Background Technology

[0002] As the size of large model parameters, the length of context, and the number of concurrent requests increase, the demand for computing and storage resources in large model inference processes continues to rise. To reduce resource consumption during inference, existing inference systems typically employ mechanisms such as model quantization, request batching, key-value caching, and resource preloading.

[0003] In continuous reasoning tasks, the task phase, context, response time, and inference resource status change as the task is executed, and the operating conditions upon which each processing mechanism relies also change accordingly. However, existing inference systems typically configure each processing mechanism independently, lacking the transmission of inference status and processing results between them, making it difficult to make correlated adjustments based on the current inference task's execution status. Summary of the Invention

[0004] To address the mismatch between existing large-scale model inference methods and the operational status of inference tasks, this application provides a method, apparatus, device, and medium for optimizing large-scale model hybrid inference.

[0005] The above-mentioned objective of this application is achieved through the following technical solution:

[0006] A large-scale model hybrid inference optimization method, the method comprising:

[0007] Obtain the current inference request and determine the task stage, context features, and latency constraints corresponding to the current inference request;

[0008] Based on the task stage and the current inference resource status, determine the quantitative configuration of the large model;

[0009] Based on the context features and the running configuration of the large model, a key-value cache that matches the current inference request is searched in the preset cache space to obtain the cache lookup result;

[0010] Based on the quantization configuration, the cache lookup result, and the latency constraint, the batch processing wait time of the current inference request is determined, and the current inference request is combined with other inference requests that arrive within the batch processing wait time and match the running configuration of the large model to form an inference batch.

[0011] The large model is run according to the quantization configuration, and when a matching key-value cache is found in the cache lookup result representation, the matching key-value cache is used to perform inference processing on the inference batch to obtain the current inference result;

[0012] Based on the task stage and the current inference result, predict the next task stage, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request for the next task stage.

[0013] By adopting the above technical solutions, model quantization configuration, key-value cache reuse method, batch processing wait time, and inference resource preloading order can be collaboratively determined based on task stage, context characteristics, latency constraints, and inference resource status, ensuring that different inference stages match corresponding computational precision and resource configurations. By reusing key-value caches corresponding to continuously matching contexts, redundant computations are reduced, and the batching process is dynamically controlled based on quantization configuration and cache hit status. By predicting the next task stage and preloading associated resources, resource loading time during task stage switching is shortened, thereby reducing inference latency and resource consumption, improving the stability of concurrent inference processes, and increasing the utilization rate of computational and storage resources.

[0014] Preferably, the step of obtaining the current inference request and determining the task stage, context features, and latency constraints corresponding to the current inference request includes:

[0015] Parse the current inference request to obtain the task identifier, task execution status, context data, and response time limit parameters;

[0016] Obtain the corresponding task stage mapping relationship based on the task identifier, and determine the task stage in the task stage mapping relationship based on the task execution status;

[0017] Feature extraction is performed on the context data to obtain the context length and context prefix identifier, and the context length and context prefix identifier are determined as the context features;

[0018] The latest response time for the current inference request is determined based on the response time limit parameter, and the latency constraint is determined based on the latest response time.

[0019] By employing the above technical solutions, task status, context information, and response time limits can be accurately extracted from inference requests, and the current task stage can be determined by combining the task stage mapping relationship. Characterizing context content through context length and context prefix identifiers improves the consistency and accuracy of context recognition. Determining latency constraints based on response time limits provides clear time boundaries for subsequent inference configuration and request scheduling.

[0020] Preferably, determining the quantization configuration of the large model based on the task stage and the current inference resource status includes:

[0021] Based on the task stage, query the preset correspondence between the task stage and the model layer sensitivity, and determine the sensitive model layer in the large model corresponding to the task stage and the accuracy loss threshold.

[0022] The available computing resources and available storage resources are determined based on the current inference resource status, and resource constraints are determined based on the available computing resources and available storage resources.

[0023] Multiple candidate quantization configurations are generated, and each candidate quantization configuration sets a first quantization bit width and a second quantization bit width for the sensitive model layer and other model layers other than the sensitive model layer, wherein the first quantization bit width is greater than the second quantization bit width.

[0024] Determine the prediction accuracy loss and prediction resource consumption corresponding to each candidate quantization configuration, and select candidate quantization configurations from the plurality of candidate quantization configurations in which the prediction accuracy loss is not greater than the accuracy loss threshold and the prediction resource consumption satisfies the resource constraint;

[0025] The quantization configuration of the large model is determined based on the prediction inference latency corresponding to the selected candidate quantization configurations.

[0026] By adopting the above technical solution, sensitive model layers can be identified in conjunction with task phases, and different quantization bit widths can be configured for sensitive and non-sensitive model layers to match the quantization accuracy with the task phase. Through joint screening of accuracy loss, resource consumption, and inference latency, the quantization configuration can be determined under the condition of meeting accuracy requirements and resource constraints, reducing the computational load and storage consumption generated by model operation, and shortening the inference processing time.

[0027] Preferably, the step of searching for a key-value cache matching the current inference request in a preset cache space based on the context features and the running configuration of the large model, and obtaining the cache search result, includes:

[0028] Based on the context length, the context data is segmented according to a preset segment length to obtain multiple context segments, and multiple context segment identifiers arranged in context order are generated based on the context prefix identifier and each context segment;

[0029] Obtain the model identifier, model version, and key-value cache precision from the running configuration of the large model, and generate a configuration identifier based on the model identifier, model version, and key-value cache precision;

[0030] Based on the configuration identifier, a corresponding prefix index tree is determined in the preset cache space, and the nodes of the prefix index tree record the context segment identifier and the key-value cache block;

[0031] The prefix index tree is traversed sequentially according to the arrangement order of the multiple context segment identifiers until the current context segment identifier does not match the corresponding node or the multiple context segment identifiers have been traversed, thus obtaining a matching node path composed of consecutively matched nodes.

[0032] Obtain the number of nodes contained in the matching node path, and combine the key-value cache blocks recorded by each node in the matching node path into a candidate key-value cache, and determine the amount of data in the candidate key-value cache;

[0033] When the number of nodes reaches a preset threshold and the amount of data is not greater than a preset data amount threshold, the candidate key-value cache is determined as the key-value cache that matches the current inference request, and a cache lookup result representing that the matching key-value cache has been found is generated.

[0034] By adopting the above technical solution, key-value caches can be segmented and continuously matched according to context order, enabling the reuse of cache blocks combined with some identical contexts. Limiting the cache lookup range by model identifier, model version, and key-value cache precision ensures that cached data matches the configuration of large model operations. Combining the number of matching nodes and the amount of cached data for cache determination reduces resource consumption caused by loading invalid caches and redundant context calculations, and shortens inference processing time.

[0035] Preferably, determining the batch processing wait time for the current inference request based on the quantization configuration, the cache lookup result, and the latency constraint includes:

[0036] The context length to be calculated is determined based on the cache lookup result and the context length.

[0037] Based on the quantization configuration and the length of the context to be calculated, determine the resource consumption of a single request and the request processing time;

[0038] The allowed batch quantity is determined based on the available storage resources and the single request resource consumption.

[0039] Obtain the number of pending requests and the request arrival frequency that match the running configuration of the large model, and determine the batch formation time based on the allowed batch size, the number of pending requests, and the request arrival frequency;

[0040] The waiting time is determined based on the latency constraint and the request processing time.

[0041] When the batch formation time is not greater than the waiting time, the batch formation time is determined as the batch processing waiting time; when the batch formation time is greater than the waiting time, the waiting time is determined as the batch processing waiting time.

[0042] By adopting the above technical solution, the actual computational load can be determined by combining cache hit data and quantization configuration, and the batch size and batch processing wait time can be dynamically determined based on storage resources, request arrival frequency, and response time limits. This allows the batch processing scale to match the current resource status and request load, improving batch resource utilization while meeting response time limits and reducing inference resource waste caused by idle computing units and request waiting.

[0043] Preferably, predicting the next task stage based on the task stage and the current inference result includes:

[0044] The current reasoning result is subjected to state recognition and semantic feature extraction to obtain the result state identifier and the result semantic feature, and a result feature vector is generated based on the result state identifier and the result semantic feature;

[0045] Based on the task stage, determine the current stage node in the preset task stage transition diagram, and obtain multiple candidate stage nodes connected to the current stage node and the stage transition parameters corresponding to each candidate stage node.

[0046] Based on the result feature vector and each of the stage transition parameters, the stage transition probability corresponding to each of the candidate stage nodes is determined respectively;

[0047] The candidate stage nodes are sorted in descending order according to the stage transition probability, and the task stage corresponding to the first candidate stage node is determined as the next task stage.

[0048] By adopting the above technical solution, the direction of task stage transition can be determined by combining the state and semantic information of the current inference results. Furthermore, the probability of multiple candidate stages can be calculated and ranked using a task stage transition graph, improving the accuracy of predicting the next task stage. Dynamically determining stage transition relationships based on inference results enhances the stage connection capability of continuous inference tasks and provides a reliable basis for subsequent inference resource allocation.

[0049] Preferably, determining the inference resources corresponding to the next task stage and preloading the inference resources before receiving the inference request for the next task stage includes:

[0050] Based on the next task stage, query the pre-defined correspondence between the task stage and the inference resources to obtain multiple resource identifiers and the loading dependencies between the multiple resource identifiers;

[0051] Based on the multiple resource identifiers, query the resource residency status to determine the non-residency resources and the amount of resource data corresponding to each non-residency resource;

[0052] The non-resident resources are sorted according to the loading dependencies to generate a resource preloading queue;

[0053] Based on the available storage resources and the amount of resource data corresponding to each of the non-resident resources, the inference resources to be preloaded are determined from the resource preloading queue;

[0054] According to the resource preloading queue, the inference resources to be preloaded are loaded before the inference request for the next task stage is received.

[0055] By adopting the above technical solution, the associated inference resources can be determined in advance according to the next task stage, and a preloading order can be generated by combining the resource residency status, loading dependencies, and available storage resources, avoiding the repeated loading of already resided resources. Preloading resources to be preloaded according to the dependency order can shorten the resource preparation time when switching task stages, reduce the cold start latency of inference requests, and improve the orderliness of storage resource allocation and inference resource loading.

[0056] The second objective of this invention is achieved through the following technical solution:

[0057] A large-scale model hybrid inference optimization device, the large-scale model hybrid inference optimization device comprising:

[0058] The request parsing module is used to obtain the current inference request and determine the task stage, context features and latency constraints corresponding to the current inference request.

[0059] The quantization configuration module is used to determine the quantization configuration of the large model based on the task stage and the current inference resource status.

[0060] The cache lookup module is used to search for a key-value cache that matches the current inference request in a preset cache space based on the context features and the running configuration of the large model, and obtain the cache lookup result;

[0061] The dynamic batch processing module is used to determine the batch processing waiting time of the current inference request based on the quantization configuration, the cache lookup result and the latency constraint, and to form an inference batch with the current inference request and other inference requests that arrive within the batch processing waiting time and match the running configuration of the large model.

[0062] The inference processing module is used to run the large model according to the quantization configuration, and when a matching key-value cache is found in the cache lookup result representation, the matching key-value cache is used to perform inference processing on the inference batch to obtain the current inference result;

[0063] The stage prediction and resource preloading module is used to predict the next task stage based on the task stage and the current inference result, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request of the next task stage.

[0064] By adopting the above technical solution, each module can collaboratively perform model quantization, cache lookup, request batching, inference processing, and resource preloading based on task stage, context characteristics, latency constraints, and inference resource status. This allows the model runtime configuration to match the current inference task, reducing resource consumption caused by repetitive context computation and invalid resource loading, shortening batch processing waiting time and loading time during task stage switching, and improving the utilization rate of computing and storage resources during concurrent inference of large models.

[0065] The above-mentioned objective three of this application is achieved through the following technical solution:

[0066] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the aforementioned large model hybrid inference optimization method.

[0067] The fourth objective of this application is achieved through the following technical solution:

[0068] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the aforementioned large-model hybrid inference optimization method.

[0069] In summary, this application includes at least one of the following beneficial technical effects:

[0070] 1. Based on task stage, context features, latency constraints, and inference resource status, it can collaboratively determine model quantization configuration, key-value cache reuse method, batch processing wait time, and inference resource preloading order, ensuring that different inference stages match corresponding computational precision and resource configurations. By reusing key-value caches corresponding to continuously matching contexts, it reduces redundant computations and dynamically controls the batching process based on quantization configuration and cache hit status. By predicting the next task stage and preloading associated resources, it shortens resource loading time during task stage switching, thereby reducing inference latency and resource consumption, improving the stability of concurrent inference processes, and increasing the utilization rate of computational and storage resources.

[0071] 2. Each module can collaboratively perform model quantization, cache lookup, request batching, inference processing, and resource preloading based on task stage, context characteristics, latency constraints, and inference resource status. This allows the model runtime configuration to match the current inference task, reducing resource consumption caused by repetitive context computation and invalid resource loading, shortening batch processing waiting time and loading time during task stage switching, and improving the utilization of computing and storage resources during concurrent inference of large models. Attached Figure Description

[0072] Figure 1 This is a flowchart of a large-model hybrid inference optimization method in one embodiment of this application.

[0073] Figure 2 This is a block diagram of a large-scale model hybrid inference optimization device according to an embodiment of this application. Detailed Implementation

[0074] The present application will be further described in detail below with reference to the accompanying drawings.

[0075] In one embodiment, such as Figure 1 As shown, this application discloses a large-scale model hybrid inference optimization method, which specifically includes the following steps:

[0076] S10: Obtain the current inference request and determine the task stage, context features, and latency constraints corresponding to the current inference request.

[0077] In this embodiment, the current inference request is the data processing request currently received by the inference system, the task stage is the processing node corresponding to the current inference request in the preset task flow, the context features include the context length and the context prefix identifier, and the latency constraint is the remaining response time corresponding to the current inference request.

[0078] Specifically, the request header and request body of the current inference request are parsed to obtain the task identifier, task execution status, context data, and response timeout parameters. The task stage mapping relationship is queried based on the task identifier. This mapping relationship records the correspondence between task execution status and processing nodes. The task execution status is matched with the status identifiers in the task stage mapping relationship, and the processing node corresponding to the matched status identifier is determined as the task stage.

[0079] The context data is segmented to obtain a sequence of lexical units arranged in context order. The number of lexical units contained in the sequence is counted and determined as the context length. The sequence of lexical units is segmented according to the preset number of lexical units. The hash value of each segment is calculated in turn. The hash values ​​are combined in the order of segmentation to obtain the context prefix identifier. The context length and the context prefix identifier are determined as the context features.

[0080] Read the request initiation time and allowed response duration from the response time limit parameter. Determine the response deadline by summing the request initiation time and allowed response duration. Calculate the time difference between the response deadline and the current system time. If the time difference is greater than zero, determine the time difference as the remaining response duration. If the time difference is not greater than zero, determine the remaining response duration as zero. The remaining response duration is then determined as the latency constraint.

[0081] S20: Determine the quantitative configuration of the large model based on the task stage and the current inference resource status.

[0082] In this embodiment, the current inference resource status is the computing resource status and storage resource status in the large model running environment, and the quantization configuration is the combination of quantization bit widths corresponding to different model layers in the large model.

[0083] Specifically, based on the task stage query, the correspondence between the task stage and the model layer sensitivity is queried, the sensitivity threshold and the accuracy loss threshold are read, the model layer sensitivity corresponding to each model layer is compared with the sensitivity threshold, and the model layer that reaches the sensitivity threshold is determined as the sensitive model layer.

[0084] Read the total computing resources, computing resource utilization rate, total storage resources, and storage resource utilization. Calculate the available computing resources based on the total computing resources and computing resource utilization rate. Calculate the available storage resources based on the difference between the total storage resources and storage resource utilization. Determine resource constraints based on the available computing resources and available storage resources.

[0085] Multiple candidate quantization configurations are generated. Each candidate quantization configuration sets a first quantization bit width for sensitive model layers and a second quantization bit width for insensitive model layers, with the first quantization bit width being greater than the second quantization bit width. The prediction accuracy loss is determined by the sum of the accuracy loss values ​​of each model layer at the corresponding quantization bit width, and the prediction resource consumption is determined by the sum of the products of the number of parameters of each model layer and the corresponding quantization bit width.

[0086] Candidate quantization configurations with prediction accuracy loss not exceeding the accuracy loss threshold and prediction resource consumption meeting resource constraints are selected. The computational complexity of each model layer in the selected candidate quantization configurations is calculated as the product of the computational coefficients of the corresponding quantization bit width. The products are summed, and the prediction inference latency is calculated based on the summation result and the available computing resources. The selected candidate quantization configurations are sorted in ascending order according to the prediction inference latency, and the candidate quantization configuration ranked first is determined as the quantization configuration of the large model.

[0087] S30: Based on contextual features and the running configuration of the large model, search for a key-value cache that matches the current inference request in the preset cache space to obtain the cache lookup result.

[0088] In this embodiment, the preset cache space is a storage area that establishes a prefix index tree according to the configuration identifier, the key-value cache is the key tensor data and value tensor data generated by the attention layer of the large model, and the cache lookup result is data that records the key-value cache lookup status.

[0089] Specifically, the number of segments is determined based on the context length and the preset segment length. The context data is segmented according to the number of segments. The hash value corresponding to each segment is read sequentially from the context prefix identifier. Each hash value is combined with the corresponding segment number to obtain multiple context segment identifiers arranged in context order.

[0090] Read the model identifier, model version, and key-value cache precision from the large model's runtime configuration. Combine and encode the model identifier, model version, and key-value cache precision to obtain the configuration identifier. Determine the corresponding prefix index tree in the preset cache space based on the configuration identifier.

[0091] The prefix index tree is traversed layer by layer according to the order of multiple context segment identifiers. When the context segment identifier is the same as the node identifier recorded in the current node, the next level node is entered. When the context segment identifier is different from the node identifier, the traversal stops and the matching node path is obtained.

[0092] The system counts the number of nodes contained in the matching node path, combines the key-value cache blocks recorded by each node according to the node order to obtain candidate key-value caches, and calculates the data volume of the candidate key-value caches. When the number of nodes reaches a preset threshold and the data volume does not exceed a preset data volume threshold, the candidate key-value cache is determined as a matching key-value cache, and a cache lookup result indicating that a matching key-value cache has been found is generated. When the number of nodes does not reach the preset threshold or the data volume exceeds the preset data volume threshold, a cache lookup result indicating that no matching key-value cache has been found is generated.

[0093] S40: Based on the quantization configuration, cache lookup results, and latency constraints, determine the batch processing wait time for the current inference request, and group the current inference request into an inference batch along with other inference requests that arrive within the batch processing wait time and match the running configuration of the large model.

[0094] In this embodiment, the batch processing waiting time is the time it takes for the current inference request to be merged into a batch after entering the batch processing queue, other inference requests are inference requests received within the batch processing waiting time, and an inference batch is a set of requests consisting of multiple inference requests with the same running configuration.

[0095] Specifically, when the cache lookup result indicates that a matching key-value cache has been found, the context length corresponding to the matching key-value cache is counted to obtain the cached context length, and the difference between the context length and the cached context length is calculated to obtain the context length to be calculated. When the cache lookup result indicates that no matching key-value cache has been found, the context length is determined as the context length to be calculated.

[0096] Read the unit resource coefficient and unit processing time corresponding to the quantization configuration. Multiply the unit resource coefficient by the length of the context to be calculated to determine the resource consumption per request, and multiply the unit processing time by the length of the context to be calculated to determine the request processing time. Calculate the ratio between available storage resources and single request resource consumption, and round down to obtain the allowed batch size.

[0097] The system counts the number of pending requests in the batch processing queue that match the running configuration of the large model, calculates the ratio between the number of matching inference requests received within a preset statistical period and the preset statistical period itself to obtain the request arrival frequency, and calculates the batch formation duration based on the difference between the allowed batch size and the number of pending requests, as well as the request arrival frequency. Finally, it determines the waiting time based on the difference between the latency constraint and the request processing time.

[0098] When the batch formation time is no greater than the available waiting time, the batch formation time is determined as the batch processing waiting time. When the batch formation time is greater than the available waiting time, the available waiting time is determined as the batch processing waiting time. Timing begins when the current inference request enters the batch processing queue. Inference requests arriving during the timing period with the same configuration identifier are added to the batch processing queue. When the timing period reaches the batch processing waiting time or the number of pending requests reaches the allowed batching limit, the current inference request and the inference requests in the batch processing queue are combined into an inference batch.

[0099] S50: Run the large model according to the quantization configuration, and when a matching key-value cache is found in the cache lookup result representation, use the matching key-value cache to perform inference processing on the inference batch to obtain the current inference result.

[0100] In this embodiment, the current inference result is the output word sequence generated by the large model in response to the current inference request.

[0101] Specifically, the quantization bit width corresponding to each model layer in the quantization configuration is read, an execution mapping relationship between the model layer identifier and the quantization bit width is established, the quantization parameters corresponding to each model layer are loaded according to the execution mapping relationship, and the calculation unit corresponding to the quantization bit width is initialized according to the connection order of each model layer in the large model.

[0102] When a matching key-value cache is found in the cache lookup result representation, the key-value cache blocks contained in the matching key-value cache are arranged according to the model layer identifier, a cache mapping relationship is established between each model layer and the corresponding key-value cache block, the lexical position offset of the current inference request is determined according to the length of the cached context, and a batch attention index is established according to the cache mapping relationship and the lexical position offset.

[0103] Based on the batch attention index, read the key-value cache block corresponding to each model layer, perform key tensor and value tensor calculations on the tokens in the current inference request that are located after the length of the cached context, and obtain the new key tensor and the new value tensor. Append the new key tensor and the new value tensor to the corresponding key-value cache block to obtain the updated key-value cache corresponding to each model layer.

[0104] Each model layer is run sequentially according to the execution mapping relationship, and attention is calculated by reading each updated key-value cache according to the batch attention index to obtain the output word sequence corresponding to each inference request in the inference batch. The output word sequence corresponding to the current inference request is determined as the current inference result.

[0105] S60: Predict the next task stage based on the task stage and the current inference result, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request for the next task stage.

[0106] In this embodiment, the next task stage is the processing node after the current task stage, the inference resources are the model parameters, adaptation parameters and cached data corresponding to the next task stage, and preloading is the process of writing the inference resources into the runtime storage area before the inference request arrives.

[0107] Specifically, state words and text word sequences are extracted from the current inference result. The state words are matched with preset state codes to obtain the result state identifier. The text word sequence is semantically encoded to obtain the result semantic features. The state vector corresponding to the result state identifier is concatenated with the result semantic features to obtain the result feature vector.

[0108] Based on the task phase, the current phase node is determined in the preset task phase transition graph. Candidate phase nodes connected to the current phase node and their corresponding phase transition parameters are read. These parameters include a state condition identifier, a transition weight vector, and a basic transition value. The resulting state identifier is matched with each state condition identifier. The phase transition values ​​for unmatched candidate phase nodes are set to zero. The dot product of the resulting feature vector and each transition weight vector is calculated. This dot product is then added to the corresponding basic transition value to obtain the phase transition value for the matched candidate phase node.

[0109] The transition values ​​of each stage are normalized to obtain the corresponding stage transition probabilities. The candidate stage nodes are then sorted in descending order according to the stage transition probabilities, and the task stage corresponding to the first candidate stage node is determined as the next task stage.

[0110] Based on the next task stage, query the correspondence between the task stage and the inference resources to obtain multiple resource identifiers and the loading dependencies between multiple resource identifiers. Based on multiple resource identifiers, query the resource residency status, determine the resources that have not been written to the runtime storage area as non-resident resources, and read the resource data volume corresponding to each non-resident resource.

[0111] Non-resident resources are sorted according to loading dependencies to generate a resource preloading queue. The resource data volume corresponding to each non-resident resource is accumulated in the order of arrangement. Non-resident resources whose accumulated value is not greater than the available storage resource volume are identified as inference resources. Before receiving the inference request of the next task stage, the inference resources are written to the runtime storage area according to the resource preloading queue.

[0112] In one embodiment, step S10, namely obtaining the current inference request and determining the task stage, context features, and latency constraints corresponding to the current inference request, includes:

[0113] S101: Parse the current inference request to obtain the task identifier, task execution status, context data, and response time limit parameters.

[0114] In this embodiment, the task identifier is a combination of task type code and task instance code, the task execution status is a status code composed of processing node code and completion status code, the context data is multiple context fragments arranged in the input order, and the response time limit parameter is time limit data composed of request initiation time and allowed response duration.

[0115] Specifically, the request header of the current inference request is read, and the task field, status field, context field, and time limit field are extracted from the current inference request based on the field offset and field length recorded in the request header.

[0116] Extract the task type code and task instance code from the task field, and concatenate the task type code and task instance code according to the preset coding order to obtain the task identifier. Extract the processing node code and completion status code from the status field, and combine the processing node code and completion status code according to the preset status format to obtain the task execution status.

[0117] Extract multiple context fragments and their corresponding sequence codes from the context field, arrange the multiple context fragments according to the sequence codes to obtain context data, extract the request initiation time and allowed response duration from the time limit field, combine the request initiation time and allowed response duration according to the preset time limit format to obtain the response time limit parameter.

[0118] S102: Obtain the corresponding task stage mapping relationship based on the task identifier, and determine the task stage in the task stage mapping relationship based on the task execution status.

[0119] In this embodiment, the task stage mapping relationship is a data set that records the correspondence between task type code, preceding stage code, state index and stage code.

[0120] Specifically, the task type code and task instance code are read from the task identifier. The preset mapping relationship set is queried according to the task type code to obtain the task stage mapping relationship. The task stage record is queried according to the task instance code. The preceding stage code is read. If no task stage record is found, the starting stage code is read from the task stage mapping relationship and the starting stage code is determined as the preceding stage code.

[0121] Read the processing node code and completion status code from the task execution status, and combine the processing node code and completion status code according to the preset coding order to obtain the status index.

[0122] In the task phase mapping relationship, find the mapping record that matches both the previous phase code and the state index, read the phase code in the mapping record, and determine the processing node corresponding to the phase code as the task phase.

[0123] S103: Extract features from the context data to obtain the context length and context prefix identifier, and determine the context length and context prefix identifier as context features.

[0124] In this embodiment, the context length is the number of tokens corresponding to the context data, and the context prefix identifier is identifier data composed of multiple prefix hash values ​​arranged in context order.

[0125] Specifically, the context data is unified in character encoding and filtered with control characters to obtain standard context data. The standard context data is then converted into lexical units according to a preset lexical encoding table to obtain a lexical sequence arranged in context order. The number of lexical units contained in the lexical sequence is counted to obtain the context length.

[0126] The lexical sequence is sequentially segmented according to a preset number of lexical units to obtain multiple context segments, and a segment number is assigned to each context segment. The lexical codes and corresponding segment numbers of the first context segment are hashed to obtain a prefix hash value. Then, according to the segment number, a combined hash calculation is performed on the prefix hash value of the previous context segment, the lexical codes of the current context segment, and the segment number of the current context segment to obtain the prefix hash value of the current context segment.

[0127] Arrange the prefix hash values ​​according to the segment number to obtain the context prefix identifier, and determine the context length and context prefix identifier as context features.

[0128] S104: Determine the latest response time for the current inference request based on the response time limit parameter, and determine the latency constraint based on the latest response time.

[0129] In this embodiment, the response deadline is the time point corresponding to the completion of the current inference request response.

[0130] Specifically, the request initiation time and allowed response duration are read from the response time limit parameter, the request initiation time and allowed response duration are converted into a uniform time unit, and the converted request initiation time is added to the allowed response duration to obtain the response deadline.

[0131] Obtain the current system time, calculate the time difference between the response deadline and the current system time. If the time difference is greater than zero, determine the time difference as the remaining response duration. If the time difference is not greater than zero, determine the remaining response duration as zero and use the remaining response duration as the delay constraint.

[0132] In one embodiment, step S20, namely determining the quantization configuration of the large model based on the task stage and the current inference resource state, includes:

[0133] S201: Based on the task stage query, determine the correspondence between the preset task stage and the model layer sensitivity, and determine the sensitive model layer in the large model corresponding to the task stage and the accuracy loss threshold.

[0134] In this embodiment, the model layer sensitivity is the distance between the output probability distribution before quantization and the output probability distribution after quantization when a single model layer uses the baseline quantization bit width. The correspondence between the task stage and the model layer sensitivity is a data set of recording stage encoding, model layer identifier, model layer sensitivity, sensitivity ratio threshold and accuracy loss threshold. The sensitive model layer is the model layer whose model layer sensitivity meets the sensitivity ratio threshold.

[0135] Specifically, the stage code corresponding to the task stage is read, and the correspondence between the task stage and the model layer sensitivity is queried based on the stage code to obtain multiple model layer identifiers, the model layer sensitivity corresponding to each model layer identifier, the sensitivity ratio threshold, and the accuracy loss threshold.

[0136] The sensitivity of each model layer is summed to obtain the total sensitivity value. The multiple model layer identifiers are sorted in descending order according to their sensitivity. Starting from the first identifier, the sensitivity of each model layer is accumulated sequentially. The ratio between the accumulated sensitivity value and the total sensitivity value is calculated to obtain the sensitivity accumulation ratio.

[0137] The model layer represented by the model layer identifier corresponding to the first position of the sequence until the cumulative sensitivity ratio first reaches the sensitivity ratio threshold is determined as the sensitive model layer, and the precision loss threshold corresponding to the stage encoding is read.

[0138] S202: Determine the available computing resources and available storage resources based on the current inference resource status, and determine resource constraints based on the available computing resources and available storage resources.

[0139] In this embodiment, the available computing resources are the total computing resources minus the computing resource usage and computing resource fluctuations; the available storage resources are the total storage resources minus the storage resource usage and storage resource fluctuations; and the resource constraint is the upper limit data of the available computing resources and available storage resources.

[0140] Specifically, the total amount of computing resources, the total amount of storage resources, and the amount of computing resources and storage resources occupied at multiple sampling moments within a preset sampling period are read from the current inference resource status.

[0141] Calculate the average value of multiple computing resource occupancy and the average value of multiple storage resource occupancy to obtain the average computing resource occupancy and the average storage resource occupancy. Calculate the absolute value of the difference between computing resource occupancy and the absolute value of the difference between storage resource occupancy at adjacent sampling times, and average the absolute values ​​of each difference to obtain the computing resource fluctuation and the storage resource fluctuation.

[0142] The available computing resources are obtained by subtracting the average computing resource usage and the fluctuation of computing resources from the total computing resources. Similarly, the available storage resources are obtained by subtracting the average storage resource usage and the fluctuation of storage resources from the total storage resources.

[0143] Set the available computing resources as the computing resource limit, set the available storage resources as the storage resource limit, and combine the computing resource limit and the storage resource limit into a resource constraint.

[0144] S203: Generate multiple candidate quantization configurations. Each candidate quantization configuration sets the first quantization bit width and the second quantization bit width for the sensitive model layer and other model layers, respectively. The first quantization bit width is greater than the second quantization bit width.

[0145] In this embodiment, the candidate quantization configuration is candidate mapping data between the model layer identifier and the quantization bit width. The first quantization bit width is the quantization bit width corresponding to the sensitive model layer, and the second quantization bit width is the quantization bit width corresponding to the non-sensitive model layer.

[0146] Specifically, read all model layer identifiers contained in the large model, delete the model layer identifiers corresponding to sensitive model layers from all model layer identifiers, and obtain a set of non-sensitive model layer identifiers.

[0147] Read the multiple quantization bit widths supported by the current computing unit and the quantization operator compatibility table. The quantization operator compatibility table records the compatibility status corresponding to different quantization bit width combinations. Combine multiple quantization bit widths in pairs and determine the quantization bit width combination where the previous quantization bit width is greater than the next quantization bit width and the compatibility status is allowed as the candidate bit width combination.

[0148] Each candidate bit width combination is read sequentially. The previous quantization bit width is set as the first quantization bit width, and the next quantization bit width is set as the second quantization bit width. A mapping relationship is established between the model layer identifier corresponding to the sensitive model layer and the first quantization bit width. A mapping relationship is also established between the model layer identifier in the non-sensitive model layer identifier set and the second quantization bit width. The two mapping relationships are combined into a candidate quantization configuration to obtain multiple candidate quantization configurations.

[0149] S204: Determine the prediction accuracy loss and prediction resource consumption corresponding to each candidate quantization configuration, and select candidate quantization configurations from multiple candidate quantization configurations whose prediction accuracy loss is not greater than the accuracy loss threshold and whose prediction resource consumption meets the resource constraints.

[0150] In this embodiment, the prediction accuracy loss is the prediction value composed of the model layer quantization loss and the bit width switching loss of adjacent model layers, and the prediction resource consumption is the resource data composed of the prediction computing resource consumption and the prediction storage resource consumption.

[0151] Specifically, the mapping relationship between model layer identifier and quantization bit width in each candidate quantization configuration is read sequentially. The bit width loss coefficient is queried according to each model layer identifier and the corresponding quantization bit width. The model layer sensitivity corresponding to each model layer identifier is multiplied by the bit width loss coefficient to obtain the model layer quantization loss corresponding to each model layer. Finally, the quantization losses of each model layer are summed.

[0152] The quantization bit widths of adjacent model layers are detected according to the connection order of the model layers. When the quantization bit widths of adjacent model layers are different, the bit width switching loss value is queried according to the two quantization bit widths. The bit width switching loss values ​​are summed and the summation result is added to the summation result of the quantization loss of the model layer to obtain the prediction accuracy loss.

[0153] Read the model parameter quantity and model computation quantity corresponding to each model layer, sum the product of each model parameter quantity and the corresponding quantization bit width to obtain the predicted storage resource consumption, query the operation coefficient corresponding to each quantization bit width, multiply each model computation quantity and the corresponding operation coefficient and sum them to obtain the predicted computing resource consumption, and combine the predicted computing resource consumption and the predicted storage resource consumption to obtain the predicted resource consumption.

[0154] The prediction accuracy loss is compared with the accuracy loss threshold, and the prediction resource consumption is compared with the upper limits of computing resources and storage resources in the resource constraints. Candidate quantization configurations with prediction accuracy loss not greater than the accuracy loss threshold, prediction computing resource consumption not greater than the upper limit of computing resources, and prediction storage resource consumption not greater than the upper limit of storage resources are retained.

[0155] S205: Determine the quantization configuration of the large model based on the prediction inference latency corresponding to the selected candidate quantization configurations.

[0156] In this embodiment, the prediction inference latency is the prediction time corresponding to the sequential execution of each model layer according to the candidate quantization configuration.

[0157] Specifically, the mapping relationship between the model layer identifier and the quantization bit width in each of the selected candidate quantization configurations is read sequentially. The corresponding operation coefficient is queried according to the model operation volume and quantization bit width of each model layer. The model operation volume is multiplied by the operation coefficient, and the ratio between the product and the available computing resources is determined as the model layer processing time of the corresponding model layer. The processing times of each model layer are summed to obtain the model execution time.

[0158] The quantization bit width of adjacent model layers is detected according to the connection order of the model layers. When the quantization bit widths of adjacent model layers are different, the corresponding bit width switching time is queried. The bit width switching times of each bit width are summed to obtain the bit width conversion time.

[0159] The model execution time is added to the bit width conversion time to obtain the prediction and inference latency corresponding to each candidate quantization configuration. The selected candidate quantization configurations are sorted in ascending order according to the prediction and inference latency. When the prediction and inference latency are the same, they are sorted in ascending order according to the prediction accuracy loss. The candidate quantization configuration ranked first is determined as the quantization configuration of the large model.

[0160] In one embodiment, in step S30, based on contextual features and the runtime configuration of the large model, a key-value cache matching the current inference request is searched in a preset cache space to obtain the cache lookup result, including:

[0161] S301: Based on the context length, segment the context data according to the preset segment length to obtain multiple context segments, and generate multiple context segment identifiers arranged in context order based on the context prefix identifier and each context segment.

[0162] In this embodiment, the preset segment length is the number of tokens corresponding to a single context segment, the context segment is a sequence of tokens continuously extracted from the context data, and the context segment identifier is identifier data composed of prefix hash value, segment number, number of tokens in the segment, and segment boundary code.

[0163] Specifically, calculate the integer quotient and remainder between the context length and the preset segment length. When the remainder is zero, the integer quotient is determined as the number of segments. When the remainder is not zero, the integer quotient is incremented by one to obtain the number of segments.

[0164] According to the preset segment length, words are extracted sequentially from the starting position of the word sequence corresponding to the context data to obtain multiple context segments corresponding to the number of segments, and segment numbers are set for each context segment according to the extraction order.

[0165] Read the prefix hash value corresponding to each context segment from the context prefix identifier, count the number of tokens contained in each context segment, and read the token codes corresponding to the start and end positions of each context segment. Combine the two token codes into segment boundary codes.

[0166] Based on the segment number, the corresponding prefix hash value, segment number, number of segment tokens, and segment boundary code are combined to obtain the context segment identifier for each context segment. The context segment identifiers are then arranged according to the segment number.

[0167] S302: Obtain the model identifier, model version, and key-value cache precision from the runtime configuration of the large model, and generate a configuration identifier based on the model identifier, model version, and key-value cache precision.

[0168] In this embodiment, the model identifier is coded data representing the structure and parameter set of the large model, the model version is version data representing the batch of parameter updates of the large model, the key-value cache precision is the numerical format and storage bit width corresponding to the key tensor data and the value tensor data, and the configuration identifier is coded data composed of the model identifier, the model version, and the key-value cache precision.

[0169] Specifically, the model encoding field, version field, and cache precision field are read from the runtime configuration of the large model. The model encoding field is encoded with a fixed length to obtain the model identifier. The main version code, sub-version code, and revision code are extracted from the version field and arranged according to the version hierarchy to obtain the model version.

[0170] Extract the key tensor value format, key tensor storage width, value tensor value format, and value tensor storage width from the cache precision field, and arrange them in the order of key tensor data first and value tensor data last to obtain the key-value cache precision.

[0171] According to the order of model identifier, model version, and key-value cache precision, write the corresponding data length and data content respectively to obtain the configuration encoding sequence. Perform hash calculation on the configuration encoding sequence to obtain the configuration verification code. Combine the configuration encoding sequence and the configuration verification code to obtain the configuration identifier.

[0172] S303: Based on the configuration identifier, determine the corresponding prefix index tree in the preset cache space. The nodes of the prefix index tree record the context segment identifier and the key-value cache block.

[0173] In this embodiment, the prefix index tree is a tree-shaped data structure that establishes the parent-child node connection relationship according to the context segment order, and the key-value cache block is the key tensor data block and value tensor data block corresponding to a single context segment.

[0174] Specifically, the configuration verification code is read from the configuration identifier, the location code is extracted from the configuration verification code according to the preset truncation length, the location code is converted into a cache partition number, and the corresponding cache partition is determined in the preset cache space according to the cache partition number.

[0175] Read the configuration directory in the cache partition, match the configuration identifier with the configuration directory entries in the configuration directory in turn, and when a matching configuration directory entry exists, read the root node address from the matching configuration directory entry and determine the prefix index tree based on the root node address.

[0176] If no matching configuration directory entry exists, a root node is created in the cache partition, the configuration identifier and the root node address corresponding to the root node are written into the new configuration directory entry, and a prefix index tree is created based on the new configuration directory entry.

[0177] The root node of the prefix index tree records the configuration identifier, while nodes other than the root node record the context segment identifier, key-value cache block, and parent node address. Nodes with continuous context order establish parent-child node connection relationships through the parent node address.

[0178] S304: Traverse the prefix index tree sequentially according to the order of multiple context segment identifiers until the current context segment identifier does not match the corresponding node or multiple context segment identifiers have been traversed, and obtain the matching node path composed of consecutively matched nodes.

[0179] In this embodiment, the matching node path is an ordered data consisting of multiple node addresses matched consecutively in context order, starting from the root node of the prefix index tree.

[0180] Specifically, the root node address of the prefix index tree is set to the current node address, the first context segment identifier is set to the current context segment identifier, and an empty node address sequence is created.

[0181] Based on the current node address, query the nodes whose parent node address is the same as the current node address to obtain candidate nodes. Then, read the prefix hash value, segment number, segment token count, and segment boundary code from the current context segment identifier and the context segment identifier of each candidate node, and compare them according to the corresponding fields.

[0182] When all fields are the same, the corresponding candidate node is determined as the matching node, the node address of the matching node is written into the node address sequence, the node address of the matching node is updated to the current node address, and the next context segment identifier is read in the order of arrangement as the current context segment identifier.

[0183] The traversal stops when any field is different and no corresponding matching node exists. The traversal ends when multiple context segment identifiers have been compared. The nodes recorded in the node address sequence are determined as continuously matching nodes, and the node address sequence is determined as the matching node path.

[0184] S305: Obtain the number of nodes contained in the matching node path, and combine the key-value cache blocks recorded by each node in the matching node path into a candidate key-value cache, and determine the amount of data in the candidate key-value cache.

[0185] In this embodiment, the number of nodes is the number of node addresses that match the node path record, the candidate key-value cache is the cache data obtained by combining multiple key-value cache blocks according to the context order, and the data volume is the number of storage bytes corresponding to the key tensor data and value tensor data contained in the candidate key-value cache.

[0186] Specifically, the node addresses in the matching node path are counted to obtain the number of nodes. According to the order of the node addresses in the matching node path, the key-value cache blocks of each node are read in sequence, and the model layer identifier, key tensor data and value tensor data are extracted from each key-value cache block.

[0187] The key tensor data and value tensor data are grouped according to the model layer identifier. Within each group corresponding to the model layer identifier, the key tensor data and value tensor data are concatenated along the lexical dimension according to the order of node addresses to obtain the combined key tensor and combined value tensor corresponding to each model layer. The combined key tensor and combined value tensor corresponding to each model layer are combined into a candidate key-value cache.

[0188] The number of tensor elements contained in each key-value tensor and each value-value tensor is counted separately. The number of tensor elements is multiplied by the corresponding storage width and converted into the number of storage bytes. The number of storage bytes is summed to obtain the amount of data in the candidate key-value cache.

[0189] S306: When the number of nodes reaches a preset threshold and the amount of data is not greater than a preset data amount threshold, the candidate key-value cache is determined as the key-value cache that matches the current inference request, and a cache lookup result representing the found matching key-value cache is generated.

[0190] In this embodiment, the preset quantity threshold is the lower limit of the number of nodes participating in cache matching, the preset data volume threshold is the upper limit of the cache data volume participating in cache matching, and the matching key-value cache is the candidate key-value cache that simultaneously meets the preset quantity threshold and the preset data volume threshold.

[0191] Specifically, the stage code is read from the task stage, and the key-value cache precision is read from the configuration identifier. Based on the stage code and key-value cache precision, the preset cache threshold table is queried to obtain the preset quantity threshold and the preset data volume threshold.

[0192] The number of nodes is compared with a preset threshold to generate a quantity comparison result, and the data volume is compared with a preset data volume threshold to generate a data volume comparison result. When the quantity comparison result indicates that the number of nodes reaches the preset threshold, and the data volume comparison result indicates that the data volume is not greater than the preset data volume threshold, the candidate key-value cache is determined as the matching key-value cache.

[0193] Read the number of segmented tokens corresponding to each node in the matching node path, sum the number of segmented tokens to obtain the cached context length, combine the configuration identifier with the node address sequence in the matching node path to obtain the cache identifier, combine the search status code, cache identifier, cached context length and data volume to generate a cache search result that represents the found matching key-value cache.

[0194] In one embodiment, step S40, namely determining the batch processing wait time for the current inference request based on the quantization configuration, cache lookup results, and latency constraints, includes:

[0195] S401: Determine the context length to be calculated based on the cache lookup result and the context length.

[0196] In this embodiment, the length of the context to be calculated is the number of terms in the current inference request that are not included in the matching key-value cache.

[0197] Specifically, the lookup status code is read from the cache lookup results. When the lookup status code indicates that a matching key-value cache has been found, the cached context length is read from the cache lookup results and compared with the context length.

[0198] When the length of the cached context is not greater than the length of the context, calculate the difference between the length of the context and the length of the cached context, and determine the difference as the length of the context to be calculated. When the length of the cached context is greater than the length of the context, determine the length of the context to be calculated.

[0199] When no matching key-value cache is found in the search state encoding representation, the context length is determined as the context length to be calculated.

[0200] S402: Determine the resource consumption and request processing time for a single request based on the quantization configuration and the length of the context to be calculated.

[0201] In this embodiment, the single request resource consumption is the amount of storage resources used when processing the metadata corresponding to the context length to be calculated, and the request processing time is the prediction time required to process the metadata corresponding to the context length to be calculated according to the quantization configuration.

[0202] Specifically, the quantization bit width corresponding to each model layer is read from the quantization configuration, and the number of intermediate data elements and model computation amount generated when each model layer processes a single word are read.

[0203] Multiply the number of intermediate data elements corresponding to each model layer by the corresponding quantization bit width, and convert the product into the number of storage bytes. Sum the number of storage bytes corresponding to each model layer to obtain the word meta-resource usage. Multiply the word meta-resource usage by the length of the context to be computed to obtain the single request resource usage.

[0204] Based on the quantization bit width of each model layer, query the corresponding operation coefficients, multiply the model operation volume of each model layer by the corresponding operation coefficients, and sum the products to obtain the word meta-operation volume. Multiply the word meta-operation volume by the length of the context to be computed to obtain the request operation volume. Calculate the ratio between the request operation volume and the available computing resources to obtain the request processing time.

[0205] S403: Determine the allowed batch size based on the available storage resources and the resource consumption per request.

[0206] In this embodiment, the allowed batch size is the number of inference requests that a single inference batch can contain.

[0207] Specifically, the preset resource retention ratio is read, the available storage resources are multiplied by the preset resource retention ratio to obtain the reserved storage resources, and the difference between the available storage resources and the reserved storage resources is calculated to obtain the batch storage resources.

[0208] Calculate the ratio between the total batch storage resource quantity and the single request resource consumption, and round down the ratio to obtain the batch quantity. When the batch quantity is zero, adjust the batch quantity to one.

[0209] Read the preset batch capacity threshold. When the number of resources merged into a batch is not greater than the preset batch capacity threshold, the number of resources merged into a batch is determined as the allowed number of merged batches. When the number of resources merged into a batch is greater than the preset batch capacity threshold, the preset batch capacity threshold is determined as the allowed number of merged batches.

[0210] S404: Obtain the number of pending requests and the request arrival frequency that match the running configuration of the large model, and determine the batch formation time based on the allowed batch size, the number of pending requests, and the request arrival frequency.

[0211] In this embodiment, the number of pending requests is the number of inference requests in the batch processing queue that match the running configuration of the large model, the request arrival frequency is the number of matching inference requests received per unit time, and the batch formation time is the prediction time corresponding to the increase of the number of pending requests to the allowed batch size.

[0212] Specifically, the configuration identifier corresponding to the running configuration of the large model is read, the configuration identifier is compared with the configuration identifier corresponding to each inference request in the batch processing queue, and the inference requests with the same configuration identifier are counted to obtain the number of requests to be processed.

[0213] The preset statistical period is divided into multiple statistical sub-periods. The number of inference requests with the same configuration identifier received in each statistical sub-period is counted. Increasing time weights are set according to the time order of the multiple statistical sub-periods. The product of the number of inference requests and the time weight for each statistical sub-period is calculated and summed to obtain the weighted request number. The product of the duration of each statistical sub-period and the time weight is calculated and summed to obtain the weighted statistical duration. The ratio between the weighted request number and the weighted statistical duration is calculated to obtain the request arrival frequency.

[0214] Calculate the difference between the allowed batch size and the number of pending requests to obtain the number of requests to be supplemented. When the number of requests to be supplemented is not greater than zero, the batch formation time is set to zero. When the number of requests to be supplemented is greater than zero and the request arrival frequency is greater than zero, calculate the ratio between the number of requests to be supplemented and the request arrival frequency to obtain the batch formation time. When the number of requests to be supplemented is greater than zero and the request arrival frequency is zero, the preset formation time threshold is set as the batch formation time.

[0215] S405: Determine the waiting time based on latency constraints and request processing time.

[0216] In this embodiment, the waiting time can be the time obtained after deducting the time reserved for request processing from the delay constraint.

[0217] Specifically, read the processing time fluctuation ratio corresponding to the quantization configuration, multiply the request processing time by the processing time fluctuation ratio to obtain the processing fluctuation time, and add the request processing time to the processing fluctuation time to obtain the request processing reserved time.

[0218] Calculate the difference between the latency constraint and the request processing reserve time. If the difference is greater than zero, the difference is determined as the waiting time; if the difference is not greater than zero, the waiting time is determined as zero.

[0219] S401: When the batch formation time is not greater than the waiting time, the batch formation time is determined as the batch processing waiting time; when the batch formation time is greater than the waiting time, the waiting time is determined as the batch processing waiting time.

[0220] In this embodiment, batch formation time, waiting time, and batch processing waiting time are expressed using the same time unit.

[0221] Specifically, the batch formation time is subtracted from the waiting time to obtain a time comparison value. When the time comparison value is not greater than zero, the batch formation time is written into the batch processing waiting time field to obtain the batch processing waiting time. When the time comparison value is greater than zero, the waiting time is written into the batch processing waiting time field to obtain the batch processing waiting time.

[0222] In one embodiment, step S60, namely predicting the next task stage based on the task stage and the current inference result, includes:

[0223] S601: Perform state recognition and semantic feature extraction on the current inference result to obtain the result state identifier and result semantic features, and generate the result feature vector based on the result state identifier and result semantic features.

[0224] In this embodiment, the result state identifier is encoded data representing the state category corresponding to the current inference result, the result semantic feature is vector data generated based on the text content in the current inference result, and the result feature vector is vector data composed of the state encoding vector corresponding to the result state identifier and the result semantic feature.

[0225] Specifically, the output word sequence is read from the current inference result, and the output word sequence is divided into a state word sequence and a content word sequence according to the preset word type table. The state word sequence is combined according to the word order, and the preset state encoding table is queried according to the combination result to obtain the result state identifier.

[0226] Each content word in the content word sequence is converted into a word feature vector. The corresponding stage semantic center vector is queried according to the task stage. The vector similarity between each word feature vector and the stage semantic center vector is calculated. The vector similarity is normalized to obtain the semantic weight corresponding to each word feature vector. Each word feature vector is multiplied by its corresponding semantic weight and summed to obtain the resulting semantic feature.

[0227] The result state identifier is converted into a state encoding vector according to the preset state vector encoding table, and then concatenated in the order of state encoding vector first and result semantic features last to obtain the result feature vector.

[0228] S602: Based on the task stage, determine the current stage node in the preset task stage transition diagram, and obtain multiple candidate stage nodes connected to the current stage node and the stage transition parameters corresponding to each candidate stage node.

[0229] In this embodiment, the preset task stage transition graph is a graph structure composed of multiple stage nodes and multiple directed edges. The current stage node is the stage node whose stage code matches the task stage, and the candidate stage node is the stage node connected to the current stage node through a directed edge. The stage transition parameters include state condition identifier, transition weight vector, and basic transition value.

[0230] Specifically, the phase code corresponding to the task phase is read, the phase code is hashed to obtain the node index value, the node index table in the preset task phase transition diagram is queried according to the node index value to obtain the candidate node address, the phase node corresponding to each candidate node address is read, and the phase node whose phase code is the same as the phase code corresponding to the task phase is determined as the current phase node.

[0231] Read the set of directed edges corresponding to the current stage node, extract the target node address, state condition identifier, transition weight vector and basic transition value from each directed edge, and read the corresponding stage node according to each target node address to obtain multiple candidate stage nodes.

[0232] The state condition identifier, transition weight vector, and basic transition value in the same directed connection edge are combined into stage transition parameters, and each stage transition parameter is associated with the corresponding candidate stage node according to the target node address.

[0233] S603: Determine the stage transition probability corresponding to each candidate stage node based on the result feature vector and the transition parameters of each stage.

[0234] In this embodiment, the stage transition probability is the normalized value obtained by normalizing the stage transition value corresponding to each candidate stage node.

[0235] Specifically, the stage transition parameters corresponding to each candidate stage node are read sequentially, and the state condition identifier, transition weight vector and basic transition value are extracted from each stage transition parameter. The result state identifier is compared with each state condition identifier. Candidate stage nodes whose state condition identifier is the same as the result state identifier are determined as participating nodes, and the stage transition probability corresponding to the candidate stage nodes that are not determined as participating nodes is set to zero.

[0236] Calculate the dot product between the resulting feature vector and the transition weight vector corresponding to each participating node, and add each dot product to the corresponding basic transition value to obtain the stage transition value corresponding to each participating node.

[0237] Perform exponential calculations on the transition values ​​of each stage to obtain the corresponding transition index values. Sum the transition index values ​​to obtain the total transition index value. Calculate the ratio between each transition index value and the total transition index value to obtain the stage transition probability for each participating node.

[0238] S604: Sort multiple candidate stage nodes in descending order according to the stage transition probability, and determine the task stage corresponding to the first candidate stage node as the next task stage.

[0239] Specifically, the node address of each candidate stage node is associated with the corresponding stage transition probability to obtain multiple node probability data, and the multiple node probability data are sorted in descending order according to the stage transition probability.

[0240] When the stage transition probabilities corresponding to multiple node probability data are the same, the stage codes of the corresponding candidate stage nodes are read and sorted in ascending order according to the stage codes to obtain the candidate stage node sorting sequence.

[0241] Read the first candidate stage node in the candidate stage node sorting sequence, read the stage code from the first candidate stage node, and determine the task stage corresponding to the stage code as the next task stage.

[0242] In one embodiment, step S60, namely determining the inference resources corresponding to the next task stage and preloading the inference resources before receiving the inference request for the next task stage, includes:

[0243] S605: Based on the next task stage, query the pre-defined correspondence between the task stage and the inference resources to obtain multiple resource identifiers and the loading dependencies between the multiple resource identifiers.

[0244] In this embodiment, the correspondence between task stages and inference resources is a data set of record stage codes, resource identifiers, and dependent resource identifiers. The resource identifier is a combination of resource type code, resource version code, and resource content code. The loading dependency relationship is a directed connection between dependent resource identifiers and corresponding resource identifiers.

[0245] Specifically, the stage code corresponding to the next task stage is read, the stage code is hashed to obtain the resource mapping index value, the correspondence between the task stage and the inference resources is queried based on the resource mapping index value, multiple resource records are obtained, and the resource records with the same stage code as the stage code corresponding to the next task stage are retained.

[0246] The resource type code, resource version code, and resource content code are read from each resource record respectively, and combined according to the preset coding order to obtain the resource identifier corresponding to each resource record.

[0247] Read the dependent resource identifiers from each resource record, set the multiple resource identifiers as resource nodes respectively, and establish directed connection edges between the resource nodes corresponding to the dependent resource identifiers and the resource nodes corresponding to the corresponding resource identifiers. The relationship data composed of each directed connection edge is determined as the loading dependency relationship.

[0248] S606: Query the resource residency status based on multiple resource identifiers to determine the non-residency resources and the amount of resource data corresponding to each non-residency resource.

[0249] In this embodiment, the resource residency status refers to the write status of resource data in the runtime storage area, the non-residency resource refers to the inference resource whose resource data has not been completely written to the runtime storage area, and the resource data volume refers to the number of storage bytes corresponding to the resource block to be written in the non-residency resource.

[0250] Specifically, the resource residency table is queried based on each resource identifier to obtain the corresponding resource residency record. If no corresponding resource residency record is found, the corresponding inference resource is determined as a non-residency resource, and all resource blocks contained in the non-residency resource are determined as resource blocks to be written.

[0251] When the corresponding resource residency record is found, the resource version code, resource content code, and resource block residency bitmap are read from the resource residency record, and the resource version code and resource content code are compared with the resource version code and resource content code in the resource identifier, respectively.

[0252] When any of the codes are different, the corresponding inference resource is identified as a non-resident resource, and all resource blocks contained in the non-resident resource are identified as resource blocks to be written. When both codes are the same, the resource blocks not written to the runtime storage area are identified according to the resource block resident bitmap. When there are unwritten resource blocks, the corresponding inference resource is identified as a non-resident resource, and the unwritten resource blocks are identified as resource blocks to be written.

[0253] Read the length of each resource block to be written, and sum the lengths of the resource blocks corresponding to the same non-resident resource to obtain the amount of resource data corresponding to each non-resident resource.

[0254] S607: Sort non-resident resources according to loading dependencies and generate a resource preloading queue.

[0255] In this embodiment, the resource preloading queue is a queue of multiple non-resident resources arranged in the order of loading dependencies.

[0256] Specifically, the resource identifiers corresponding to each non-resident resource are set as resource nodes, and directed connections are established between each resource node according to the loading dependencies to obtain the non-resident resource dependency graph. Then, the directed connections corresponding to the dependent resources that are already resident in the non-resident resource dependency graph are deleted.

[0257] The number of directed edges pointing to each resource node is counted to obtain the number of dependencies for each resource node. Resource nodes with zero dependencies are identified as resource nodes to be arranged. The resource nodes to be arranged are sorted in ascending order according to their corresponding resource data volume. When the resource data volume is the same, they are sorted in ascending order according to their resource identifier.

[0258] The arranged resource nodes to be arranged are written into an empty preload queue in sequence. The written resource nodes and the directed connection edges from the written resource nodes are deleted from the non-resident resource dependency graph. The dependency count of the remaining resource nodes is recounted, and the resource nodes to be arranged with zero dependency count are determined until all resource nodes corresponding to the non-resident resources are written into the preload queue.

[0259] The resource preloading queue is obtained by associating the resource identifier, resource data volume, and resource block to be written with each resource node in the preloading queue.

[0260] S608: Determine the inference resources to be preloaded from the resource preloading queue based on the amount of available storage resources and the amount of resource data corresponding to each non-resident resource.

[0261] In this embodiment, the inference resources to be preloaded are non-resident resources selected from the resource preloading queue and whose corresponding resource data volume does not exceed the available storage resource volume.

[0262] Specifically, an empty resource selection list is created, and the preloaded cumulative data volume is set to zero. The resource identifier, resource data volume, and resource block to be written are read sequentially from the resource preload queue according to the sorting order.

[0263] Based on the loading dependencies, read the dependent resource identifiers corresponding to the current resource identifier, query the resource residency status corresponding to each dependent resource identifier, and query whether each dependent resource identifier is recorded in the resource selection list. If the inference resource corresponding to each dependent resource identifier has resided or has been recorded in the resource selection list, generate the dependency satisfaction result.

[0264] The preloaded cumulative data volume is added to the resource data volume corresponding to the current resource identifier to obtain the candidate cumulative data volume. When the dependency is satisfied and the candidate cumulative data volume is not greater than the available storage resource volume, the current resource identifier and the corresponding resource block to be written are written to the resource selection list, and the candidate cumulative data volume is updated to the preloaded cumulative data volume.

[0265] If no dependency satisfaction result is generated or the cumulative amount of candidate data is greater than the available storage resources, continue reading the next resource identifier in the resource preloading queue. After the resource preloading queue has been traversed, the inference resource corresponding to the resource identifier recorded in the resource selection list is determined as the inference resource to be preloaded.

[0266] S609: Load the inference resources to be preloaded according to the resource preloading queue before receiving the inference request for the next task stage.

[0267] In this embodiment, loading refers to the process of writing the resource block to be written from the resource storage area to the runtime storage area.

[0268] Specifically, the resource identifiers corresponding to the inference resources to be preloaded are read from the resource preloading queue, and a resource loading sequence is generated according to the order in the resource preloading queue.

[0269] The resource identifiers in the resource loading sequence are read sequentially. The resource residency status of the corresponding dependent resources is queried according to the loading dependency relationship. When the corresponding dependent resources have resided, the resource block to be written corresponding to the current resource identifier is read from the resource selection list, and the storage address, resource block length and resource block verification code corresponding to each resource block to be written are obtained.

[0270] According to the storage address and resource block length, the corresponding resource block data is read from the resource storage area, the resource block data is verified and calculated to obtain the loading verification code, and when the loading verification code is the same as the resource block verification code, the resource block data is written to the running storage area and the resource block resident bitmap is updated.

[0271] Once all the resource blocks to be written corresponding to the current resource identifier have been written, the resource residency status corresponding to the current resource identifier is updated to resided, and the next resource identifier in the resource loading sequence continues to be loaded until the inference resources to be preloaded are loaded. The loading process is executed before the inference request of the next task stage is received.

[0272] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0273] In one embodiment, a large-model hybrid inference optimization apparatus is provided, which corresponds one-to-one with the large-model hybrid inference optimization method described in the above embodiments. For example... Figure 2 As shown, this large-scale model hybrid inference optimization device includes a request parsing module, a quantization configuration module, a cache lookup module, a dynamic batch processing module, an inference processing module, and a stage prediction and resource preloading module.

[0274] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to perform the following steps:

[0275] Obtain the current inference request, determine the corresponding task stage, context features, and latency constraints.

[0276] Based on the task stage and the current state of inference resources, determine the quantitative configuration of the large model.

[0277] Based on contextual features and the runtime configuration of the large model, the system searches the preset cache space for a key-value cache that matches the current inference request, and obtains the cache lookup results.

[0278] Based on the quantization configuration, cache lookup results, and latency constraints, the batch processing wait time for the current inference request is determined. The current inference request, along with other inference requests arriving within the batch processing wait time that match the runtime configuration of the large model, are then grouped into an inference batch.

[0279] The large model is run according to the quantization configuration. When a matching key-value cache is found in the cache lookup result representation, the matching key-value cache is used to perform inference processing on the inference batch to obtain the current inference result.

[0280] Predict the next task stage based on the task stage and the current inference results, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request for the next task stage.

[0281] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, the computer program performing the following steps when executed by a processor:

[0282] Obtain the current inference request, determine the corresponding task stage, context features, and latency constraints.

[0283] Based on the task stage and the current state of inference resources, determine the quantitative configuration of the large model.

[0284] Based on contextual features and the runtime configuration of the large model, the system searches the preset cache space for a key-value cache that matches the current inference request, and obtains the cache lookup results.

[0285] Based on the quantization configuration, cache lookup results, and latency constraints, the batch processing wait time for the current inference request is determined. The current inference request, along with other inference requests arriving within the batch processing wait time that match the runtime configuration of the large model, are then grouped into an inference batch.

[0286] The large model is run according to the quantization configuration. When a matching key-value cache is found in the cache lookup result representation, the matching key-value cache is used to perform inference processing on the inference batch to obtain the current inference result.

[0287] Predict the next task stage based on the task stage and the current inference results, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request for the next task stage.

[0288] For the sake of convenience and brevity, only the above-mentioned functional units and modules are used as examples. The above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.

[0289] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.

Claims

1. A large-scale model hybrid inference optimization method, characterized in that, The method includes: Obtain the current inference request and determine the task stage, context features, and latency constraints corresponding to the current inference request; Based on the task stage and the current inference resource status, determine the quantitative configuration of the large model; Based on the context features and the running configuration of the large model, a key-value cache that matches the current inference request is searched in the preset cache space to obtain the cache lookup result; Based on the quantization configuration, the cache lookup result, and the latency constraint, the batch processing wait time of the current inference request is determined, and the current inference request is combined with other inference requests that arrive within the batch processing wait time and match the running configuration of the large model to form an inference batch. The large model is run according to the quantization configuration, and when a matching key-value cache is found in the cache lookup result representation, the matching key-value cache is used to perform inference processing on the inference batch to obtain the current inference result; Based on the task stage and the current inference result, predict the next task stage, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request for the next task stage.

2. The large-scale model hybrid inference optimization method according to claim 1, characterized in that, The step of obtaining the current inference request and determining the task stage, context features, and latency constraints corresponding to the current inference request includes: Parse the current inference request to obtain the task identifier, task execution status, context data, and response time limit parameters; Obtain the corresponding task stage mapping relationship based on the task identifier, and determine the task stage in the task stage mapping relationship based on the task execution status; Feature extraction is performed on the context data to obtain the context length and context prefix identifier, and the context length and context prefix identifier are determined as the context features; The latest response time for the current inference request is determined based on the response time limit parameter, and the latency constraint is determined based on the latest response time.

3. The large-scale model hybrid inference optimization method according to claim 1, characterized in that, The step of determining the quantitative configuration of the large model based on the task stage and the current inference resource status includes: Based on the task stage, query the preset correspondence between the task stage and the model layer sensitivity, and determine the sensitive model layer in the large model corresponding to the task stage and the accuracy loss threshold. The available computing resources and available storage resources are determined based on the current inference resource status, and resource constraints are determined based on the available computing resources and available storage resources. Multiple candidate quantization configurations are generated, and each candidate quantization configuration sets a first quantization bit width and a second quantization bit width for the sensitive model layer and other model layers other than the sensitive model layer, wherein the first quantization bit width is greater than the second quantization bit width. Determine the prediction accuracy loss and prediction resource consumption corresponding to each candidate quantization configuration, and select candidate quantization configurations from the plurality of candidate quantization configurations in which the prediction accuracy loss is not greater than the accuracy loss threshold and the prediction resource consumption satisfies the resource constraint; The quantization configuration of the large model is determined based on the prediction inference latency corresponding to the selected candidate quantization configurations.

4. The large-scale model hybrid inference optimization method according to claim 1, characterized in that, The step of searching for a key-value cache matching the current inference request in a preset cache space based on the context features and the running configuration of the large model, and obtaining the cache lookup result, includes: Based on the context length, the context data is segmented according to a preset segment length to obtain multiple context segments, and multiple context segment identifiers arranged in context order are generated based on the context prefix identifier and each context segment; Obtain the model identifier, model version, and key-value cache precision from the running configuration of the large model, and generate a configuration identifier based on the model identifier, model version, and key-value cache precision; Based on the configuration identifier, a corresponding prefix index tree is determined in the preset cache space, and the nodes of the prefix index tree record the context segment identifier and the key-value cache block; The prefix index tree is traversed sequentially according to the arrangement order of the multiple context segment identifiers until the current context segment identifier does not match the corresponding node or the multiple context segment identifiers have been traversed, thus obtaining a matching node path composed of consecutively matched nodes. Obtain the number of nodes contained in the matching node path, and combine the key-value cache blocks recorded by each node in the matching node path into a candidate key-value cache, and determine the amount of data in the candidate key-value cache; When the number of nodes reaches a preset threshold and the amount of data is not greater than a preset data amount threshold, the candidate key-value cache is determined as the key-value cache that matches the current inference request, and a cache lookup result representing that the matching key-value cache has been found is generated.

5. The large-scale model hybrid inference optimization method according to claim 1, characterized in that, The step of determining the batch processing wait time for the current inference request based on the quantization configuration, the cache lookup result, and the latency constraint includes: The context length to be calculated is determined based on the cache lookup result and the context length. Based on the quantization configuration and the length of the context to be calculated, determine the resource consumption of a single request and the request processing time; The allowed batch quantity is determined based on the available storage resources and the single request resource consumption. Obtain the number of pending requests and the request arrival frequency that match the running configuration of the large model, and determine the batch formation time based on the allowed batch size, the number of pending requests, and the request arrival frequency; The waiting time is determined based on the latency constraint and the request processing time. When the batch formation time is not greater than the waiting time, the batch formation time is determined as the batch processing waiting time; when the batch formation time is greater than the waiting time, the waiting time is determined as the batch processing waiting time.

6. The large-scale model hybrid inference optimization method according to claim 1, characterized in that, The step of predicting the next task stage based on the task stage and the current inference result includes: The current reasoning result is subjected to state recognition and semantic feature extraction to obtain the result state identifier and the result semantic feature, and a result feature vector is generated based on the result state identifier and the result semantic feature; Based on the task stage, determine the current stage node in the preset task stage transition diagram, and obtain multiple candidate stage nodes connected to the current stage node and the stage transition parameters corresponding to each candidate stage node. Based on the result feature vector and each of the stage transition parameters, the stage transition probability corresponding to each of the candidate stage nodes is determined respectively; The candidate stage nodes are sorted in descending order according to the stage transition probability, and the task stage corresponding to the first candidate stage node is determined as the next task stage.

7. The large-scale model hybrid inference optimization method according to claim 1, characterized in that, The step of determining the inference resources corresponding to the next task stage and preloading the inference resources before receiving the inference request for the next task stage includes: Based on the next task stage, query the pre-defined correspondence between the task stage and the inference resources to obtain multiple resource identifiers and the loading dependencies between the multiple resource identifiers; Based on the multiple resource identifiers, query the resource residency status to determine the non-residency resources and the amount of resource data corresponding to each non-residency resource; The non-resident resources are sorted according to the loading dependencies to generate a resource preloading queue; Based on the available storage resources and the amount of resource data corresponding to each of the non-resident resources, the inference resources to be preloaded are determined from the resource preloading queue; According to the resource preloading queue, the inference resources to be preloaded are loaded before the inference request for the next task stage is received.

8. A large-scale model hybrid inference optimization device, characterized in that, The large-model hybrid inference optimization device includes: The request parsing module is used to obtain the current inference request and determine the task stage, context features and latency constraints corresponding to the current inference request. The quantization configuration module is used to determine the quantization configuration of the large model based on the task stage and the current inference resource status. The cache lookup module is used to search for a key-value cache that matches the current inference request in a preset cache space based on the context features and the running configuration of the large model, and obtain the cache lookup result; The dynamic batch processing module is used to determine the batch processing waiting time of the current inference request based on the quantization configuration, the cache lookup result and the latency constraint, and to form an inference batch with the current inference request and other inference requests that arrive within the batch processing waiting time and match the running configuration of the large model. The inference processing module is used to run the large model according to the quantization configuration, and when a matching key-value cache is found in the cache lookup result representation, the matching key-value cache is used to perform inference processing on the inference batch to obtain the current inference result; The stage prediction and resource preloading module is used to predict the next task stage based on the task stage and the current inference result, determine the inference resources corresponding to the next task stage, and preload the inference resources before receiving the inference request of the next task stage.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the large model hybrid inference optimization method as described in any one of claims 1 to 7.

10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the large model hybrid inference optimization method as described in any one of claims 1 to 7.