Step 3: Download the
MHA2MLA models
and run inference.
Take
fnlp/Llama-2-7B-MLA-d_kv_64
as an example:
import torch
from transformers import AutoConfig, AutoTokenizer, LlamaForCausalLM
from monkey_patch import infer_monkey_patch
model_name = "fnlp/Llama-2-7B-MLA-d_kv_64"# Monkey Patch: MHA -> MLA
config = AutoConfig.from_pretrained(model_name)
if"RoPE"in config:
config.RoPE["qk_tensor_path"] = "qk_tensor_7B.pth"# Configuration for Specific Models
infer_monkey_patch(config.RoPE)
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = LlamaForCausalLM.from_pretrained(model_name, config=config, torch_dtype=torch.bfloat16).cuda()
# Generate
text = "Which American-born Sinclair won the Nobel Prize for Literature in 1930?"
inputs = tokenizer(text, return_tensors="pt").to(model.device)
generation_kwargs = {"do_sample": False, "use_cache": True, "max_new_tokens": 128}
output = model.generate(**inputs, **generation_kwargs)
print(tokenizer.decode(output[0], skip_special_tokens=True))
# - Sinclair Lewis
Citation
@misc{ji2025economicalinferenceenablingdeepseeks,
title={Towards Economical Inference: Enabling DeepSeek's Multi-Head Latent Attention in Any Transformer-based LLMs},
author={Tao Ji and Bin Guo and Yuanbin Wu and Qipeng Guo and Lixing Shen and Zhan Chen and Xipeng Qiu and Qi Zhang and Tao Gui},
year={2025},
eprint={2502.14837},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2502.14837},
}
Runs of OpenMOSS-Team Llama-2-7B-MLA-d_kv_64 on huggingface.co
14
Total runs
0
24-hour runs
0
3-day runs
7
7-day runs
-13
30-day runs
More Information About Llama-2-7B-MLA-d_kv_64 huggingface.co Model
Llama-2-7B-MLA-d_kv_64 huggingface.co is an AI model on huggingface.co that provides Llama-2-7B-MLA-d_kv_64's model effect (), which can be used instantly with this OpenMOSS-Team Llama-2-7B-MLA-d_kv_64 model. huggingface.co supports a free trial of the Llama-2-7B-MLA-d_kv_64 model, and also provides paid use of the Llama-2-7B-MLA-d_kv_64. Support call Llama-2-7B-MLA-d_kv_64 model through api, including Node.js, Python, http.
Llama-2-7B-MLA-d_kv_64 huggingface.co is an online trial and call api platform, which integrates Llama-2-7B-MLA-d_kv_64's modeling effects, including api services, and provides a free online trial of Llama-2-7B-MLA-d_kv_64, you can try Llama-2-7B-MLA-d_kv_64 online for free by clicking the link below.
OpenMOSS-Team Llama-2-7B-MLA-d_kv_64 online free url in huggingface.co:
Llama-2-7B-MLA-d_kv_64 is an open source model from GitHub that offers a free installation service, and any user can find Llama-2-7B-MLA-d_kv_64 on GitHub to install. At the same time, huggingface.co provides the effect of Llama-2-7B-MLA-d_kv_64 install, users can directly use Llama-2-7B-MLA-d_kv_64 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
Llama-2-7B-MLA-d_kv_64 install url in huggingface.co: