A model memory usage optimization method, device, medium, product and system

By receiving inference requests, extracting and generating memory occupancy information in large language models, predicting maximum memory occupancy and optimizing memory usage, it solves the problem of reduced reasoning efficiency caused by insufficient memory and achieves the ability to efficiently run inference tasks under limited memory.

CN118409873BActive Publication Date: 2024-08-30SHANDONG HAILIANG INFORMATION TECH RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410874870.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-02
Publication Date
2024-08-30
Estimated Expiration
2044-07-02

AI Technical Summary

Technical Problem

During the inference process of large language models, if there is insufficient memory, the existing technology needs to sacrifice inference performance to reduce memory usage, resulting in a decrease in model inference efficiency and the inability to run as many inference tasks as possible under limited memory resources.

Method used

By receiving inference requests from pre-trained models, we use strategies to extract and generate memory usage information, predict the maximum memory usage information of inference results, determine the memory usage range based on the current remaining memory space of heterogeneous computing devices, and optimize the memory usage of inference results. quantity.

Benefits of technology

Under limited memory resources, it can run as many inference tasks as possible to avoid idle computing power and waste of resources, while improving the efficiency of inference request processing and the number of concurrencies without any user awareness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118409873B
    Figure CN118409873B
Patent Text Reader

Abstract

The present application discloses a model memory occupancy optimization method, device, medium, product and system in the field of computer technology. The present application predicts the memory occupancy range of the inference result for a specific inference request, constrains the memory occupancy of the inference result, and the process comprehensively considers the current remaining memory space of the target heterogeneous computing power device where the pre-trained model is located, thereby performing memory optimization design in combination with the actual memory usage of the device, which can not only save the memory of heterogeneous computing power, avoid idle computing power and waste of resources, but also achieve user-unawareness, providing the possibility of improving the processing efficiency and concurrency of inference requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, medium, product and system for optimizing model memory usage. Background Art

[0002] Currently, during the Large Language Model (LLM) reasoning process, if the memory is insufficient, it is necessary to abandon the cache resources occupied by the model reasoning, that is, to reduce the memory usage by abandoning the reasoning performance to achieve the purpose of memory optimization. Obviously, this method will affect the efficiency of model reasoning.

[0003] Therefore, how to run as many reasoning tasks as possible with limited memory resources is a problem that technicians in this field need to solve. Summary of the invention

[0004] In view of this, the purpose of this application is to provide a model memory usage optimization method, device, medium, product and system to run as many inference tasks as possible under limited memory resources. The specific scheme is as follows:

[0005] In a first aspect, the present application provides a method for optimizing model memory usage, comprising:

[0006] Receive inference requests for pre-trained models;

[0007] Utilizing a first strategy to extract memory occupancy information of an inference result corresponding to the inference request from the inference request, utilizing a second strategy to generate memory occupancy information of an inference result corresponding to the inference request according to the inference request, and obtaining at least two memory occupancy information; the second strategy can control the inference quality of the inference result;

[0008] Predicting the maximum memory occupancy information of the inference result according to the current remaining memory space of the target heterogeneous computing device where the pre-trained model is located and the maximum value of the at least two memory occupancy information;

[0009] A memory occupancy range of the inference result is determined according to the maximum value and the maximum memory occupancy information.

[0010] Optionally, the first strategy includes: at least one rule matching strategy and at least one model generation strategy;

[0011] Accordingly, extracting memory usage information of the inference result corresponding to the inference request from the inference request using the first strategy includes:

[0012] Performing field matching on the inference request using the at least one rule matching strategy to extract a minimum number of characters set in the inference request, and using the minimum number of characters or a memory length obtained by the minimum number of characters as memory occupancy information;

[0013] Predicting the minimum number of characters of the inference result by using the at least one model generation strategy, and using the minimum number of characters or a memory length obtained by the minimum number of characters as memory occupancy information;

[0014] Accordingly, using the second strategy to generate memory usage information of the inference result corresponding to the inference request according to the inference request includes:

[0015] The inference request is input into a preset target model so that the preset target model predicts the minimum number of characters of the inference result under the premise of controlling the inference quality of the inference result, and uses the minimum number of characters or the memory length obtained by the minimum number of characters as memory occupancy information.

[0016] Optionally, predicting the maximum memory occupancy information of the inference result according to the current remaining memory space where the pre-trained model is located and the maximum value of the at least two memory occupancy information includes:

[0017] Set memory thresholds and adjustment parameter values;

[0018] Constructing a target formula based on the current remaining memory space, the maximum value, the memory threshold value and the adjustment parameter;

[0019] Calculating the maximum number of characters of the inference result using the target formula;

[0020] The maximum number of characters or the maximum memory length obtained from the maximum number of characters is used as the maximum memory occupancy information.

[0021] Optionally, the target formula is: , L represents the maximum number of characters, K represents the maximum value, α represents the adjustment parameter, M represents the memory threshold value, and m represents the current remaining memory space. Indicates the round-up symbol.

[0022] Optionally, after determining the memory usage range of the inference result according to the maximum value and the maximum memory usage information, the method further includes:

[0023] Building model prompt information based on the inference request and the memory usage range;

[0024] The model prompt information is input into the pre-trained model so that the pre-trained model outputs the inference result according to the memory occupancy range in the target heterogeneous computing power device.

[0025] Optionally, it also includes:

[0026] Detecting actual memory usage information of the inference result;

[0027] If the actual memory occupancy information is greater than the maximum memory occupancy information, after changing the at least two prediction strategies, the steps of extracting the memory occupancy information of the inference result corresponding to the inference request from the inference request using the first strategy, and generating the memory occupancy information of the inference result corresponding to the inference request according to the inference request using the second strategy, to obtain at least two memory occupancy information and subsequent other steps.

