{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/meda-dynamic-kv-cache-allocation-for","title":"MEDA: Dynamic KV Cache Allocation for Efficient Multimodal Long-Context Inference","arxiv_id":"2502.17599","date":"2025-02-24","proceeding":null,"authors":["Zhongwei Wan","Hui Shen","Xin Wang","Che Liu","Zheda Mai","Mi Zhang"],"abstract":"Long-context Multimodal Large Language Models (MLLMs) that incorporate long text-image and text-video modalities, demand substantial resources as their multimodal Key-Value (KV) caches grow with increasing input lengths, challenging inference efficiency. Existing methods for KV cache compression, in both text-only and multimodal LLMs, have neglected attention density variations across layers, thus often adopting uniform or progressive reduction strategies for layer-wise cache allocation. In this work, we propose MEDA, a dynamic layer-wise KV cache allocation method for efficient multimodal long-context inference. As its core, MEDA utilizes cross-modal attention entropy to determine the KV cache size at each MLLMs layer. Given the dynamically allocated KV cache size at each layer, MEDA also employs a KV pair selection scheme to identify which KV pairs to select and a KV pair merging strategy that merges the selected and non-selected ones to preserve information from the entire context. MEDA achieves up to 72% KV cache memory reduction and 2.82 times faster decoding speed, while maintaining or enhancing performance on various multimodal tasks in long-context settings, including multi-images and long-video scenarios. Our code is released at https://github.com/AIoT-MLSys-Lab/MEDA.","url_abs":"https://arxiv.org/abs/2502.17599v1","url_pdf":"https://arxiv.org/pdf/2502.17599v1.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"meda-dynamic-kv-cache-allocation-for","repo_url":"https://github.com/aiot-mlsys-lab/meda","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[],"methods":[{"method_slug":"attention","method_name":"Attention"},{"method_slug":"softmax","method_name":"Softmax"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2502.17599","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2502.17599"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/aiot-mlsys-lab/meda","reach":null}],"summary":{"ran":1,"ran_honours":1,"ran_fixture":1,"unverified":2},"by_repo_kind":{"official":{"samples":5,"ran":3,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"2e14541ab89507cc","entry":"LlamaConfig","repo":"aiot-mlsys-lab/meda","repo_kind":"official","path":"Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","file_url":"https://github.com/aiot-mlsys-lab/meda/blob/HEAD/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2e14541ab89507cc"}},{"code_sha256_prefix":"f3114ee33d500c6c","entry":"_make_causal_mask","repo":"aiot-mlsys-lab/meda","repo_kind":"official","path":"Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","file_url":"https://github.com/aiot-mlsys-lab/meda/blob/HEAD/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f3114ee33d500c6c"}},{"code_sha256_prefix":"c0fa64892f2fc8ee","entry":"apply_rotary_pos_emb_single","repo":"aiot-mlsys-lab/meda","repo_kind":"official","path":"Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","file_url":"https://github.com/aiot-mlsys-lab/meda/blob/HEAD/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c0fa64892f2fc8ee"}},{"code_sha256_prefix":"46067e9c33ae2a58","entry":"AttnEntropyTextPivotMerge_LayerWise","repo":"aiot-mlsys-lab/meda","repo_kind":"official","path":"Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","file_url":"https://github.com/aiot-mlsys-lab/meda/blob/HEAD/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"46067e9c33ae2a58"}},{"code_sha256_prefix":"c11c5eb9ee9537da","entry":"DynamicLlamaAttention_drop","repo":"aiot-mlsys-lab/meda","repo_kind":"official","path":"Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","file_url":"https://github.com/aiot-mlsys-lab/meda/blob/HEAD/Dynamic-MLLMs/LLaVA-mix_merge_v1/llava/model/kv_token_merge/modify_llama.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c11c5eb9ee9537da"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}