Lightweight multi-modal large model inference optimization method and system

By generating global semantic summary vectors and dynamic visual sparsification in a multimodal large model, combined with visual dependency strength perception, the problem of static adjustment of visual compression strategy is solved, and the on-demand retention of visual tokens and coordinated release of text cache are realized, thereby improving computational efficiency and long text decoding performance.

CN123180348APending Publication Date: 2026-11-27XIAMEN OCEAN VOCATIONAL & TECH COLLEGE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611354144.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-02
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

The existing visual compression strategy of multimodal large models in the inference stage cannot adaptively adjust according to the dynamic changes in the degree of dependence on visual information in the decoding step, resulting in redundant computation, wasting computing power and memory bandwidth. The visual token cache cannot be released as needed, affecting the throughput efficiency of long text decoding.

Method used

By generating and caching a fixed-length global semantic summary vector during the pre-filling stage, and combining it with the visual dependency strength perception at each decoding step, the amount of visual tokens retained is dynamically adjusted, and text cache pruning is triggered under low dependency conditions, thereby achieving coordinated release of visual and text caches.

Benefits of technology

The computational efficiency of visual information was optimized, the computational power and memory usage were reduced, the semantic coherence of the generated content and the throughput efficiency of long text decoding were maintained, and the overall performance of the model was improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123180348A_ABST
    Figure CN123180348A_ABST
Patent Text Reader

Abstract

The application provides a lightweight multi-modal large model inference optimization method and system, relates to the field of large model optimization, and includes obtaining an input image, generating a complete visual Token sequence through a visual encoder as a candidate pool; performing cross-attention calculation on a query vector of a current decoding step and a key vector of a visual Token in the candidate pool to obtain an attention score, determining a visual dependence intensity coefficient based on the attention score; if the visual dependence intensity coefficient meets a first preset condition, all visual Tokens are retained; if the visual dependence intensity coefficient meets a second preset condition, part of the visual Tokens are retained from the candidate pool according to the attention score, and the rest of the visual Tokens are set to a mask state. Under the condition of high visual dependence, the application enables fine-grained visual information such as spatial relationship and object attribute to be obtained by the model; under the condition of low visual dependence, the calculation amount of redundant visual Tokens is reduced, and the occupation of computing power and display memory bandwidth is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of large model optimization, and more specifically, to a lightweight multimodal large model inference optimization method and system. Background Technology

[0002] In existing multimodal large models, visual information processing during the inference phase follows a fixed process of "encoding-compression-caching-decoding". After the input image generates a visual token sequence through a visual encoder, compression or pruning operations are performed once during the pre-padding stage (e.g., reducing the number of visual tokens to a fixed length through pooling, sparsification, or cross-modal projection). Subsequently, this fixed compression result or the original full set of visual tokens is used throughout the autoregressive decoding process. Some schemes additionally introduce a visual summary vector as supplementary global information, but this summary is also pre-computed and statically invariant.

[0003] In actual inference, the dependence of different decoding steps on visual details changes dynamically: when generating descriptive content involving spatial relationships and object attributes, the model highly relies on fine-grained visual information; when generating content involving logical deduction or linguistic coherence, the contribution of visual information decreases. Since visual compression and pruning are only performed once in the pre-filling stage, the number of visual tokens retained cannot be adjusted according to actual needs throughout the subsequent decoding process, leading to two consequences: if a more conservative compression strategy is adopted (retaining more visual tokens), redundant visual tokens will continue to participate in cross-attention calculations in decoding steps with low dependence, resulting in a waste of computing power and memory bandwidth; if a more aggressive compression strategy is adopted (retaining very few visual tokens), accuracy will be lost in decoding steps with high dependence due to insufficient visual details.

[0004] Meanwhile, the key-value caches for visual tokens and historical text tokens continue to grow, consuming significant GPU memory resources. The visual token cache, due to its fixed compression strategy, resides throughout the inference process and cannot be released on demand based on its current importance. The historical text token cache, on the other hand, monotonically increases with each decoding step, further crowding out GPU memory. The lack of a collaborative release mechanism based on real-time dependency states leads to a continuous expansion of the key-value cache sequence length, hindering the throughput efficiency of long text decoding.

[0005] Therefore, we have made improvements to this by proposing a lightweight multimodal large model inference optimization method and system. Summary of the Invention

