Inference acceleration method for artificial intelligence model and related system
By caching the key-value vectors of document fragment vectors in the key-value cache, the problem of long processing time in the RAG scheme is solved, achieving efficient inference acceleration and improving the efficiency of answering complex professional questions and the utilization of computing resources.
Patent Information
- Application Number
- CN202510653162.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2026-11-20
AI Technical Summary
Existing retrieval augmentation generation (RAG) schemes based on large language models are time-consuming when dealing with complex and specialized problems, especially as the length of the input lexical units increases, making it difficult to meet business needs.
By pre-caching the key-value vectors corresponding to the document fragment vectors of domain documents in the key-value cache, the forward calculation process of retrieval results in online question answering is replaced, thereby enabling parallel acquisition of question-related document fragment vectors and reducing the forward calculation steps in the reasoning process.
It significantly reduces reasoning time, improves reasoning performance, increases the efficiency of answering complex professional questions, and reduces the waste of computing resources.
Smart Images

Figure CN123140164A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence (AI) technology, and in particular to a method for accelerating inference of an AI model, an inference system, a cluster of computing devices, a computer-readable storage medium, and a computer program product. Background Technology
[0002] With the continuous development of artificial intelligence (AI) technology, especially the rapid development of large language models (LLM) represented by generative pre-trained transformers (GPT), more and more fields are beginning to apply various large models, including LLM.
[0003] LLMs can be trained on large amounts of text data. This text data typically covers many different topics and domains; therefore, LLMs usually possess broad knowledge, including general knowledge across many specialized fields. However, for highly specialized fields or advanced topics, LLMs may lack domain-specific knowledge, potentially leading to inaccurate or incomplete answers. For example, when faced with complex medical, legal, or engineering questions, the accuracy and comprehensiveness of LLM answers may fall short of those of experts in the corresponding fields. Furthermore, the knowledge possessed by an LLM is limited to the expiration date of its training data; therefore, an LLM may be unaware of the latest developments or research since that date.
[0004] For complex, knowledge-intensive tasks, a system based on a large model (such as an agent) can be built, combining external knowledge sources to complete the task. This helps alleviate the "illusion" problem of large models and improves the accuracy of responses. To this end, the industry has introduced the Retrieval Augmented Generation (RAG) scheme. RAG enhances the capabilities of large models by integrating retrieval mechanisms. RAG acts as a bridge, connecting numerous external knowledge sources to the large model, giving it more knowledge and context-awareness.
[0005] However, the RAG solution has a long question-answering time, and the time increases with the length of the input token or query token, making it difficult to meet business needs. Summary of the Invention
[0006] This application provides a method for accelerating inference in AI models. When answering online questions, this method retrieves the key-value vectors corresponding to document fragment vectors related to the question from a key-value cache, eliminating the need for forward computation of the document fragment vectors to obtain the first key-value vector. The prefilling process of the retrieval results is replaced by querying the key-value cache, eliminating the need to retrieve the first key-value vector after prefilling the question. Question prefilling and retrieval of the first key-value vector can be performed in parallel, thereby achieving efficient inference, shortening inference time, and significantly improving inference performance. This application also provides an inference system, computing device cluster, computer-readable storage medium, and computer program product corresponding to the above method.
[0007] Firstly, this application provides a method for accelerating inference of an AI model. This method can be applied to an inference system. The inference system may include a software system, which may include, but is not limited to, an intelligent question-answering system. The software system can be a standalone software system, such as various intelligent agents or native large-model question-answering systems. Alternatively, the software system can be integrated into other systems through functional modules, plugins, components, services, etc. For example, the software system may include, but is not limited to, an intelligent question-answering module used to assist development in code development applications, or an intelligent question-answering module used to provide investment advice to users in financial applications. In some possible implementations, the inference system may also include a hardware system. For example, the inference system may include a cluster of computing devices, which executes the AI model inference acceleration method of this application when the computing device cluster is running.
[0008] Specifically, the inference system receives a question input by the user and then retrieves a document fragment vector related to the question from a knowledge base. For example, the inference system can search the knowledge base based on the question to obtain a document fragment vector related to the question. Next, the inference system can retrieve the first key-value vector corresponding to the document fragment vector from a key-value cache. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector. This document fragment information indicates the content of the document fragment. For example, the document fragment information may include the position of the document fragment in the document and the topic of the document fragment. The inference system can use an AI model to perform a prefill calculation on the question and the first key-value vector to obtain a prefill result. The prefill result includes a first output token generated based on the second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector, and the second value vector includes a feature vector corresponding to the second key vector used to generate the output sequence. The first output token includes the first token of the output sequence. Based on the prefill result, the inference system performs decoding calculations on the AI model to obtain the inference result. For example, the inference system can add the first output token to the input sequence, and then generate the remaining output tokens one by one through decoding, such as the second output token.
[0009] In this method, the key-value cache stores the key-value vectors corresponding to the document fragment vectors of the domain documents. For example, it is the key-value vector corresponding to the document fragment vector cached during the offline construction phase when the document fragment vector is input into the AI model for inference. In this way, the prefilling process of the search results (e.g., the process of performing forward calculation to obtain the key-value vector) in the online question answering phase can be replaced by the process of querying the key-value cache. The process of using the AI model to process the question to obtain the second key-value vector and the process of querying the key-value cache to obtain the first key-value vector corresponding to the search result can be parallelized. This achieves efficient inference, shortens the inference time, and significantly improves inference performance.
[0010] In some possible implementations, before retrieving the first key-value vector corresponding to the document fragment vector from the key-value cache, the inference system can also retrieve the domain document, then segment and vectorize the domain document to obtain multiple document fragment vectors. Next, while the inference system uses the AI model to infer at least one document fragment vector from the multiple document fragment vectors, it caches the key-value vector corresponding to at least one document fragment vector.
[0011] This method caches the key-value vectors generated during inference by pre-segmenting and vectorizing the domain documents to obtain document fragment vectors. This lays the foundation for obtaining the key-value vectors corresponding to the search results by querying the key-value cache during subsequent online question answering. Obtaining the key-value vectors corresponding to the questions and obtaining the key-value vectors corresponding to the search results can be done in parallel, thereby shortening the inference time and improving inference performance.
[0012] In some possible implementations, the inference system can construct question-answer pair prompts based on at least one document fragment vector. These prompts include a question vector constructed from the document fragment vector and context. The inference system can then cache the key-value vectors corresponding to at least one document fragment vector while inferring the question-answer pair prompts into the AI model for inference and question-answer pair generation.
[0013] This method employs two approaches. First, it utilizes AI models (such as large models) to process domain documents and obtain question-answer pairs. This enables rapid responses to frequently asked or simple questions during subsequent online question answering, reducing unnecessary reasoning and saving computational resources. Second, it caches the key-value vectors generated during the AI model's reasoning process to produce the answers to the questions. This allows for the retrieval of key-value vectors corresponding to document fragment vectors in subsequent online question answering by using a lookup-based approach. This eliminates the need to wait for forward computation of the question to obtain the key-value vector before performing forward computation of the document fragment vector, thus accelerating reasoning.
[0014] In some possible implementations, the inference system can query the question-answer cache to see if the answer to the question is included; if not, the inference system obtains a vector of document fragments related to the question from the knowledge base.
[0015] This method queries the question-and-answer cache. If the answer to the question does not exist in the cache, it retrieves the document fragment vector related to the question from the knowledge base. This fully utilizes cached and computational resources and avoids wasting resources by repeatedly reasoning about the same question.
[0016] In some possible implementations, the inference system can use an AI model to perform a linear transformation on the problem to obtain a second key-value vector corresponding to the problem. For example, the inference system can vectorize the problem to obtain a problem vector, and then use the weights corresponding to the key vector and value vector in the AI model to perform a multiplication operation on the problem vector, thereby achieving a linear transformation of the problem and obtaining a second key-value vector corresponding to the problem. Then, the inference system can use the AI model to calculate the first key-value vector and the second key-value vector to obtain the first output word.
[0017] This method decouples the process of obtaining the key-value vector corresponding to the question from the process of obtaining the key-value vector corresponding to the search results (such as the document fragment vector related to the question). It can obtain the key-value vector corresponding to the question and the key-value vector of the search results in parallel, without waiting for the question vector to be forward-computed to obtain the second key-value vector corresponding to the question before obtaining the key-value vector corresponding to the search results. This shortens the reasoning time and improves the reasoning performance.
[0018] In some possible implementations, the inference system can reorder the document fragment vectors related to the question to obtain the target document fragment vector, and then retrieve the first key-value vector corresponding to the target document fragment vector from the key-value cache.
[0019] This method reorders the search results, filters out key words, and then obtains the key-value vectors corresponding to the key words from the key-value cache. While ensuring accuracy, it reduces the number of words input to the AI model, thereby reducing the number of inferences required by the AI model and improving inference performance.
[0020] Among some possible implementations, AI models include autoregressive generative models. Autoregression is a commonly used generative approach, particularly in language models. It is primarily used for sequence generation tasks, progressively generating each element in a sequence while using previously generated elements as input to predict the next element.
[0021] The method described in this application can accelerate the pre-filling process of autoregressive generative models and improve inference performance.
[0022] Secondly, this application provides an inference system. The inference system is used to accelerate inference for artificial intelligence models, and the inference system includes:
[0023] The interaction module is used to receive user input questions;
[0024] The retrieval module is used to obtain a vector of document fragments related to the question from the knowledge base based on the question.
[0025] The query module is used to retrieve the first key-value vector corresponding to the document fragment vector from the key-value cache. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector.
[0026] The model calculation module is used to perform prefill calculation on the question and the first key-value vector using the artificial intelligence (AI) model to obtain a prefill result. The prefill result includes a first output word generated based on the second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector. The second value vector includes a feature vector corresponding to the second key vector for generating an output sequence. The first output word includes the first word of the output sequence.
[0027] The model calculation module is also used to perform decoding calculations on the AI model based on the pre-filled results to obtain inference results.
[0028] In some possible implementations, the system further includes:
[0029] A construction module is used to acquire domain documents; segment and vectorize the domain documents to obtain multiple document fragment vectors; and cache the key-value vectors corresponding to the at least one document fragment vector during the inference process of using the AI model to infer at least one of the multiple document fragment vectors.
[0030] In some possible implementations, the building module is specifically used for:
[0031] A question-answer pair prompt is constructed based on the at least one document fragment vector, the question-answer pair prompt including a question vector constructed based on the at least one document fragment vector and context;
[0032] During the process of inputting the question-answer pair prompts into the AI model for reasoning and generating question-answer pairs, the key-value vector corresponding to the at least one document fragment vector is cached.
[0033] In some possible implementations, the retrieval module is specifically used for:
[0034] Check the question-and-answer cache to see if the answer to the question is included.
[0035] If not, obtain a vector of document fragments related to the question from the knowledge base.
[0036] In some possible implementations, the model calculation module is specifically used for:
[0037] The AI model is used to perform a linear transformation on the problem to obtain the second key-value vector corresponding to the problem.
[0038] The AI model is used to calculate the first key-value vector and the second key-value vector to obtain the first output word.
[0039] In some possible implementations, the query module is specifically used for:
[0040] The document fragment vectors related to the problem are reordered to obtain the target document fragment vector;
[0041] Retrieve the first key-value vector corresponding to the target document fragment vector from the key-value cache.
[0042] In some possible implementations, the AI model includes an autoregressive generative model.
[0043] Thirdly, this application provides an inference system. The inference system includes an inference server, and further, may also include a construction server. The inference server is used to execute the inference acceleration method for the AI model as described in the first aspect or any implementation thereof, or to implement the functions performed by the interaction module, retrieval module, query module, and model calculation module as described in the second aspect or any implementation thereof. Similarly, the construction server is used to execute the step of caching key-value vectors in the inference acceleration method for the AI model as described in the first aspect or any implementation thereof, or to implement the functions performed by the construction module as described in the second aspect or any implementation thereof.
[0044] Fourthly, this application provides a computing device cluster. The computing device cluster includes at least one computing device, which includes at least one processor and at least one memory. The at least one processor and the at least one memory communicate with each other. The at least one processor is used to execute instructions stored in the at least one memory to cause the computing device or the computing device cluster to perform the inference acceleration method for the AI model as described in the first aspect or any implementation thereof.
[0045] Fifthly, this application provides a computer-readable storage medium storing instructions that instruct a computing device or a cluster of computing devices to execute the inference acceleration method for the AI model described in the first aspect or any implementation thereof.
[0046] In a sixth aspect, this application provides a computer program product containing instructions that, when run on a computing device or a cluster of computing devices, cause the computing device or cluster of computing devices to execute the inference acceleration method for the AI model described in the first aspect or any implementation thereof.
[0047] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0048] To more clearly illustrate the technical methods of this application, the accompanying drawings used will be briefly described below.
[0049] Figure 1 A flowchart illustrating a question-and-answer process based on RAG provided for this application;
[0050] Figure 2 A schematic diagram of the RAG timing sequence before and after the improvement provided in this application;
[0051] Figure 3 A system architecture diagram of a reasoning system provided in this application;
[0052] Figure 4 A framework diagram of software for deploying an inference system provided in this application;
[0053] Figure 5 A flowchart of a reasoning acceleration method provided in this application;
[0054] Figure 6A A timing diagram for AI model inference provided in this application;
[0055] Figure 6B A schematic diagram illustrating the structure of a prompt used in AI model reasoning, as provided in this application;
[0056] Figure 7 A flowchart illustrating an inference acceleration method provided in this application during the offline construction phase;
[0057] Figure 8 A schematic diagram of the structure of a reasoning system provided in this application;
[0058] Figure 9A A schematic diagram of the structure of a computing device provided in this application;
[0059] Figure 9B A hardware structure diagram of a computing device provided in this application;
[0060] Figure 10 This application provides a schematic diagram of the structure of a computing device cluster;
[0061] Figure 11 A schematic diagram of another computing device cluster provided in this application;
[0062] Figure 12 This is a schematic diagram of another computing device cluster provided in this application. Detailed Implementation
[0063] The terms "first" and "second" used in the embodiments of this application are for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature.
[0064] First, some technical terms involved in the embodiments of this application will be introduced.
[0065] Artificial intelligence (AI) models are mathematical models with reasoning capabilities built using techniques such as machine learning (ML) and deep learning. AI models can be categorized into large and small models based on their parameter scale. For example, AI models with hundreds of billions or trillions of parameters are typically large models. Typical examples of large models include large language models (LLMs), such as generative pre-trained transformers (GPTs). AI models, represented by LLMs, can be applied to various fields, such as engineering, finance, law, or medicine, to achieve tasks like intelligent question answering.
[0066] Retrieval Augmented Generation (RAG) refers to optimizing the output of large models so that they can reference knowledge bases beyond the training data source before generating responses. Specifically, large models like LLMs are typically trained on massive amounts of data, using hundreds of billions, trillions, or even trillions of parameters to generate raw outputs for tasks such as answering questions. Building on the powerful capabilities of LLMs, RAG extends them to access domain-specific or organizational internal knowledge bases, thereby improving output quality. Furthermore, RAG eliminates the need to retrain the model, enabling efficient improvement of LLM outputs at a lower cost, ensuring LLMs maintain accuracy and usability across various contexts.
[0067] To make it easier to understand, the process of answering questions based on RAG will be introduced below.
[0068] See Figure 1 The diagram shows a flowchart of a question-and-answer process based on RAG. The complete process of question-and-answer based on RAG can include an offline construction phase and an online question-and-answer (or simply "Q&A") phase. The process of each phase is explained in detail below.
[0069] During the offline construction phase, the inference system performs steps such as document parsing, document segmentation, vectorization (embedding), question-answer pair generation, and data storage on domain documents to build a knowledge base outside the source of training data.
[0070] Domain documents refer to professional documents within a specific field, containing specialized knowledge within that field. For example, domain documents might include internal documents from relevant institutions in the legal field. Domain documents can be obtained from different data sources and come in various formats. Document parsing is used to process documents from different data sources and in different formats into a single format. Document segmentation is used to divide a document into multiple document fragments. The main factors considered during document segmentation are: 1) the token limitations of the embedding model; and 2) the impact of semantic integrity on the overall retrieval performance. A token, also known as a lexicon, is typically the smallest unit of text data in natural language processing. A token can be a word, a portion of a word, a character, or a subword. Based on this, the inference system can use sentence segmentation to segment at the sentence level, thus preserving the complete semantics of the sentence. Commonly used delimiters for sentence segmentation include periods, exclamation marks, question marks, and newlines. Alternatively, the inference system can segment the domain document text into fixed-length segments (e.g., 256 / 512 tokens) based on the token length limitations of the embedding model. This segmentation method loses a lot of semantic information, which can be mitigated by adding redundancy at the beginning and end. Vectorization is used to convert text data into vector form. Question-answer pairs can be generated using a large model. Specifically, the inference system can generate question-answer prompts (QA prompts) based on the vectorized results of document fragments (such as document fragment vectors), and then input the QA prompts into the large model for inference to obtain the question-answer pairs. The inference system can store the document fragment vectors and question-answer pairs in a vector database, thus achieving data storage.
[0071] During the online question-answering phase, the inference system can query the question-answer cache for the user's query. If the answer to the question exists in the cache, the system responds based on that answer. If the answer does not exist, the system performs steps such as question preprocessing, vectorization, retrieval (e.g., recall), ranking (also known as reranking), and answer generation. It's worth noting that the inference system can also perform input and output security checks to filter sensitive information, inappropriate content, or content that violates ethical standards, preventing the system from being used for illegal purposes.
[0072] The question preprocessing process includes cleaning, normalizing, and parsing the user-input question to extract key information for subsequent retrieval and generation. The vectorization process is similar to that in the offline construction phase and will not be elaborated here. Retrieval specifically involves using database retrieval algorithms, such as approximate retrieval, to recall document fragment vectors related to the question. Since the retrieved document fragment vectors are numerous, the inference system can further refine them by reordering them to select the most relevant document fragment vectors, such as the top 50 most relevant vectors, thus improving the quality of subsequent model generation. Answer generation is achieved through large-scale model inference. Specifically, the inference system inputs the question and document fragment vectors into a large model, such as a model gateway. The model gateway then calls the corresponding large model to perform inference and returns the answer to the user.
[0073] Depend on Figure 1 It is known that the question-answering process based on RAG is sequential. Question preprocessing takes approximately 100 milliseconds (ms), vectorization approximately 40 ms, retrieval approximately 70 ms, and ranking approximately 60 ms. The entire question-answering process is relatively long, for example, up to 5 seconds. To address this, the industry has proposed a scheme that parallelizes retrieval and question prefilling. Specifically, the large model's inference can be divided into a prefilling stage and a decoding stage. The prefilling stage refers to the process by which the large model processes the tokens in the input prompt. Token processing can include inputting the tokens into the large model for forward propagation until the first output token is generated. The decoding stage involves generating output tokens one by one. Each generated output token is added to the input sequence and then fed back into the large model to generate the next output token.
[0074] like Figure 2As shown, the original solution involved first performing retrieval and ranking, then constructing a prompt based on the retrieval results (e.g., the ranked results) and the question, and prefilling the tokens in the prompt. The improved solution involves parallel execution of retrieval and prefilling stage 1 (prefillstage1) for the user-input question. Prefillstage1 prefills the tokens in the question, specifically by performing a linear transformation on the tokens to obtain the query vector Q, key vector K, and value vector V for each token. Then, prefillstage2 is executed. Prefillstage2 prefills the tokens in the retrieval results, obtaining the query vector Q, key vector K, and value vector V for each token. This yields the complete key-value (KV) vector of the prompt. During the decoding stage, the inference system can decode based on the complete prompt's KV vector, thereby outputting the token.
[0075] The improved scheme described above masks the retrieval time by parallelizing the retrieval and prefill stage 1. However, the retrieval time is relatively small in the overall RAG process, resulting in limited performance improvement.
[0076] In view of this, this application provides a method for accelerating AI model inference. This method can be executed by an inference system. The inference system may include a software system, which may be an intelligent question-answering system. The software system can be a standalone software system, such as various intelligent agents or native large-model question-answering systems. Alternatively, the software system can be integrated into other systems through functional modules, plugins, components, services, etc. For example, the software system may include, but is not limited to, an intelligent question-answering module used to assist development in code development applications, or an intelligent question-answering module used to provide investment advice to users in financial applications. In some possible implementations, the inference system may also include a hardware system; for example, the inference system may include a cluster of computing devices, which executes the AI model inference acceleration method of this application when the computing device cluster is running.
[0077] Specifically, the inference system receives a question input by the user and then retrieves a document fragment vector related to the question from the knowledge base. Next, the inference system can retrieve the first key-value vector corresponding to the document fragment vector from the key-value cache. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector. This document fragment information indicates the content of the document fragment. For example, the document fragment information may include the position of the document fragment in the document and the topic of the document fragment. The inference system can use an AI model to perform a prefill calculation on the question and the first key-value vector to obtain a prefill result. The prefill result includes a first output token generated based on the second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector, and the second value vector includes a feature vector corresponding to the second key vector used to generate the output sequence. The first output token includes the first token of the output sequence. Based on the prefill result, the inference system performs decoding calculations on the AI model to obtain the inference result. For example, the inference system can add the first output token to the input sequence, and then generate the remaining output tokens, i.e., the second output tokens, one by one through decoding.
[0078] In this method, the key-value cache stores the key-value vectors corresponding to the document fragment vectors of the domain documents. For example, it is the key-value vector corresponding to the document fragment vector cached during the offline construction phase when the document fragment vector is input into the AI model for inference. In this way, the prefilling process of the search results (e.g., the process of performing forward calculation to obtain the key-value vector) in the online question answering phase can be replaced by the process of querying the key-value cache. The process of using the AI model to process the question to obtain the second key-value vector and the process of querying the key-value cache to obtain the first key-value vector corresponding to the search result can be parallelized. This achieves efficient inference, shortens the inference time, and significantly improves inference performance.
[0079] To make the technical solution of this application clearer and easier to understand, the architecture of the inference system of this application will be described below with reference to the accompanying drawings.
[0080] First, see Figure 3 The diagram illustrates a system architecture for an inference system. The inference system 30 includes a build server 302 and an inference server 304. The build server 302 acquires domain documents, such as professional documents within a specific field, typically including internal documents from an organization or institution. It then segments and vectorizes these domain documents to obtain multiple document fragment vectors. The build server 302 also caches the key-value vector corresponding to at least one document fragment vector during the inference process using an AI model on at least one of the multiple document fragment vectors.
[0081] In specific implementation, the construction server 302 constructs a question-and-answer prompt (QA prompt) based on at least one document fragment vector. Then, during the process of inputting the QA prompt into the AI model for inference and question-and-answer pair generation, it caches the key-value vectors corresponding to at least one document fragment vector. The key-value vectors generated by the AI model include key vectors and value vectors. The key vectors and value vectors are vectors obtained by linear transformation of the input sequence (such as document fragment vectors). The key vectors represent the features of the input sequence to facilitate subsequent matching calculations, while the value vectors represent specific information about the input sequence, such as document fragment information corresponding to the key vectors. The process of the construction server 302 generating question-and-answer pairs may include: the construction server 302 weights and aggregates the value vectors based on the matching degree between the query vector and the key vector to generate an output focusing on specific information. This output can be the answer to the question. Then, the construction server 302 can obtain the question-and-answer pair based on the question and its corresponding answer. In this application, the structure for caching key-value vectors is called a key-value cache.
[0082] like Figure 3 As shown, AI model inference can be divided into two stages: pre-filling and decoding. The specific implementation of the pre-filling and decoding stages will be explained in detail below.
[0083] The pre-filling stage refers to the process by which the AI model processes the token in the input prompt, such as a QA prompt. Token processing can include inputting the token into the AI model for forward propagation until the first output token is generated. During forward propagation, the AI model's transformer layer uses a self-attention mechanism to compute the query vector Q, key vector K, and value vector V of the input sequence X through linear transformations. Typically, the query vector Q, key vector K, and value vector V can be obtained by multiplying the input sequence X by the corresponding weight matrix.
[0084] The query vector Q helps the AI model formulate questions, representing the information the AI model wants to focus on or acquire. In the self-attention mechanism, the query vector Q is used to calculate similarity with the key vector K to determine the degree of association between different tokens in the input sequence. The key vector K is also used to calculate similarity with the query vector Q, thus helping the AI model find the key content of the question. The key vector K is typically multiplied by the query vector Q to obtain an attention score, which reflects the association between different tokens in the input sequence. The value vector includes document fragment information corresponding to the key vector, used to provide the actual answer or information. Specifically, the AI model generates the final output representation, such as the vector representation of the first output token, by multiplying the attention score by the value vector and performing a weighted sum.
[0085] In this application, the build server 302 is used to cache the key-value vectors corresponding to at least one document fragment vector generated by the AI model through pre-filling calculation. For example, the build server 302 is used to cache the key-value vectors generated by the AI model through pre-filling calculation to a key-value cache.
[0086] The decoding phase refers to the stage where the AI model generates output tokens one by one. Each generated output token is added to the input sequence and fed back into the AI model to generate the next output token. The token generation process stops when a special stop token (also known as an end flag) is generated or when a user-defined termination condition is met (such as reaching the maximum sequence length).
[0087] The AI model supports multiple generation methods. In some examples, the AI model can be an autoregressive generative model. Autoregression is a commonly used generation method, especially in language models such as GPT. Autoregression is mainly used to handle sequence generation tasks, generating each element in the sequence step by step, while using previously generated elements as input to predict the next element. The AI model's autoregressive decoding is based on the probabilistic chain rule to decode and generate the next token. For example, the AI model can generate the second output token iteratively from the input sequence and the first output token, then generate the third output token iteratively from the input sequence, the first output token, and the second output token, and so on. The AI model can output the (i+1)th output token iteratively from the input sequence, the first output token, the second output token, ..., the i-th output token. The generation process of the second output token, the third output token, ..., the (i+1)-th output token can refer to the first output token. The above output tokens can form an output sequence. The output sequence can be processed to recover the answer in text form.
[0088] The server 302 is also used to construct question-answer pairs from answers and questions, and store these pairs in a database. Specifically, the server 302 can store the question-answer pairs as vectors in a vector database. It should be noted that the server 302 is also used to store document fragment vectors in the vector database. Furthermore, the server 302 is also used to generate an index for the document fragment vectors in the database (e.g., a vector database) based on the database's indexing functionality. For example, the server 302 can generate the document fragment vector index using methods such as random number generation.
[0089] The inference server 304 receives a question input by the user, obtains a document fragment vector related to the question from a knowledge base, and retrieves a first key-value vector corresponding to the document fragment vector from a key-value cache. The knowledge base can be the vector database storing the document fragment vectors mentioned above. The first key-value vector includes a first key vector and a first value vector, where the first value vector includes document fragment information corresponding to the first key vector. The inference server 304 also performs a prefill calculation on the question and the first key-value vector using an AI model to obtain a prefill result. The prefill result includes a first output token generated based on a second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector, where the second value vector includes a feature vector corresponding to the second key vector used to generate the output sequence. The first output token includes the first token of the output sequence. The inference server 304 also performs decoding calculations on the AI model based on the prefill result to obtain an inference result. For example, the inference server 304 uses the first output token to decode and obtain a second output token of the output sequence using the AI model. The second output token can be any of the remaining tokens in the output sequence other than the first output token.
[0090] like Figure 3As shown, the inference server 304 is specifically used to query whether the question-and-answer cache contains the answer to the question; if so, it returns the answer to the user; if not, it obtains the document fragment vector related to the question from the knowledge base to generate the answer to the question. Furthermore, the inference server 304 is also used to preprocess the question, such as performing cleaning, normalization, and parsing operations to extract key information and prepare for subsequent retrieval and generation. Considering that the knowledge base typically stores document fragments in vector form, such as storing document fragment vectors of domain documents, the inference server 304 is also used to vectorize the question or the key information extracted from the question to obtain a question vector. Thus, the inference server 304 can retrieve the document fragment vector related to the question from the knowledge base based on the question vector. In addition, the inference server 304 can perform security checks on the input (e.g., the question) to filter questions containing sensitive information, inappropriate content, or that violate ethical standards, preventing them from being used for illegal purposes. It should be noted that... Figure 3 The example illustrates that input security checks are performed after a search. In practice, input security checks can be performed before a search or in parallel, and this application does not impose any restrictions on this.
[0091] Furthermore, considering that the search results may include multiple document fragment vectors related to the question, the inference server 304 can also reorder these multiple document fragment vectors to obtain the target document fragment vector. The target document fragment vector may include, but is not limited to, the document fragment vectors ranked in the top n by relevance. This reordering process is also called fine-tuning, which improves the quality of the subsequently generated answers by reordering the search results. Accordingly, the inference server 304 can retrieve the first key-value vector corresponding to the target document fragment vector from the key-value cache.
[0092] After the AI model generates an answer via the model gateway, the inference server 304 can also perform an output security check. Similar to the input security check, the output security check verifies whether the answer generated by the AI model contains sensitive information, inappropriate content, or violates ethical standards, thereby preventing the generation of harmful content. Considering scenarios involving duplicate questions, the inference server 304 can also update the question-and-answer cache by updating the answer corresponding to the question in the cache. This allows subsequent responses to duplicate questions to retrieve the answer from the cache, avoiding resource waste caused by repeatedly calling the AI model.
[0093] Figure 3 The system architecture of the inference system 30 will be introduced from a hardware perspective. The inference system 30 will then be introduced from a software perspective.
[0094] See Figure 4The diagram shows a software framework for an inference system 30, on which firmware 402 and a driver 404 can be installed. Firmware 402 is typically a program written to read-only memory that can directly control and interact with the hardware, and check for any hardware errors. Driver 404 is specifically a small piece of code added to the operating system, containing information about the hardware. When a computer program requests to interact with certain hardware, driver 404 can act as a translator of instructions between the hardware and the program using it. For example, firmware 402 can control devices (such as graphics processors, neural network processors, or other accelerators in the inference server 304), interact with the devices, and check for any device errors; driver 404 can act as a translator of instructions between the device and the program using it.
[0095] Furthermore, when the hardware architecture of the build server 302 and inference server 304 in the inference system 30 adopts a heterogeneous computing architecture (including computing architectures using computing units with different types of instruction sets), a heterogeneous computing framework 406 can also be installed on the build server 302 and inference server 304. In a distributed computing scenario, the heterogeneous computing framework 406 can be a heterogeneous computing framework for neural networks (Compute Architecture for Neural Net, CANN). CANN can support users to quickly build AI applications by providing multi-level programming interfaces. Among them, AI applications include applications built based on AI models (such as LLM). It should be noted that the heterogeneous computing framework 406 is an optional framework. The inference acceleration method of the AI model in this application embodiment can still be executed even without installing the above framework on the build server 302 and inference server 304. The role of the above framework is to improve inference efficiency.
[0096] It should be noted that firmware 402, driver 404 or heterogeneous computing framework 406 can be pre-installed when the build server 302 and inference server 304 are shipped from the factory, or users can install them themselves according to their business needs.
[0097] Users can install a deep learning framework 408 on the build server 302 and the inference server 304. The deep learning framework 408 is used to construct a large-scale computational graph by compiling the methods for implementing AI models, and to automatically perform gradient calculations within the computational graph. This computational graph is also called the graph compilation result. Thus, the inference system 30 can perform calculations based on the graph compilation result, thereby achieving inference. Depending on the compilation method, deep learning frameworks can be divided into frameworks that support static compilation and frameworks that support dynamic compilation. Users can choose to install one or more deep learning frameworks 408 on the inference server 304 according to their business needs. In some embodiments, the deep learning framework 408 may not be installed on the inference server 304; in this case, the inference server 304 can implement the model from scratch using a programming language such as Python.
[0098] Users can also install a software development kit (SDK) 410 for accelerators (such as AI accelerators like neural network processors) on the build server 302 and inference server 304. The software system in the inference system 30 used to implement inference acceleration may include components from the software development kit 410. Furthermore, the software development kit 410 can also provide a very easy-to-use application programming interface (API) for inference acceleration.
[0099] In some possible implementations, a model library 412 can also be deployed on the build server 302 and the inference server 304. This model library 412 includes AI models implemented using a unified framework, which have standardized parameters and APIs. The AI models include reusable configuration items defined within the unified framework. This reduces the configuration work required for the AI models.
[0100] The inference system 30 can accelerate inference based on AI models (such as LLMs) in the model library 412 and APIs provided in the software development kit 410.
[0101] To make the technical solution of this application clearer and easier to understand, the inference acceleration method of the AI model of this application is introduced below with reference to the accompanying drawings.
[0102] See Figure 5 The flowchart shown is a method for accelerating inference, which includes the following steps:
[0103] S502, the inference system 30 receives user input.
[0104] In some possible ways, the question may include a question described using natural language. The inference system 30 can provide various methods to support user input of questions. For example, the inference system 30 can provide an interactive interface, which may be a graphical user interface (GUI) through which the user inputs questions, and the inference system 30 can receive the questions input by the user through the GUI. As another example, the inference system 30 can provide a voice interaction interface through which the user inputs questions in voice form, and the inference system 30 can convert the voice questions into text forms using a speech recognition algorithm.
[0105] In other possible approaches, the problem can include a problem described using a lightweight annotation language. Accordingly, the problem can be in JavaScript object notation (JSON) format or in Extensible Markup Language (XML) format.
[0106] S504, Reasoning System 30 obtains a vector of document fragments related to the question from the knowledge base based on the question.
[0107] The knowledge base includes multiple document fragment vectors obtained by segmenting and vectorizing domain documents. The inference system 30 can retrieve document fragment vectors related to a question from the knowledge base. Specifically, the inference system 30 can preprocess the question, such as by cleaning, normalizing, and parsing it, and then vectorize it to obtain a question vector. Correspondingly, the inference system 30 can match the question vector with the document fragment vectors in the knowledge base to obtain document fragment vectors related to the question.
[0108] Cleaning refers to identifying and correcting identifiable errors in the question, such as duplicate, incorrect, or incomplete information. Normalization involves transforming the question according to predefined rules or standards, giving it a uniform format or representation for easier retrieval and generation. Normalization improves data comparability and consistency, allowing data from different sources to be processed under the same standard. Normalization may include stop word removal, stemming, and part-of-speech tagging. Parsing involves extracting key information from the question according to rules or formats.
[0109] For questions in text format, the inference system 30 parses them using regular expression matching or natural language processing to obtain key information. This key information includes structured data that the computing device can understand and process. For example, the inference system 30 can extract email addresses and phone numbers from text-based questions using regular expression matching. Alternatively, the inference system 30 can use natural language processing to perform part-of-speech tagging and named entity recognition on text-based questions to extract key information.
[0110] For structured problems, including those in JSON or XML formats, the inference system 30 can use parsers in the corresponding languages. For example, the inference system 30 can use the JSON module in the Python framework to parse JSON-formatted problems and the xml.etree.ElementTree module to parse XML-formatted problems.
[0111] Vectorization can be achieved through an embedding model. Specifically, the inference system 30 can input the question or key information extracted from the question into the embedding model, which encodes the question to obtain a question vector. The embedding model is a machine learning model widely used in fields such as NLP. It can transform high-dimensional data (e.g., user-input questions) into a low-dimensional embedding space representation (also called an embedding representation), while preserving the data's features and semantic information, thereby improving the efficiency and accuracy of AI model inference. The embedding model can include, but is not limited to, the Word2Vec model or an autoencoder model.
[0112] Furthermore, considering that the same user can raise the same question at different times, or different users can raise the same question, to avoid resource waste caused by repeated reasoning and to improve response efficiency, the inference system 30 also supports caching the answers to questions. Accordingly, when receiving a question, the inference system 30 can first check whether the question-and-answer cache contains the answer to the question. If so, the inference system 30 can directly return the answer to the question; if not, the inference system 30 can obtain the document fragment vectors related to the question from the knowledge base based on the question, and then generate the subsequent answer.
[0113] S506, the inference system 30 retrieves the first key-value vector corresponding to the document fragment vector from the key-value cache.
[0114] The key-value cache includes key-value vectors corresponding to multiple document fragment vectors obtained by segmenting and vectorizing the domain documents. These key-value vectors can be obtained by pre-filling the document fragment vectors during the offline build phase. The inference system 30 can match the question-related document fragment vectors with the document fragment vectors in the key-value cache to obtain the first key-value vector corresponding to the document fragment vector. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector. This document fragment information indicates the content of the document fragment. For example, the document fragment information may include the document fragment's position in the document and its topic.
[0115] In some possible implementations, the key-value cache can store the index of a document fragment vector and the corresponding key-value vector. The index of the document fragment vector identifies that document fragment vector. For example, the index of the document fragment vector can be a random number generated when storing the document fragment vector in the vector database. Accordingly, the inference system 30 can match the document fragment vector related to the question with the document fragment vector in the key-value cache based on the index of the document fragment vector related to the question and the index of the document fragment vector in the key-value cache. When a match is successful, the inference system 30 can retrieve the first key-value vector corresponding to the document fragment vector from the key-value cache. This can significantly reduce the storage space required by the key-value cache and reduce memory access overhead.
[0116] Considering that the number of document fragment vectors related to the question retrieved by the inference system 30 from the knowledge base may be large, for example, in recommendation applications, the inference system 30 may recall thousands of document fragment vectors. In order to improve the quality of the generated answer and reduce the generation overhead (or generation cost), the inference system 30 can reorder the document fragment vectors related to the question to obtain the target document fragment vector.
[0117] In some examples, the inference system 30 can employ a relevance-based reordering algorithm to reorder document fragment vectors related to the question. For instance, the inference system 30 can determine the relevance of document fragment vectors to the question based on at least one of the semantic relevance of word vectors or context, and then reorder them according to relevance. In other examples, the inference system 30 can also reorder document fragment vectors related to the question based on user behavior. For instance, the inference system 30 can record user clicks, browsing, and favorites, determine user interests or preferences based on these behaviors, and then obtain target document vectors for question-related document fragment vectors based on user interests or preferences. Accordingly, the inference system 30 can retrieve the first key-value vector corresponding to the target document fragment vector from a key-value cache.
[0118] S508, the inference system 30 uses an AI model to perform pre-filling calculations on the question and the first key-value vector to obtain pre-filling results. The pre-filling results include a first output token generated based on the second key-value vector corresponding to the question and the first key-value vector.
[0119] The second key-value vector includes a second key vector and a second value vector. The second value vector includes a feature vector corresponding to the second key vector, used to generate the output sequence. The first output token includes the first token of the output sequence. Specifically, the inference system 30 can use an AI model to perform a linear transformation on the question to obtain the second key-value vector corresponding to the question. For example, after vectorizing the question to obtain a question vector, the inference system 30 can multiply the question vector by the corresponding weight matrix to obtain the second key vector and the second value vector. Then, the inference system can use the AI model to calculate the first key-value vector and the second key-value vector to obtain the first output token.
[0120] In practice, the inference system 30 can input the question into the AI model and perform a linear transformation to obtain the second key-value vector corresponding to the question. The first and second key-value vectors are then concatenated to obtain the complete prompt's key-value vector. The inference system 30 can then use the AI model to perform prefill calculations on the complete prompt's key-value vector to generate the first output token in the output sequence. The first output token may include the first token in the output sequence.
[0121] To facilitate understanding, the following will be combined with... Figure 6A , Figure 6B Example illustration. See also Figure 6A The diagram illustrates a timing diagram of AI model inference. In this application's solution, the inference system 30 performs pre-filling of the user-input question to obtain the second key-value vector and retrieves the first key-value vector from the key-value cache in parallel. It uses a query-based key-value cache approach instead of pre-filling the retrieval results. This achieves lookup-based computation, shortening the time, and breaks the sequential nature of prefill stage 1 and prefill stage 2 in related technologies, further reducing time and improving inference efficiency. Correspondingly, as... Figure 6B As shown, the structure of the prompt in the scheme of this application will also change accordingly. The prompt input to the AI model by the inference system 30 may include the question and the first key-value vector pulled from the key-value cache, rather than the question and retrieval results (e.g., document fragment vectors related to the question) in related technologies. This allows the AI model to perform forward computation only on the question, without having to perform forward computation on the retrieval results to obtain the key-value vector, which greatly shortens the inference time and improves the inference efficiency.
[0122] S510 and the inference system 30 perform decoding calculations on the AI model based on the pre-filled results to obtain the inference results.
[0123] Specifically, the AI model can be an autoregressive generative model. Correspondingly, the inference system 30 can perform autoregressive decoding using the AI model based on the first output token, thereby generating the second output token for each output sequence. For example, the inference system 30 can add the first output token to the input sequence, then calculate an attention score for the key vector and query vector of each input token based on the input sequence, and perform a weighted operation on the value vector of the input token based on the attention score to obtain the second output token. Similarly, when the AI model decodes to obtain the i-th output token, it can add the i-th output token to the input sequence, then calculate an attention score for the key vector and query vector of each input token based on the input sequence, and perform a weighted operation on the value vector of the input token based on the attention score to obtain the (i+1)-th output token. The inference system 30 can repeat the above token generation process, stopping the token generation process when a special stop token (also called an end marker) is generated or a user-defined termination condition (e.g., reaching the maximum sequence extent) is met.
[0124] In this method, the key-value cache stores the key-value vectors corresponding to the document fragment vectors of the domain documents. For example, it stores the key-value vectors cached during the offline construction phase when the document fragment vectors are input into the AI model for inference. Thus, when the inference system 30 receives a question, it can first retrieve the document fragment vectors related to the question, and then obtain the first key-value vector corresponding to the document fragment vector from the key-value cache. There is no need to perform forward calculation on the document fragment vector to obtain the first key-value vector. The process of prefilling the retrieval result is replaced by querying the key-value cache. Moreover, it is not necessary to obtain the first key-value vector after prefilling the question. Prefilling the question and obtaining the first key-value vector can be done in parallel, thereby achieving efficient inference, shortening the inference time, and significantly improving inference performance.
[0125] Figure 5 The illustrated embodiment primarily describes the process of the online question-answering phase of the inference system 30. The inference system 30 achieves inference acceleration by relying on the key-value vectors cached during the offline construction phase. The process of the offline construction phase of the inference system 30 will be described in detail below with reference to the accompanying drawings.
[0126] See Figure 7 The flowchart shown here illustrates an inference acceleration method during the offline build phase, specifically including the following steps:
[0127] S702, Reasoning System 30 acquires domain documents.
[0128] Domain documents refer to specialized documents within a particular professional field, typically including internal documents from organizations or institutions within that field. For example, in the legal field, domain documents might include articles posted by lawyers on internal forums. In a specific implementation, the inference system 30 can pre-fetch the domain documents. For instance, the inference system 30 can retrieve the domain documents before obtaining the first key-value vector corresponding to the document fragment vector from the key-value cache.
[0129] S704 and the inference system 30 segment and vectorize the domain documents to obtain multiple document fragment vectors.
[0130] Specifically, the inference system 30 can segment the domain document using a sentence segmentation method. For example, the inference system 30 can identify delimiters in the domain document, which may include, but are not limited to, periods, exclamation marks, question marks, and line breaks. Then, it can segment the domain document based on these delimiters to obtain multiple document fragments. The inference system 30 can then use an embedding model to vectorize each document fragment, obtaining multiple document fragment vectors.
[0131] Considering the token length limitation of the embedding model, the inference system 30 can also segment the text of the domain document into fixed-length segments based on the token length limitation of the embedding model. To avoid losing a lot of semantic information, the inference system 30 can mitigate semantic loss by adding redundancy at the beginning and end.
[0132] S706, In the process of using the AI model to infer at least one document fragment vector among multiple document fragment vectors, the inference system 30 caches the key-value vector corresponding to at least one document fragment vector.
[0133] Specifically, the inference system 30 can construct question-answer pair prompts based on at least one document fragment vector. The question-answer pair prompts include a question vector constructed from the at least one document fragment vector and context. The context can be information extracted from the document fragment containing the question. Furthermore, the question-answer pair prompts may also include the format of the expected output answer. Then, the inference system 30 can input the question-answer pair prompts into an AI model to generate the answer corresponding to the question. The question and its corresponding answer can form a question-answer pair. During the process of inputting the question-answer pair prompts into the AI model for inference and question-answer pair generation, the inference system 30 can cache the key-value vector corresponding to at least one document fragment vector.
[0134] The AI model inference process can include a pre-filling stage and a decoding stage. In the pre-filling stage, the AI model can perform forward calculations for each token in the question-and-answer prompt to generate a query vector Q, a key vector K, and a value vector V. The inference system 30 can cache the key vector K and the value vector V so that the key-value vector in the key-value cache can be reused to accelerate inference in the online question-and-answer stage.
[0135] Based on the above description, this method processes domain documents to obtain multiple document fragment vectors. At least one of these document fragment vectors is input into an AI model for inference. During inference, the key-value vector corresponding to at least one document fragment vector is cached, thus laying the foundation for the pre-filling process in the online question-answering stage. In the online question-answering stage, there is no need to calculate the key-value vector corresponding to the search results in real time. Instead, when calculating the key-value vector corresponding to the question, the key-value cache is queried in parallel to obtain the key-value vector corresponding to the search results. This achieves efficient inference, shortens inference time, and significantly improves inference performance. Related data shows that by replacing the prefilling process of search content with a querying of the key-value cache, inference performance can be improved by 20%.
[0136] Based on the aforementioned AI model-based inference acceleration method, this application also provides an inference system 30. For example... Figure 8 As shown, the reasoning system 30 includes:
[0137] Interaction module 802 is used to receive user input questions;
[0138] The retrieval module 804 is used to obtain a vector of document fragments related to the question from the knowledge base based on the question.
[0139] The query module 806 is used to retrieve the first key-value vector corresponding to the document fragment vector from the key-value cache. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector.
[0140] The model calculation module 808 is used to perform prefill calculation on the question and the first key-value vector using the artificial intelligence (AI) model to obtain a prefill result. The prefill result includes a first output word generated based on the second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector. The second value vector includes a feature vector corresponding to the second key vector for generating an output sequence. The first output word includes the first word of the output sequence.
[0141] The model calculation module 808 is further configured to perform decoding calculations on the AI model based on the pre-filled results to obtain inference results.
[0142] For example, the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 described above can be implemented in hardware or software. For instance, the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 can be… Figure 3 The module in the inference server 304 shown.
[0143] When implemented in software, the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 can be applications running on computing devices (e.g., inference server 304), such as computing engines. These applications can also be virtualized and provided to users as virtualization services. Virtualization services can include virtual machine (VM) services, bare metal server (BMS) services, or container services. VM services can be services that use virtualization technology to create virtual machine (VM) resource pools on multiple physical hosts to provide VMs for users to use on demand. BMS services are services that create virtual BMS resource pools on multiple physical hosts to provide BMS for users to use on demand. Container services are services that create virtual container resource pools on multiple physical hosts to provide containers for users to use on demand. A VM is a simulated virtual computer, that is, a logical computer. A BMS is a scalable, high-performance computing service with computing performance indistinguishable from traditional physical machines and features secure physical isolation. Containers are a kernel virtualization technology that provides lightweight virtualization to isolate user space, processes, and resources. It should be understood that the VM service, BMS service, and container service mentioned above are merely specific examples. In practical applications, virtualization services can also include other lightweight or heavyweight virtualization services, which are not specifically limited here.
[0144] When implemented in hardware, the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 may include at least one computing device (such as a server) or at least one computing core. Alternatively, the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 may also be devices implemented using application-specific integrated circuits (ASICs) or programmable logic devices (PLDs). The aforementioned PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0145] In some possible implementations, the inference system 30 may also include:
[0146] The construction module 801 is used to acquire domain documents; segment and vectorize the domain documents to obtain multiple document fragment vectors; and cache the key-value vectors corresponding to the at least one document fragment vector during the inference process of using the AI model to infer at least one of the multiple document fragment vectors.
[0147] The building module can be a module in the building server 302. The building module 801 can be implemented in hardware or in software.
[0148] When implemented in software, building module 801 can be an application running on a computing device (e.g., building server 302), such as a computing engine. This application can also be virtualized and provided to users as a virtualization service such as a BMS, VM, or container. When implemented in hardware, building module 801 can include at least one computing device (e.g., a server) or at least one computing core. Alternatively, building module 801 can also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD).
[0149] In some possible implementations, the building module 801 is specifically used for:
[0150] A question-answer pair prompt is constructed based on the at least one document fragment vector, the question-answer pair prompt including a question vector constructed based on the at least one document fragment vector and context;
[0151] During the process of inputting the question-answer pair prompts into the AI model for reasoning and generating question-answer pairs, the key-value vector corresponding to the at least one document fragment vector is cached.
[0152] In some possible implementations, the retrieval module 804 is specifically used for:
[0153] Check the question-and-answer cache to see if the answer to the question is included.
[0154] If not, obtain a vector of document fragments related to the question from the knowledge base.
[0155] In some possible implementations, the model calculation module 808 is specifically used for:
[0156] The AI model is used to perform a linear transformation on the problem to obtain the second key-value vector corresponding to the problem.
[0157] The AI model is used to calculate the first key-value vector and the second key-value vector to obtain the first output word.
[0158] In some possible implementations, the query module 806 is specifically used for:
[0159] The document fragment vectors related to the problem are reordered to obtain the target document fragment vector;
[0160] Retrieve the first key-value vector corresponding to the target document fragment vector from the key-value cache.
[0161] In some possible implementations, the AI model includes an autoregressive generative model.
[0162] This application also provides a computing device. The computing device may include the aforementioned inference server 304 for implementing the aforementioned AI model inference acceleration method. Further, the computing device may also include the aforementioned construction server 302, with the construction server 302 and the inference server 304 collaboratively implementing the aforementioned AI model inference acceleration method. The hardware structure of the computing device will be described below with reference to the accompanying drawings.
[0163] See Figure 9A The diagram illustrates the structure of a computing device 900, which includes a bus 902, a processor 904, a memory 906, and a communication interface 908. The processor 904, memory 906, and communication interface 908 communicate via the bus 902. The computing device 900 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 900.
[0164] The 902 bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 9A The bus 902 may be represented by a single line, but this does not mean that there is only one bus or one type of bus. The bus 902 may include a path for transmitting information between various components of the computing device 900 (e.g., memory 906, processor 904, communication interface 908).
[0165] Processor 904 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0166] Memory 906 may include volatile memory, such as random access memory (RAM). Memory 906 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid-state drive (SSD). Memory 906 stores executable program code, which processor 904 executes to implement the aforementioned AI model inference acceleration method. Specifically, memory 906 stores instructions for the inference system 30 to execute the AI model inference acceleration method. For example, memory 906 may store instructions for implementing the functions of interaction module 802, retrieval module 804, query module 806, and model calculation module 808. Furthermore, memory 906 may also store instructions for implementing the functions of construction module 801.
[0167] The communication interface 908 uses transceiver modules, such as, but not limited to, network interface cards and transceivers, to enable communication between the computing device 900 and other devices or communication networks.
[0168] It should be noted that, Figure 9AThis example uses a computing device as a general-purpose server. However, in training or inference scenarios, to improve performance, the computing device can be a heterogeneous server. A heterogeneous server includes servers that provide computing power using various different types of processors, typically used in specialized fields. These different types of processors can include processors using different instruction sets. For example, a heterogeneous server can include at least one of the following: a Neural-network Processing Unit (NPU), a Graphics Processing Unit (GPU), a Tensor Processing Unit (TPU), an Application-Specific Integrated Circuit (ASIC), a Complex Programmable Logic Device (CPLD), a Field-Programmable Gate Array (FPGA), and a Central Processing Unit (CPU). For instance, a computing device can be a heterogeneous server built on a CPU and an NPU, or a heterogeneous server built on a CPU and a GPU.
[0169] The following example, using a heterogeneous server, illustrates the hardware architecture of a computing device.
[0170] See Figure 9B The diagram illustrates a hardware structure of a computing device 900, which includes a host 22 and at least one device 24. The host 22 and the at least one device 24 are connected. The device 24 is used to accelerate computation on the host 22.
[0171] The host 22 includes a processor and memory. The processor can be a central processing unit (CPU), and the memory can be a dual in-line memory module (DIMM). Specifically, the DIMM can be of double data rate (DDR) type, for example, the memory can be a DDR4 DIMM. Figure 9B In the example, host 22 includes 4 CPUs and 4 DDR4 DIMM groups, with each CPU connected to one DDR4 DIMM group, and each DDR4 DIMM group including 8 DDR4 DIMMs. Multiple CPUs of host 22 can be connected via hydra interfaces to form a hydra mesh.
[0172] Optionally, host 22 may also include interfaces, such as one or more of the following: Serial Advanced Technology Attachment (SATA) interface, Next Generation Non-Volatile Memoryexpress (NVMe) interface, and Gigabit Ethernet (GE) interface. Host 22 may also include memory. The memory may include SATA-enabled memory or NVMe-enabled memory, such as a SATA-enabled hard disk drive (HDD) or an NVMe-enabled solid-state drive (SSD).
[0173] Device 24 includes a computing card, also known as an accelerator, for accelerating the CPU. Figure 9B In the example, the accelerator included in device 24 may be a neural network processing unit (NPU). In other possible implementations of the embodiments of this application, device 24 may also include more types or more numbers of accelerators, such as GPUs or TPUs.
[0174] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0175] like Figure 10 As shown, the computing device cluster includes at least one computing device 900. The memory 906 of one or more computing devices 900 in the computing device cluster may store instructions from the same inference system 30 for executing inference acceleration methods for AI models.
[0176] In some possible implementations, one or more computing devices 900 in the computing device cluster can also be used to execute some of the instructions of the inference system 30 for executing the inference acceleration method of the AI model. In other words, a combination of one or more computing devices 900 can jointly execute the instructions of the inference system 30 for executing the inference acceleration method of the AI model.
[0177] It should be noted that the memory 906 in different computing devices 900 in the computing device cluster can store different instructions for executing some functions of the inference system 30.
[0178] Figure 11One possible implementation is shown. For example... Figure 11 As shown, two computing devices 900A and 900B are connected via a communication interface 908. The memory in computing device 900A stores instructions for executing the functions of the interaction module 802, retrieval module 804, query module 806, and model calculation module 808. In other words, computing device 900A implements the functions of the inference server 304. The memory in computing device 900B stores instructions for executing the functions of the aforementioned construction module 801. In other words, computing device 900B implements the functions of the construction server 302. The memory 906 of computing devices 900A and 900B jointly stores instructions for the inference system 30 to execute the inference acceleration method for the AI model.
[0179] Figure 11 The connection method between the computing device clusters shown is based on the consideration that the AI model inference acceleration method provided in this application requires a lot of resources for inference. Therefore, it is considered that the functions implemented by the interaction module 802, retrieval module 804, query module 806, model calculation module 808, and construction module 801 are executed by different computing devices. For example, the functions implemented by the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 can be executed by computing device 900A, and the functions implemented by the construction module 801 can be executed by computing device 900B.
[0180] It should be understood that Figure 11 The functions of the computing device 900A shown can also be performed by multiple computing devices 900. For example, the functions of the retrieval module 804 and the query module 806 can be performed by a separate computing device. Similarly, the functions of the computing device 900B can also be performed by multiple computing devices 900.
[0181] In some possible implementations, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Figure 12 One possible implementation is shown. For example... Figure 12 As shown, the two computing devices 900C and 900D are connected via a network. Specifically, they are connected to the network through the communication interfaces in each computing device. In this possible implementation, the memory 906 in computing device 900C stores instructions for executing the functions of the interaction module 802, the retrieval module 804, the query module 806, and the model calculation module 808. Simultaneously, the memory 906 in computing device 900D stores instructions for executing the functions of the aforementioned construction module 801.
[0182] Figure 12The connection method between the computing device clusters shown can be based on the fact that the AI model inference acceleration method provided in this application requires a large amount of resources for inference. Therefore, the functions implemented by the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 are considered to be executed by independent computing devices. For example, the functions implemented by the interaction module 802, retrieval module 804, query module 806, and model calculation module 808 are executed by computing device 900C, and the functions implemented by the construction module 801 are executed by computing device 900D.
[0183] It should be understood that Figure 12 The functions of the computing device 900C shown can also be performed by multiple computing devices 900. Similarly, the functions of the computing device 900D can also be performed by multiple computing devices 900.
[0184] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the aforementioned inference acceleration method applied to the inference system 30 for executing an AI model.
[0185] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product runs on at least one computing device, it causes the at least one computing device to execute the inference acceleration method of the aforementioned AI model.
[0186] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the protection scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for accelerating inference in an artificial intelligence model, characterized in that, The method includes: The problem of receiving user input; Based on the question, obtain a vector of document fragments related to the question from the knowledge base; Retrieve the first key-value vector corresponding to the document fragment vector from the key-value cache. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector. The AI model is used to perform prefill calculation on the question and the first key-value vector to obtain a prefill result. The prefill result includes a first output word generated based on the second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector. The second value vector includes a feature vector corresponding to the second key vector for generating an output sequence. The first output word includes the first word of the output sequence. Based on the pre-filled results, the AI model is used to perform decoding calculations to obtain the inference results.
2. The method according to claim 1, characterized in that, Before retrieving the first key-value vector corresponding to the document fragment vector from the key-value cache, the method further includes: Obtain domain documentation; The domain documents are segmented and vectorized to obtain multiple document fragment vectors; During the process of reasoning about at least one document fragment vector among the plurality of document fragment vectors using the AI model, the key-value vector corresponding to the at least one document fragment vector is cached.
3. The method according to claim 2, characterized in that, During the process of reasoning about at least one document fragment vector among the plurality of document fragment vectors using the AI model, caching the key-value vector corresponding to the at least one document fragment vector includes: A question-answer pair prompt is constructed based on the at least one document fragment vector, the question-answer pair prompt including a question vector constructed based on the at least one document fragment vector and context; During the process of inputting the question-answer pair prompts into the AI model for reasoning and generating question-answer pairs, the key-value vector corresponding to the at least one document fragment vector is cached.
4. The method according to any one of claims 1 to 3, characterized in that, The step of obtaining a vector of document fragments related to the question from the knowledge base includes: Check the question-and-answer cache to see if the answer to the question is included. If not, obtain a vector of document fragments related to the question from the knowledge base.
5. The method according to any one of claims 1 to 4, characterized in that, The step of using the artificial intelligence (AI) model to perform prefill calculations on the problem and the first key-value vector to obtain prefill results includes: The AI model is used to perform a linear transformation on the problem to obtain the second key-value vector corresponding to the problem. The AI model is used to calculate the first key-value vector and the second key-value vector to obtain the first output word.
6. The method according to any one of claims 1 to 5, characterized in that, The step of retrieving the first key-value vector corresponding to the document fragment vector from the key-value cache includes: The document fragment vectors related to the problem are reordered to obtain the target document fragment vector; Retrieve the first key-value vector corresponding to the target document fragment vector from the key-value cache.
7. The method according to any one of claims 1 to 6, characterized in that, The AI model includes an autoregressive generative model.
8. A reasoning system, characterized in that, The inference system is used to accelerate inference for artificial intelligence models, and the inference system includes: The interaction module is used to receive user input questions; The retrieval module is used to obtain a vector of document fragments related to the question from the knowledge base based on the question. The query module is used to retrieve the first key-value vector corresponding to the document fragment vector from the key-value cache. The first key-value vector includes a first key vector and a first value vector. The first value vector includes document fragment information corresponding to the first key vector. The model calculation module is used to perform prefill calculation on the question and the first key-value vector using the artificial intelligence (AI) model to obtain a prefill result. The prefill result includes a first output word generated based on the second key-value vector corresponding to the question and the first key-value vector. The second key-value vector includes a second key vector and a second value vector. The second value vector includes a feature vector corresponding to the second key vector for generating an output sequence. The first output word includes the first word of the output sequence. The model calculation module is also used to perform decoding calculations on the AI model based on the pre-filled results to obtain inference results.
9. The system according to claim 8, characterized in that, The system also includes: A construction module is used to acquire domain documents; segment and vectorize the domain documents to obtain multiple document fragment vectors; and cache the key-value vectors corresponding to the at least one document fragment vector during the inference process of using the AI model to infer at least one of the multiple document fragment vectors.
10. The system according to claim 9, characterized in that, The building module is specifically used for: A question-answer pair prompt is constructed based on the at least one document fragment vector, the question-answer pair prompt including a question vector constructed based on the at least one document fragment vector and context; During the process of inputting the question-answer pair prompts into the AI model for reasoning and generating question-answer pairs, the key-value vector corresponding to the at least one document fragment vector is cached.
11. The system according to any one of claims 8 to 10, characterized in that, The retrieval module is specifically used for: Check the question-and-answer cache to see if the answer to the question is included. If not, obtain a vector of document fragments related to the question from the knowledge base.
12. The system according to any one of claims 8 to 11, characterized in that, The model calculation module is specifically used for: The AI model is used to perform a linear transformation on the problem to obtain the second key-value vector corresponding to the problem. The AI model is used to calculate the first key-value vector and the second key-value vector to obtain the first output word.
13. The system according to any one of claims 8 to 12, characterized in that, The query module is specifically used for: The document fragment vectors related to the problem are reordered to obtain the target document fragment vector; Retrieve the first key-value vector corresponding to the target document fragment vector from the key-value cache.
14. The system according to any one of claims 8 to 13, characterized in that, The AI model includes an autoregressive generative model.
15. A computing device cluster, characterized in that, The computing device cluster includes at least one computing device, the at least one computing device including at least one processor and at least one memory, the at least one memory storing computer-readable instructions; the at least one processor executes the computer-readable instructions to cause the computing device cluster to perform the inference acceleration method of the artificial intelligence model as described in any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that, Includes computer-readable instructions; the computer-readable instructions are used to implement the inference acceleration method of the artificial intelligence model according to any one of claims 1 to 7.
17. A computer program product, characterized in that, Includes computer-readable instructions; the computer-readable instructions are used to implement the inference acceleration method of the artificial intelligence model according to any one of claims 1 to 7.
