Gausson commited on
Commit
e8a171c
·
verified ·
1 Parent(s): 0afb1c9

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +363 -3
README.md CHANGED
@@ -1,3 +1,363 @@
1
- ---
2
- license: llama3
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama3
3
+ language:
4
+ - en
5
+ base_model:
6
+ - meta-llama/Meta-Llama-3-8B-Instruct
7
+ tags:
8
+ - custom_generate
9
+ ---
10
+ # SepCache - Native Sparse Attention Cache
11
+
12
+ This repository is just a fork of `transformers-community/sep_cache` used for backup purposes.
13
+
14
+ **Please prioritize using the official [HuggingFace](https://huggingface.co/transformers-community/sep_cache) repository** [`transformers-community/sep_cache`](https://huggingface.co/transformers-community/sep_cache); they are the same.
15
+
16
+
17
+ ## Table of Contents
18
+
19
+ - [1. Abstract](#1-abstract)
20
+ - [2. Usage](#2-usage)
21
+ - [2.1 Sample Base Model](#21-sample-base-model)
22
+ - [2.2 Quick Start](#22-quick-start)
23
+ - [2.2.1 Environment Setup](#221-environment-setup)
24
+ - [2.2.2 A Simple Example](#222-a-simple-example)
25
+ - [2.2.3 Frequently-Used Parameters](#223-frequently-used-parameters)
26
+ - [2.2.4 Update Function](#224-update-function)
27
+ - [2.2.5 Monkey Patch Demo](#225-monkey-patch-demo)
28
+ - [2.2.6 Downstream Task Evaluation](#226-downstream-task-evaluation)
29
+ - [2.2.7 The Detailed Signature of `generate` Function](#227-the-detailed-signature-of-generate-function)
30
+ - [3. Adaptation for Other Models](#3-adaptation-for-other-models)
31
+ - [3.1 Method 1 - Monkey Patching](#31-method-1---monkey-patching)
32
+ - [3.2 Method 2 - Direct Code Modification](#32-method-2---direct-code-modification)
33
+ - [3.3 Important Note](#33-important-note)
34
+ - [4. Other Advanced Usage](#4-other-advanced-usage)
35
+
36
+ ---
37
+
38
+ ## 1. Abstract
39
+ `SepCache` is a simple yet effective, native sparse attention `Cache` class proposed in the [`SepLLM paper - ICML 2025`](https://icml.cc/virtual/2025/poster/45536), which most closely aligns with the semantic distribution of natural language. In the training phase, `SepLLM` condenses the segment information into the KV of the separator that divides the segment. In the inference phase, the corresponding `SepCache` only needs to store the KVs of initial tokens, separator tokens, and recent tokens for generation.
40
+
41
+ Notably, `SepCache` also delivers strong performance across many tasks in training-free scenarios. Moreover, `SepLLM` (or simply `SepCache`) is the **most suitable baseline method for sparse attention mechanisms and KV compression/management**, as it is the natively sparse attention mechanism that best aligns with the natural semantic distribution of language.
42
+
43
+ See more details and advanced usage in https://github.com/HKUDS/SepLLM
44
+
45
+ ![image](https://hackmd.io/_uploads/r1POJoR4yg.png)
46
+
47
+ ## 2. Usage
48
+
49
+ ### 2.1 Sample Base Model
50
+
51
+ We recommend using models from the **Llama 3 series**. Our example model is based on `meta-llama/Meta-Llama-3-8B-Instruct`, for which we have already prepared a targeted `monkey patch`.
52
+
53
+ For other models, using `SepCache` requires minor modifications to the corresponding `modeling_xxx.py` file or writing a **custom monkey patch**. These changes are **very simple** -- you only need to pass arguments like `input_ids` to the `update` function of `SepCache` when calling it.
54
+
55
+ We will provide a detailed guide later on how to modify your `modeling_xxx.py` file or `monkey patch` file to adapt `SepCache` to any model.
56
+
57
+ ### 2.2 Quick Start
58
+
59
+ #### 2.2.1 Environment Setup
60
+ You need to install `transformers>=4.53.0,<4.54.0`, and we recommend using `lm_eval>=0.4.9` for running evaluations. We suggest managing your Python environment with `conda` for better dependency control.
61
+
62
+ ```bash
63
+ conda create -n sepcache python=3.10
64
+ conda activate sepcache
65
+ pip install transformers==4.53
66
+ pip install lm_eval==0.4.9
67
+ ```
68
+ #### 2.2.2 A Simple Example
69
+ You can use `SepCache` by specifying `custom_generate="transformers-community/sep_cache"` or `custom_generate="Gausson/sep_cache"` when calling the `generate` function. In our demo, we have already prepared sample monkey patching for the `Llama 3 series` models and provided some common parameters for initializing `SepCache`.
70
+
71
+ ```python
72
+ # requires `transformers>=4.53.0,<4.54.0`
73
+ from transformers import AutoModelForCausalLM, AutoTokenizer
74
+
75
+ # Preparing model, tokenizer, and model inputs
76
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct")
77
+ model = AutoModelForCausalLM.from_pretrained("meta-llama/Meta-Llama-3-8B-Instruct", device_map="auto")
78
+
79
+
80
+ messages = [{"role": "user", "content": "Tell me a story about a cat."}]
81
+ text = tokenizer.apply_chat_template(
82
+ messages,
83
+ tokenize=False,
84
+ add_generation_prompt=True,
85
+ enable_thinking=False
86
+ )
87
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
88
+
89
+
90
+ # Using SepCache for generation
91
+ gen_out = model.generate(
92
+ # usual `generate` arguments
93
+ **model_inputs,
94
+ do_sample=False,
95
+ max_new_tokens=100,
96
+ return_dict_in_generate=True,
97
+ monkey_patch_verbose = True, # To see which functions are actually being monkey patched for `SepCache`.
98
+
99
+ # Using SepCache
100
+ custom_generate="transformers-community/sep_cache", ## Alternatively, you can use `Gausson/sep_cache`
101
+ trust_remote_code=True,
102
+
103
+ # SepCache arguments
104
+ init_cache_size = 4,
105
+ sep_cache_size = 128,
106
+ local_size = 256,
107
+ cache_size = 512,
108
+ USE_MAX_SEP_CACHE = True,
109
+ model_type = 'llama'
110
+ )
111
+
112
+ print(tokenizer.batch_decode(gen_out.sequences, skip_special_tokens=True))
113
+ assert "sepcache" in str(type(gen_out.past_key_values)).lower()
114
+ ```
115
+
116
+ It is worth noting that you must specify the `separator_token_ids: List[int]` and `PADDING_ID: int` parameters for initializing `SepCache`. In the example above, we did not do this because, for convenience, in the demo above, we specified `model_type = "llama"`, in which case `separator_token_ids` and `PADDING_ID` will be automatically filled.
117
+
118
+ However, when you use a tokenizer for a non-Llama 3 series model, you need to specify the specific values of `separator_token_ids` and `PADDING_ID` based on the tokenizer you are using. For example, the following example is based on the values obtained from a Llama 3 series tokenizer.
119
+ ```python
120
+ # Using SepCache for generation
121
+ gen_out = model.generate(
122
+ # usual `generate` arguments
123
+ **model_inputs,
124
+ do_sample=False,
125
+ max_new_tokens=100,
126
+ return_dict_in_generate=True,
127
+ monkey_patch_verbose = True, # To see which functions are actually being monkey patched for `SepCache`.
128
+
129
+ # Using SepCache
130
+ custom_generate="transformers-community/sep_cache", ## Alternatively, you can use `Gausson/sep_cache`
131
+ trust_remote_code=True,
132
+
133
+ # SepCache arguments
134
+ init_cache_size = 4,
135
+ sep_cache_size = 128,
136
+ local_size = 256,
137
+ cache_size = 512,
138
+ USE_MAX_SEP_CACHE = True,
139
+ separator_token_ids = [128000, 13, 11, 30, 0, 26, 25, 198, 220, 662, 1174, 949, 758, 2652, 551, 720, 256,262],
140
+ PADDING_ID = 128009
141
+ )
142
+ ```
143
+
144
+
145
+ #### 2.2.3 Frequently-Used Parameters
146
+
147
+ Below, we provide explanations and examples for the most commonly used parameters when initializing `SepCache`. These parameters can be passed through the `generate` function.
148
+
149
+ ```
150
+ `SepCache` stores the Key and Value states as lists of tensors, two lists for each layer. The expected shape for each tensor is
151
+ `[batch_size, num_heads, seq_len, head_dim]`.
152
+
153
+ Frequently-Used Parameters:
154
+
155
+ `init_cache_size: Union[int, List]`:
156
+ The maximum number of KVs to be stored for initial tokens.
157
+ In the paper, the hyperparameter `a` is an abbreviated alias for `init_cache_size`.
158
+
159
+ `sep_cache_size: Union[int, List]`:
160
+ The maximum number of KVs to be stored for separator tokens.
161
+ In the paper, the hyperparameter `s` is an abbreviated alias for `sep_cache_size`.
162
+
163
+ `local_size: Union[int, List]`:
164
+ The maximum number of KVs to be stored for local tokens (i.e., sliding window).
165
+ In the paper, the hyperparameter `w` is an abbreviated alias for `local_size`.
166
+
167
+ `cache_size: Union[int, List]`:
168
+ The maximum number of KVs to be stored for all the tokens, i.e., the size for the whole KV cache.
169
+ In the paper, the hyperparameter `c` is an abbreviated alias for `cache_size`.
170
+
171
+ Concerning these four parameters above:
172
+ When a list is passed (its length must be `layer_num`), it represents different values for each layer.
173
+ When an integer is passed, it means the setting is the same for all layers.
174
+
175
+
176
+ `USE_MAX_SEP_CACHE: bool`:
177
+ If True, it means we only keep at most `sep_cache_size` separators' KVs.
178
+ If the number exceeds this limit, older separators' KVs will be discarded, keeping only the most recent `sep_cache_size` KVs.
179
+ In the paper, the hyperparameter `s` is an abbreviated alias for `sep_cache_size`.
180
+
181
+ `separator_token_ids: List[int]`:
182
+ The token ids of the separator tokens for the current model's tokenizer.
183
+ We have some examples, such as the Llama-3 series models, where setting `model_type='llama'` allows you
184
+ to skip setting `separator_token_ids` and `PADDING_ID` (SepCache will auto-fill them).
185
+
186
+ `PADDING_ID: int`:
187
+ The token id of the padding token. You can just set `PADDING_ID` to the id of "<|endoftext|>" token of the tokenizer for the pretrained model.
188
+ ```
189
+ Important Note:
190
+ - When `cache_size` and `local_size` are set to infinity (i.e., sufficiently large positive integers), and `USE_MAX_SEP_CACHE` is `False`, `SepCache` degenerates into a regular Cache.
191
+ - You must always ensure that `init_cache_size` + `sep_cache_size` + `local_size` + `left_padding_offset` < `cache_size`. Here, `left_padding_offset` denotes the number of padding tokens in the record with the largest left paddings within a runtime batch. `left_padding_offset` can only be determined at runtime.
192
+ - To guarantee the above inequality always holds during runtime, when setting, you can intentionally create a sufficient margin between both sides of the following inequality:
193
+ `init_cache_size` + `sep_cache_size` + `local_size` < `cache_size`, i.e., `a`+`s`+`w`<`c` in the [SepLLM paper - ICML 2025](https://arxiv.org/abs/2412.12094) to leave room for `left_padding_offset`.
194
+
195
+ **More Important Note: In practice, no need to do positional encoding (PE) shifting like [StreamingLLM](https://github.com/mit-han-lab/streaming-llm/) if the actual length does not exceed the pretrained max PE length (which applies to most downstream tasks.) . So, for most basic usages, just set `APPLY_PE_SHIFT=False` (`False` is also the default setting) and `APPLY_PES_INSIDE=False` for initialization.**
196
+
197
+
198
+ #### 2.2.4 Update Function
199
+ After initialization, another key point to note is that when using the `update` function of `SepCache` to update the **keys/values** and the **past token IDs** (which is necessary in SepCache), the current `input_ids` must also be provided.
200
+ ```python
201
+ key_states, value_states = past_key_values.update(
202
+ key_states = key_states,
203
+ value_states = value_states,
204
+ input_ids = input_ids, ## required
205
+ layer_idx = layer_idx,
206
+ PREFILLING_FLAG = q_len > 1, ## `q_len` is the sequence length of the current `query_states`
207
+ )
208
+ ```
209
+
210
+
211
+ #### 2.2.5 Monkey Patch Demo
212
+ To adapt the `update` function of `SepCache` mentioned in [`2.2.4 Update Function`](#224-update-function), i.e., passing the current `input_ids` as a parameter to the `update` function. It is worth noting that during the prefilling stage, the shape of the input_ids tensor is `[batch_size, seq_len]`, while during the decoding stage of auto-regressive models, the shape of the `input_ids` tensor should be `[batch_size, 1]`.
213
+
214
+
215
+ In our `custom_generate/generate.py` file, we provide the `monkey_patching` function, which works by replacing the `forward` function in all the related instances of the `XXXAttention` class (for example, in the Llama 3 series model, it would be `LlamaAttention`) with our customized forward function (specified by the `model_atten_forward` parameter of the `monkey_patching` function).
216
+ ```python
217
+ def monkey_patching(model_obj,
218
+ model_atten_forward , ## The `forward` function used to patch.
219
+ possible_inner_model_names: List[str] = ["model", "transformer", "gpt_neox"] , # In `XXXForCausalLM` class, the possible name of internal attribute for model. e.g., "model", "transformer", "gpt_neox", etc.
220
+ possible_layers_names: List[str] = ["layers", "h" ], # In `XXXModel` class, the possible name of internal attribute for decoder layers, e.g., "layers", "h", etc.
221
+ atten_attr_name_pattern_list: List[str] = ["attention", "self_attn"], # In `XXXDecoderLayer` class, the possible name of internal attribute for self-attention, e.g., "attention", "self_attn", etc.
222
+ atten_attr_name_pattern_exclude: List[str] = ["norm", "layer"], # In `XXXDecoderLayer` class, the impossible name patterns (i.e., the patterns to be excluded) of internal attribute for self-attention module class, e.g., "norm" , etc. Sometimes, there will be some attributes like "post_attention_norm" and we do not want modify the `forward` function of it - we want to modify the `forward` function of `XXXAttention`. So, we need to exclude attribute name patterns like "norm" to accurately find the correct "forward" function to replace.
223
+ verbose = True):
224
+
225
+ """
226
+ This `monkey_patching` function is to
227
+ - find the `forward` function of the `XXXAttention` class.
228
+ - replace all the related `forward` functions of the instances of `XXXAttention` class with `model_atten_forward`.
229
+ """
230
+
231
+ ## To avoid the argument check failure, i.e., let "sepllm_kwargs" pass the check.
232
+ transformers.generation.GenerationMixin._validate_model_kwargs = _validate_model_kwargs
233
+
234
+ ## Get inner model obj
235
+ inner_model_type = PreTrainedModel
236
+ inner_model = find_inner_attribute(model_obj, possible_inner_model_names, inner_model_type)
237
+
238
+ ## Get the decoder layers (`nn.ModuleList`) obj
239
+ layers_type = nn.ModuleList
240
+ model_layers = find_inner_attribute(inner_model, possible_layers_names, layers_type)
241
+
242
+ ## Replace all the related `forward` functions of XXXAttention class's instances.
243
+ for i, decoder_layer in enumerate(model_layers):
244
+ self_attn_module = find_attribute_name(decoder_layer, atten_attr_name_pattern_list, atten_attr_name_pattern_exclude, nn.Module)
245
+ result = monkey_patch_by_class_path(self_attn_module, model_atten_forward)
246
+ if verbose:
247
+ decoder_class_name = get_importable_class_path(decoder_layer)
248
+ print(f"For Layer {i}'s `{decoder_class_name}`: {result}")
249
+
250
+ return model_layers
251
+ ```
252
+
253
+ The `monkey_patching` function primarily does three things:
254
+ - Precisely locate the `forward` function of all instances of the `XXXAttention` class.
255
+ - Replace the `forward` function with the `model_atten_forward` function you provide.
256
+ - Return the corresponding properties of the decoder layers found during the process, typically of type `nn.ModuleList`. This return value (`model_layers`) is only used to determine the number of layers in the current model later on (obtained by `len(model_layers)`).
257
+
258
+ In addition, the `monkey_patching` function replaces `transformers.generation.GenerationMixin._validate_model_kwargs` with our `_validate_model_kwargs` to bypass some parameter checks, as we will provide an additional `sepllm_kwargs` parameter to wrap the `input_ids` for eventual transmission to the `SepCache` `update` function.
259
+
260
+
261
+ **Please ensure that the `monkey_patching` function accurately locates and replaces the `forward` function of the `XXXAttention` class. The current `monkey_patching` is designed for the `Llama 3 series` models. For other models, you need to appropriately modify `monkey_patching` to ensure its correctness of targeting and replacement !** You can monitor the monkey patching process by setting `verbose=True` in the `monkey_patching` function (or, `monkey_patch_verbose = True` for the `generate` function.)
262
+
263
+
264
+ ```python
265
+ def truncate_input_ids_4_autoregression(input_ids, key_states):
266
+ if input_ids.shape[-1] != key_states.shape[-2]:
267
+ assert input_ids.shape[-1] >= key_states.shape[-2]
268
+ truncated_input_ids = input_ids[..., -key_states.shape[-2]: ]
269
+ return truncated_input_ids
270
+ else:
271
+ return input_ids
272
+ ```
273
+ The `truncate_input_ids_4_autoregression` function in the `custom_generate/generate.py` file is used to shape the `input_ids` tensor to `[batch_size, 1]` during decoding.
274
+
275
+ #### 2.2.6 Downstream Task Evaluation
276
+ We recommend using `lm_eval==0.4.9` for downstream task evaluation. You can pass model-related parameters via `--model_args` and generation-related parameters (including those required for initializing `SepCache`) via `--gen_kwargs`. Notably, you typically need to pass a `list` to `separator_token_ids` using a string format like `"id1;id2;id3"` (as shown in the example below).
277
+ ```bash
278
+ lm_eval --model hf \
279
+ --model_args pretrained=meta-llama/Meta-Llama-3-8B-Instruct,attn_implementation=flash_attention_2 \
280
+ --tasks gsm8k_cot \
281
+ --gen_kwargs custom_generate=transformers-community/sep_cache,trust_remote_code=True,monkey_patch_verbose=True,init_cache_size=4,sep_cache_size=128,local_size=256,cache_size=512,separator_token_ids="128000;13;11;30;0;26;25;198;220;662;1174;949;758;2652;551;720;256;262",PADDING_ID=128009 \
282
+ --device cuda:0\
283
+ --batch_size 80 2>&1 | tee log.txt
284
+ ```
285
+ Note: `SepCache` is typically used in combination with `Flash Attention` to maximize generation efficiency.
286
+
287
+ <img width="1022" height="248" alt="1752618213617" src="https://github.com/user-attachments/assets/87e2e745-9677-4101-895e-dd6fc7b6039d" />
288
+
289
+ #### 2.2.7 The Detailed Signature of `generate` Function
290
+ Here is the detailed signature of our customized `generate` function for `SepCache` in `custom_generate/generate.py` file:
291
+
292
+ ```python
293
+ def generate(model,
294
+ ## For SepCache
295
+ init_cache_size: Union[int, List] = 4,
296
+ sep_cache_size: Union[int, List] = 128,
297
+ local_size: Union[int, List]=256,
298
+ cache_size: Union[int, List]=512,
299
+ SEP_ACCUMULATION: bool = True,
300
+ USE_MAX_SEP_CACHE: bool = False,
301
+ SEP_PADDING_IN_BATCH: bool = False,
302
+ separator_token_ids: List[int] = None, ## required for initialization if `model_type` is not provided.
303
+ PADDING_ID: int = None, ## required for initialization if `model_type` is not provided.
304
+
305
+ ## For inheritance & initialization states
306
+ past_tok_ids: List[torch.Tensor] = None, ## It saves all the token ids corresponding to the saved KVs for all layers in SepCache.
307
+ key_cache: List[torch.Tensor] = None,
308
+ value_cache: List[torch.Tensor] = None,
309
+
310
+ ## For debugging
311
+ PRINT_KV_RATIO_INSIDE: bool = False,
312
+ print_KV_inside_per_steps: int = 1000,
313
+ _seen_tokens: int = 0,
314
+ _kept_kv_ratio: List[Tuple[int]] = None,
315
+
316
+ ### For positional encoding shifting
317
+ APPLY_PE_SHIFT: bool = False,
318
+ APPLY_PES_INSIDE: bool = False,
319
+ _shifted_position_ids: List[torch.Tensor] = None,
320
+ _rope_unsqueeze_dim: int = 1, ## The unsqueeze_dim when applying RoPE.
321
+ _rope_seq_dim: int=1, ## The seq_len dimension for the `cos` or `sin` tensors.
322
+ pe_scaling_factor:float = 1.0,
323
+ pe_dim:int=128, ## The number of dims for positional encoding. Typically, just set the `head_dim` to this.
324
+ max_position_embeddings: int = 8192,
325
+ base: int=10000, ## The base for RoPE.
326
+
327
+ ## For basic transformer architecture
328
+ k_seq_dim: int=2, ## The dimension for seq_len in key tensors
329
+ v_seq_dim: int=2, ## The dimension for seq_len in value tensors
330
+ layer_num: int = None, ## required for initialization
331
+
332
+ model_type: str = 'llama', ## The model type for running the example. choose from ['llama', 'pythia','falcon'].
333
+ device = None,
334
+
335
+ ## For verbosity of monkey patching
336
+ monkey_patch_verbose: bool = False,
337
+
338
+ **kwargs
339
+ ):
340
+ ...
341
+ ```
342
+
343
+ ## 3. Adaptation for Other Models
344
+
345
+ Adapting `SepCache` to various models is simple - two approaches:
346
+
347
+
348
+ ### 3.1 Method 1 - Monkey Patching
349
+ - Modify the `monkey_patching` function to correctly locate and target the `forward` function of your model's `XXXAttention` class (e.g., `LlamaAttention` for Llama 3).
350
+ - Write your custom `model_atten_forward` function and use `monkey_patching` to replace the `forward` function of all `XXXAttention` class instances. The key modification is passing `input_ids` to `SepCache`'s `update` function.
351
+
352
+ ### 3.2 Method 2 - Direct Code Modification (Recommended for Simplicity)
353
+ Simply edit your `modeling_xxx.py` file to implement:
354
+
355
+ - Initialize `past_key_values` as a `SepCache` instance at the appropriate location (e.g., in `XXXForCausalLM` or `XXXModel` class' `forward` function).
356
+ - Modify the `forward` function of the `XXXAttention` class to pass `input_ids` to `SepCache`'s `update` function.
357
+
358
+ ### 3.3 Important Note
359
+ The shape of `input_ids` is `[batch_size, seq_len]` during prefilling, and `[batch_size, 1]` during generation.
360
+
361
+ ## 4. Other Advanced Usage
362
+
363
+ Please refer to https://github.com/HKUDS/SepLLM, in which there are detailed explanations and examples.