[0006] The purpose of this invention is to address the following issues: Current visual compression strategies are statically executed only during the pre-filling stage, failing to adaptively adjust the amount of visual tokens retained based on the dynamic changes in the degree of visual information dependence during the decoding step. This leads to redundant computations wasting computing power and GPU memory bandwidth during conservative compression, and insufficient visual details causing accuracy loss during aggressive compression. Furthermore, the visual token key-value cache resides throughout the inference process due to a fixed compression strategy, preventing dynamic release based on current importance and causing continuous GPU memory resource occupation. Finally, the lack of a collaborative release mechanism based on real-time dependency states between visual and text key-value caches results in a continuous expansion of the key-value cache sequence length, hindering the throughput efficiency of long text decoding.

[0007] To achieve the above-mentioned objectives, this invention provides a lightweight multimodal large model inference optimization method and system to improve the aforementioned problems.

[0008] The application is as follows: A lightweight multimodal large model inference optimization method includes the following steps: Step 1, Pre-filling initialization: Obtain the input image, generate a complete visual token sequence through the visual encoder as a candidate pool; at the same time, pool and compress the visual token sequence to generate a set of fixed-length global semantic summary vectors and cache them. This summary vector is not sparsified and serves as the global background information that is always present throughout the process. It also participates in the cross-attention calculation of each decoding step in parallel with the visual tokens after subsequent sparsification. Step 2, Dependency Strength Perception: For the current decoding step, cross-attention calculation is performed using the query vector of the current decoding step and the key vector of the visual token in the candidate pool to obtain an attention score, and the visual dependency strength coefficient is determined based on the attention score. Step 3, Dynamic Visual Sparsity: If the visual dependency strength coefficient meets the first preset condition, all visual tokens are retained; if the visual dependency strength coefficient meets the second preset condition, some visual tokens are retained from the candidate pool according to the attention score, and the remaining visual tokens are set to a masked state and do not participate in the forward calculation of the current step. Step 4, Summary Injection: The visual token processed in Step 3 and the global semantic summary vector cached in Step 1 are injected in parallel into the multi-head attention module as key-value pairs to participate in cross-attention calculation; the global semantic summary vector participates in cross-attention calculation as an independent key-value pair, and no positional encoding based on the incremental position of the text sequence is assigned to the global semantic summary vector. Step 5, Text Cache Collaborative Pruning: When the visual dependency strength coefficient continuously meets the third preset condition, text key-value cache pruning is triggered: Based on the attention relationship between historical text tokens, at least one redundant token is removed, and the storage corresponding to the redundant token in the key-value cache is deleted.

[0009] As a preferred technical solution of this application, in step two, the attention calculation is the dot product operation between the query vector of the current decoding step and the key vector of all visual tokens in the candidate pool to obtain the original attention score vector; the visual dependency strength coefficient is the maximum value of the unnormalized logits value in the original attention score vector, which reflects the highest degree of attention of the current decoding step to the most relevant single visual token in the candidate pool.

[0010] As a preferred technical solution of this application, in step three, the first preset condition is that the visual dependence intensity coefficient is higher than a preset threshold, and the second preset condition is that the visual dependence intensity coefficient is lower than or equal to the preset threshold; the partial visual tokens are the top K visual tokens with the highest attention scores; the preset threshold is pre-calibrated and stored in the inference system based on the distribution of the visual dependence intensity coefficients of each decoding step on the verification set.