[0028] Optionally, it also includes:

[0029] If the actual memory occupancy information is not greater than the maximum memory occupancy information, the inference result is output.

[0030] Optionally, the process of selecting the target heterogeneous computing power device includes:

[0031] In a heterogeneous computing power system, querying an optional heterogeneous computing power device storing the pre-trained model;

[0032] A heterogeneous computing power device with the largest remaining memory space and an operating performance greater than a target value is selected from the optional heterogeneous computing power devices as the target heterogeneous computing power device.

[0033] Optionally, in a heterogeneous computing power system, querying an optional heterogeneous computing power device storing the pre-trained model includes:

[0034] Querying a list of models stored in each heterogeneous computing device in the heterogeneous computing system;

[0035] Query the model identification information of the pre-trained model in the model list.

[0036] Optionally, receiving an inference request for a pre-trained model includes:

[0037] Receive the inference request distributed by the control device in the heterogeneous computing system.

[0038] In a second aspect, the present application provides a model memory usage optimization device, comprising:

[0039] A receiving module, used to receive an inference request of a pre-trained model;

[0040] A first prediction module is used to extract memory occupancy information of an inference result corresponding to the inference request from the inference request using a first strategy, and to generate memory occupancy information of the inference result corresponding to the inference request according to the inference request using a second strategy, so as to obtain at least two memory occupancy information; the second strategy can control the inference quality of the inference result;

[0041] A second prediction module is used to predict the maximum memory occupancy information of the inference result according to the current remaining memory space of the target heterogeneous computing power device where the pre-trained model is located and the maximum value of the at least two memory occupancy information;

[0042] A determination module is used to determine the memory occupancy range of the inference result according to the maximum value and the maximum memory occupancy information.

[0043] In a third aspect, the present application provides an electronic device, including:

[0044] Memory for storing computer programs;

[0045] A processor is used to execute the computer program to implement the aforementioned disclosed model memory occupancy optimization method.

[0046] In a fourth aspect, the present application provides a non-volatile storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the aforementioned disclosed model memory occupancy optimization method.

[0047] In a fifth aspect, the present application provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the steps of the aforementioned disclosed model memory occupancy optimization method.

[0048] In a sixth aspect, the present application provides a heterogeneous computing power system, including: a client, a control device, and a plurality of heterogeneous computing power devices;

[0049] The control device is used to collect the inference request of the pre-trained model sent by the client, select the target heterogeneous computing power device where the pre-trained model is located, and forward the inference request to the target heterogeneous computing power device;

[0050] The target heterogeneous computing device is used to receive the inference request; use a first strategy to extract memory occupancy information of the inference result corresponding to the inference request from the inference request, and use a second strategy to generate memory occupancy information of the inference result corresponding to the inference request according to the inference request, to obtain at least two memory occupancy information; the second strategy can control the inference quality of the inference result; predict the maximum memory occupancy information of the inference result based on its own current remaining memory space and the maximum value of the at least two memory occupancy information; determine the memory occupancy range of the inference result based on the maximum value and the maximum memory occupancy information.

[0051] Optionally, the control device collects device operation information of the multiple heterogeneous computing devices in real time; accordingly, the target heterogeneous computing device with the largest remaining memory space and an operation performance greater than a target value is selected according to the device operation information.

[0052] It can be seen from the above scheme that the present application provides a model memory occupancy optimization method, including: receiving an inference request for a pre-trained model; using a first strategy to extract memory occupancy information of the inference result corresponding to the inference request from the inference request, and using a second strategy to generate memory occupancy information of the inference result corresponding to the inference request according to the inference request, to obtain at least two memory occupancy information; predicting the maximum memory occupancy information of the inference result based on the current remaining memory space of the target heterogeneous computing device where the pre-trained model is located and the maximum value of the at least two memory occupancy information; determining the memory occupancy range of the inference result based on the maximum value and the maximum memory occupancy information.

[0053] It can be seen that the beneficial effects of this application are: predicting the memory usage range of the reasoning result for a specific reasoning request, constraining the memory usage of the reasoning result, and the process comprehensively considers the current remaining memory space of the target heterogeneous computing power device where the pre-trained model is located, thereby combining the actual memory usage of the device for memory optimization design, which can not only save the memory of heterogeneous computing power, but also run as many reasoning tasks as possible under limited memory resources, avoid idle computing power and waste of resources, and achieve user-unawareness, which provides the possibility of improving the processing efficiency and concurrency of reasoning requests. This application is applicable to any pre-trained model, that is: for any pre-trained model, the model memory usage can be optimized according to this application.

[0054] Correspondingly, the model memory usage optimization device, medium and program product provided by the present application also have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0055] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0056] Figure 1 A flow chart of a model memory usage optimization method disclosed in this application;

[0057] Figure 2 A schematic diagram of a heterogeneous computing system disclosed in this application;

[0058] Figure 3 A design diagram of a model memory usage optimization solution disclosed in this application;

[0059] Figure 4 A flow chart of another model memory usage optimization method disclosed in this application;

[0060] Figure 5 A schematic diagram of an electronic device disclosed in this application;

[0061] Figure 6 A server structure diagram provided for this application;

[0062] Figure 7 A terminal structure diagram provided for this application. DETAILED DESCRIPTION

[0063] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other examples obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0064] In order to ensure the latency and service quality of the pre-trained model, the pre-trained model usually uses KVcache, a technology that exchanges space for time, during the inference process. This leads to very serious memory consumption during the inference of the pre-trained model and a significant increase in the cost of memory resource overhead.

