Papers › Towards Economical Inference: Enabling DeepSeek's Multi-Head Latent Attention in Any...

Towards Economical Inference: Enabling DeepSeek's Multi-Head Latent Attention in Any Transformer-based LLMs

20 Feb 2025arXiv:2502.14837archive 2025-07-28

Tao Ji, Bin Guo, Yuanbin Wu, Qipeng Guo, Lixing Shen, Zhan Chen, Xipeng Qiu, Qi Zhang, Tao Gui

Multi-head Latent Attention (MLA) is an innovative architecture proposed by DeepSeek, designed to ensure efficient and economical inference by significantly compressing the Key-Value (KV) cache into a latent vector. Compared to MLA, standard LLMs employing Multi-Head Attention (MHA) and its variants such as Grouped-Query Attention (GQA) exhibit significant cost disadvantages. Enabling well-trained LLMs (e.g., Llama) to rapidly adapt to MLA without pre-training from scratch is both meaningful and challenging. This paper proposes the first data-efficient fine-tuning method for transitioning from MHA to MLA (MHA2MLA), which includes two key components: for partial-RoPE, we remove RoPE from dimensions of queries and keys that contribute less to the attention scores, for low-rank approximation, we introduce joint SVD approximations based on the pre-trained parameters of keys and values. These carefully designed strategies enable MHA2MLA to recover performance using only a small fraction (0.3% to 0.6%) of the data, significantly reducing inference costs while seamlessly integrating with compression techniques such as KV cache quantization. For example, the KV cache size of Llama2-7B is reduced by 92.19%, with only a 0.5% drop in LongBench performance.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2502.14837")

Code

Syntology Ran 0 of 15 code samples harvested from 1 repository linked to this paper; 15 have no recorded run.

By repository: official repository: 15 samples from 1 repository, 0 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

JT-Ushio/MHA2MLA officialmentioned on GitHubpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

15 samples harvested; 0 ran; 0 honoured the contract we drafted; 15 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

15unverified

Licence: 0 of the 15 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from JT-Ushio/MHA2MLA. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: 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. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

SVD JT-Ushio/MHA2MLA/src/mha2mla/patch_func.py official repository unverified Apache-2.0 (permissive) · d1722a47a6e68260 · report
create_custom_apply_rotary_pos_emb JT-Ushio/MHA2MLA/src/mha2mla/patching_llama.py official repository unverified Apache-2.0 (permissive) · bd8982c35600a2b7 · report
create_custom_apply_rotary_pos_emb JT-Ushio/MHA2MLA/src/mha2mla/patching_qwen2.py official repository unverified Apache-2.0 (permissive) · f73327d915050f1a · report
create_custom_apply_rotary_pos_emb JT-Ushio/MHA2MLA/src/mha2mla/patching_qwen3.py official repository unverified Apache-2.0 (permissive) · 4b3aa5813125a737 · report
create_custom_apply_rotary_pos_emb JT-Ushio/MHA2MLA/src/mha2mla/patching_qwen3_moe.py official repository unverified Apache-2.0 (permissive) · e3be3d316dce65ea · report
create_hook_fn JT-Ushio/MHA2MLA/src/mha2mla/2_norm.py official repository unverified Apache-2.0 (permissive) · 3e838680cc326966 · report
custom_LlamaAttention_forward JT-Ushio/MHA2MLA/src/mha2mla/patching_llama.py official repository unverified Apache-2.0 (permissive) · 19448606f10d10d8 · report
custom_Qwen2Attention_forward JT-Ushio/MHA2MLA/src/mha2mla/patching_qwen2.py official repository unverified Apache-2.0 (permissive) · 7ac64d7242a38034 · report
custom_Qwen3Attention_forward JT-Ushio/MHA2MLA/src/mha2mla/patching_qwen3.py official repository unverified Apache-2.0 (permissive) · ccace102b231da7d · report
custom_Qwen3MoeAttention_forward JT-Ushio/MHA2MLA/src/mha2mla/patching_qwen3_moe.py official repository unverified Apache-2.0 (permissive) · 88a635fd8ae25685 · report
generate_random_input_ids JT-Ushio/MHA2MLA/eval/benchmark_latency_memory.py official repository unverified Apache-2.0 (permissive) · c72933732661bbe4 · report
mha2mla_ref JT-Ushio/MHA2MLA/src/mha2mla/mla_triton_kernel.py official repository unverified Apache-2.0 (permissive) · c836c0fa19b74615 · report
partial_rope_mask JT-Ushio/MHA2MLA/src/mha2mla/patch_func.py official repository unverified Apache-2.0 (permissive) · 818485f3147eb543 · report
reorder_matrix_rows JT-Ushio/MHA2MLA/src/mha2mla/patching_model_load.py official repository unverified Apache-2.0 (permissive) · 937f754d0af3a99a · report
svd_low_rank_approx JT-Ushio/MHA2MLA/src/mha2mla/patch_func.py official repository unverified Apache-2.0 (permissive) · 1b387fd9635cb3ad · report

Tasks

Quantization

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

AttentionDense ConnectionsFeedforward NetworkGrouped-query attentionLinear LayerMulti-Head AttentionSoftmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections