Ring-mini-linear-2.0:融合线性注意力与稀疏专家的下一代高效大语言模型
【免费下载链接】Ring-mini-linear-2.0项目地址: https://ai.gitcode.com/hf_mirrors/inclusionAI/Ring-mini-linear-2.0
📖 技术报告 | 🤗 Hugging Face | 🤖 ModelScope
模型概述
今日,我们正式对外开源Ring-mini-linear-2.0大语言模型。该模型创新性地采用线性注意力与标准注意力混合架构,在保证模型性能的同时显著提升运行效率。作为Ling 2.0系列的重要成员,它继承了高效的混合专家(MoE)设计理念,并通过1/32专家激活比例和MTP层等架构优化,实现了仅激活164亿总参数中的16亿参数,就能达到约80亿稠密模型性能的突破。
本模型基于Ling-mini-base-2.0进行转换,并在额外6000亿 tokens 的语料上持续训练。实验结果表明,这种混合线性模型在整体性能上可与同规模的标准注意力模型(如Ring-mini-2)相媲美,同时在多项挑战性基准测试中超越了其他同级别开源MoE和稠密模型。特别值得一提的是,通过YaRN技术将上下文窗口外推4倍,实现了512k超长上下文支持,这使其在处理长输入输出任务时展现出卓越的速度优势。
上图展示了Ring-mini-linear-2.0的混合线性模型架构。该架构清晰呈现了线性注意力与标准注意力的融合方式,以及MoE机制的实现路径,帮助开发者直观理解模型的底层设计逻辑。
性能评估
为全面验证模型的推理能力,我们选取数学、代码和科学三大领域的5项挑战性推理基准,将Ring-mini-linear-2.0与Ring-mini-2.0、Qwen3-8B-thinking和GPT-OSS-20B-Medium三款模型进行对比测试。测试结果充分证明,混合线性架构能够达到与softmax注意力模型相当的性能水平,尤其在复杂推理任务中展现出独特优势。
这张模型性能对比图清晰呈现了各模型在不同基准测试中的得分情况。通过横向比较可以直观看到Ring-mini-linear-2.0在保持高效性的同时,如何实现与传统模型的性能抗衡,为用户选择合适模型提供数据支持。
线性注意力驱动的高效推理:稀疏架构与极速生成
得益于创新的混合注意力机制和高度稀疏的MoE架构,Ring-mini-linear-2.0实现了近线性时间复杂度和常数空间复杂度,带来了卓越的推理效率。为充分展示这一优势,我们将其与同级别或同性能的顶级竞争模型进行了全面的推理效率对比,结果有力证明了该模型在推理速度上的显著领先地位。
该图展示了Ring-mini-linear-2.0的预填充吞吐量表现。预填充阶段是长文本处理的关键环节,高吞吐量意味着模型能够更快地处理长输入,这对于文档理解等应用场景至关重要。
此图呈现了模型的解码吞吐量性能。解码速度直接影响用户交互体验,高解码吞吐量意味着模型能更快生成响应,特别适合实时对话等交互场景。
快速上手指南
环境要求
使用前需安装以下依赖包,确保环境配置正确:
pip install flash-linear-attention==0.3.2 pip install transformers==4.56.1🤗 Hugging Face Transformers使用示例
以下是基于Hugging Face Transformers库的快速调用代码,适用于大多数标准推理场景:
from transformers import AutoModelForCausalLM, AutoTokenizer model_name = "inclusionAI/Ring-mini-linear-2.0" model = AutoModelForCausalLM.from_pretrained( model_name, dtype="auto", device_map="auto", trust_remote_code=True, ) tokenizer = AutoTokenizer.from_pretrained(model_name) prompts = [ "Give me a short introduction to large language models." ] input_texts = [] for prompt in prompts: messages = [ {"role": "user", "content": prompt} ] text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) input_texts.append(text) print(input_texts) model_inputs = tokenizer(input_texts, return_tensors="pt", return_token_type_ids=False, padding=True, padding_side='left').to(model.device) generated_ids = model.generate( **model_inputs, max_new_tokens=8192, do_sample=False, ) generated_ids = [ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids) ] responses = tokenizer.batch_decode(generated_ids, skip_special_tokens=True) print("*" * 30) print(responses) print("*" * 30)🚀 SGLang部署方案
环境准备
我们已向SGLang官方提交PR,该PR将在后续版本中合并。目前,可通过以下步骤准备运行环境:首先安装社区版SGLang及所需依赖包:
pip install sglang==0.5.2 sgl-kernel==0.3.9.post2 vllm==0.10.2 torch==2.8.0 torchvision==0.23.0 torchao然后安装我们提供的sglang wheel包:
pip install https://media.githubusercontent.com/media/inclusionAI/Ring-V2/refs/heads/main/hybrid_linear/whls/sglang-0.5.2-py3-none-any.whl --no-deps --force-reinstall推理运行
SGLang当前支持BF16和FP8模型,具体取决于${MODEL_PATH}中模型的 dtype设置。两种精度模型的启动命令相同:
- 启动服务端:
python -m sglang.launch_server \ --model-path <model_path> \ --trust-remote-code \ --tp-size 1 \ --disable-radix-cache \ --json-model-override-args "{\"linear_backend\": \"seg_la\"}"- 客户端调用:
curl -s http://localhost:${PORT}/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{"model": "auto", "temperature": 0.6, "messages": [{"role": "user", "content": "Give me a short introduction to large language models."}]}'更多使用方法可参考SGLang官方文档
🚀 vLLM部署方案
环境准备
由于目前尚未向vLLM社区提交Pull Request,需按以下步骤准备环境:
首先,创建Python 3.10和CUDA 12.8的Conda环境:
conda create -n vllm python=3.10 conda activate vllm接着安装我们提供的vLLM wheel包:
pip install https://media.githubusercontent.com/media/zheyishine/vllm_whl/refs/heads/main/vllm-0.8.5.post2.dev28%2Bgd327eed71.cu128-cp310-cp310-linux_x86_64.whl --force-reinstall最后,在安装vLLM后安装兼容版本的transformers:
pip install transformers==4.51.1离线推理
from transformers import AutoTokenizer from vllm import LLM, SamplingParams if __name__ == '__main__': tokenizer = AutoTokenizer.from_pretrained("inclusionAI/Ring-mini-linear-2.0", trust_remote_code=True) sampling_params = SamplingParams(temperature=0.6, top_p=1.0, max_tokens=1024) # 使用`max_num_seqs=1`关闭并发 llm = LLM(model="inclusionAI/Ring-mini-linear-2.0", dtype='auto', enable_prefix_caching=False, max_num_seqs=128) prompt = "Give me a short introduction to large language models." messages = [ {"role": "user", "content": prompt} ] text = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True ) outputs = llm.generate([text], sampling_params) for output in outputs: print(output.outputs[0].text)在线推理
vllm serve inclusionAI/Ring-mini-linear-2.0 \ --tensor-parallel-size 1 \ --pipeline-parallel-size 1 \ --gpu-memory-utilization 0.90 \ --max-num-seqs 128 \ --no-enable-prefix-caching --api-key your-api-key引用说明
如果您在研究或应用中使用了Ring-mini-linear-2.0模型,请按以下格式引用:
@misc{lingteam2025attentionmattersefficienthybrid, title={Every Attention Matters: An Efficient Hybrid Architecture for Long-Context Reasoning}, author={Ling Team and Bin Han and Caizhi Tang and Chen Liang and Donghao Zhang and Fan Yuan and Feng Zhu and Jie Gao and Jingyu Hu and Longfei Li and Meng Li and Mingyang Zhang and Peijie Jiang and Peng Jiao and Qian Zhao and Qingyuan Yang and Wenbo Shen and Xinxing Yang and Yalin Zhang and Yankun Ren and Yao Zhao and Yibo Cao and Yixuan Sun and Yue Zhang and Yuchen Fang and Zibin Lin and Zixuan Cheng and Jun Zhou}, year={2025}, eprint={2510.19338}, archivePrefix={arXiv}, primaryClass={cs.LG}, url={https://arxiv.org/abs/2510.19338}, }Ring-mini-linear-2.0的开源发布,为大语言模型的高效部署提供了新的解决方案。其混合线性架构与稀疏专家设计的创新结合,不仅解决了传统模型在长上下文处理中的效率瓶颈,还为资源受限场景下的AI应用开辟了新路径。随着模型的广泛应用,我们期待看到更多基于该架构的创新实践,共同推动大语言模型技术向更高效、更经济的方向发展。
【免费下载链接】Ring-mini-linear-2.0项目地址: https://ai.gitcode.com/hf_mirrors/inclusionAI/Ring-mini-linear-2.0
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考