[0065] At present, during the pre-training model reasoning process, if there is insufficient memory, it is necessary to abandon the cache resources occupied by the model reasoning, that is, to reduce the memory usage by abandoning the reasoning performance to achieve the purpose of memory optimization. Obviously, this method will affect the efficiency of model reasoning. To this end, this application provides a model memory occupancy optimization solution that can run as many reasoning tasks as possible under limited memory resources.

[0066] See also Figure 1 As shown, the embodiment of the present application discloses a method for optimizing model memory usage, including:

[0067] S101: Receive an inference request for a pre-trained model.

[0068] In this embodiment, the pre-trained model can be a natural language model that can handle any task. As a deep learning model, the pre-trained model completes a specific task by training on a large-scale data set. The features learned by this model on general tasks can be transferred to other specific tasks. LLM is a specific application of the pre-trained model in the field of natural language processing, that is, the large language model is a form of the pre-trained model.

[0069] S102. Use the first strategy to extract memory usage information of the inference result corresponding to the inference request from the inference request, and use the second strategy to generate memory usage information of the inference result corresponding to the inference request according to the inference request to obtain at least two memory usage information.

[0070] In this embodiment, at least two memory occupancy information are obtained by using the first strategy and the second strategy, and then the maximum value is selected from them to execute S103; the second strategy can control the reasoning quality of the reasoning result. In one embodiment, the first strategy includes: at least one rule matching strategy and at least one model generation strategy; accordingly, the memory occupancy information of the reasoning result corresponding to the reasoning request is extracted from the reasoning request by using the first strategy, including: using the at least one rule matching strategy to perform field matching on the reasoning request to extract the minimum number of characters set in the reasoning request, and using the minimum number of characters or the memory length obtained by the minimum number of characters as the memory occupancy information; using the at least one model generation strategy to predict the minimum number of characters of the reasoning result, and using the minimum number of characters or the memory length obtained by the minimum number of characters as the memory occupancy information; accordingly, using the second strategy to generate the memory occupancy information of the reasoning result corresponding to the reasoning request according to the reasoning request, including: inputting the reasoning request into a preset target model, so that the preset target model predicts the minimum number of characters of the reasoning result under the premise of controlling the reasoning quality of the reasoning result, and using the minimum number of characters or the memory length obtained by the minimum number of characters as the memory occupancy information. It can be seen that the difference between the preset target model and the model generation strategy is that the preset target model can guarantee the quality of the inference results, while the model generation strategy focuses on determining the minimum number of characters in the inference results, while ignoring the quality and accuracy of the inference results. The preset target model can be any neural network model, which can specifically include: MLP layer (Multi-Layer Perceptron), multi-layer transformer and embedding layer.

[0071] S103: predict the maximum memory occupancy information of the inference result according to the current remaining memory space of the target heterogeneous computing device where the pre-trained model is located and the maximum value of at least two memory occupancy information.

[0072] In one embodiment, based on the current remaining memory space where the pre-trained model is located and the maximum value of at least two memory occupancy information, the maximum memory occupancy information of the inference result is predicted, including: setting the memory threshold value of the inference result and the value of the adjustment parameter; constructing a target formula based on the current remaining memory space, the maximum value of at least two memory occupancy information, the memory threshold value and the adjustment parameter; using the target formula to calculate the maximum number of characters of the inference result; using the maximum number of characters or the maximum memory length obtained by the maximum number of characters as the maximum memory occupancy information. In one embodiment, the target formula is: , L represents the maximum number of characters, K represents the maximum value of at least two memory usage information, α represents the adjustment parameter, M represents the memory threshold value, and m represents the current remaining memory space. Indicates the rounding symbol. The objective formula is used to control the maximum length of the inference result, where α is an adjustable parameter. When the available memory (i.e., the current remaining memory space) is M, L takes the value of α×K; when the available memory approaches 0, L approaches K.

[0073] It should be noted that the memory threshold is also used to determine whether to perform the requested secondary processing before model inference, that is, to execute S102-S104 before model inference. If the current remaining memory space of the target heterogeneous computing device where the pre-trained model is located is greater than M, no secondary processing is required. If it is less than or equal to M, it indicates that the remaining memory of the heterogeneous computing device is not much, and the requested secondary processing is performed to save memory.

[0074] S104: Determine the memory usage range of the inference result according to the maximum value and the maximum memory usage information.

[0075] In one embodiment, after determining the memory usage range of the inference result according to the maximum value and the maximum memory usage information, the method further includes: constructing model prompt information based on the inference request and the memory usage range; and inputting the model prompt information into the pre-trained model so that the pre-trained model outputs the inference result according to the memory usage range in the target heterogeneous computing device. The memory usage range is used to constrain the number of characters of the inference result, thereby constraining the memory size occupied by it.

[0076] In one embodiment, it also includes: detecting the actual memory occupancy information of the inference result; if the actual memory occupancy information is greater than the maximum memory occupancy information, then after changing at least two prediction strategies, executing the steps of extracting the memory occupancy information of the inference result corresponding to the inference request from the inference request using the first strategy, and generating the memory occupancy information of the inference result corresponding to the inference request according to the inference request using the second strategy, to obtain at least two memory occupancy information and other subsequent steps. That is: using at least two new prediction strategies to predict the memory occupancy information of the inference result corresponding to the inference request, so as to redetermine the corresponding memory occupancy range for this inference result. If the actual memory occupancy information is not greater than the maximum memory occupancy information, the inference result is output. The output inference result is returned to the client along the original path.

