Method for accelerating multi-modal large language model reasoning by utilizing advanced withdrawal of visual tokens
By determining the early withdrawal layer of visual tokens in the multi-modal large language model, the problems of high inference overhead, poor flexibility and incompatibility of KV cache in the existing technology are solved, and flexible visual token retention and KV cache are achieved. Compatible, significantly saving computational overhead and maintaining performance.
Patent Information
- Application Number
- CN202410554989.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-07
- Publication Date
- 2024-08-23
AI Technical Summary
Existing multi-modal large language models have high reasoning overhead in real-time interaction scenarios, and the existing technology lacks flexibility, incomplete importance evaluation indicators, and is incompatible with KV cache technology, making it unable to effectively accelerate the reasoning of multi-modal tasks.
Determine the early withdrawal layer of visual tokens by performing a policy search on a subset of the target dataset, using Kullback-Leibler divergence to determine the number of visual token withdrawal layers, and early withdrawal of visual tokens at that layer, Only system tokens, instruction tokens and output tokens are retained for forward reasoning, achieving flexible retention of visual tokens and compatibility with KV cache.
Withdrawing visual tokens in advance from a certain layer in the middle of the multi-modal large language model reduces computing overhead, flexibly responds to different problems, avoids the design of importance evaluation indicators, and achieves compatibility with KV cache technology, saving time Over 40% computational overhead while maintaining performance.
Smart Images

