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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
library_name: transformers
|
| 9 |
tags:
|
| 10 |
- moe
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Ring-flash-linear-2.0-128k
|
| 14 |
+
|
| 15 |
+
<p align="center">
|
| 16 |
+
<img src="https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*4QxcQrBlTiAAAAAAQXAAAAgAemJ7AQ/original" width="100"/>
|
| 17 |
+
<p>
|
| 18 |
+
<p align="center">🤗 <a href="https://huggingface.co/inclusionAI">Hugging Face</a>   |   🤖 <a href="https://modelscope.cn/organization/inclusionAI">ModelScope</a></p>
|
| 19 |
+
|
| 20 |
+
## Introduction
|
| 21 |
+
|
| 22 |
+
We are excited to announce the official open-source release of Ring-flash-linear-2.0-128k!
|
| 23 |
+
|
| 24 |
+
Building on the success of our Ling 2.0 series, this model continues to leverage a powerful hybrid architecture of linear and standard attention, perfectly balancing high performance with superior efficiency. By integrating our proven MoE design with optimizations like a 1/32 expert activation ratio and MTP layers, Ring-flash-linear achieves the performance of a 40B dense model while activating only 6.1B parameters. This model was converted from [Ling-flash-base-2.0](https://huggingface.co/inclusionAI/Ling-flash-base-2.0), further trained on an additional 1T tokens.
|
| 25 |
+
When it comes to benchmarks, Ring-flash-linear-2.0-128k not only holds its own against standard attention models (like Ring-flash-2.0) but also outperforms other open-source MoE and Dense models in its class on several demanding tasks. Plus, we natively support a 128K context window and can extend it to 512K using YaRN. It's faster and more precise than ever, especially when handling long-form inputs and outputs.
|
| 26 |
+
|
| 27 |
+
<div style="display: flex; justify-content: center;">
|
| 28 |
+
<div style="text-align: center;">
|
| 29 |
+
<img src="https://cdn-uploads.huggingface.co/production/uploads/68d20104a6f8ea66da0cb447/PHRg8ipzJtr0p6sojAa5T.png" width="800">
|
| 30 |
+
<p style="margin-top: 8px; font-size: 14px;"><strong>Figure 1:</strong> Hybrid Linear Model Architecture</p>
|
| 31 |
+
</div>
|
| 32 |
+
</div>
|
| 33 |
+
|
| 34 |
+
## Evaluation
|
| 35 |
+
|
| 36 |
+
To better demonstrate the model's capabilities, we selected representative open-source thinking models and closed-source APIs for comparison.
|
| 37 |
+
We present results on several challenging reasoning benchmarks spanning domains such as mathematics, agent, coding, and science. We observe that our model achieves performance on par with other models.
|
| 38 |
+
|
| 39 |
+
<div style="display: flex; justify-content: center;">
|
| 40 |
+
<div style="text-align: center;">
|
| 41 |
+
<img src="https://mdn.alipayobjects.com/huamei_t783ie/afts/img/_MiTQ7VbRPsAAAAARfAAAAgADgCDAQFr/original" width="1000">
|
| 42 |
+
<p style="margin-top: 8px; font-size: 14px;"><strong>Figure 2:</strong> Model Performance Comparison </p>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<div style="display: flex; justify-content: center;">
|
| 47 |
+
<div style="text-align: center;">
|
| 48 |
+
<img src="https://mdn.alipayobjects.com/huamei_t783ie/afts/img/56VaRZ0JldcAAAAAS1AAAAgADgCDAQFr/original" width="1000">
|
| 49 |
+
<p style="margin-top: 8px; font-size: 14px;"><strong>Figure 3:</strong> Model Performance Comparison </p>
|
| 50 |
+
</div>
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
## Linear Attention, Highly Sparse, High-Speed Generation
|
| 55 |
+
|
| 56 |
+
Thanks to its hybrid attention mechanism and highly sparse MoE architecture, Ring-flash-linear-2.0-128k achieves near-linear time complexity and constant space complexity, resulting in outstanding inference efficiency.
|
| 57 |
+
To fully demonstrate this advantage, we conducted a comparison between our model and top-tier competitors of similar size or performance.
|
| 58 |
+
The results clearly demonstrate the advantage of our model in inference efficiency.
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
<div style="display: flex; justify-content: center; align-items: flex-start; gap: 20px;">
|
| 62 |
+
<div style="text-align: center;">
|
| 63 |
+
<img src="https://mdn.alipayobjects.com/huamei_t783ie/afts/img/wtM_TJ4KVqYAAAAARpAAAAgADgCDAQFr/original" width="500">
|
| 64 |
+
<p style="margin-top: 8px; font-size: 14px;"><strong>Figure 4:</strong> Ring-flash-linear-2.0-128k prefill throughput</p>
|
| 65 |
+
</div>
|
| 66 |
+
|
| 67 |
+
<div style="text-align: center;">
|
| 68 |
+
<p align="center">
|
| 69 |
+
<img src="https://mdn.alipayobjects.com/huamei_t783ie/afts/img/3n9lSZscvBwAAAAAUhAAAAgADgCDAQFr/original" width="500">
|
| 70 |
+
</p>
|
| 71 |
+
<p style="margin-top: 8px; font-size: 14px;"><strong>Figure 5:</strong> Ring-flash-linear-2.0-128k decode throughput</p>
|
| 72 |
+
</div>
|
| 73 |
+
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
## Quickstart
|
| 77 |
+
|
| 78 |
+
### Requirements
|
| 79 |
+
|
| 80 |
+
```bash
|
| 81 |
+
pip install flash-linear-attention==0.3.2
|
| 82 |
+
pip install transformers==4.56.1
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
### 🤗 Hugging Face Transformers
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 89 |
+
|
| 90 |
+
model_name = "inclusionAI/Ring-flash-linear-2.0-128k"
|
| 91 |
+
|
| 92 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 93 |
+
model_name,
|
| 94 |
+
dtype="auto",
|
| 95 |
+
device_map="auto",
|
| 96 |
+
trust_remote_code=True,
|
| 97 |
+
)
|
| 98 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
prompts = [
|
| 102 |
+
"Give me a short introduction to large language models."
|
| 103 |
+
]
|
| 104 |
+
input_texts = []
|
| 105 |
+
for prompt in prompts:
|
| 106 |
+
messages = [
|
| 107 |
+
{"role": "user", "content": prompt}
|
| 108 |
+
]
|
| 109 |
+
text = tokenizer.apply_chat_template(
|
| 110 |
+
messages,
|
| 111 |
+
tokenize=False,
|
| 112 |
+
add_generation_prompt=True
|
| 113 |
+
)
|
| 114 |
+
input_texts.append(text)
|
| 115 |
+
|
| 116 |
+
print(input_texts)
|
| 117 |
+
|
| 118 |
+
model_inputs = tokenizer(input_texts, return_tensors="pt", return_token_type_ids=False, padding=True, padding_side='left').to(model.device)
|
| 119 |
+
|
| 120 |
+
generated_ids = model.generate(
|
| 121 |
+
**model_inputs,
|
| 122 |
+
max_new_tokens=8192,
|
| 123 |
+
do_sample=False,
|
| 124 |
+
)
|
| 125 |
+
generated_ids = [
|
| 126 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 127 |
+
]
|
| 128 |
+
|
| 129 |
+
responses = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
| 130 |
+
|
| 131 |
+
print("*" * 30)
|
| 132 |
+
print(responses)
|
| 133 |
+
print("*" * 30)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
### 🚀 SGLang
|
| 137 |
+
|
| 138 |
+
#### Environment Preparation
|
| 139 |
+
|
| 140 |
+
We have submitted our [PR](https://github.com/sgl-project/sglang/pull/10917) to SGLang official release and it will be merged later, for now we can prepare the environment following steps, firstly install the community version SGLang and required packages:
|
| 141 |
+
```shell
|
| 142 |
+
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
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
Then you should install our sglang wheel package:
|
| 146 |
+
```shell
|
| 147 |
+
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
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
#### Run Inference
|
| 151 |
+
|
| 152 |
+
BF16 and FP8 models are supported by SGLang now, it depends on the dtype of the model in ${MODEL_PATH}. They both share the same command in the following:
|
| 153 |
+
|
| 154 |
+
- Start server:
|
| 155 |
+
```shell
|
| 156 |
+
python -m sglang.launch_server \
|
| 157 |
+
--model-path <model_path> \
|
| 158 |
+
--trust-remote-code \
|
| 159 |
+
--tp-size 4 \
|
| 160 |
+
--disable-radix-cache \
|
| 161 |
+
--tool-call-parser qwen25 \
|
| 162 |
+
--json-model-override-args "{\"linear_backend\": \"seg_la\"}"
|
| 163 |
+
```
|
| 164 |
+
|
| 165 |
+
- Client:
|
| 166 |
+
|
| 167 |
+
```shell
|
| 168 |
+
curl -s http://localhost:${PORT}/v1/chat/completions \
|
| 169 |
+
-H "Content-Type: application/json" \
|
| 170 |
+
-d '{"model": "auto", "temperature": 0.6, "messages": [{"role": "user", "content": "Give me a short introduction to large language models."}]}'
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
More usage can be found [here](https://docs.sglang.ai/basic_usage/send_request.html)
|
| 174 |
+
|
| 175 |
+
### 🚀 vLLM
|
| 176 |
+
|
| 177 |
+
#### Environment Preparation
|
| 178 |
+
|
| 179 |
+
Since the Pull Request (PR) has not been submitted to the vLLM community at this stage, please prepare the environment by following the steps below:
|
| 180 |
+
```shell
|
| 181 |
+
pip install torch==2.7.0 torchvision==0.22.0
|
| 182 |
+
```
|
| 183 |
+
|
| 184 |
+
Then you should install our vLLM wheel package:
|
| 185 |
+
```shell
|
| 186 |
+
pip install https://media.githubusercontent.com/media/inclusionAI/Ring-V2/refs/heads/main/hybrid_linear/whls/vllm-0.8.5%2Bcuda12_8_gcc10_2_1-cp310-cp310-linux_x86_64.whl --no-deps --force-reinstall
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
#### Offline Inference
|
| 190 |
+
|
| 191 |
+
```python
|
| 192 |
+
from transformers import AutoTokenizer
|
| 193 |
+
from vllm import LLM, SamplingParams
|
| 194 |
+
|
| 195 |
+
tokenizer = AutoTokenizer.from_pretrained("inclusionAI/Ring-flash-linear-2.0-128k")
|
| 196 |
+
|
| 197 |
+
sampling_params = SamplingParams(temperature=0.6, top_p=1.0, max_tokens=8192)
|
| 198 |
+
|
| 199 |
+
llm = LLM(model="inclusionAI/Ring-flash-linear-2.0-128k", dtype='bfloat16', enable_prefix_caching=False)
|
| 200 |
+
prompt = "Give me a short introduction to large language models."
|
| 201 |
+
messages = [
|
| 202 |
+
{"role": "user", "content": prompt}
|
| 203 |
+
]
|
| 204 |
+
|
| 205 |
+
text = tokenizer.apply_chat_template(
|
| 206 |
+
messages,
|
| 207 |
+
tokenize=False,
|
| 208 |
+
add_generation_prompt=True
|
| 209 |
+
)
|
| 210 |
+
outputs = llm.generate([text], sampling_params)
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
#### Online Inference
|
| 214 |
+
```shell
|
| 215 |
+
vllm serve inclusionAI/Ring-flash-linear-2.0-128k \
|
| 216 |
+
--tensor-parallel-size 4 \
|
| 217 |
+
--gpu-memory-utilization 0.90 \
|
| 218 |
+
--no-enable-prefix-caching
|
| 219 |
+
```
|