[0077] In one embodiment, the process of selecting a target heterogeneous computing power device includes: in a heterogeneous computing power system, querying optional heterogeneous computing power devices that store pre-trained models; selecting a heterogeneous computing power device with the largest remaining memory space and operating performance greater than a target value from the optional heterogeneous computing power devices as the target heterogeneous computing power device. Among them, in a heterogeneous computing power system, querying the optional heterogeneous computing power device that stores pre-trained models includes: querying the model list stored in each heterogeneous computing power device in the heterogeneous computing power system; querying the model identification information of the pre-trained model in the model list. That is, each heterogeneous computing power device in the heterogeneous computing power system stores at least one pre-trained model, and the pre-trained models stored in different heterogeneous computing power devices may be the same or different.

[0078] It should be noted that when a large number of inference requests arrive at the control device, the control device queries the optional heterogeneous computing devices that store the relevant pre-trained models; and selects the heterogeneous computing device with the largest remaining memory space and operating performance greater than the target value from the optional heterogeneous computing devices as the target heterogeneous computing device for running the current inference request. Therefore, the target heterogeneous computing device receives the inference request of the pre-trained model, including: the target heterogeneous computing device receives the inference request distributed by the control device in the heterogeneous computing system.

[0079] In a multi-heterogeneous computing system (i.e., a heterogeneous computing power system), heterogeneous computing power (heterogeneous computing chips or computing cards) with different computing performance and different memory capacity will be connected to the same distributed computing system to be called according to customer needs. On the one hand, heterogeneous computing power devices such as GPU, FPGA, and ASIC have different advantages in different AI (Artificial Intelligence) application scenarios. On the other hand, the real-time status of heterogeneous computing power will also affect the reasoning efficiency of the pre-trained model. Therefore, when actually performing model reasoning, it is often necessary to select computing power between different heterogeneous computing power nodes. Reasonable computing power selection for the reasoning request of the pre-trained model is the key to effectively reduce memory consumption, reduce the probability of OOM (Out Of Memory) failure, and reduce costs. This embodiment allocates appropriate heterogeneous computing power to each pre-trained model reasoning request based on the real-time memory remaining of the heterogeneous computing power. At the same time, when the memory is tight, constraining the memory usage of the reasoning result can increase the number of reasoning requests that the system can respond to.

[0080] It can be seen that this embodiment predicts the memory usage range of the inference result of a specific inference request, constrains the memory usage of the inference result, and the process comprehensively considers the current remaining memory space of the target heterogeneous computing power device where the pre-trained model is located. Therefore, memory optimization design is performed in combination with the actual memory usage of the device, which can not only save the memory of heterogeneous computing power, avoid idle computing power and waste of resources, but also achieve user-unawareness, thereby providing the possibility of improving the processing efficiency and concurrency of inference requests.

[0081] See also Figure 2 , a heterogeneous computing system may include multiple heterogeneous computing devices: heterogeneous computing device 1 (XPU1), heterogeneous computing device 2 (XPU2), heterogeneous computing device 3 (XPU3), and heterogeneous computing device 4 (XPU4). According to the characteristics of each computing device, different trained LLMs will be assigned to different heterogeneous computing devices. When there is no inference task being executed in a heterogeneous computing device, only the trained LLM occupies the memory in the memory of the computing power; when there is an inference task being executed, the inference business will also occupy a part of the memory. Among them, since KVcache (a caching technology) is required for inference, once the length of the output text of an inference request is large, the memory occupancy of the inference task will be greatly increased. Based on this problem, this embodiment provides the following three modules: heterogeneous computing system information collection module: used to collect computing power information of heterogeneous computing systems in real time. Inference request computing power selection module: selects appropriate computing power to execute inference requests for large language models. Reasoning request secondary processing module: When the memory of a heterogeneous computing system is tight, this module is used to perform secondary processing on reasoning requests, thereby optimizing the memory usage of reasoning requests without the user noticing, and increasing the number of reasoning requests that the heterogeneous computing system can respond to.

[0082] See also Figure 3 When a large language model inference request arrives, the heterogeneous computing power system information collection module will collect information about the heterogeneous computing power system. The inference request is: a question or dialogue about the large model described in natural language. The collected information includes: the identifier of the currently deployed trained LLM in each heterogeneous computing power. The absolute value of the currently remaining available memory in each heterogeneous computing power. These data collected in real time from the heterogeneous computing system will be sent to the inference request computing power selection module.

[0083] The inference request computing power selection module is used to send large model inference requests to appropriate heterogeneous computing power according to the status of the current heterogeneous computing system. Specifically, according to the LLM specified by the inference request and the collected LLM identifiers, all heterogeneous computing powers that deploy the LLM can be screened out, and then the one with the most remaining available memory is taken as the heterogeneous computing power used for this request. In this way, during the inference allocation process of the request, the memory usage of each computing power can be kept balanced as much as possible to avoid idle computing power and waste of resources. Subsequently, the module will send the content of the inference request and the selected heterogeneous computing power identifier to the inference request secondary processing module.

[0084] The inference request secondary processing module performs secondary processing on the inference request based on the received request and the absolute value of the available memory of the selected heterogeneous computing power. Specifically, based on the pre-defined computing power memory remaining threshold M, determine whether the inference request needs to be secondary processed. If the remaining available memory value of the selected heterogeneous computing power is greater than M, no secondary processing is required. If the remaining available memory value of the selected heterogeneous computing power is less than or equal to M, it indicates that the remaining memory of the heterogeneous computing power is not much, and the inference request memory optimization algorithm needs to be used to perform secondary processing on the inference request to save memory. After the inference request memory optimization algorithm, the secondary processed inference request will be inferred in the corresponding heterogeneous computing power, and then the inference result will be returned to the client according to the normal large model inference process for the user to view.

[0085] The purpose of the inference request memory optimization algorithm is to minimize the character length of the inference result and reduce the memory used for large model inference while ensuring the quality of the inference result. When the remaining available memory value of the heterogeneous computing power is less than or equal to M, it means that the available memory in the heterogeneous computing power is small and the computing power may not be able to support the continuous arrival of large model inference requests. Therefore, the inference request memory optimization algorithm is used for memory optimization. Figure 4 The specific process includes:

[0086] Step 1: When an inference request arrives, we first try to extract the minimum word count limit from the text of the inference request.

[0087] (1) You can use the vocabulary matching + rule method to obtain the minimum word limit, and directly use regular expressions or keywords to match the limit words and quantifiers. For example: the inference request includes: answer my question with at least 5 words, then 5 words are quantifiers, at least the limit words. Then you can specify the rule that if the distance between the quantifier and the limit word does not exceed 2 characters, it is considered that there is a minimum word limit, and the quantifier is used as the result of its minimum word limit. If the rule is not met, it is considered that no minimum word limit is set in the request. By continuously building a vocabulary and continuously improving the rules, the minimum word limit set in the request can be extracted.

[0088] (2) The vocabulary + rule method is difficult to cover all situations and has poor generalization. Therefore, artificial intelligence methods can also be used to extract the minimum word count limit. Specifically, the neural network model is trained using an annotated data set so that the neural network model can use the reasoning request as input data to predict the minimum word count limit of the corresponding reasoning result. The annotated data set can be obtained by manual writing, random generation, etc. The data set includes natural language reasoning requests entered by users in the past, and its label is the minimum word count limit of the reasoning result corresponding to the request that is manually annotated. It can be a specific value or unlimited. The trained neural network can then be used to predict the minimum word count limit of the relevant results of the request.

[0089] Step 2: Predict the minimum word count limit of the relevant results of the inference request again.

[0090] This step is used to ensure the quality of the inference results and to limit the minimum number of words. The structure of the neural network model can be consistent or inconsistent with that of the previous one. Specifically, the input data of the model can be historical questions, and the minimum number of words required for the output can be based on manual labeling to construct a training set for model training.

[0091] Step 3: Predict the maximum length limit of the inference response.

[0092] Take the maximum value of step 1 and step 2, record it as the minimum word limit K, and calculate and set the length limit of LLM reasoning reply according to the memory status of the current heterogeneous computing power. If the remaining memory space of the current heterogeneous computing power is m (m∈[0,M]), the maximum word length L can be deduced according to the following formula: , L represents the maximum number of characters, K represents the maximum value, α represents the adjustment parameter, M represents the memory threshold value, and m represents the current remaining memory space. Indicates the rounding up symbol. α is an adjustable parameter used to control the maximum length of the reply. For example, when α is 2, the maximum value of L is 2K. As the remaining memory m decreases, L gradually approaches K. The recommended value of α is between 1 and 3.

[0093] Step 4: Perform secondary processing on the original reasoning request based on the obtained L value. The specific process is as follows: When L is not equal to K, the reasoning request after processing is: original request + "\n (newline symbol) Please use K to L words to answer the above content". When L is equal to K, the reasoning request after processing is: original request + "\n Please use K words to answer the above content". There is no restriction on the expression method of the added content here. It mainly uses natural language to tell LLM the word limit of the answer, thereby limiting the LLM output length, and ultimately achieving the effect of reducing the memory used for large model reasoning when the memory of the heterogeneous computing system is insufficient, while ensuring the service quality.

[0094] Step 5: Send the processed request to LLM for inference, and allocate inference memory space according to the length of L inference outputs when calling the inference request, and finally output the final inference result.

[0095] In one example, if M=10GB, α=2, and the large model reasoning task is: Recommend me a dinner tonight, and hope to use LLaMA (Large Language Model Meta AI, a large language model) for reasoning. Assume that there are three computing powers, A100, H100, and MLU370, that deploy the large model of LLaMA. Through real-time heterogeneous computing power information collection, it is found that one of the A100 has the largest available memory capacity, so the request is assigned to the A100. However, the available memory capacity of the A100 is still less than the set M value, and it is determined that the request needs to be processed again. In the processing stage, the algorithm finds that the reasoning task does not limit the minimum number of output words, and infers that 50 words (K=50) can achieve a reasonable response quality, and the current available memory is 5GB. Therefore, according to the above calculation formula, L=1.5*50=75 can be calculated. Finally, the reasoning request output to LLM is: Recommend me a dinner tonight + Please use 50 to 75 words to answer the above content. Then the inference memory space will be allocated according to the output length of 75 words.

[0096] It can be seen that this embodiment allocates appropriate heterogeneous computing power to each large language model inference request according to the real-time memory usage of heterogeneous computing power, avoids idle computing power and waste of resources, and increases the number of responding inference requests without the user's perception, thereby saving memory of the heterogeneous computing system.

[0097] A model memory occupancy optimization device provided in an embodiment of the present application is introduced below. The model memory occupancy optimization device described below can be referenced to other embodiments described in this document.

[0098] The embodiment of the present application discloses a model memory occupancy optimization device, comprising:

[0099] A receiving module, used to receive an inference request of a pre-trained model;

[0100] A first prediction module is used to extract memory occupancy information of an inference result corresponding to the inference request from the inference request using a first strategy, and to generate memory occupancy information of the inference result corresponding to the inference request according to the inference request using a second strategy, so as to obtain at least two memory occupancy information;

[0101] The second prediction module is used to predict the maximum memory occupancy information of the inference result according to the current remaining memory space of the target heterogeneous computing power device where the pre-trained model is located and the maximum value of at least two memory occupancy information;

[0102] The determination module is used to determine the memory usage range of the inference result according to the maximum value and the maximum memory usage information.

[0103] In one embodiment, the first strategy includes: at least one rule matching strategy and at least one model generation strategy;

[0104] Accordingly, the first prediction module is specifically used for:

[0105] At least one rule matching strategy is used to perform field matching on the inference request to extract the minimum number of characters set in the inference request, and the minimum number of characters or the memory length obtained from the minimum number of characters is used as memory occupancy information; at least one model generation strategy is used to predict the minimum number of characters of the inference result, and the minimum number of characters or the memory length obtained from the minimum number of characters is used as memory occupancy information; the inference request is input into a preset target model, so that the preset target model predicts the minimum number of characters of the inference result under the premise of controlling the inference quality of the inference result, and the minimum number of characters or the memory length obtained from the minimum number of characters is used as memory occupancy information.

[0106] In one implementation, the second prediction module is specifically used to:

[0107] Set the memory threshold of the inference result and the value of the adjustment parameter;

[0108] Build the target formula based on the current remaining memory space, maximum value, memory threshold value and adjustment parameters;

[0109] Use the target formula to calculate the maximum number of characters in the inference result;

[0110] The maximum number of characters or the maximum memory length obtained from the maximum number of characters is used as the maximum memory occupancy information.

[0111] In one embodiment, the target formula is: , L represents the maximum number of characters, K represents the maximum value of at least two memory usage information, α represents the adjustment parameter, M represents the memory threshold value, and m represents the current remaining memory space. Indicates the round-up symbol.

[0112] In one embodiment, it further includes:

[0113] The inference module is used to determine the memory usage range of the inference result according to the maximum value and the maximum memory usage information, and then build model prompt information based on the inference request and the memory usage range; input the model prompt information into the pre-trained model so that the pre-trained model outputs the inference result according to the memory usage range in the target heterogeneous computing power device.

[0114] In one embodiment, it further includes:

[0115] A detection module is used to detect the actual memory occupancy information of the inference result; if the actual memory occupancy information is greater than the maximum memory occupancy information, then after changing at least two prediction strategies, the first strategy is used to extract the memory occupancy information of the inference result corresponding to the inference request from the inference request, and the second strategy is used to generate the memory occupancy information of the inference result corresponding to the inference request according to the inference request, to obtain at least two memory occupancy information steps and other subsequent steps. If the actual memory occupancy information is not greater than the maximum memory occupancy information, the inference result is output.

[0116] In one embodiment, the process of selecting a target heterogeneous computing power device includes: in a heterogeneous computing power system, querying optional heterogeneous computing power devices that store pre-trained models; selecting a heterogeneous computing power device with the largest remaining memory space and an operating performance greater than a target value from the optional heterogeneous computing power devices as the target heterogeneous computing power device.

[0117] In one embodiment, in a heterogeneous computing system, querying an optional heterogeneous computing device storing a pre-trained model includes: querying a list of models stored in each heterogeneous computing device in the heterogeneous computing system; and querying the model identification information of the pre-trained model in the model list.

[0118] In one implementation, the receiving module is specifically configured to:

[0119] Receive inference requests distributed by control devices in heterogeneous computing systems.

[0120] Among them, for more specific working processes of each module and unit in this embodiment, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0121] It can be seen that this embodiment provides a model memory occupancy optimization device, which can allocate appropriate heterogeneous computing power to each pre-trained model inference request according to the real-time memory usage of the heterogeneous computing power, avoid idle computing power and waste of resources, and increase the number of responding inference requests without the user's perception, thereby saving the memory of the heterogeneous computing system.

[0122] An electronic device provided in an embodiment of the present application is introduced below. The electronic device described below can be referenced to other embodiments described in this document.

[0123] See also Figure 5 As shown, the embodiment of the present application discloses an electronic device, including:

[0124] Memory 501, used for storing computer programs;

[0125] The processor 502 is used to execute the computer program to implement the method disclosed in any of the above embodiments.

[0126] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: receiving an inference request of a pre-trained model; extracting memory occupancy information of an inference result corresponding to the inference request from the inference request using a first strategy, and generating memory occupancy information of the inference result corresponding to the inference request according to the inference request using a second strategy to obtain at least two memory occupancy information; predicting the maximum memory occupancy information of the inference result based on the current remaining memory space of the target heterogeneous computing power device where the pre-trained model is located and the maximum value of at least two memory occupancy information; determining the memory occupancy range of the inference result based on the maximum value and the maximum memory occupancy information.

[0127] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: using at least one rule matching strategy to perform field matching on the inference request to extract the minimum number of characters set in the inference request, and using the minimum number of characters or the memory length obtained by the minimum number of characters as memory occupancy information; using at least one model generation strategy to predict the minimum number of characters of the inference result, and using the minimum number of characters or the memory length obtained by the minimum number of characters as memory occupancy information.

[0128] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: setting the memory threshold value and adjustment parameter value of the inference result; constructing a target formula based on the current remaining memory space, the maximum value of at least two memory occupancy information, the memory threshold value and the adjustment parameter; using the target formula to calculate the maximum number of characters of the inference result; and using the maximum number of characters or the maximum memory length obtained from the maximum number of characters as the maximum memory occupancy information.

[0129] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: constructing model prompt information based on the inference request and the memory occupancy range; inputting the model prompt information into the pre-trained model so that the pre-trained model outputs the inference result according to the memory occupancy range in the target heterogeneous computing power device.

[0130] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: detecting the actual memory occupancy information of the inference result; if the actual memory occupancy information is greater than the maximum memory occupancy information, then changing at least two prediction strategies, executing the steps of extracting the memory occupancy information of the inference result corresponding to the inference request from the inference request using the first strategy, generating the memory occupancy information of the inference result corresponding to the inference request according to the inference request using the second strategy, and obtaining at least two steps of memory occupancy information and subsequent other steps.

[0131] In this embodiment, when the processor executes the computer program stored in the memory, the following steps may be specifically implemented: if the actual memory occupancy information is not greater than the maximum memory occupancy information, an inference result is output.

[0132] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: in the heterogeneous computing power system, query the optional heterogeneous computing power device that stores the pre-trained model; select the heterogeneous computing power device with the largest remaining memory space and the operating performance greater than the target value from the optional heterogeneous computing power devices as the target heterogeneous computing power device.

[0133] In this embodiment, when the processor executes the computer program stored in the memory, the following steps can be specifically implemented: querying the model list stored in each heterogeneous computing device in the heterogeneous computing system; querying the model identification information of the pre-trained model in the model list.

[0134] Furthermore, the present application also provides an electronic device. The electronic device can be Figure 6 The server shown can also be Figure 7 Terminal shown. Figure 6 and Figure 7 All of them are structural diagrams of electronic devices according to an exemplary embodiment, and the contents in the diagrams cannot be regarded as any limitation on the scope of use of the present application.

[0135] Figure 6 A schematic diagram of the structure of a server provided in an embodiment of the present application. The server may specifically include: at least one processor, at least one memory, a power supply, a communication interface, an input / output interface, and a communication bus. The memory is used to store a computer program, which is loaded and executed by the processor to implement the relevant steps in the model memory usage optimization disclosed in any of the aforementioned embodiments.

[0136] In this embodiment, the power supply is used to provide working voltage for each hardware device on the server; the communication interface can create a data transmission channel between the server and external devices, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0137] In addition, the memory as a carrier for resource storage can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon include operating system, computer programs and data, etc. The storage method can be temporary storage or permanent storage.

[0138] The operating system is used to manage and control the hardware devices and computer programs on the server to realize the operation and processing of the data in the memory by the processor, and it can be Windows Server, Netware, Unix, Linux, etc. In addition to the computer program that can be used to complete the model memory usage optimization method disclosed in any of the aforementioned embodiments, the computer program can further include computer programs that can be used to complete other specific tasks. In addition to data such as application update information, the data can also include data such as application developer information.

[0139] Figure 7 A schematic diagram of the structure of a terminal provided in an embodiment of the present application, the terminal may specifically include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer, etc.

[0140] Generally, the terminal in this embodiment includes: a processor and a memory.

[0141] Among them, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0142] The memory may include one or more computer non-volatile storage media, which may be non-transitory. The memory may also include high-speed random access memory, and non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory is at least used to store the following computer program, wherein, after the computer program is loaded and executed by the processor, it can implement the relevant steps in the model memory occupancy optimization method performed by the terminal side disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory may also include an operating system and data, etc., and the storage method may be short-term storage or permanent storage. Among them, the operating system may include Windows, Unix, Linux, etc. The data may include, but is not limited to, update information of the application.

[0143] In some embodiments, the terminal may also include a display screen, an input and output interface, a communication interface, a sensor, a power supply, and a communication bus.

[0144] Those skilled in the art will understand that Figure 7 The structure shown in the figure does not constitute a limitation on the terminal, and may include more or fewer components than those shown in the figure.

[0145] A non-volatile storage medium provided in an embodiment of the present application is introduced below. The non-volatile storage medium described below can be cross-referenced with other embodiments described herein.

[0146] A non-volatile storage medium for storing a computer program, wherein the computer program, when executed by a processor, implements the model memory usage optimization method disclosed in the above-mentioned embodiment. The non-volatile storage medium is a computer-readable non-volatile storage medium, which, as a carrier for resource storage, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system, a computer program and data, etc., and the storage method can be temporary storage or permanent storage.

[0147] A computer program product provided in an embodiment of the present application is introduced below. The computer program product described below can be cross-referenced with other embodiments described in this document.

[0148] A computer program product includes a computer program / instruction, which implements the steps of the aforementioned disclosed model memory usage optimization method when executed by a processor.

[0149] A heterogeneous computing system provided in an embodiment of the present application is introduced below. The heterogeneous computing system described below can be referenced to other embodiments described in this document.

[0150] An embodiment of the present application discloses a heterogeneous computing power system, including: a client, a control device and multiple heterogeneous computing power devices; the control device is used to collect inference requests of pre-trained models sent by the client, and select a target heterogeneous computing power device where the pre-trained model is located, and forward the inference request to the target heterogeneous computing power device; the target heterogeneous computing power device is used to receive the inference request; using a first strategy to extract memory occupancy information of the inference result corresponding to the inference request from the inference request, using a second strategy to generate memory occupancy information of the inference result corresponding to the inference request according to the inference request, and obtaining at least two memory occupancy information; predicting the maximum memory occupancy information of the inference result according to its own current remaining memory space and the maximum value of at least two memory occupancy information; determining the memory occupancy range of the inference result according to the maximum value and the maximum memory occupancy information.

[0151] In one embodiment, a control device collects device operation information of multiple heterogeneous computing devices in real time; accordingly, a target heterogeneous computing device with the largest remaining memory space and an operation performance greater than a target value is selected according to the device operation information.

[0152] Among them, for more specific working processes of each device in this embodiment, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0153] It can be seen that this embodiment provides a heterogeneous computing power system that can allocate appropriate heterogeneous computing power to each pre-trained model inference request according to the real-time memory usage of the heterogeneous computing power, avoid idle computing power and waste of resources, and increase the number of responding inference requests without the user's perception, thereby saving the memory of the heterogeneous computing system.