[0011] The initial value of K, which is the preferred technical solution in this application, is set as the total number of visual tokens in the candidate pool. This ensures that all visual tokens are retained during the initial decoding stage; the K can be within a closed interval [ , Gradual adjustment within, including It is 5% of the total number of visual tokens in the candidate pool; when the strength coefficient is lower than the threshold for multiple consecutive decoding steps and the current K> At that time, the K value is gradually reduced according to the preset fixed step size.

[0012] As a preferred technical solution of this application, in step five, the third preset condition includes: The visual dependence intensity coefficient is lower than the preset threshold for N consecutive steps; Alternatively, the proportion of the visual dependence intensity coefficient that is below the preset threshold in the most recent M decoding steps exceeds the preset proportion threshold R; The number of times text key-value cache pruning is triggered during the same decoding process is capped at T. Once the cap is reached, no new pruning operation will be triggered until the current decoding process ends. N, M, R, and T are all preset values.

[0013] As a preferred technical solution of this application, step five, which involves removing at least one redundant token and deleting its corresponding storage in the key-value cache, specifically includes: Calculate the self-attention score among all historical text tokens that have been generated so far, identify and remove the token with the lowest attention score, and delete the key vector and value vector corresponding to the token in the key-value cache. For the remaining text tokens, their original rotation position encoding information used during generation is retained unchanged. The stored key-value pairs are not recalculated or modified. After the key-value pairs of the removed tokens are removed, since the rotation position encoding naturally reflects the relative position relationship, the relative position information between the remaining tokens is directly maintained by their original rotation position encoding, without the need for renumbering or applying additional masks.

[0014] As a preferred technical solution of this application, the modification of the attention mask matrix in the subsequent decoding step is specifically as follows: the rotation position encoding encodes the absolute position of the query vector and key vector of each Token through the rotation matrix, and at the same time introduces relative position dependency in the attention calculation, so that after deleting the key vector and value vector corresponding to any Token in the key-value cache, the relative position relationship of the remaining Tokens in the self-attention calculation remains unchanged.

[0015] A lightweight multimodal large model inference optimization system includes: The pre-filling initialization module is configured to acquire the input image, generate a complete visual token sequence as a candidate pool through the visual encoder, and simultaneously pool and compress the visual token sequence to generate a set of fixed-length global semantic summary vectors and cache them. These summary vectors are not sparsified and serve as global background information that is always present throughout the process. They also participate in the cross-attention calculation of each decoding step in parallel with the visual tokens after subsequent sparsification. The dependency strength perception module is configured to perform cross-attention calculation with the query vector of the current decoding step and the key vector of the visual token in the candidate pool at each decoding step to obtain an attention score, and determine the visual dependency strength coefficient based on the attention score. The dynamic visual sparsification module is configured to: if the visual dependency strength coefficient meets a first preset condition, then retain all visual tokens; if the visual dependency strength coefficient meets a second preset condition, then retain some visual tokens from the candidate pool according to the attention score, and set the remaining visual tokens to a masked state, so that they do not participate in the forward calculation of the current step. The abstract parallel injection module is configured to inject the visual token processed by the dynamic visual sparsification module and the global semantic summary vector cached by the pre-filling initialization module in parallel as key-value pairs into the multi-head attention module to participate in cross-attention calculation; the global semantic summary vector participates in cross-attention calculation as an independent key-value pair, and no position encoding based on the incremental position of the text sequence is assigned to the global semantic summary vector. The text cache collaborative pruning module is configured to trigger text key-value cache pruning when the visual dependency strength coefficient continuously meets the third preset condition: based on the attention relationship between historical text tokens, at least one redundant token is removed, and the storage corresponding to the redundant token in the key-value cache is deleted.

[0016] As a preferred technical solution of this application, the text cache collaborative pruning module is further configured to: calculate the self-attention score among all currently generated historical text tokens, identify and remove the token with the lowest attention score as a redundant token, and delete the key vector and value vector corresponding to the token in the key-value cache; retain the original rotation position encoding information used when the remaining text tokens were generated unchanged, without recalculating or modifying the stored key-value pairs, and after the key-value pairs of the removed tokens are removed, since the rotation position encoding naturally reflects the relative position relationship, the relative position information among the remaining tokens is directly maintained by their respective original rotation position encodings, without the need for renumbering or applying additional masks.

[0017] Compared with the prior art, the beneficial effects of the present invention are as follows: In the scheme of this application: 1. By performing cross-attention calculations between the query vector of each decoding step and the key vectors of all visual tokens in the candidate pool, a visual dependency strength coefficient is obtained. Based on the relationship between this coefficient and a preset threshold, the model dynamically selects to retain either all visual tokens or the Top-K most relevant tokens for cross-attention calculation. This changes the existing technology where visual compression is only performed once in the pre-filling stage and cannot be adjusted throughout the subsequent decoding process. Under high visual dependency conditions, all visual tokens participate in the current step calculation, enabling the model to acquire fine-grained visual information such as spatial relationships and object attributes. Under low visual dependency conditions, the Top-K most relevant visual tokens are retained for calculation, reducing the computational load of redundant visual tokens and lowering the consumption of computing power and GPU memory bandwidth. The K value can be gradually decreased between the total number of visual tokens and a preset lower limit. When the dependency strength recovers to above the threshold, the masked visual tokens resume participation in the current step calculation, so that the availability of visual information recovers synchronously with the dependency state. 2. By generating a fixed-length global semantic summary vector and caching it independently during the pre-filling stage, this summary vector is not sparsified and participates in the cross-attention calculation of each decoding step as an independent key-value pair, without being assigned an incremental position index. In low-dependency decoding steps, even if only a small number of local visual tokens are retained for calculation, the summary vector still provides global background information for the cross-attention module, compensating for the loss of global contextual information that may be caused by dynamic sparsification and maintaining the semantic coherence of the generated content. 3. By triggering text-side key-value cache pruning when the visual dependency strength coefficient continuously meets the preset low dependency condition, redundant tokens are removed based on the self-attention scores between historical text tokens, and their corresponding key-value storage is released. This establishes a cross-modal relationship between the visual dependency state and the text-side cache lifecycle, changing the way visual and text caches grow independently and lack coordinated release. During pruning, the original rotation position encoding of the remaining tokens remains unchanged. After the key-value pairs of the removed tokens are physically removed, the relative positional relationship between the remaining tokens is naturally reflected by the rotation position encoding, without the need for renumbering, recalculating key-value pairs, or applying additional attention masks. At the same time, each round of triggering removes only a single token, releasing the cache in a gradual manner, reducing the possibility of context jumps caused by batch deletion. Thus, while releasing video memory resources and suppressing the growth of the KV cache sequence, the relative positional relationship and context modeling capability of the remaining tokens are maintained, improving the throughput efficiency of long text decoding under the same generation quality conditions. Attached Figure Description

[0018] Figure 1 A flowchart illustrating the lightweight multimodal large model inference optimization method provided in this application; Figure 2 A schematic diagram of the module structure of the lightweight multimodal large model inference optimization system provided in this application. Detailed Implementation

[0019] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0020] The present invention will be further described below with reference to embodiments.

