GitHub 代码库 | 技术报告 | 加入我们
MiniCPM-SALA(稀疏注意力与线性注意力融合模型)是首个有效融合稀疏注意力与线性注意力机制的大规模混合模型,专为百万级token上下文建模而打造。
✅ 创新混合架构:将25%的稀疏注意力(InfLLM-v2)用于高保真长上下文建模,与75%的线性注意力(Lightning Attention)相结合,实现全局效率优化。
✅ 突破效率壁垒:成功打破“计算墙”与“内存墙”,相比密集型基线模型,推理速度提升3.5倍,KV缓存开销显著降低。
✅ 百万级token上下文:借助HyPE(混合位置嵌入)技术,模型可扩展至100万+token,同时保持强大的长度泛化能力。
✅ HALO适配技术:采用混合注意力层优化(HALO)这一新颖的蒸馏方案,将密集注意力的能力有效迁移至混合架构,避免了纯线性模型常见的严重性能下降问题。
MiniCPM-SALA 是一种高效的混合模型,其中 25% 的层采用 InfLLM-V2,其余 75% 的层则使用 Lightning Attention。这种架构使得在消费级 GPU(如 NVIDIA RTX 5090)上能够对一百万 tokens 进行推理。
SALA 混合注意力机制
Transformer 到混合模型的持续训练
HyPE(混合位置编码)
长序列的高效推理
为获得最佳性能,我们建议使用 Temperature=0.9。
我们的模型可直接与 🤗 Hugging Face transformers 兼容。您可以按以下方式使用我们的模型进行推理:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "openbmb/MiniCPM-SALA"
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True, device_map="auto")
model.eval()
prompts = ["My name is", "The capital of China is"]
with torch.no_grad():
inputs = tokenizer(prompts, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs)
output_texts = tokenizer.batch_decode(outputs)
print(output_texts)gcc / g++ 编译器uv 包管理器(脚本将进行检查)# Clone repository
git clone -b minicpm_sala https://github.com/OpenBMB/sglang.git
cd sglang
# One-click installation (creates venv and compiles all dependencies)
bash install_minicpm_sala.sh
# Or specify PyPI mirror
bash install_minicpm_sala.sh https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple安装脚本执行以下步骤:
sglang_minicpm_sala_env 虚拟环境(Python 3.12)3rdparty/(infllmv2)并初始化子模块(sparse_kernel)infllmv2_cuda_implsparse_kerneltilelang 和 flash-linear-attention# Activate environment
source sglang_minicpm_sala_env/bin/activate
# Launch Inference Server (Replace MODEL_PATH with actual path)
MODEL_PATH=/path/to/your/MiniCPM-SALA
python3 -m sglang.launch_server \
--model ${MODEL_PATH} \
--trust-remote-code \
--disable-radix-cache \
--attention-backend minicpm_flashinfer \
--chunked-prefill-size 8192 \
--max-running-requests 32 \
--skip-server-warmup \
--port 31111 \
--dense-as-sparse| 参数 | 描述 |
|---|---|
--trust-remote-code | 允许模型中包含自定义代码 |
--disable-radix-cache | 禁用 RadixAttention 前缀缓存 |
--attention-backend minicpm_flashinfer | 使用 MiniCPM FlashInfer 后端 |
--chunked-prefill-size 8192 | 分块预填充大小 |
--max-running-requests 32 | 最大并发请求数 |
--skip-server-warmup | 跳过服务器预热 |
--port 31111 | 服务器端口 |
--dense-as-sparse | 使用稠密转稀疏模式 |
如果脚本运行失败,请按照以下步骤操作:
# 0. Ensure uv is installed
pip install uv
# 1. Create venv
uv venv --python 3.12 sglang_minicpm_sala_env
source sglang_minicpm_sala_env/bin/activate
# 2. Install SGLang
uv pip install --upgrade pip setuptools wheel
uv pip install -e ./python[all]
# 3. Compile CUDA Extensions
# (Ensure dependencies are cloned to 3rdparty/)
cd 3rdparty/infllmv2_cuda_impl && python setup.py install && cd ../..
cd 3rdparty/sparse_kernel && python setup.py install && cd ../..
# 4. Install extra deps
uv pip install tilelang flash-linear-attention问:CUDA 扩展编译失败?
nvcc --version 命令检查)。gcc / g++。CXX 环境变量被设置为 clang++ -pthread,请手动执行 export CXX=g++ 进行修改。




@article{minicpm4,
title={{MiniCPM-SALA}: Hybridizing Sparse and Linear Attention for Efficient Long-Context Modeling},
author={MiniCPM Team},
year={2026}
}