[0154] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0155] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of non-volatile storage medium known in the art.

[0156] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A method for optimizing model memory usage, characterized in that: include: Receive inference requests for pre-trained models; Extracting memory occupancy information of the inference result corresponding to the inference request from the inference request using a first strategy, and generating memory occupancy information of the inference result corresponding to the inference request according to the inference request using a second strategy, to obtain at least two memory occupancy information; The second strategy can control the reasoning quality of the reasoning result; Predicting the maximum memory occupancy information of the inference result according to the current remaining memory space of the target heterogeneous computing device where the pre-trained model is located and the maximum value of the at least two memory occupancy information; A memory occupancy range of the inference result is determined according to the maximum value and the maximum memory occupancy information.

2. The method according to claim 1, characterized in that The first strategy includes: at least one rule matching strategy and at least one model generation strategy; Accordingly, extracting memory usage information of the inference result corresponding to the inference request from the inference request using the first strategy includes: Performing field matching on the inference request using the at least one rule matching strategy to extract a minimum number of characters set in the inference request, and using the minimum number of characters or a memory length obtained by the minimum number of characters as memory occupancy information; Predicting the minimum number of characters of the inference result by using the at least one model generation strategy, and using the minimum number of characters or a memory length obtained by the minimum number of characters as memory occupancy information; Accordingly, using the second strategy to generate memory usage information of the inference result corresponding to the inference request according to the inference request includes: The inference request is input into a preset target model so that the preset target model predicts the minimum number of characters of the inference result under the premise of controlling the inference quality of the inference result, and uses the minimum number of characters or the memory length obtained by the minimum number of characters as memory occupancy information.

3. The method according to claim 1, characterized in that Predicting the maximum memory occupancy information of the inference result according to the current remaining memory space where the pre-trained model is located and the maximum value of the at least two memory occupancy information, including: Set memory thresholds and adjustment parameter values; Constructing a target formula based on the current remaining memory space, the maximum value, the memory threshold value and the adjustment parameter; Calculating the maximum number of characters of the inference result using the target formula; The maximum number of characters or the maximum memory length obtained from the maximum number of characters is used as the maximum memory occupancy information.

4. The method according to claim 3, characterized in that The target formula is: , L represents the maximum number of characters, K represents the maximum value, α represents the adjustment parameter, M represents the memory threshold value, and m represents the current remaining memory space. Indicates the round-up symbol.

5. The method according to claim 1, characterized in that After determining the memory usage range of the inference result according to the maximum value and the maximum memory usage information, the method further includes: Building model prompt information based on the inference request and the memory usage range; The model prompt information is input into the pre-trained model so that the pre-trained model outputs the inference result according to the memory occupancy range in the target heterogeneous computing power device.

6. The method according to claim 5, characterized in that Also includes: Detecting actual memory usage information of the inference result; If the actual memory occupancy information is greater than the maximum memory occupancy information, after changing the at least two prediction strategies, the steps of extracting the memory occupancy information of the inference result corresponding to the inference request from the inference request using the first strategy, and generating the memory occupancy information of the inference result corresponding to the inference request according to the inference request using the second strategy, to obtain at least two memory occupancy information and subsequent other steps.

7. The method according to claim 6, characterized in that Also includes: If the actual memory occupancy information is not greater than the maximum memory occupancy information, the inference result is output.

8. The method according to any one of claims 1 to 7, characterized in that: The process of selecting the target heterogeneous computing power device includes: In a heterogeneous computing power system, querying an optional heterogeneous computing power device storing the pre-trained model; A heterogeneous computing power device with the largest remaining memory space and an operating performance greater than a target value is selected from the optional heterogeneous computing power devices as the target heterogeneous computing power device.

9. The method according to claim 8, characterized in that In a heterogeneous computing power system, querying an optional heterogeneous computing power device storing the pre-trained model includes: Querying a list of models stored in each heterogeneous computing device in the heterogeneous computing system; Query the model identification information of the pre-trained model in the model list.

10. The method according to any one of claims 1 to 7, characterized in that: Receive inference requests for pre-trained models, including: Receive the inference request distributed by the control device in the heterogeneous computing system.

11. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute the computer program to implement the method according to any one of claims 1 to 10.

12. A non-volatile storage medium, characterized in that: Used to store a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 10 is implemented.

13. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instructions are executed by a processor, the method according to any one of claims 1 to 10 is implemented.

14. A heterogeneous computing system, characterized in that: include: Client, control device and multiple heterogeneous computing devices; The control device is used to collect the inference request of the pre-trained model sent by the client, select the target heterogeneous computing power device where the pre-trained model is located, and forward the inference request to the target heterogeneous computing power device; The target heterogeneous computing device is used to receive the inference request; Extracting memory occupancy information of the inference result corresponding to the inference request from the inference request using a first strategy, and generating memory occupancy information of the inference result corresponding to the inference request according to the inference request using a second strategy, to obtain at least two memory occupancy information; The second strategy can control the reasoning quality of the reasoning result; Predicting the maximum memory occupancy information of the inference result according to the current remaining memory space of the device and the maximum value of the at least two memory occupancy information; A memory occupancy range of the inference result is determined according to the maximum value and the maximum memory occupancy information.

15. The system according to claim 14, characterized in that The control device collects the device operation information of the multiple heterogeneous computing devices in real time; accordingly, the target heterogeneous computing device with the largest remaining memory space and an operation performance greater than a target value is selected according to the device operation information.

Citation Information

Patent Citations

  • Cloud computing application memory management method based on real-time content prediction and historical resource occupation

    CN114461538A

  • Optimization method and system for dynamic reasoning memory allocation based on predictor

    CN118227336A