Model reasoning method, device and system, storage medium and program product
Through virtual video memory technology and block optimization strategy, the context length limitation caused by insufficient video memory of the large model inference service is solved, and the effect of increasing the maximum context length without increasing hardware costs is achieved.
Patent Information
- Application Number
- CN202410865956.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-28
- Publication Date
- 2024-11-01
AI Technical Summary
In multi-user scenarios, the large-scale inference service uses too much GPU memory, resulting in the use of video memory exceeding the total physical memory, limiting the maximum context length supported by the inference service.
Virtual video memory technology is used to save and update the specified matrix chunking in the system's memory, and load it into physical video memory when needed. The use of video memory is optimized through chunking and first-in-first-out strategies to avoid insufficient video memory.
Without increasing GPU hardware costs, the maximum context length supported by the big model inference service is extended, improving system performance and efficiency.
Smart Images

Figure CN118886500A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to the field of data processing, and more specifically, to a model reasoning method, device, system, storage medium, and program product. Background Art
[0002] The GPU memory occupied by the large model inference service in the production environment is mainly composed of model weights, KV Cache, intermediate results and input data. Among them, KV Cache is indispensable for the performance considerations of the large model inference service in multi-user scenarios (the core transformer library is enabled by default).
[0003] The video memory occupied by the large model inference service will increase linearly with the maximum context length (contextlength) (maximum length of input + output) supported by the inference service, and the larger the model parameters, the faster the increase. The reason for this phenomenon is that when using the GPU to calculate the inference of a new token, all the data used must be saved in the GPU's video memory before it can be performed. As the question + answer (context length) of an inference request becomes longer and longer, the GPU video memory occupied becomes larger and larger, which will eventually cause the video memory usage to exceed the total physical video memory, thereby limiting the maximum context length that the inference service can support when the hardware resources (total GPU video memory) are determined. Summary of the invention
[0004] An exemplary embodiment of the present disclosure is to provide a model reasoning method, device, system, storage medium and program product, which can increase the maximum context length that can be supported by large model reasoning services that are originally limited by the physical video memory capacity without increasing the GPU hardware cost.
[0005] According to an exemplary embodiment of the present disclosure, a model inference method is provided, comprising: in a process of performing inference using a target model, in response to insufficient free physical video memory of a system executing the target model inference, partial matrix blocks of at least one specified matrix are moved out of the physical video memory of the system; in a case where a target matrix block required for inference calculation is not stored in the physical video memory, the target matrix block is loaded from the virtual video memory of the system to the physical video memory; wherein each specified matrix includes a plurality of matrix blocks; wherein the target matrix block is a matrix block of the specified matrix; wherein the virtual video memory is implemented by the internal memory of the system and is used to store and update the specified matrix.
[0006] Optionally, the specified matrix includes at least one of the following items: K matrix, V matrix, Q matrix.
[0007] Optionally, in response to insufficient free physical video memory of the system, the step of dividing a portion of at least one specified matrix into blocks and moving the blocks out of the physical video memory of the system includes: in response to the free physical video memory being unable to meet current physical video memory allocation requirements, dividing a portion of at least one specified matrix into blocks and moving the blocks out of the physical video memory.
[0008] Optionally, in response to the idle physical video memory being unable to meet the current physical video memory allocation demand, the step of moving a partial matrix block of at least one designated matrix out of the physical video memory of the system includes: in response to the idle physical video memory being unable to meet the current physical video memory allocation demand for the target matrix block, moving a partial matrix block of the designated matrix to which the target matrix block belongs out of the physical video memory.
[0009] Optionally, in response to insufficient free physical video memory of the system, the step of dividing a portion of at least one designated matrix into blocks and moving the blocks out of the physical video memory of the system includes: in response to free physical video memory being lower than a first preset proportion of the total physical video memory, dividing a portion of at least one designated matrix into blocks and moving the blocks out of the physical video memory of the system so that the free physical video memory is higher than a second preset proportion of the total physical video memory.
[0010] Optionally, it also includes: if the idle physical video memory meets the preset conditions, writing the data increment of the specified matrix that needs to be updated into the physical video memory and the virtual video memory; if the idle physical video memory does not meet the preset conditions, writing the data increment of the specified matrix that needs to be updated only into the virtual video memory.
[0011] Optionally, in response to insufficient free physical video memory of the system, the step of dividing a portion of at least one specified matrix into blocks and moving the blocks out of the physical video memory of the system includes: in response to insufficient free physical video memory of the system, dividing a portion of at least one specified matrix into blocks and moving the blocks out of the physical video memory according to a first-in-first-out removal strategy.
[0012] According to an exemplary embodiment of the present disclosure, a model inference device is provided, comprising: a removal unit configured to, in a process of using a target model for reasoning, in response to insufficient free physical video memory of a system executing the target model reasoning, remove partial matrix blocks of at least one specified matrix out of the physical video memory of the system; a loading unit configured to load the target matrix blocks required for the inference calculation from the virtual video memory of the system to the physical video memory if the target matrix blocks are not stored in the physical video memory; wherein each specified matrix includes a plurality of matrix blocks; wherein the target matrix blocks are matrix blocks of the specified matrix; wherein the virtual video memory is implemented by the memory of the system and is used to store and update the specified matrix.
[0013] Optionally, the specified matrix includes at least one of the following items: K matrix, V matrix, Q matrix.
[0014] Optionally, the removal unit is configured to: in response to the idle physical video memory being unable to meet the current physical video memory allocation requirement, divide a part of at least one designated matrix into blocks and remove the blocks from the physical video memory.
[0015] Optionally, the removal unit is configured to: in response to the idle physical video memory being unable to meet the current physical video memory allocation requirement for the target matrix block, remove part of the matrix blocks of the designated matrix to which the target matrix block belongs from the physical video memory.
[0016] Optionally, the removal unit is configured to: in response to the free physical video memory being lower than a first preset proportion of the total physical video memory, divide a portion of at least one specified matrix into blocks and remove the blocks from the physical video memory of the system so that the free physical video memory is higher than a second preset proportion of the total physical video memory.
[0017] Optionally, it also includes: an update unit, configured to: if the free physical video memory meets the preset conditions, write the data increment of the specified matrix that needs to be updated into the physical video memory and the virtual video memory; if the free physical video memory does not meet the preset conditions, write the data increment of the specified matrix that needs to be updated only into the virtual video memory.
[0018] Optionally, the removal unit is configured to: in response to insufficient free physical video memory of the system, according to a first-in-first-out removal strategy, divide a portion of at least one designated matrix into blocks and remove the blocks from the physical video memory.
[0019] According to an exemplary embodiment of the present disclosure, a system is provided, including at least one computing device and at least one storage device storing instructions, wherein when the instructions are executed by the at least one computing device, the at least one computing device is prompted to perform the model reasoning method as described above.
[0020] According to an exemplary embodiment of the present disclosure, a computer-readable storage medium storing instructions is provided, wherein when the instructions are executed by at least one computing device, the at least one computing device is prompted to perform the model reasoning method as described above.
[0021] According to an exemplary embodiment of the present disclosure, a computer program product is provided, comprising computer executable instructions, wherein the computer executable instructions implement the model reasoning method as described above when executed by at least one processor.
[0022] According to the model inference method, device, system, storage medium and program product of the exemplary embodiments of the present disclosure, it is possible to utilize virtual video memory technology to timely move data that will not be used for inference calculations in a short period of time out of the physical video memory during the large model inference process without the user's perception, and then load it back into the physical video memory to participate in the calculation when needed, thereby increasing the maximum context length that can be supported by the large model inference service, which was originally limited by the physical video memory capacity, without increasing the GPU hardware cost.
[0023] Additional aspects and / or advantages of the present general inventive concept will be set forth in part in the following description and in part will be apparent from the description or may be learned through practice of the present general inventive concept. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The above and other objects and features of the exemplary embodiments of the present disclosure will become more apparent through the following description in conjunction with the accompanying drawings which exemplarily illustrate the embodiments, in which:
[0025] Figure 1 shows an example of a memory hierarchy;
[0026] Figure 2 A flowchart showing a model reasoning method according to an exemplary embodiment of the present disclosure is shown;
[0027] Figure 3 Show an example of the standard Attention calculation formula;
[0028] Figure 4 Shows an example of decomposing the standard Attention calculation formula using the idea of block division;
[0029] Figure 5 An example of a pseudo code of the Attention calculation process after adding virtual video memory according to an exemplary embodiment of the present disclosure is shown;
[0030] Figure 6 A structural block diagram of a model reasoning device according to an exemplary embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0031] Reference will now be made in detail to the embodiments of the present disclosure, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to like parts throughout. The embodiments will be described below with reference to the drawings in order to explain the present disclosure.
[0032] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.
[0033] It should be noted that the phrase "at least one of the items" in the present disclosure includes three types of parallel situations: "any one of the items", "a combination of any number of the items", and "all of the items". For example, "including at least one of A and B" includes the following three parallel situations: (1) including A; (2) including B; (3) including A and B. Another example is "executing at least one of step 1 and step 2" which means the following three parallel situations: (1) executing step 1; (2) executing step 2; (3) executing step 1 and step 2.
[0034] The present disclosure relates to large model reasoning and virtual memory technology, and may involve large model application products (for example, including private deployment and cloud forms). The present disclosure proposes a method for increasing the maximum context length supported by large model reasoning services by using virtual memory technology without increasing GPU hardware costs (large model reasoning requires expensive GPU computing power) and without changing model accuracy.
[0035] Key Terms:
[0036] GPU: Graphics Processing Unit, in Chinese, is the core component of the graphics card but is not equivalent to the graphics card. It has a multi-core high-performance architecture, designed for large-scale parallel processing of complex and data-intensive computing tasks, and is widely used in many fields such as games, scientific computing, artificial intelligence, virtual reality, and deep learning. It is an indispensable hardware for the implementation of large-scale model applications today.
[0037] Virtual video memory technology: GPUs are used in combination with video memory (GPU memory, DDR6 / HBM, etc.) that is faster but more expensive than traditional memory (DDR4 / 5memory used by CPU) to form a graphics card (which can be plugged into the server motherboard), and the video memory itself does not have the scalability of traditional memory (the video memory capacity on a graphics card cannot be changed). In the context of large-scale applications that require increasingly higher video memory capacity, virtual video memory technology has been proposed to use the larger traditional memory DRAM (memory used by CPU) installed in the server of the GPU as an extension of the video memory, so that the graphics card appears to have a larger video memory than the physical video memory, so it is called virtual video memory.
[0038] Maximum context length: refers to the maximum input + output length that a large model can handle in processing an inference request. The part exceeding the maximum context length will be truncated.
[0039] KV Cache: For the Causal Model, the generation process is the output of tokens one by one. The output of each token depends only on the previous question (prompt) and the generated tokens. Therefore, the core idea of KV-Cache is that each time a new token is generated, there is no need to repeatedly calculate the attention of the generated token and all previous tokens. Instead, the previously calculated values stored in the video memory are used to generate new tokens using the incremental calculation method, and the attention calculated during the reasoning process of the new token (Attention(Q,K,V)=Softmax(Q·K′ / √(d))·V) is appended to the K matrix and V matrix in the video memory to become the new K matrix and V matrix. This is the origin of the name of KV Cache.
[0040] The present disclosure takes into account that, unlike several other modules that occupy video memory, the video memory occupied by KV Cache increases linearly with the maximum context length (context length) supported by the inference service (maximum length of input + output), and the larger the model parameters, the faster the increase. The reason for this phenomenon is that when using the GPU to calculate and infer new tokens, all the data used must have been saved in the GPU's video memory before it can be performed, of which the model weights, K matrix and V matrix account for a large proportion. As the question + answer (context length) of an inference request becomes longer and longer, the GPU video memory occupied by the K matrix and the V matrix becomes larger and larger, which eventually causes the video memory usage to exceed the total physical video memory, thereby limiting the maximum context length that the inference service can support when the hardware resources (total GPU video memory) are determined.
[0041] Figure 1 An example of a memory hierarchy is shown. Figure 1 As shown in the figure, physical video memory generally refers to the GPU HBM in the middle, where the KV Cache is located. SRAM is the on-chip memory of the GPU chip, mainly used for cache and a small number of special storage units. When the hardware starts computing, it will first load data from the video memory (HBM) to the on-chip (SRAM), perform the calculation on the chip, and then write the calculation results back to the video memory.
[0042] Therefore, existing attention optimization algorithms (such as flash attention 1 / 2) are designed for HBM-SRAM and do not consider the situation of insufficient physical video memory. There is also an attention optimization algorithm (paged attention) that deals with insufficient video memory when processing multiple concurrent requests at the same time: directly abandon some requests and complete the other requests as much as possible, so it cannot solve the problem of insufficient video memory when processing a single request.
[0043] In order to solve the above problems, the method proposed in this disclosure is: using virtual video memory technology, in the process of large model inference, without the user's perception, timely move the data that will not be used for calculation in a short period of time (for example, K matrix blocks, V matrix blocks, Q matrix blocks) out of the physical video memory, and load it back into the physical video memory to participate in the calculation when needed, thereby increasing the maximum context length that can be supported by the large model inference service that was originally limited by the physical video memory capacity without increasing the GPU hardware cost. Figures 2 to 6 Provide detailed explanation.
[0044] Figure 2 A flowchart of a model inference method according to an exemplary embodiment of the present disclosure is shown.
[0045] Reference Figure 2 In step S100, during the process of using the target model for reasoning, in response to insufficient free physical video memory of the system executing the target model reasoning, a portion of at least one specified matrix is divided into blocks and moved out of the physical video memory of the system, thereby releasing free physical video memory.
[0046] Each designated matrix includes a plurality of matrix blocks. It should be understood that the present disclosure does not limit the specific division method of the matrix blocks.
[0047] As an exemplary embodiment, the specified matrix may include but is not limited to at least one of the following items: K matrix, V matrix, Q matrix. Here, K matrix, V matrix, Q matrix are the K matrix, V matrix, Q matrix involved in Attention.
[0048] As an exemplary embodiment, step S100 may include: in response to insufficient free physical video memory of the system, according to a first-in-first-out removal strategy, dividing a portion of at least one designated matrix into blocks and removing the blocks from the physical video memory.
[0049] As an exemplary embodiment, the step of moving a partial matrix block of at least one designated matrix out of the physical video memory may include: directly discarding a partial matrix block of the at least one designated matrix.
[0050] Two exemplary embodiments of determining that free physical video memory is insufficient are given below.
[0051] As a first exemplary embodiment, step S100 may include: in response to the idle physical video memory being unable to meet the current physical video memory allocation demand, partially matrix blocks of at least one designated matrix are moved out of the physical video memory. In other words, when physical video memory needs to be allocated for data and the idle physical video memory is insufficient for allocation, partially matrix blocks of at least one designated matrix are moved out of the physical video memory to release sufficient idle physical video memory for allocation to the data. That is, in this manner, the elimination of matrix blocks of the designated matrix is only passively triggered when insufficient physical video memory is found when physical video memory needs to be allocated.
[0052] Further, as an exemplary embodiment, step S100 may include: in response to the idle physical video memory being unable to meet the current physical video memory allocation requirement for the target matrix block, moving part of the matrix blocks of the designated matrix to which the target matrix block belongs out of the physical video memory.
[0053] The target matrix block is a matrix block of a specified matrix. For example, the target matrix block can be any matrix block of any specified matrix.
[0054] As an example, if the target matrix block is a matrix block of the K matrix, in response to the idle physical video memory being unable to meet the current physical video memory allocation requirement for the target matrix block, another matrix block of the K matrix is moved out of the physical video memory. For example, the other matrix block may be determined and moved out according to a first-in-first-out removal strategy.
[0055] As a second exemplary embodiment, step S100 may include: in response to the idle physical video memory being lower than a first preset ratio of the total physical video memory, partially partitioning at least one designated matrix out of the physical video memory, so that the idle physical video memory is higher than a second preset ratio of the total physical video memory. That is, an "active" triggering method in this method: for example, an independent background monitoring process, after the idle physical video memory is lower than a certain ratio (such as 10% of the total physical video memory), actively starts to move out the matrix partitions of the designated matrix in the physical video memory using, for example, a FIFO strategy, so as to save time for subsequent physical video memory allocation.
[0056] In step S200, when the target matrix block required for the inference calculation is not stored in the physical video memory, the target matrix block is loaded from the virtual video memory into the physical video memory.
[0057] The virtual video memory is implemented by the system memory and is used to save and update the specified matrix. In this disclosure, for ease of understanding, the system memory portion used as video memory extension is referred to as virtual video memory, that is, the video memory of the GPU includes virtual video memory and physical video memory.
[0058] As an exemplary embodiment, when the target matrix block required for the inference calculation is not saved in the physical video memory (for example, the target matrix block needs to be loaded into the on-chip memory SRAM for the upcoming inference calculation, but the target matrix block is not saved in the physical video memory), it is necessary to allocate physical video memory for the target matrix block, and in response to the idle physical video memory being unable to meet the current physical video memory allocation demand for the target matrix block, some matrix blocks of the specified matrix to which the target matrix block belongs are moved out of the physical video memory (i.e., executing step S100), and then, the target matrix block is loaded from the virtual video memory to the physical video memory (i.e., executing step S200), and then the target matrix block is loaded from the physical video memory to the SRAM to participate in the inference calculation.
[0059] As an exemplary embodiment, during the inference calculation process, whenever the data increment of the designated matrix that needs to be updated is calculated, the designated matrix is updated, and the specific updating method may be writing in an append manner.
[0060] As an exemplary embodiment, the model inference method according to the exemplary embodiments of the present disclosure may also include: if the free physical video memory meets the preset conditions (for example, sufficient), the data increment of the specified matrix that needs to be updated is written to the physical video memory and the virtual video memory; if the free physical video memory does not meet the preset conditions (for example, insufficient), the data increment of the specified matrix that needs to be updated is written only to the virtual video memory.
[0061] The present disclosure takes into account that in the process of calculating attention, the K matrix / V matrix does not have to be completely present in the GPU memory at the same time. The attention calculation process can use the idea of "divide and conquer", that is, the K matrix and the V matrix are first divided into blocks (or slices), and independent calculations are performed on each of them, and finally the intermediate results are summarized into the final result.
[0062] Reference Figure 3 , the standard Attention calculation formula is as follows:
[0063] Where S = QK T ,P=softmax(S).
[0064] Reference Figure 4 , the calculation of Attention can be decomposed into the following blocks by using the idea of block division: Figure 4 The process shown:
[0065] First, cut the Q matrix into T r Blocks, each block is of length B r , use Q i Indicates; then K T Both matrices T and V are cut into c Blocks, each block is of length B c , using K T j and V j By parallel computing S ij =Q i *K T j , P ij =softmax(S ij ), O ij =P ij *V j , and the output O of each block is obtained ij , and finally sum them together to get the output O.
[0066] In the process of large model inference, there are actually two stages: prefill and decode. Prefill is to process the prompt (that is, the input "question" given to the large model in the request). The prefill process will convert the token in the question into the above-mentioned Q matrix, K matrix, and V matrix for calculation, and finally convert the result O into the first generated Token.
[0067] After the first Token is generated, the decoding phase begins. Due to the existence of K / V cache, the generation of each new Token no longer requires the calculation of the K matrix and V matrix corresponding to all previous Tokens. Instead, it only needs to incrementally update the K matrix and V matrix in the previous Token generation process and write them into the K / V Cache to complete the Attention calculation and thus complete the generation of the new Token.
[0068] About K Matrix and V Matrix
[0069] The present disclosure proposes to use virtual video memory technology for the K matrix and the V matrix. When the physical video memory is insufficient, the K matrix blocks / V matrix blocks that will not be used for calculation in a short time are moved out of the physical video memory to obtain more free physical video memory. In addition, the complete K matrix / V matrix is saved using the system memory (DRAM), so that it can be loaded back into the physical video memory to participate in the calculation when needed.
[0070] Considering that this method will have an impact on performance, because moving the K matrix and the V matrix back and forth between the GPU video memory and the system memory DRAM requires additional data transmission time, resulting in a slower token generation speed, the present disclosure further uses the following two improvement methods to reduce the impact on performance.
[0071] An improved method: It is observed that all attention calculation processes traverse the K matrix blocks / V matrix blocks in order. Therefore, when the physical video memory is insufficient and the K matrix blocks / V matrix blocks in the physical video memory need to be removed, the elimination strategy adopted is FIFO (first in, first out), and the K matrix and V matrix are managed independently to minimize the data exchange between the physical video memory and the system memory.
[0072] Another improvement method: Observe that the update of K matrix / V matrix after each new token is generated is an append operation, and the related data of this token in K matrix / V matrix will not change in the subsequent calculation process, which means that the update of K matrix block / V matrix block is a "write-once" write mode. Therefore, the management of virtual video memory does not need to consider traditional complex issues such as data consistency and in-place update, thereby simplifying the logic when elimination occurs: K matrix block / V matrix block removed from video memory can be directly discarded without writing back to system memory; only after the update of the new K matrix / V matrix is completely calculated after each token is generated, it is written to the system memory in an append manner.
[0073] About Q Matrix
[0074] The present disclosure also proposes that when the physical video memory is insufficient, the Q matrix blocks that will no longer be used for inference calculations will be moved out of the physical video memory to obtain more free physical video memory. However, it is worth noting that, unlike the K matrix blocks and the V matrix blocks, the moved Q matrix blocks will no longer participate in inference calculations and therefore do not need to be loaded back into the physical video memory.
[0075] Figure 5 An example of a pseudo code of an Attention calculation process after adding a virtual video memory according to an exemplary embodiment of the present disclosure is shown.
[0076] As you can see, the Attention calculation logic has not changed, only the preparation of the calculation data has been modified. The original algorithm requires that all the input and output data of the calculation exist in the physical video memory. However, after adding virtual video memory, according to the needs of the specific calculation steps, when the video memory is insufficient, the Q matrix block / K matrix block / V matrix block that will not be used in a short time will be moved out of the video memory. The following functions are explained in detail.
[0077] vAllocate() / vFree()
[0078] The former will allocate enough physical video memory for the target variable. If the physical video memory is insufficient, the matrix blocks occupying the physical video memory in the K matrix / V matrix will be eliminated with the FIFO strategy; the latter will directly release the physical video memory of the target variable.
[0079] vLoad()
[0080] This method will load the target block of Q matrix / K matrix / V matrix into the on-chip memory SRAM for the upcoming calculation. There are two cases: if the target block is already in the physical video memory, the data block is directly loaded from the physical video memory to the SRAM; if the target block is not in the physical video memory (because it is removed by the virtual video memory elimination mechanism), additional operations are required: first perform vAllocate() to allocate physical video memory for the target block. If there is no free video memory, other blocks of the same type as the target block are removed using the FIFO strategy (which means that the allocation of a certain K matrix block will only eliminate another K matrix block, but will not eliminate the V matrix block); then, read the target block from the system memory DRAM into the physical video memory. Then load the target block from the physical video memory to SRAM.
[0081] AppendKVcache()
[0082] This method will first incrementally write the K matrix / V matrix data that needs to be updated into the system memory DRAM, and then divide it into two cases: if the physical video memory is sufficient, the updated data of the K matrix / V matrix will be incrementally written into the K / V Cache in the physical video memory to avoid reading the physical video memory from DRAM again later; if the physical video memory is insufficient, no additional operation will be performed.
[0083] ComputeOij()
[0084] In this method, since there are intermediate calculation results, the physical video memory needs to be stored and read, so vAllocate() / vFree() is also used, but the logic is consistent with the above vAllocate() / vFree(), so it is not repeated.
[0085] Figure 6A structural block diagram of a model reasoning device according to an exemplary embodiment of the present disclosure is shown.
[0086] like Figure 6 As shown, the model reasoning device according to the exemplary embodiment of the present disclosure includes: a removal unit 100 and a loading unit 200 .
[0087] Specifically, the removal unit 100 is configured to, in the process of using the target model for reasoning, in response to insufficient free physical video memory of the system executing the target model reasoning, divide a portion of at least one specified matrix into blocks and remove the blocks from the physical video memory of the system.
[0088] The loading unit 200 is configured to load the target matrix block from the virtual video memory of the system to the physical video memory when the target matrix block required for the inference calculation is not stored in the physical video memory.
[0089] Each specified matrix includes a plurality of matrix blocks.
[0090] The target matrix block is a matrix block of the specified matrix.
[0091] The virtual display memory is implemented by the memory of the system and is used to store and update the specified matrix.
[0092] As an exemplary embodiment, the designated matrix may include at least one of the following items: a K matrix, a V matrix, and a Q matrix.
[0093] As an exemplary embodiment, the removal unit 100 may be configured to: in response to the idle physical video memory being unable to meet the current physical video memory allocation requirement, divide a portion of at least one designated matrix into blocks and remove the blocks from the physical video memory.
[0094] As an exemplary embodiment, the removal unit 100 may be configured to: in response to the idle physical video memory being unable to meet the current physical video memory allocation requirement for the target matrix block, remove part of the matrix blocks of the designated matrix to which the target matrix block belongs out of the physical video memory.
[0095] As an exemplary embodiment, the removal unit 100 may be configured to: in response to the free physical video memory being lower than a first preset proportion of the total physical video memory, divide a portion of at least one specified matrix into blocks and remove the blocks from the physical video memory of the system so that the free physical video memory is higher than a second preset proportion of the total physical video memory.
[0096] As an exemplary embodiment, the removal unit 100 may be configured to: in response to insufficient free physical video memory of the system, according to a first-in-first-out removal strategy, divide a portion of at least one designated matrix into blocks and remove them from the physical video memory.
[0097] As an exemplary embodiment, the model inference device according to the exemplary embodiment of the present disclosure may also include: an update unit (not shown), the update unit being configured to: if the idle physical video memory meets a preset condition, write the data increment of the specified matrix that needs to be updated into the physical video memory and the virtual video memory; if the idle physical video memory does not meet the preset condition, write the data increment of the specified matrix that needs to be updated only into the virtual video memory.
[0098] It should be understood that the specific implementation of the model reasoning device according to the exemplary embodiment of the present disclosure can be referred to in conjunction with Figures 2 to 5 The relevant specific implementation methods described are implemented and will not be repeated here.
[0099] The units included in the model reasoning device according to the exemplary embodiment of the present disclosure may be configured as software, hardware, firmware or any combination of the above items to perform specific functions. For example, these units may correspond to dedicated integrated circuits, pure software codes, or modules that combine software and hardware. In addition, one or more functions implemented by these units may also be uniformly executed by components in physical entity devices (e.g., processors, clients, or servers, etc.).
[0100] It should be understood that the model reasoning method according to the exemplary embodiments of the present disclosure can be implemented by a program recorded on a computer-readable medium. For example, according to the exemplary embodiments of the present disclosure, a computer-readable medium can be provided, wherein the computer-readable medium records a program for executing the model reasoning method as described in the above exemplary embodiments.
[0101] The computer program in the computer-readable medium can be run in an environment deployed in a computer device such as a client, a host, an agent device, a server, etc. It should be noted that the computer program can also be used to perform additional steps in addition to the above steps or perform more specific processing when performing the above steps. The contents of these additional steps and further processing have been referred to in Figures 2 to 5 The description has been made, and will not be repeated here to avoid repetition.
[0102] It should be noted that the model reasoning device according to the exemplary embodiment of the present disclosure can completely rely on the operation of the computer program to realize the corresponding functions, that is, each unit corresponds to each step in the functional architecture of the computer program, so that the entire system is called through a special software package (for example, lib library) to realize the corresponding function.
[0103] On the other hand, the various units included in the model reasoning device according to the exemplary embodiment of the present disclosure may also be implemented by hardware, software, firmware, middleware, microcode, or any combination thereof. When implemented by software, firmware, middleware, or microcode, the program code or code segment for performing the corresponding operation may be stored in a computer-readable medium such as a storage medium, so that the processor can perform the corresponding operation by reading and running the corresponding program code or code segment.
[0104] For example, an exemplary embodiment of the present disclosure may also be implemented as a computing device, which includes a storage component and a processor, wherein a set of computer executable instructions is stored in the storage component, and when the set of computer executable instructions is executed by the processor, the model reasoning method described in the above exemplary embodiment is executed.
[0105] Specifically, the computing device may be deployed in a server or client, or may be deployed on a node device in a distributed network environment. In addition, the computing device may be a PC, a tablet device, a personal digital assistant, a smart phone, a web application, or other device capable of executing the above instruction set.
[0106] Here, the computing device is not necessarily a single computing device, but may be any device or circuit collection that can execute the above instructions (or instruction sets) individually or jointly. The computing device may also be part of an integrated control system or system manager, or may be configured as a portable electronic device that is interconnected with a local or remote (e.g., via wireless transmission) interface.
[0107] In the computing device, the processor may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller or a microprocessor. By way of example and not limitation, the processor may also include an analog processor, a digital processor, a microprocessor, a multi-core processor, a processor array, a network processor, etc.
[0108] According to the exemplary embodiment of the present disclosure, some operations described in the model reasoning method can be implemented by software, some operations can be implemented by hardware, and furthermore, these operations can also be implemented by a combination of software and hardware.
[0109] The processor may execute instructions or codes stored in one of the storage components, which may also store data. Instructions and data may also be sent and received over a network via a network interface device, which may employ any known transmission protocol.
[0110] The storage component may be integrated with the processor, for example, RAM or flash memory is arranged within an integrated circuit microprocessor, etc. In addition, the storage component may include a separate device, such as an external disk drive, a storage array, or any other storage device that can be used by a database system. The storage component and the processor may be operatively coupled, or may communicate with each other, such as through an I / O port, a network connection, etc., so that the processor can read files stored in the storage component.
[0111] In addition, the computing device may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, a mouse, a touch input device, etc.) All components of the computing device may be connected to each other via a bus and / or a network.
[0112] The operations involved in the model reasoning method according to the exemplary embodiment of the present disclosure can be described as various interconnected or coupled functional blocks or functional diagrams. However, these functional blocks or functional diagrams can be equally integrated into a single logical device or operate according to non-exact boundaries.
[0113] For example, as described above, a computing device according to an exemplary embodiment of the present disclosure may include a storage component and a processor, wherein a set of computer executable instructions is stored in the storage component, and when the set of computer executable instructions is executed by the processor, the model reasoning method described in the above exemplary embodiment is executed.
[0114] The above describes various exemplary embodiments of the present disclosure, and it should be understood that the above description is only exemplary and not exhaustive, and the present disclosure is not limited to the disclosed exemplary embodiments. Without departing from the scope and spirit of the present disclosure, many modifications and changes are obvious to those of ordinary skill in the art. Therefore, the scope of protection of the present disclosure should be based on the scope of the claims.
Claims
1. A model reasoning method, characterized in that: include: In the process of using the target model for reasoning, in response to insufficient free physical video memory of a system executing the target model reasoning, a portion of at least one specified matrix is divided into blocks and moved out of the physical video memory of the system; When the target matrix block required for the inference calculation is not stored in the physical video memory, loading the target matrix block from the virtual video memory of the system to the physical video memory; Wherein, each specified matrix includes a plurality of matrix blocks; Wherein, the target matrix block is the matrix block of the specified matrix; The virtual video memory is implemented by the memory of the system and is used to store and update the specified matrix.
2. The model reasoning method according to claim 1, characterized in that: The specified matrix includes at least one of the following items: a K matrix, a V matrix, and a Q matrix.
3. The model reasoning method according to claim 1, characterized in that: In response to insufficient free physical video memory of the system, the step of dividing a portion of at least one designated matrix into blocks and moving the blocks out of the physical video memory of the system comprises: In response to the idle physical video memory being unable to meet the current physical video memory allocation requirement, a portion of at least one designated matrix is divided into blocks and moved out of the physical video memory.
4. The model reasoning method according to claim 3, characterized in that: In response to the idle physical video memory being unable to meet the current physical video memory allocation requirement, the step of dividing a portion of at least one designated matrix into blocks and moving the blocks out of the physical video memory of the system comprises: In response to the idle physical video memory being unable to satisfy the current physical video memory allocation requirement for the target matrix block, a portion of matrix blocks of a designated matrix to which the target matrix block belongs is moved out of the physical video memory.
5. The model reasoning method according to claim 1, characterized in that: In response to insufficient free physical video memory of the system, the step of dividing a portion of at least one designated matrix into blocks and moving the blocks out of the physical video memory of the system comprises: In response to the free physical video memory being lower than a first preset ratio of the total physical video memory, a portion of at least one designated matrix is divided into blocks and moved out of the physical video memory of the system so that the free physical video memory is higher than a second preset ratio of the total physical video memory.
6. The model reasoning method according to claim 1, characterized in that: Also includes: If the idle physical video memory meets the preset condition, writing the data increment of the specified matrix to be updated into the physical video memory and the virtual video memory; If the free physical video memory does not meet the preset condition, the data increment of the designated matrix that needs to be updated is only written into the virtual video memory.
7. A model reasoning device, characterized in that: include: a removal unit configured to, in a process of using a target model for reasoning, in response to insufficient free physical video memory of a system for performing the target model reasoning, divide a portion of at least one specified matrix into blocks and remove the blocks from the physical video memory of the system; A loading unit configured to load the target matrix block required for inference calculation into the physical video memory from the virtual video memory of the system when the target matrix block required for inference calculation is not stored in the physical video memory; Wherein, each specified matrix includes a plurality of matrix blocks; Wherein, the target matrix block is the matrix block of the specified matrix; The virtual video memory is implemented by the memory of the system and is used to store and update the specified matrix.
8. A system comprising at least one computing device and at least one storage device storing instructions, wherein: When the instructions are executed by the at least one computing device, the at least one computing device is prompted to perform the model reasoning method according to any one of claims 1 to 6.
9. A computer-readable storage medium storing instructions, wherein: When the instructions are executed by at least one computing device, the at least one computing device is prompted to perform the model reasoning method according to any one of claims 1 to 6.
10. A computer program product comprising computer executable instructions, characterized in that: When the computer executable instructions are executed by at least one processor, the model reasoning method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Method and device for allocating GPU physical memories
CN113377545A
Data processing method, computing device and storage medium
CN116841918A
Tensor unloading method and device, computer equipment and storage medium
CN117130693A
Accelerated reasoning method and system for cognitive model question and answer prediction
CN117910576A
System and methods for adaptive multi-level cache allocation for kv store
US20170206164A1
Cited By
Processing method and device of reasoning request, storage medium and product
CN119621350A