[0021] Example: Please refer to Figures 1 to 2As shown, a lightweight multimodal large model inference optimization method is mainly used to address the following problems: Visual compression strategies are statically executed only during the pre-filling stage, failing to adaptively adjust the amount of visual tokens retained based on the dynamic changes in the degree of visual information dependence in the decoding step. This leads to redundant computation and wasted computing power and GPU memory bandwidth during conservative compression, and insufficient visual details causing accuracy loss during aggressive compression. Furthermore, the visual token key-value cache resides throughout the inference process due to the fixed compression strategy, failing to dynamically release it according to its current importance, resulting in continuous GPU memory resource occupation. Finally, the lack of a collaborative release mechanism based on real-time dependency states between visual and text key-value caches causes the key-value cache sequence length to continuously expand, restricting the throughput efficiency of long text decoding. The specific method includes the following steps: Step 1, Pre-filling initialization: Obtain the input image, generate a complete visual token sequence through the visual encoder as a candidate pool; at the same time, pool and compress the visual token sequence to generate a set of fixed-length global semantic summary vectors and cache them. This summary vector is not sparsified and serves as the global background information that is always present throughout the process. It also participates in the cross-attention calculation of each decoding step in parallel with the visual tokens after subsequent sparsification. Preferably, in this step, the visual encoder can adopt the Vision Transformer architecture; by dividing the input image into fixed-size image blocks (such as 16×16 pixels), mapping each image block to a vector through linear projection, and outputting a visual token sequence after multi-layer Transformer encoding; the visual encoder can also adopt an alternative architecture based on convolutional neural networks to achieve the same function; the candidate pool retains the key-value cache of all visual tokens for subsequent decoding steps to call as needed.

[0022] Pooling compression can be implemented using adaptive average pooling; for example, the visual token sequence is pooled in the spatial dimension to compress the visual token sequence of arbitrary length to a preset fixed length (e.g., compressed to 4 digest vectors); after compression, the digest vectors are normalized and cached independently, so that they remain independent from the visual tokens after subsequent sparsification in terms of data storage and computation path.

[0023] Step 2, Dependency Strength Perception: For the current decoding step, cross-attention calculation is performed using the query vector of the current decoding step and the key vector of the visual token in the candidate pool to obtain an attention score, and the visual dependency strength coefficient is determined based on the attention score. Preferably, in this step, the attention calculation is performed as follows: in the multi-head attention module, the query vector comes from the text-side representation of the decoder in the current step, and the key vector and value vector come from the visual token sequence output by the encoder.