Figure CN118536595A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of neural network model reasoning acceleration, and in particular to a method for accelerating the reasoning of a multimodal large language model by utilizing early withdrawal of visual tokens. Background Art
[0002] The multimodal large language model (MLLM) can perceive information of different modalities, and then use the powerful reasoning ability of the large language model (LLM) to make corresponding responses. The emergence of the multimodal large language model has changed the way humans interact with artificial intelligence systems, breaking the limitation that conversations are limited to language modalities. However, the currently popular multimodal large language models have billions of parameters, and their reasoning overhead is quadratic to the length of the input token; at the same time, the existing multimodal large language models convert visual information into a large number of tokens as the input of the multimodal large language model, which further increases its reasoning overhead and hinders the application of multimodal large language models in real-time interaction scenarios.
[0003] Existing technologies reduce the number of tokens by retaining important tokens and removing or merging unimportant tokens, thereby reducing the inference overhead of a large multimodal language model. For example, LLaVA-PruMerge selects important visual tokens based on the attention scores of the class tokens to other visual tokens in the visual encoder, and removes or merges unimportant visual tokens before inputting them into the large multimodal language model to reduce the number of input tokens, thereby reducing its inference overhead; FastV selects important visual tokens and removes unimportant visual tokens by outputting the attention of tokens to other tokens after the second layer of the large multimodal language model. Existing technologies have the following main disadvantages:
[0004] (1) Lack of flexibility
[0005] When faced with question-answering tasks involving multiple questions about a single image, methods such as LLaVA-PruMerge only use the information from the visual encoder to remove unimportant tokens, and therefore cannot flexibly retain different visual tokens for different questions. For example, for a picture consisting of a cat and a dog, when we need to ask about the dog, we need to retain the token corresponding to the dog, and when we need to ask about the cat, we need to retain the token corresponding to the cat. Retaining the same token for different questions will result in the removal of visual tokens that are important to the current question, resulting in a serious performance loss on such tasks.
[0006] (2) Incomplete importance evaluation index
[0007] Existing technologies all need to design an importance evaluation index to retain important visual tokens, but there is no sufficient theory to prove which importance evaluation index is the best. Therefore, using this incomplete importance evaluation index will also cause the truly important visual tokens to be mistakenly removed.
[0008] (3) Incompatible with KV cache technology
[0009] KV cache technology accelerates the reasoning of multimodal large language models by storing and reusing the key values generated in the previous prediction process. It is a common and crucial technology for accelerating the reasoning of multimodal large language models. Methods like FastV retain different visual tokens at each reasoning, so it is impossible to directly reuse the key values stored in the previous prediction process to accelerate reasoning.
[0010] In summary, existing technologies cannot fully meet the needs of accelerating reasoning of large multimodal language models on different multimodal tasks. Summary of the invention
[0011] The purpose of the present invention is to provide a method for accelerating the reasoning of a multimodal large language model by withdrawing visual tokens in advance, so as to solve the problems existing in the prior art, avoid the design of importance evaluation indicators, flexibly respond to and answer different questions, and achieve compatibility with KV cache technology.
[0012] In order to achieve the above object, the solution of the present invention is:
[0013] A method for accelerating the reasoning of a multimodal large language model by using early withdrawal of visual tokens, wherein the input of the multimodal large language model consists of system tokens, visual tokens, instruction tokens, and output tokens, and the method comprises:
[0014] The withdrawal layer K for early withdrawal of visual tokens is determined by performing a strategy search on a subset of the target dataset. The specific steps are as follows:
[0015] a1. Randomly extract 20 samples from the target data set to form a data subset;
[0016] a2. Use a large multimodal language model to process a data subset and retain the predicted distribution of the classification head of the large multimodal language model for each sample;
[0017] a3. Define N as the number of layers of the multimodal large language model, traverse K = {5, 6, 7, ..., N} and perform the following steps:
[0018] a3-1. Perform normal forward reasoning on the 1st to K-1th layers of the multimodal large language model;
[0019] a3-2. Remove all visual tokens at layer K;
[0020] a3-3. Perform forward reasoning involving only system tokens, instruction tokens, and output tokens in the Kth to Nth layers of the multimodal large language model;
[0021] a3-4. Calculate the Kullback-Leibler divergence of the predicted distribution obtained by inference of the Kth layer of the multimodal large language model without visual tokens and the predicted distribution obtained by normal inference of the multimodal large language model, and take the average of 20 samples of the Kullback-Leibler divergence data subset. If the averaged Kullback-Leibler divergence is less than the preset threshold, exit the loop and use the current K as the number of layers from which the visual tokens are withdrawn in advance;
[0022] After determining the withdrawal layer K for withdrawing visual tokens in advance, the specific steps for accelerating the inference of the multimodal large language model by withdrawing visual tokens in advance are as follows:
[0023] b1. Perform normal forward reasoning on the 1st to K-1th layers of the multimodal large language model;
[0024] b2. Remove all visual tokens at layer K;
[0025] b3. Perform forward reasoning involving only system tokens, instruction tokens, and output tokens in the Kth to Nth layers of the multimodal large language model;
[0026] b4. Calculate the predicted distribution of the Kth layer of the multimodal large language model after removing the visual token, determine the next token based on the current predicted distribution, and then splice the token after the input token of the last prediction;
[0027] b5. Return to b1 until the multimodal large language model predicts a stop symbol.
[0028] Preferably, in step a3-4, the preset threshold is 0.003.
[0029] After adopting the above technical solution, the present invention has the following technical effects:
[0030] The present invention withdraws visual tokens in advance at a certain layer in the middle of the multimodal large language model to accelerate the reasoning of the multimodal large language model, so that all visual tokens can be retained in the initial layers of the multimodal large language model, so different questions can be flexibly responded to and answered; secondly, the present invention no longer needs to select important visual tokens, thereby avoiding the design of importance evaluation indicators; finally, for a certain layer of the multimodal large language model, its visual tokens either exist together or are removed together, so the KV cache stored in the previous prediction process can be reused, achieving compatibility with the KV cache technology. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A schematic diagram of the input composition of a multimodal large language model according to a specific embodiment of the present invention;
[0032] Figure 2 A schematic diagram of early withdrawal of a visual token according to a specific embodiment of the present invention;
[0033] Figure 3 The figure is a schematic diagram of the present invention applied to a multimodal large language model chat robot. DETAILED DESCRIPTION
[0034] In order to further explain the technical solution of the present invention, the present invention is described in detail below through specific embodiments.
[0035] refer to Figures 1 to 3 As shown, the present invention discloses a method for accelerating the reasoning of a multimodal large language model by using visual tokens to withdraw in advance. The input of the multimodal large language model consists of four tokens: system tokens, vision tokens, instruction tokens, and output tokens (see Figure 1 ), the present invention only withdraws the visual tokens in advance at a specific withdrawal layer K. Since the optimal withdrawal layer K of different data sets and different multimodal large language models is different, the withdrawal layer K for withdrawing the visual tokens in advance is first determined by performing a strategy search on a subset of the target data set. The specific steps are as follows:
[0036] a1. Randomly extract 20 samples from the target data set to form a data subset;
[0037] a2. Use the multimodal large language model to process the data subset and retain the predicted distribution P of the multimodal large language model classification head for each sample;
[0038] a3. Define N as the number of layers of the multimodal large language model, traverse K = {5, 6, 7, ..., N} and perform the following steps:
[0039] a3-1. Perform normal forward reasoning in the 1st to K-1th layers of the multimodal large language model (i.e., system tokens, visual tokens, command tokens, and output tokens are all involved);
[0040] a3-2. Remove all visual tokens at layer K;
[0041] a3-3. Perform forward reasoning involving only system tokens, instruction tokens, and output tokens in the Kth to Nth layers of the multimodal large language model;
[0042] a3-4. Calculate the Kullback-Leibler divergence of the predicted distribution L obtained after removing the visual token from the Kth layer of the multimodal large language model and the predicted distribution P (from step a2) obtained by normal reasoning of the multimodal large language model. The Kullback-Leibler divergence is averaged over 20 samples of the data subset. If the averaged Kullback-Leibler divergence is less than a preset threshold (0.003 in this embodiment), the loop is exited and the current K is used as the number of layers from which the visual token is withdrawn in advance.
[0043] See also Figure 2 After determining the withdrawal layer K for withdrawing visual tokens in advance, the specific steps of using visual tokens in advance to accelerate the reasoning of the multimodal large language model are as follows:
[0044] b1. Perform normal forward reasoning on the 1st to K-1th layers of the multimodal large language model;
[0045] b2. Remove all visual tokens at layer K;
[0046] b3. Perform forward reasoning involving only system tokens, instruction tokens, and output tokens in the Kth to Nth layers of the multimodal large language model;
[0047] b4. Calculate the predicted distribution L obtained by removing the visual token from the Kth layer of the multimodal large language model, determine the next token based on the current predicted distribution L (the question-answering task selects the token with the highest probability in the predicted distribution, and the dialogue task samples the next token from the probability distribution), and then concatenate the token after the last predicted input token (concatenation means directly placing it after the previous output token, for example, if the previous input token is [1,2] and the current output token is [3], then the concatenated token is [1,2,3]);
[0048] b5. Return to b1 until the multimodal large language model predicts a stop symbol.
[0049] Through the above scheme, the present invention withdraws visual tokens in advance at a certain layer in the middle of the multimodal large language model to accelerate the reasoning of the multimodal large language model, so that all visual tokens can be retained in the initial layers of the multimodal large language model, so different questions can be flexibly responded to and answered; secondly, the present invention no longer needs to select important visual tokens, thereby avoiding the design of importance evaluation indicators; finally, for a certain layer of the multimodal large language model, its visual tokens either exist together or are removed together, so the KV cache stored in the previous prediction process can be reused, achieving compatibility with the KV cache technology.
[0050] Figure 2The process of visual token early withdrawal (VTW) is fully demonstrated. The results of applying the present invention to different multimodal large language models on different data sets are shown in the following table:
[0051] The following table compares the results of different multimodal large language model inference acceleration methods on different data sets (the smaller the TFLOPs, the better, and the larger the other indicators, the better).
[0052]
[0053]
[0054] By comparison, we can see that:
[0055] The present invention can save more than 40% of computational overhead on multiple multimodal task datasets without sacrificing performance. Specifically, for visual question answering tasks such as AI2D and SQA (Image), the present invention achieves higher performance with less computational overhead than the previous method FastV; for visual reasoning tasks such as MMMU (Val) and MMB (EN), the present invention can still show performance comparable to FastV or even the baseline model with less computational overhead; for hallucination tasks such as POPE, the present invention has a significant lead over the previous method FastV; for comprehensive evaluation datasets such as MME, the present invention uses less computational overhead on the models LLaVA-1.5-7B and LLaVA-NeXT-7B and achieves higher scores.
[0056] In addition, the present invention can also be directly applied to a chatbot with a multimodal large language model, which can speed up the chatbot's response speed without affecting the quality of the answer. An example of a dialogue result is shown in FIG. Figure 3 shown.
[0057] The above embodiments and drawings do not limit the product form and style of the present invention. Any appropriate changes or modifications made by ordinary technicians in the relevant technical field should be deemed to be within the patent scope of the present invention.
Claims
1. A method for accelerating the reasoning of a multimodal large language model by using visual tokens to be withdrawn in advance, wherein the input of the multimodal large language model consists of system tokens, visual tokens, instruction tokens and output tokens, characterized in that include: The withdrawal layer K for early withdrawal of visual tokens is determined by performing a strategy search on a subset of the target dataset. The specific steps are as follows: a1. Randomly extract 20 samples from the target data set to form a data subset; a2. Use a large multimodal language model to process a data subset and retain the predicted distribution of the classification head of the large multimodal language model for each sample; a3. Define N as the number of layers of the multimodal large language model, traverse K = {5, 6, 7, ..., N} and perform the following steps: a3-1. Perform normal forward reasoning on the 1st to K-1th layers of the multimodal large language model; a3-2. Remove all visual tokens at layer K; a3-3. Perform forward reasoning involving only system tokens, instruction tokens, and output tokens in the Kth to Nth layers of the multimodal large language model; a3-4. Calculate the Kullback-Leibler divergence of the predicted distribution obtained by removing the visual token inference of the Kth layer of the multimodal large language model and the predicted distribution obtained by normal inference of the multimodal large language model. The Kullback-Leibler divergence is averaged over 20 samples of the data subset. If the averaged Kullback-Leibler divergence is less than the preset threshold, the loop is exited and the current K is used as the number of layers from which the visual token is withdrawn in advance. After determining the withdrawal layer K for withdrawing visual tokens in advance, the specific steps for accelerating the inference of the multimodal large language model by withdrawing visual tokens in advance are as follows: b1. Perform normal forward reasoning on the 1st to K-1th layers of the multimodal large language model; b2. Remove all visual tokens at layer K; b3. Perform forward reasoning involving only system tokens, instruction tokens, and output tokens in the Kth to Nth layers of the multimodal large language model; b4. Calculate the predicted distribution of the Kth layer of the multimodal large language model after removing the visual token, determine the next token based on the current predicted distribution, and then splice the token after the input token of the last prediction; b5. Return to b1 until the multimodal large language model predicts a stop symbol.
2. The method for accelerating the reasoning of a multimodal large language model by using early withdrawal of visual tokens as claimed in claim 1, characterized in that: In the step a3-4, the preset threshold is 0.003.
Citation Information
Cited By
Illusion relieving method and device for multi-modal large model, electronic equipment and medium
CN119128061A
Classification task processing method and device, terminal equipment and storage medium
CN119312137A
A processing method and device of a classification task, a terminal device, and a storage medium
CN119312137B
Multi-modal large model non-training reasoning acceleration method and device based on visual token pruning
CN119761519A
Large-scale language model reasoning acceleration method based on cache fusion, electronic equipment and storage medium
CN119831032A