[0024] Attention is calculated by performing a dot product operation between the query vector of the current decoding step and the key vectors of all visual tokens in the candidate pool, resulting in the original attention score vector. The visual dependency strength coefficient is the maximum value of the unnormalized logits in the original attention score vector. This coefficient reflects the highest level of attention given to the most relevant single visual token in the candidate pool in the current decoding step. The calculation process reuses the intermediate calculation results of the multi-head attention module without introducing an additional independent evaluation network or forward propagation.

[0025] Step 3, Dynamic Visual Sparsity: If the visual dependency strength coefficient meets the first preset condition, all visual tokens are retained; if the visual dependency strength coefficient meets the second preset condition, some visual tokens are retained from the candidate pool according to the attention score, and the remaining visual tokens are set to a masked state and do not participate in the forward calculation of the current step. In this step, "mask state" means that in the attention calculation of the current decoding step, the value of the corresponding visual token position is set to negative infinity through the attention mask matrix, so that it does not participate in the forward calculation of the current step; the visual tokens in the candidate pool and their key-value caches are still completely retained in the video memory and have not been physically deleted, so that they can be restored to participate in the calculation in subsequent highly dependent decoding steps. Preferably, the first preset condition is that the visual dependence intensity coefficient is higher than a preset threshold, and the second preset condition is that the visual dependence intensity coefficient is lower than or equal to the preset threshold; the partial visual tokens are the top K visual tokens with the highest attention scores; the preset threshold is pre-calibrated and stored in the inference system based on the distribution of the visual dependence intensity coefficients of each decoding step on the verification set. The preset threshold is calibrated as follows: run model inference on the validation set, record the visual dependency strength coefficient of each decoding step, and statistically analyze its distribution characteristics (such as mean, standard deviation or specific quantiles). Based on this, determine the threshold and store it in the configuration file of the inference system for use during actual inference.

[0026] Preferably, the initial value of K is set to the total number of visual tokens in the candidate pool. This ensures that all visual tokens are retained during the initial decoding stage; the K can be within a closed interval [ , Gradual adjustment within, including It is 5% of the total number of visual tokens in the candidate pool; when the strength coefficient is lower than the threshold for multiple consecutive decoding steps and the current K> At that time, the K value is gradually reduced according to the preset fixed step size.

[0027] The "preset fixed step size value" is preset according to the actual application scenario's memory resources and precision requirements. For example, it can be set to a positive integer such as 1 or 2, or take max(1, ( - The step size is 10 / 10; the process of gradually decreasing the K value is gradual, decreasing by only one step size each time the reduction condition is triggered, reducing the risk of sudden drops in the K value causing abrupt changes in visual information. When the visual dependency intensity coefficient of any decoding step recovers to above the threshold, the K value immediately recovers to 10 / 10. This allows all visual tokens to participate in the current step's calculation.

[0028] Step 4, Summary Injection: The visual token processed in Step 3 and the global semantic summary vector cached in Step 1 are injected in parallel into the multi-head attention module as key-value pairs to participate in cross-attention calculation; the global semantic summary vector participates in cross-attention calculation as an independent key-value pair, and no positional encoding based on the incremental position of the text sequence is assigned to the global semantic summary vector. In this step, "parallel injection" means that the sparsed visual tokens and the global semantic summary vector are treated as two independent key-value pairs and simultaneously fed into the multi-head attention module for computation in the same decoding step. The global semantic summary vector is not assigned an incrementing position index, meaning it is not considered part of the text sequence. This ensures that the positional encoding of the summary vector does not participate in the positional encoding calculation of the text sequence, thus not interfering with the relative positional relationships between text tokens.

[0029] Therefore, even after sparsification and retaining only local visual tokens, the global semantic summary vector still provides complete background context information to the multi-head attention module, thus maintaining the global semantic coherence of the generated content. Step 5, Text Cache Collaborative Pruning: When the visual dependency strength coefficient continuously meets the third preset condition, text key-value cache pruning is triggered: Based on the attention relationship between historical text tokens, at least one redundant token is removed, and the storage corresponding to the redundant token in the key-value cache is deleted.

[0030] In this step, the key-value cache is used to store calculated key-value pairs during the autoregressive decoding process of the large model, avoiding the recalculation of the key and value vectors of historical tokens each time a new token is generated. When pruning is triggered, the self-attention scores among all generated historical text tokens are calculated, and redundant tokens are identified based on the attention relationships. The criteria for determining redundant tokens are: in the currently generated text sequence, the token with the lowest self-attention score contributes the least to subsequent generation and can be removed as a redundant token. After removal, the key and value vectors corresponding to that token in the key-value cache are released from GPU memory to reduce GPU memory usage.

[0031] Therefore, the pruning trigger condition depends on the real-time dependency state on the visual side, while the released object is the key-value cache on the text side, forming a cross-modal association and collaborative control between the visual side state and the lifecycle of the text side cache. Preferably, the third preset condition includes: The visual dependence intensity coefficient is lower than the preset threshold for N consecutive steps; Alternatively, the proportion of the visual dependence intensity coefficient that is below the preset threshold in the most recent M decoding steps exceeds the preset proportion threshold R; The number of times text key-value cache pruning is triggered during the same decoding process is capped at T. Once the cap is reached, no new pruning operation will be triggered until the current decoding process ends. N, M, R, and T are all preset values.

[0032] In this preferred embodiment, "N consecutive steps below the threshold" is used to capture the steady-state situation where visual dependence continues to decrease; "the proportion of low-dependency steps in the most recent M decoding steps exceeds R" is used to capture the situation where dependence fluctuates frequently but does not form a continuous low dependency, as a supplement to the previous condition. The upper limit T of the number of triggers is used to prevent excessive pruning from destroying the contextual integrity of long text generation. The specific values ​​of N, M, R, and T are preset according to the memory capacity and accuracy requirements of the actual application scenario. For example, N can be 3 to 5, M can be 10 to 20, R can be 0.6 to 0.8, and T can be 3 to 5. The specific values ​​can be determined by parameter search on the validation set using memory usage and generation quality (such as downstream task accuracy or perplexity) as evaluation indicators. Preferably, in step five, removing at least one redundant token and deleting its corresponding storage in the key-value cache specifically includes: Calculate the self-attention score among all historical text tokens that have been generated so far, identify and remove the token with the lowest attention score, and delete the key vector and value vector corresponding to the token in the key-value cache. For the remaining text tokens, their original rotation position encoding information used during generation is retained unchanged, and the stored key-value pairs are not recalculated or modified. Since the rotation position encoding encodes the absolute position of each token's query vector and key vector through the rotation matrix, and naturally introduces relative position dependence in the attention calculation, after the key-value pairs of the removed tokens are removed, the relative position relationship between the remaining tokens is directly reflected by their original rotation position encoding, without the need for renumbering or applying additional masks, thus saving the corresponding computational overhead.

[0033] A lightweight multimodal large model inference optimization system, used in the aforementioned lightweight multimodal large model inference optimization method, includes the following modules: The pre-filling initialization module is configured to acquire the input image, generate a complete visual token sequence as a candidate pool through the visual encoder, and simultaneously pool and compress the visual token sequence to generate a set of fixed-length global semantic summary vectors and cache them. These summary vectors are not sparsified and serve as global background information that is always present throughout the process. They also participate in the cross-attention calculation of each decoding step in parallel with the visual tokens after subsequent sparsification. The dependency strength perception module is configured to perform cross-attention calculation with the query vector of the current decoding step and the key vector of the visual token in the candidate pool at each decoding step to obtain an attention score, and determine the visual dependency strength coefficient based on the attention score. The dynamic visual sparsification module is configured to: if the visual dependency strength coefficient meets a first preset condition, then retain all visual tokens; if the visual dependency strength coefficient meets a second preset condition, then retain some visual tokens from the candidate pool according to the attention score, and set the remaining visual tokens to a masked state, so that they do not participate in the forward calculation of the current step. The abstract parallel injection module is configured to inject the visual token processed by the dynamic visual sparsification module and the global semantic summary vector cached by the pre-filling initialization module in parallel as key-value pairs into the multi-head attention module to participate in cross-attention calculation; the global semantic summary vector participates in cross-attention calculation as an independent key-value pair, and no position encoding based on the incremental position of the text sequence is assigned to the global semantic summary vector. The text cache collaborative pruning module is configured to trigger text key-value cache pruning when the visual dependency strength coefficient continuously meets the third preset condition: based on the attention relationship between historical text tokens, at least one redundant token is removed, and the storage corresponding to the redundant token in the key-value cache is deleted.

[0034] In this system implementation, each module can be implemented as a software module, a hardware module, or a combination of both. The pre-filling initialization module is executed once during the inference startup phase. Subsequently, each module works collaboratively in sequence in each decoding step: the dependency strength perception module calculates the visual dependency strength coefficient of the current step; the dynamic visual sparsity module determines the retention strategy of the visual token based on this coefficient; the summary parallel injection module sends the sparsified visual token and the global semantic summary vector into the multi-head attention module in parallel; and the text cache collaborative pruning module performs a text key-value cache cleanup operation when the trigger condition is met. The specific implementation methods of each module are described in the relevant descriptions of the aforementioned method implementation methods and will not be repeated here. Preferably, the text cache collaborative pruning module is further configured to: calculate the self-attention score among all currently generated historical text tokens, identify and remove the token with the lowest attention score as a redundant token, and delete the key vector and value vector corresponding to the token in the key-value cache; retain the original rotation position encoding information used when generating the remaining text tokens unchanged, without recalculating or modifying the stored key-value pairs; since the rotation position encoding naturally introduces relative position dependence in the attention calculation, after the key-value pairs of the removed tokens are removed, the relative position relationship between the remaining tokens is directly reflected by their respective retained original rotation position encodings, without the need for renumbering or applying additional masks.

[0035] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," "linking," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection, an electrical connection, or a connection that allows communication between them; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components, unless otherwise explicitly limited. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0036] Obviously, the embodiments described above are merely some embodiments of the present invention, not all embodiments. The accompanying drawings show preferred embodiments of the present invention, but do not limit the patent scope of the present invention. The present invention can be implemented in many different forms; rather, these embodiments are provided to provide a more thorough and complete understanding of the disclosure of the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing specific embodiments, or make equivalent substitutions for some of the technical features. Any equivalent structures made using the content of this specification and drawings, directly or indirectly applied to other related technical fields, are similarly within the patent protection scope of this invention.

Claims

1. A lightweight multimodal large model inference optimization method, characterized in that, Includes the following steps: Step 1, Pre-filling initialization: Obtain the input image, generate a complete visual token sequence through the visual encoder as a candidate pool; at the same time, pool and compress the visual token sequence to generate a set of fixed-length global semantic summary vectors and cache them. This summary vector is not sparsified and serves as the global background information that is always present throughout the process. It also participates in the cross-attention calculation of each decoding step in parallel with the visual tokens after subsequent sparsification. Step 2, Dependency Strength Perception: For the current decoding step, cross-attention calculation is performed using the query vector of the current decoding step and the key vector of the visual token in the candidate pool to obtain an attention score, and the visual dependency strength coefficient is determined based on the attention score. Step 3, Dynamic Visual Sparsity: If the visual dependency strength coefficient meets the first preset condition, all visual tokens are retained; if the visual dependency strength coefficient meets the second preset condition, some visual tokens are retained from the candidate pool according to the attention score, and the remaining visual tokens are set to a masked state and do not participate in the forward calculation of the current step. Step 4, Summary Injection: The visual token processed in Step 3 and the global semantic summary vector cached in Step 1 are injected in parallel into the multi-head attention module as key-value pairs to participate in cross-attention calculation; the global semantic summary vector participates in cross-attention calculation as an independent key-value pair, and no positional encoding based on the incremental position of the text sequence is assigned to the global semantic summary vector. Step 5, Text Cache Collaborative Pruning: When the visual dependency strength coefficient continuously meets the third preset condition, text key-value cache pruning is triggered: Based on the attention relationship between historical text tokens, at least one redundant token is removed, and the storage corresponding to the redundant token in the key-value cache is deleted.

2. The lightweight multimodal large model inference optimization method according to claim 1, characterized in that, In step two, the attention calculation is the dot product operation between the query vector of the current decoding step and the key vectors of all visual tokens in the candidate pool to obtain the original attention score vector; the visual dependency strength coefficient is the maximum value of the unnormalized logits value in the original attention score vector, which reflects the highest degree of attention of the current decoding step to the most relevant single visual token in the candidate pool.

3. The lightweight multimodal large model inference optimization method according to claim 1, characterized in that, In step three, the first preset condition is that the visual dependence intensity coefficient is higher than a preset threshold, and the second preset condition is that the visual dependence intensity coefficient is lower than or equal to the preset threshold; the partial visual tokens are the top K visual tokens with the highest attention scores; the preset threshold is pre-calibrated and stored in the inference system based on the distribution of the visual dependence intensity coefficients of each decoding step on the verification set.

4. The lightweight multimodal large model inference optimization method according to claim 3, characterized in that, The initial value of K is set to the total number of visual tokens in the candidate pool. This ensures that all visual tokens are retained during the initial decoding stage; the K can be within a closed interval [ , Gradual adjustment within, including It is 5% of the total number of visual tokens in the candidate pool; When the intensity coefficient is below the threshold for multiple consecutive decoding steps and the current K> At that time, the K value is gradually reduced according to the preset fixed step size.

5. The lightweight multimodal large model inference optimization method according to claim 3, characterized in that, In step five, the third preset condition includes: The visual dependence intensity coefficient is lower than the preset threshold for N consecutive steps; Alternatively, the proportion of the visual dependence intensity coefficient that is below the preset threshold in the most recent M decoding steps exceeds the preset proportion threshold R; The number of times text key-value cache pruning is triggered during the same decoding process is capped at T. Once the cap is reached, no new pruning operation will be triggered until the current decoding process ends. N, M, R, and T are all preset values.

6. The lightweight multimodal large model inference optimization method according to claim 1, characterized in that, Step five, which involves removing at least one redundant token and deleting its corresponding storage in the key-value cache, specifically includes: Calculate the self-attention score among all historical text tokens that have been generated so far, identify and remove the token with the lowest attention score, and delete the key vector and value vector corresponding to the token in the key-value cache. For the remaining text tokens, their original rotation position encoding information used during generation is retained unchanged. The stored key-value pairs are not recalculated or modified. After the key-value pairs of the removed tokens are removed, since the rotation position encoding naturally reflects the relative position relationship, the relative position information between the remaining tokens is directly maintained by their original rotation position encoding, without the need for renumbering or applying additional masks.

7. The lightweight multimodal large model inference optimization method according to claim 6, characterized in that, The modification of the attention mask matrix in the subsequent decoding step is specifically as follows: the rotation position encoding encodes the absolute position of the query vector and key vector of each Token through the rotation matrix, and at the same time introduces relative position dependency in the attention calculation, so that after deleting the key vector and value vector corresponding to any Token in the key-value cache, the relative position relationship of the remaining Tokens in the self-attention calculation remains unchanged.

8. A lightweight multimodal large model inference optimization system, used to implement the lightweight multimodal large model inference optimization method according to any one of claims 1 to 7, characterized in that, include: The pre-filling initialization module is configured to acquire the input image, generate a complete visual token sequence as a candidate pool through the visual encoder, and simultaneously pool and compress the visual token sequence to generate a set of fixed-length global semantic summary vectors and cache them. These summary vectors are not sparsified and serve as global background information that is always present throughout the process. They also participate in the cross-attention calculation of each decoding step in parallel with the visual tokens after subsequent sparsification. The dependency strength perception module is configured to perform cross-attention calculation with the query vector of the current decoding step and the key vector of the visual token in the candidate pool at each decoding step to obtain an attention score, and determine the visual dependency strength coefficient based on the attention score. The dynamic visual sparsification module is configured to: if the visual dependency strength coefficient meets a first preset condition, then retain all visual tokens; if the visual dependency strength coefficient meets a second preset condition, then retain some visual tokens from the candidate pool according to the attention score, and set the remaining visual tokens to a masked state, so that they do not participate in the forward calculation of the current step. The abstract parallel injection module is configured to inject the visual token processed by the dynamic visual sparsification module and the global semantic summary vector cached by the pre-filling initialization module in parallel as key-value pairs into the multi-head attention module to participate in cross-attention calculation; the global semantic summary vector participates in cross-attention calculation as an independent key-value pair, and no position encoding based on the incremental position of the text sequence is assigned to the global semantic summary vector. The text cache collaborative pruning module is configured to trigger text key-value cache pruning when the visual dependency strength coefficient continuously meets the third preset condition: based on the attention relationship between historical text tokens, at least one redundant token is removed, and the storage corresponding to the redundant token in the key-value cache is deleted.

9. A lightweight multimodal large model inference optimization system according to claim 8, characterized in that, The text cache collaborative pruning module is further configured to: calculate the self-attention score among all currently generated historical text tokens, identify and remove the token with the lowest attention score as a redundant token, and delete the key vector and value vector corresponding to the token in the key-value cache. The remaining text tokens retain their original rotation position encoding information used during generation, without recalculating or modifying the stored key-value pairs. After the key-value pairs of the removed tokens are removed, the relative position information between the remaining tokens is directly maintained by their original rotation position encoding, since the rotation position encoding naturally reflects the relative position relationship, without the need for renumbering or applying additional masks.