LongMountain commited on
Commit
3ef8780
·
1 Parent(s): 3ade3e4

first model commit

Browse files
README.md CHANGED
@@ -1,3 +1,62 @@
1
  ---
2
- license: mit
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: llama3.1
3
+ library_name: transformers
4
+ base_model:
5
+ - meta-llama/Llama-3.1-8B-Instruct
6
+ base_model_relation: "adapter"
7
  ---
8
+
9
+
10
+ # SeerAttention-Llama-3.1-8B
11
+
12
+ This is a reproduction of the [SeerAttention](https://arxiv.org/abs/2410.13276) paper. The model contains additional learnable AttnGate modules on top of [meta-llama/Meta-Llama-3-8B-Instruct](https://huggingface.co/meta-llama/Llama-3.1-8B-Instruct). The AttnGate modules accelerate long-context attention inference by enabling block-level sparsity. During training, the AttnGates are optimized via self-distillation while keeping the original model weights frozen. Specifically, the AttnGates learn to mimic the 2D-maxpooled outputs of the attention maps. At inference time, the soft scores produced by the gates are converted into binary masks, thereby reducing both the I/O overhead and computational cost of the attention mechanism.
13
+
14
+
15
+
16
+ ## Original Github Repo
17
+ [https://github.com/microsoft/SeerAttention](https://github.com/microsoft/SeerAttention).
18
+
19
+ ## Evaluation Results
20
+
21
+ ### Perplexity on PG19
22
+ | Density | 8192 | 16384 | 32768 | 65536 | 131072 |
23
+ |---------|-------|-------|-------|-------|--------|
24
+ | 1.00 | 10.03 | 9.88 | 9.92 | 9.97 | 10.03 |
25
+ | 0.50 | 10.04 | 9.89 | 9.92 | 9.99 | 10.05 |
26
+ | 0.40 | 10.06 | 9.89 | 9.93 | 9.99 | 10.07 |
27
+ | 0.30 | 10.09 | 9.91 | 9.95 | 10.01 | 10.15 |
28
+ | 0.20 | 10.19 | 9.94 | 9.97 | 10.04 | 10.37 |
29
+ | 0.10 | 10.61 | 10.08 | 10.04 | 10.09 | 10.88 |
30
+
31
+ ### LongBench
32
+
33
+ With threshold set to 2e-3.
34
+
35
+ | Task | 0-4k | 4-8k | 8k+ |
36
+ |----------------------|-------|-------|-------|
37
+ | 2wikimqa | 51.1 | 47.85 | 33.36 |
38
+ | gov_report | 35.03 | 35.05 | 34.57 |
39
+ | hotpotqa | 63.97 | 60.0 | 56.7 |
40
+ | lcc | 67.98 | 73.18 | 65.28 |
41
+ | multi_news | 28.1 | 25.78 | 24.25 |
42
+ | multifieldqa_en | 58.63 | 51.45 | 51.87 |
43
+ | passage_count | 18.0 | 10.15 | 11.88 |
44
+ | passage_retrieval_en | 100.0 | 99.0 | 98.0 |
45
+ | qasper | 47.77 | 44.04 | 39.63 |
46
+ | repobench-p | 51.78 | 56.24 | 56.75 |
47
+ | samsum | 43.28 | 41.19 | 45.29 |
48
+ | trec | 64.0 | 76.0 | 75.0 |
49
+ | triviaqa | 90.91 | 88.45 | 92.43 |
50
+ | averaged | 55.43 | 54.49 | 52.69 |
51
+
52
+
53
+ ### RULER
54
+
55
+ | | Dense Baseline | SeerAttn | Avg density |
56
+ |-------|---------------:|---------:|------------:|
57
+ | 4k | 95.53 | 95.53 | 0.87 |
58
+ | 8k | 92.27 | 92.71 | 0.72 |
59
+ | 16k | 92.01 | 92.02 | 0.56 |
60
+ | 32k | 87.63 | 88.49 | 0.46 |
61
+ | 64k | 84.39 | 83.48 | 0.32 |
62
+ | 128k | 76.26 | 73.37 | 0.17 |
attn_pooling_kernel.py ADDED
@@ -0,0 +1,277 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Original code from Triton's official fused attention example (https://triton-lang.org/main/getting-started/tutorials/06-fused-attention.html).
3
+ """
4
+ """
5
+ Modified by Zhichen Zeng,
6
+ Self-attention output with 2D maxpooling attention map.
7
+ """
8
+
9
+ import torch
10
+
11
+ import triton
12
+ import triton.language as tl
13
+
14
+
15
+ def is_hip():
16
+ return triton.runtime.driver.active.get_current_target().backend == "hip"
17
+
18
+ @triton.jit
19
+ def _attn_fwd_inner(acc, l_i, m_i, q, #
20
+ K_block_ptr, V_block_ptr, #
21
+ R_block_ptr, #
22
+ A_block_ptr, #
23
+ start_m, qk_scale, #
24
+ BLOCK_M: tl.constexpr, HEAD_DIM: tl.constexpr, BLOCK_N: tl.constexpr, #
25
+ STAGE: tl.constexpr, offs_m: tl.constexpr, offs_n: tl.constexpr, #
26
+ N_CTX: tl.constexpr, fp8_v: tl.constexpr):
27
+ # range of values handled by this stage
28
+ if STAGE == 1:
29
+ lo, hi = 0, start_m * BLOCK_M
30
+ elif STAGE == 2:
31
+ lo, hi = start_m * BLOCK_M, (start_m + 1) * BLOCK_M
32
+ lo = tl.multiple_of(lo, BLOCK_M)
33
+ # causal = False
34
+ else:
35
+ lo, hi = 0, N_CTX
36
+ K_block_ptr = tl.advance(K_block_ptr, (0, lo))
37
+ V_block_ptr = tl.advance(V_block_ptr, (lo, 0))
38
+ # loop over k, v and update accumulator
39
+ for start_n in range(lo, hi, BLOCK_N):
40
+ start_n = tl.multiple_of(start_n, BLOCK_N)
41
+ # -- compute qk ----
42
+ k = tl.load(K_block_ptr)
43
+ qk = tl.dot(q, k)
44
+
45
+ if STAGE == 2:
46
+ mask = offs_m[:, None] >= (start_n + offs_n[None, :])
47
+ qk += tl.where(mask, 0, -1.0e6)
48
+
49
+ max = tl.max(qk, 1) * qk_scale
50
+ m_ij = tl.maximum(m_i, max)
51
+ qk = qk * qk_scale - m_ij[:, None]
52
+
53
+ tl.store(tl.advance(R_block_ptr, (0, start_n // BLOCK_N)), max[:, None].to(q.dtype))
54
+
55
+ p = tl.math.exp2(qk)
56
+ l_ij = tl.sum(p, 1)
57
+ # -- update m_i and l_i
58
+ alpha = tl.math.exp2(m_i - m_ij)
59
+ l_i = l_i * alpha + l_ij
60
+ # -- update output accumulator --
61
+ acc = acc * alpha[:, None]
62
+ # update acc
63
+ v = tl.load(V_block_ptr)
64
+ if fp8_v:
65
+ p = p.to(tl.float8e5)
66
+ else:
67
+ p = p.to(q.dtype)
68
+ acc = tl.dot(p, v, acc)
69
+ # update m_i and l_i
70
+ m_i = m_ij
71
+ V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))
72
+ K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))
73
+
74
+ # -- update Po --
75
+ if STAGE == 2:
76
+ for start_n in range(0, (start_m + 1) * BLOCK_N, BLOCK_N):
77
+ start_n = tl.multiple_of(start_n, BLOCK_N)
78
+ row_max = tl.load(R_block_ptr)
79
+ xi = row_max - m_i[:, None]
80
+ row_max = tl.exp2(xi)/l_i[:, None]
81
+ col_max = tl.max(row_max, 0)
82
+ col_max = col_max[:, None].to(q.dtype)
83
+ tl.store(A_block_ptr, col_max)
84
+ A_block_ptr = tl.advance(A_block_ptr, (0, 1))
85
+ R_block_ptr = tl.advance(R_block_ptr, (0, 1))
86
+
87
+ elif STAGE == 3:
88
+ for start_n in range(lo, hi, BLOCK_N):
89
+ start_n = tl.multiple_of(start_n, BLOCK_N)
90
+ row_max = tl.load(R_block_ptr)
91
+ xi = row_max - m_i[:, None]
92
+ row_max = tl.exp2(xi)/l_i[:, None]
93
+ col_max = tl.max(row_max, 0)
94
+ col_max = col_max[:, None].to(q.dtype)
95
+ tl.store(A_block_ptr, col_max)
96
+ A_block_ptr = tl.advance(A_block_ptr, (0, 1))
97
+ R_block_ptr = tl.advance(R_block_ptr, (0, 1))
98
+
99
+ return acc, l_i, m_i
100
+
101
+
102
+ @triton.jit
103
+ def _attn_fwd(Q, K, V, sm_scale, M, Out, #
104
+ R, Po,
105
+ stride_qz, stride_qh, stride_qm, stride_qk, #
106
+ stride_kz, stride_kh, stride_kn, stride_kk, #
107
+ stride_vz, stride_vh, stride_vk, stride_vn, #
108
+ stride_oz, stride_oh, stride_om, stride_on, #
109
+ stride_rz, stride_rh, stride_rm, stride_rn, #
110
+ stride_poz, stride_poh, stride_pom, stride_pon, #
111
+ Z, H, N_CTX, #
112
+ n_rep, #
113
+ HEAD_DIM: tl.constexpr, #
114
+ BLOCK_M: tl.constexpr, #
115
+ BLOCK_N: tl.constexpr, #
116
+ N_DOWNSAMPLE: tl.constexpr, #
117
+ STAGE: tl.constexpr #
118
+ ):
119
+ tl.static_assert(BLOCK_N <= HEAD_DIM)
120
+ start_m = tl.program_id(0)
121
+ off_hz = tl.program_id(1)
122
+ off_z = off_hz // H
123
+ off_h = off_hz % H
124
+ off_kvh = off_h // n_rep
125
+ q_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64) * stride_qh
126
+ k_offset = off_z.to(tl.int64) * stride_kz + off_kvh.to(tl.int64) * stride_kh
127
+ v_offset = off_z.to(tl.int64) * stride_vz + off_kvh.to(tl.int64) * stride_vh
128
+ r_offset = off_z.to(tl.int64) * stride_rz + off_h.to(tl.int64) * stride_rh
129
+ po_offset = off_z.to(tl.int64) * stride_poz + off_h.to(tl.int64) * stride_poh
130
+
131
+ # block pointers
132
+ Q_block_ptr = tl.make_block_ptr(
133
+ base=Q + q_offset,
134
+ shape=(N_CTX, HEAD_DIM),
135
+ strides=(stride_qm, stride_qk),
136
+ offsets=(start_m * BLOCK_M, 0),
137
+ block_shape=(BLOCK_M, HEAD_DIM),
138
+ order=(1, 0),
139
+ )
140
+ v_order: tl.constexpr = (0, 1) if V.dtype.element_ty == tl.float8e5 else (1, 0)
141
+ V_block_ptr = tl.make_block_ptr(
142
+ base=V + v_offset,
143
+ shape=(N_CTX, HEAD_DIM),
144
+ strides=(stride_vk, stride_vn),
145
+ offsets=(0, 0),
146
+ block_shape=(BLOCK_N, HEAD_DIM),
147
+ order=v_order,
148
+ )
149
+ K_block_ptr = tl.make_block_ptr(
150
+ base=K + k_offset,
151
+ shape=(HEAD_DIM, N_CTX),
152
+ strides=(stride_kk, stride_kn),
153
+ offsets=(0, 0),
154
+ block_shape=(HEAD_DIM, BLOCK_N),
155
+ order=(0, 1),
156
+ )
157
+ O_block_ptr = tl.make_block_ptr(
158
+ base=Out + q_offset,
159
+ shape=(N_CTX, HEAD_DIM),
160
+ strides=(stride_om, stride_on),
161
+ offsets=(start_m * BLOCK_M, 0),
162
+ block_shape=(BLOCK_M, HEAD_DIM),
163
+ order=(1, 0),
164
+ )
165
+
166
+ R_block_ptr = tl.make_block_ptr(
167
+ base=R + r_offset,
168
+ shape=(N_CTX, N_DOWNSAMPLE),
169
+ strides=(stride_rm, stride_rn),
170
+ offsets=(start_m * BLOCK_M, 0),
171
+ block_shape=(BLOCK_M, 1),
172
+ order=(0, 1),
173
+
174
+ )
175
+ A_block_ptr = tl.make_block_ptr(
176
+ base=Po + po_offset,
177
+ shape=(N_DOWNSAMPLE, N_DOWNSAMPLE),
178
+ strides=(stride_pom, stride_pon),
179
+ offsets=(start_m, 0),
180
+ block_shape=(1, 1),
181
+ order=(0, 1),
182
+ )
183
+ # initialize offsets
184
+ offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)
185
+ offs_n = tl.arange(0, BLOCK_N)
186
+ # initialize pointer to m and l
187
+ m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float("inf")
188
+ l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0
189
+ acc = tl.zeros([BLOCK_M, HEAD_DIM], dtype=tl.float32)
190
+ # load scales
191
+ qk_scale = sm_scale
192
+ qk_scale *= 1.44269504 # 1/log(2)
193
+ # load q: it will stay in SRAM throughout
194
+ q = tl.load(Q_block_ptr)
195
+ # stage 1: off-band
196
+ # For causal = True, STAGE = 3 and _attn_fwd_inner gets 1 as its STAGE
197
+ # For causal = False, STAGE = 1, and _attn_fwd_inner gets 3 as its STAGE
198
+ if STAGE & 1:
199
+ acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr, V_block_ptr, #
200
+ R_block_ptr, #
201
+ A_block_ptr, #
202
+ start_m, qk_scale, #
203
+ BLOCK_M, HEAD_DIM, BLOCK_N, #
204
+ 4 - STAGE, offs_m, offs_n, N_CTX, V.dtype.element_ty == tl.float8e5 #
205
+ )
206
+ # stage 2: on-band
207
+ if STAGE & 2:
208
+ # barrier makes it easier for compielr to schedule the
209
+ # two loops independently
210
+ acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr, V_block_ptr, #
211
+ R_block_ptr, #
212
+ A_block_ptr, #
213
+ start_m, qk_scale, #
214
+ BLOCK_M, HEAD_DIM, BLOCK_N, #
215
+ 2, offs_m, offs_n, N_CTX, V.dtype.element_ty == tl.float8e5 #
216
+ )
217
+ # epilogue
218
+ m_i += tl.math.log2(l_i)
219
+ acc = acc / l_i[:, None]
220
+ m_ptrs = M + off_hz * N_CTX + offs_m
221
+ tl.store(m_ptrs, m_i)
222
+ tl.store(O_block_ptr, acc.to(Out.type.element_ty))
223
+
224
+ class _attention_pooling(torch.autograd.Function):
225
+
226
+ @staticmethod
227
+ def forward(ctx, q, k, v, causal, sm_scale, block_size):
228
+ assert block_size in {32, 64, 128}
229
+ # shape constraints
230
+ q, k, v = q.contiguous(), k.contiguous(), v.contiguous()
231
+ HEAD_DIM_Q, HEAD_DIM_K = q.shape[-1], k.shape[-1]
232
+ # when v is in float8_e5m2 it is transposed.
233
+ HEAD_DIM_V = v.shape[-1]
234
+ assert HEAD_DIM_Q == HEAD_DIM_K and HEAD_DIM_K == HEAD_DIM_V
235
+ assert HEAD_DIM_K in {16, 32, 64, 128, 256}
236
+ NUM_HEADS_Q, NUM_HEADS_K, NUM_HEADS_V = q.shape[1], k.shape[1], v.shape[1]
237
+ assert NUM_HEADS_K == NUM_HEADS_V
238
+ n_rep = NUM_HEADS_Q // NUM_HEADS_K
239
+ o = torch.empty_like(q)
240
+ BLOCK_N = block_size
241
+ n_d = triton.cdiv(q.shape[2], BLOCK_N)
242
+ R = torch.full((q.shape[0], q.shape[1], q.shape[2], n_d), -65504.0, device=q.device, dtype=torch.bfloat16)
243
+ Po = torch.zeros((q.shape[0], q.shape[1], n_d, n_d), device=q.device, dtype=torch.bfloat16)
244
+ stage = 3 if causal else 1
245
+ extra_kern_args = {}
246
+ # Tuning for AMD target
247
+ if is_hip():
248
+ waves_per_eu = 3 if HEAD_DIM_K <= 64 else 2
249
+ extra_kern_args = {"waves_per_eu": waves_per_eu, "allow_flush_denorm": True}
250
+
251
+ grid = lambda args: (triton.cdiv(q.shape[2], args["BLOCK_M"]), q.shape[0] * q.shape[1], 1)
252
+ M = torch.empty((q.shape[0], q.shape[1], q.shape[2]), device=q.device, dtype=torch.float32)
253
+ _attn_fwd[grid](
254
+ q, k, v, sm_scale, M, o, #
255
+ R, Po, #
256
+ q.stride(0), q.stride(1), q.stride(2), q.stride(3), #
257
+ k.stride(0), k.stride(1), k.stride(2), k.stride(3), #
258
+ v.stride(0), v.stride(1), v.stride(2), v.stride(3), #
259
+ o.stride(0), o.stride(1), o.stride(2), o.stride(3), #
260
+ R.stride(0), R.stride(1), R.stride(2), R.stride(3), #
261
+ Po.stride(0), Po.stride(1), Po.stride(2), Po.stride(3), #
262
+ q.shape[0], q.shape[1], #
263
+ N_CTX=q.shape[2], #
264
+ n_rep=n_rep, #
265
+ HEAD_DIM=HEAD_DIM_K, #
266
+ STAGE=stage, #
267
+ BLOCK_M=block_size,
268
+ BLOCK_N=block_size,
269
+ N_DOWNSAMPLE=n_d,
270
+ num_stages=3,
271
+ num_warps=4,
272
+ **extra_kern_args)
273
+ Sum = torch.sum(Po, dim=-1, keepdim=True)
274
+ Po.div_(Sum)
275
+ return o, Po
276
+
277
+ attn_with_pooling = _attention_pooling.apply
block_sparse_attn.py ADDED
@@ -0,0 +1,395 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ """
3
+ Original Author: Eric Lin (xihlin) (https://huggingface.co/microsoft/Phi-3-small-8k-instruct/blob/main/triton_flash_blocksparse_attn.py)
4
+ """
5
+ """
6
+ Modified by Yizhao Gao
7
+ Use binary block mask for simplicity. Need to be updated to varlen version for batched inference.
8
+ """
9
+
10
+
11
+ from typing import TypeVar
12
+ from functools import lru_cache
13
+ import math
14
+ import torch
15
+ import numpy as np
16
+
17
+ import triton
18
+ import triton.language as tl
19
+ import torch.nn.functional as F
20
+ import os
21
+
22
+ import dataclasses
23
+
24
+
25
+
26
+ def is_hip():
27
+ return triton.runtime.driver.active.get_current_target().backend == "hip"
28
+
29
+
30
+ def get_sparse_attn_mask_from_topk(x, topk, use_dense_for_last_block=False):
31
+ bsz, num_head, downsample_len, _ = x.shape
32
+ # N_CTX = downsample_len * BLOCK
33
+ sparse_index = torch.topk(x, topk, dim=-1).indices
34
+ dense_mask = torch.full([bsz, num_head, downsample_len, downsample_len], False, dtype=torch.bool, device=x.device)
35
+ dense_mask.scatter_(-1, sparse_index, True)
36
+ if use_dense_for_last_block:
37
+ dense_mask[:, :,-2:,:] = True
38
+ dense_mask.tril_()
39
+ return dense_mask
40
+
41
+
42
+ def get_sparse_attn_mask_from_threshold(x, threshold, use_dense_for_last_block=False):
43
+ dense_mask = x > threshold
44
+ if use_dense_for_last_block:
45
+ dense_mask[:, :,-2:,:] = True
46
+ dense_mask.tril_()
47
+ return dense_mask
48
+
49
+
50
+
51
+
52
+ @triton.jit
53
+ def _fwd_kernel_inner(
54
+ acc, l_i, m_i,
55
+ q,
56
+ k_block_col_idx,
57
+ block_mask_ptr,
58
+ k_ptrs, v_ptrs,
59
+ offs_m, offs_n,
60
+ stride_kt, stride_vt, stride_bmask_n,
61
+ sm_scale,
62
+ seqlen_k,
63
+ past_len,
64
+ LAST_K_BLOCK: tl.constexpr,
65
+ BLOCK_M: tl.constexpr,
66
+ BLOCK_N: tl.constexpr,
67
+ ):
68
+
69
+ mask_val = tl.load(block_mask_ptr + k_block_col_idx * stride_bmask_n)
70
+ if mask_val == True:
71
+ start_n = k_block_col_idx * BLOCK_N
72
+ # -- compute qk ----
73
+
74
+ if LAST_K_BLOCK:
75
+ k = tl.load(k_ptrs + start_n * stride_kt,
76
+ mask=offs_n[None, :] + start_n < seqlen_k)
77
+
78
+ else:
79
+ k = tl.load(k_ptrs + start_n * stride_kt)
80
+
81
+ qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)
82
+ qk += tl.dot(q, k)
83
+
84
+ qk *= sm_scale
85
+
86
+ # the following is needed only when LAST_K_BLOCK or BLOCK_M < BLOCK_N
87
+ if LAST_K_BLOCK :
88
+ qk += tl.where(offs_m[:, None] + past_len >= (start_n + offs_n[None, :]), 0, float('-inf'))
89
+
90
+
91
+ m_ij = tl.maximum(m_i, tl.max(qk, 1))
92
+ qk -= m_ij[:, None]
93
+ p = tl.exp(qk)
94
+ l_ij = tl.sum(p, 1)
95
+ alpha = tl.exp(m_i - m_ij)
96
+ l_i = l_i * alpha + l_ij
97
+ acc = acc * alpha[:, None]
98
+
99
+ # update acc
100
+ if LAST_K_BLOCK:
101
+ v = tl.load(v_ptrs + start_n * stride_vt,
102
+ mask=offs_n[:, None] + start_n < seqlen_k)
103
+ else:
104
+ v = tl.load(v_ptrs + start_n * stride_vt)
105
+
106
+ p = p.to(v.type.element_ty)
107
+
108
+ acc += tl.dot(p, v)
109
+ # update m_i and l_i
110
+ m_i = m_ij
111
+ return acc, l_i, m_i
112
+
113
+
114
+
115
+
116
+ @triton.jit
117
+ def _fwd_kernel(
118
+ Q, K, V, sm_scale,
119
+ block_mask_ptr,
120
+ Out,
121
+ stride_qz, stride_qh, stride_qm, stride_qd,
122
+ stride_kz, stride_kh, stride_kn, stride_kd,
123
+ stride_vz, stride_vh, stride_vn, stride_vd,
124
+ stride_bmz, stride_bmh, stride_bmm, stride_bmn,
125
+ stride_oz, stride_oh, stride_om, stride_od,
126
+ H, N_CTX,
127
+ PAST_LEN,
128
+ BLOCK_M: tl.constexpr,
129
+ BLOCK_N: tl.constexpr,
130
+ BLOCK_DMODEL: tl.constexpr,
131
+ ):
132
+ Q_LEN = N_CTX - PAST_LEN
133
+ start_m = tl.program_id(0)
134
+ off_hz = tl.program_id(1)
135
+ off_h = off_hz % H
136
+ off_z = off_hz // H
137
+ Q += off_z * stride_qz + off_h * stride_qh
138
+ K += off_z * stride_kz + off_h * stride_kh
139
+ V += off_z * stride_vz + off_h * stride_vh
140
+ block_mask_ptr += off_z * stride_bmz + off_h * stride_bmh
141
+
142
+ # initialize offsets
143
+ offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)
144
+ offs_n = tl.arange(0, BLOCK_N)
145
+ offs_d = tl.arange(0, BLOCK_DMODEL)
146
+ off_q = offs_m[:, None] * stride_qm + offs_d[None, :] * stride_qd
147
+ # off_k = offs_n[:, None] * stride_kn + offs_d[None, :] * stride_kd
148
+ off_k = offs_n[None, :] * stride_kn + offs_d[:, None] * stride_kd
149
+ off_v = offs_n[:, None] * stride_vn + offs_d[None, :] * stride_vd
150
+ # Initialize pointers to Q, K, V
151
+ q_ptrs = Q + off_q
152
+ k_ptrs = K + off_k
153
+ v_ptrs = V + off_v
154
+ mask_ptrs = block_mask_ptr + start_m * stride_bmm
155
+
156
+ m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')
157
+ l_i = tl.zeros([BLOCK_M], dtype=tl.float32)
158
+ acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)
159
+
160
+ q = tl.load(q_ptrs, mask=offs_m[:, None] < Q_LEN)
161
+
162
+ k_block_start = 0
163
+ k_block_end = tl.cdiv((start_m + 1) * BLOCK_M, BLOCK_N)
164
+
165
+ # loop over k, v and update accumulator
166
+ for col_idx in range(k_block_start, k_block_end-1):
167
+ acc, l_i, m_i = _fwd_kernel_inner(
168
+ acc, l_i, m_i,
169
+ q,
170
+ col_idx,
171
+ mask_ptrs,
172
+ k_ptrs, v_ptrs,
173
+ offs_m, offs_n,
174
+ stride_kn, stride_vn, stride_bmn,
175
+ sm_scale,
176
+ N_CTX,
177
+ PAST_LEN,
178
+ False,
179
+ BLOCK_M,
180
+ BLOCK_N,
181
+ )
182
+
183
+ # last block
184
+ acc, l_i, m_i = _fwd_kernel_inner(
185
+ acc, l_i, m_i,
186
+ q,
187
+ k_block_end-1,
188
+ mask_ptrs,
189
+ k_ptrs, v_ptrs,
190
+ offs_m, offs_n,
191
+ stride_kn, stride_vn, stride_bmn,
192
+ sm_scale,
193
+ N_CTX,
194
+ PAST_LEN,
195
+ True,
196
+ BLOCK_M,
197
+ BLOCK_N,
198
+ )
199
+
200
+ m_i += tl.math.log(l_i)
201
+ l_recip = 1 / l_i[:, None]
202
+ acc = acc * l_recip
203
+ acc = acc.to(Out.dtype.element_ty)
204
+
205
+
206
+ off_o = off_z * stride_oz + off_h * stride_oh + offs_m[:, None] * stride_om + offs_d[None, :] * stride_od
207
+ out_ptrs = Out + off_o
208
+ tl.store(out_ptrs, acc, mask=offs_m[:, None] < N_CTX)
209
+
210
+ def _forward(
211
+ ctx,
212
+ q,
213
+ k,
214
+ v,
215
+ block_sparse_mask,
216
+ sm_scale,
217
+ BLOCK_M=64,
218
+ BLOCK_N=64,
219
+ num_warps=None,
220
+ num_stages=1,
221
+ out=None
222
+ ):
223
+
224
+
225
+ assert q.shape[-1] == k.shape[-1] == v.shape[-1]
226
+ assert k.shape[2] == v.shape[2]
227
+ o = out if out is not None else torch.empty_like(q).contiguous()
228
+ grid = (triton.cdiv(q.shape[2], BLOCK_M), q.shape[0] * q.shape[1])
229
+
230
+ assert q.shape[-1] in [64, 128]
231
+ BLOCK_DMODEL = q.shape[-1]
232
+
233
+ if is_hip():
234
+ num_warps, num_stages = 8, 1
235
+ else:
236
+ num_warps, num_stages = 4, 2
237
+
238
+ N_CTX = k.shape[2]
239
+ PAST_LEN = N_CTX - q.shape[2]
240
+
241
+
242
+ H = q.shape[1]
243
+
244
+ _fwd_kernel[grid](
245
+ q, k, v, sm_scale,
246
+ block_sparse_mask,
247
+ o,
248
+ *q.stride(),
249
+ *k.stride(),
250
+ *v.stride(),
251
+ *block_sparse_mask.stride(),
252
+ *o.stride(),
253
+ H, N_CTX,
254
+ PAST_LEN,
255
+ BLOCK_M,
256
+ BLOCK_N,
257
+ BLOCK_DMODEL,
258
+ num_warps=num_warps,
259
+ num_stages=num_stages,
260
+ )
261
+
262
+ return o
263
+
264
+
265
+
266
+
267
+ class _sparse_attention(torch.autograd.Function):
268
+
269
+ @staticmethod
270
+ def forward(ctx, q, k, v, block_sparse_dense, sm_scale):
271
+ # shape constraints
272
+ return _forward(ctx, q, k, v, block_sparse_dense, sm_scale)
273
+
274
+ @staticmethod
275
+ def backward(ctx, do):
276
+ # No gradient propagation.
277
+ raise NotImplementedError("It does not support gradient propagation yet")
278
+ return None, None, None, None, None
279
+
280
+ def sparse_attention_factory(BLOCK_M=64, BLOCK_N=64, **kwargs):
281
+ class _sparse_attention_config(_sparse_attention):
282
+ @staticmethod
283
+ def forward(ctx, q, k, v, block_sparse_dense, sm_scale):
284
+ # shape constraints
285
+ return _forward(ctx, q, k, v, block_sparse_dense, sm_scale, BLOCK_M, BLOCK_N,
286
+ **kwargs
287
+ )
288
+ return _sparse_attention_config.apply
289
+
290
+ block_sparse_triton_fn = _sparse_attention.apply
291
+
292
+
293
+
294
+ def test_topk_sparse_attention():
295
+ # Config
296
+ BATCH, N_HEADS, SEQ_LEN, D_HEAD = 2, 4, 256, 64
297
+ TOPK = 2 # Keep top 8 elements per row
298
+ BLOCK = 64
299
+ torch.manual_seed(0)
300
+
301
+ # Create inputs
302
+ q = torch.randn(BATCH, N_HEADS, SEQ_LEN, D_HEAD, device='cuda', dtype=torch.bfloat16)
303
+ k = torch.randn(BATCH, N_HEADS, SEQ_LEN, D_HEAD, device='cuda', dtype=torch.bfloat16)
304
+ v = torch.randn(BATCH, N_HEADS, SEQ_LEN, D_HEAD, device='cuda', dtype=torch.bfloat16)
305
+ sm_scale = 1.0 / (D_HEAD ** 0.5)
306
+
307
+ # Create sparse mask (downsampled to block level)
308
+ downsample_factor = BLOCK
309
+ downsample_len = math.ceil(SEQ_LEN / downsample_factor)
310
+ x_ds = torch.randn([BATCH, N_HEADS, downsample_len, downsample_len], device='cuda', dtype=torch.bfloat16)
311
+ x_ds[:,:,:,0] = 100
312
+ block_mask = get_sparse_attn_mask_from_topk(x_ds, topk=TOPK)
313
+
314
+ # Run Triton kernel
315
+ triton_output = block_sparse_triton_fn(
316
+ q, k, v,
317
+ block_mask,
318
+ sm_scale
319
+ )
320
+
321
+ # Compute reference
322
+ # Expand block mask to full attention matrix
323
+ full_mask = torch.kron(block_mask.float(),
324
+ torch.ones(BLOCK, BLOCK, device='cuda'))
325
+ full_mask = full_mask[..., :SEQ_LEN, :SEQ_LEN].bool()
326
+ full_mask = full_mask & torch.tril(torch.ones_like(full_mask)) # Apply causal
327
+
328
+ # PyTorch reference implementation
329
+ attn = torch.einsum('bhsd,bhtd->bhst', q, k) * sm_scale
330
+ attn = attn.masked_fill(~full_mask, float('-inf'))
331
+ attn = F.softmax(attn, dim=-1)
332
+ ref_output = torch.einsum('bhst,bhtd->bhsd', attn, v)
333
+
334
+
335
+ # Verify accuracy
336
+ assert torch.allclose(triton_output, ref_output, atol=1e-2, rtol=1e-2), \
337
+ "Triton output doesn't match reference"
338
+ print("Pass topk sparse attention test with qlen == klen")
339
+
340
+
341
+
342
+ def test_topk_sparse_attention_qlt_kl():
343
+ BATCH, N_HEADS = 2, 4
344
+ Q_LEN, K_LEN, D_HEAD = 128, 256, 64 # qlen < klen; here, past_len = 256 - 128 = 128.
345
+ TOPK = 1
346
+ BLOCK = 64 # block size used in downsampling
347
+ torch.manual_seed(0)
348
+
349
+ # Create inputs.
350
+ q = torch.randn(BATCH, N_HEADS, Q_LEN, D_HEAD, device='cuda', dtype=torch.bfloat16)
351
+ k = torch.randn(BATCH, N_HEADS, K_LEN, D_HEAD, device='cuda', dtype=torch.bfloat16)
352
+ v = torch.randn(BATCH, N_HEADS, K_LEN, D_HEAD, device='cuda', dtype=torch.bfloat16)
353
+ sm_scale = 1.0 / (D_HEAD ** 0.5)
354
+
355
+ downsample_factor = BLOCK
356
+ downsample_len = math.ceil(K_LEN / downsample_factor) # number of blocks along one dimension
357
+ x_ds = torch.randn(BATCH, N_HEADS, downsample_len, downsample_len,
358
+ device='cuda', dtype=torch.bfloat16)
359
+ # Force the first column to be high so that the first block is always selected.
360
+ x_ds[:, :, :, 0] = 100
361
+ block_mask = get_sparse_attn_mask_from_topk(x_ds, topk=TOPK)
362
+
363
+ # Run Triton kernel.
364
+ triton_output = block_sparse_triton_fn(q, k, v, block_mask, sm_scale)
365
+
366
+ past_len = K_LEN - Q_LEN
367
+
368
+ attn = torch.einsum('bhsd,bhtd->bhst', q, k) * sm_scale
369
+
370
+ full_mask_full = torch.kron(block_mask.float(), torch.ones(BLOCK, BLOCK, device='cuda')).bool()
371
+ full_mask_full = full_mask_full[..., :K_LEN, :K_LEN]
372
+
373
+ effective_mask = full_mask_full[..., past_len:K_LEN, :] # shape: (B, H, Q_LEN, K_LEN)
374
+
375
+
376
+ i_global = torch.arange(past_len, K_LEN, device=k.device).unsqueeze(1) # shape: (Q_LEN, 1)
377
+ j_global = torch.arange(K_LEN, device=k.device).unsqueeze(0) # shape: (1, K_LEN)
378
+ causal_mask = (j_global <= i_global) # shape: (Q_LEN, K_LEN)
379
+
380
+ final_mask = effective_mask & causal_mask # shape: (B, H, Q_LEN, K_LEN)
381
+
382
+ attn = attn.masked_fill(~final_mask, float('-inf'))
383
+ attn = F.softmax(attn, dim=-1)
384
+ ref_output = torch.einsum('bhst,bhtd->bhsd', attn, v)
385
+
386
+ # Verify accuracy.
387
+ assert torch.allclose(triton_output, ref_output, atol=1e-2, rtol=1e-2), \
388
+ "Triton output doesn't match reference when qlen < klen"
389
+
390
+ print("Pass topk sparse attention test with qlen < klen")
391
+
392
+
393
+ if __name__ == "__main__":
394
+ test_topk_sparse_attention()
395
+ test_topk_sparse_attention_qlt_kl()
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "SeerAttention/SeerAttention-Llama-3.1-8B",
3
+ "architectures": [
4
+ "SeerAttnLlamaForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "bos_token_id": 128000,
9
+ "eos_token_id": [
10
+ 128001,
11
+ 128008,
12
+ 128009
13
+ ],
14
+ "hidden_act": "silu",
15
+ "hidden_size": 4096,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 14336,
18
+ "max_position_embeddings": 131072,
19
+ "mlp_bias": false,
20
+ "model_type": "llama",
21
+ "num_attention_heads": 32,
22
+ "num_hidden_layers": 32,
23
+ "num_key_value_heads": 8,
24
+ "pretraining_tp": 1,
25
+ "rms_norm_eps": 1e-05,
26
+ "rope_scaling": {
27
+ "factor": 8.0,
28
+ "high_freq_factor": 4.0,
29
+ "low_freq_factor": 1.0,
30
+ "original_max_position_embeddings": 8192,
31
+ "rope_type": "llama3"
32
+ },
33
+ "rope_theta": 500000.0,
34
+ "seerattn_gate_block_size": 64,
35
+ "seerattn_gate_hidden_size": 128,
36
+ "seerattn_gate_type": "Qavg_Kmaxminavg",
37
+ "tie_word_embeddings": false,
38
+ "torch_dtype": "bfloat16",
39
+ "transformers_version": "4.44.2",
40
+ "use_cache": true,
41
+ "vocab_size": 128258
42
+ }
configuration_llama_seerattn.py ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Modified from hf transformers
2
+ """LLaMA model configuration"""
3
+
4
+ from transformers.configuration_utils import PretrainedConfig
5
+ from transformers.modeling_rope_utils import rope_config_validation
6
+
7
+
8
+ class SeerAttnLlamaConfig(PretrainedConfig):
9
+ r"""
10
+ This is the configuration class to store the configuration of a [`LlamaModel`]. It is used to instantiate an LLaMA
11
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
12
+ defaults will yield a similar configuration to that of the LLaMA-7B.
13
+
14
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
15
+ documentation from [`PretrainedConfig`] for more information.
16
+
17
+
18
+ Args:
19
+ vocab_size (`int`, *optional*, defaults to 32000):
20
+ Vocabulary size of the LLaMA model. Defines the number of different tokens that can be represented by the
21
+ `inputs_ids` passed when calling [`LlamaModel`]
22
+ hidden_size (`int`, *optional*, defaults to 4096):
23
+ Dimension of the hidden representations.
24
+ intermediate_size (`int`, *optional*, defaults to 11008):
25
+ Dimension of the MLP representations.
26
+ num_hidden_layers (`int`, *optional*, defaults to 32):
27
+ Number of hidden layers in the Transformer decoder.
28
+ num_attention_heads (`int`, *optional*, defaults to 32):
29
+ Number of attention heads for each attention layer in the Transformer decoder.
30
+ num_key_value_heads (`int`, *optional*):
31
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
32
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
33
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
34
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
35
+ by meanpooling all the original heads within that group. For more details checkout [this
36
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
37
+ `num_attention_heads`.
38
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
39
+ The non-linear activation function (function or string) in the decoder.
40
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
41
+ The maximum sequence length that this model might ever be used with. Llama 1 supports up to 2048 tokens,
42
+ Llama 2 up to 4096, CodeLlama up to 16384.
43
+ initializer_range (`float`, *optional*, defaults to 0.02):
44
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
45
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
46
+ The epsilon used by the rms normalization layers.
47
+ use_cache (`bool`, *optional*, defaults to `True`):
48
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
49
+ relevant if `config.is_decoder=True`.
50
+ pad_token_id (`int`, *optional*):
51
+ Padding token id.
52
+ bos_token_id (`int`, *optional*, defaults to 1):
53
+ Beginning of stream token id.
54
+ eos_token_id (`int`, *optional*, defaults to 2):
55
+ End of stream token id.
56
+ pretraining_tp (`int`, *optional*, defaults to 1):
57
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
58
+ document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism) to
59
+ understand more about it. This value is necessary to ensure exact reproducibility of the pretraining
60
+ results. Please refer to [this issue](https://github.com/pytorch/pytorch/issues/76232).
61
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
62
+ Whether to tie weight embeddings
63
+ rope_theta (`float`, *optional*, defaults to 10000.0):
64
+ The base period of the RoPE embeddings.
65
+ rope_scaling (`Dict`, *optional*):
66
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
67
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
68
+ accordingly.
69
+ Expected contents:
70
+ `rope_type` (`str`):
71
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
72
+ 'llama3'], with 'default' being the original RoPE implementation.
73
+ `factor` (`float`, *optional*):
74
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
75
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
76
+ original maximum pre-trained length.
77
+ `original_max_position_embeddings` (`int`, *optional*):
78
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
79
+ pretraining.
80
+ `attention_factor` (`float`, *optional*):
81
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
82
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
83
+ `factor` field to infer the suggested value.
84
+ `beta_fast` (`float`, *optional*):
85
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
86
+ ramp function. If unspecified, it defaults to 32.
87
+ `beta_slow` (`float`, *optional*):
88
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
89
+ ramp function. If unspecified, it defaults to 1.
90
+ `short_factor` (`List[float]`, *optional*):
91
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
92
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
93
+ size divided by the number of attention heads divided by 2
94
+ `long_factor` (`List[float]`, *optional*):
95
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
96
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
97
+ size divided by the number of attention heads divided by 2
98
+ `low_freq_factor` (`float`, *optional*):
99
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
100
+ `high_freq_factor` (`float`, *optional*):
101
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
102
+ attention_bias (`bool`, *optional*, defaults to `False`):
103
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
104
+ attention_dropout (`float`, *optional*, defaults to 0.0):
105
+ The dropout ratio for the attention probabilities.
106
+ mlp_bias (`bool`, *optional*, defaults to `False`):
107
+ Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.
108
+ head_dim (`int`, *optional*):
109
+ The attention head dimension. If None, it will default to hidden_size // num_heads
110
+ seerattn_apply_stage (`str`, *optional*, defaults to 'post_training'):
111
+ The stage to apply the SeerAttention. Can be one of ['post_training', 'fine_tuning', 'pre_training'].
112
+ 'post_training' means applying SeerAttention after training, only gate is trained/learned with mask_loss to predict attention mask.
113
+ 'fine_tuning' means applying SeerAttention during fine-tuning ((long context extension)), both gate and attention weights are trained/learned with both mask_loss and tok_loss (currently, tok_loss can not backpropogate seerattn_gate).
114
+ 'pre_training' means applying SeerAttention during pre-training, both gate and attention weights are trained/learned with only tok_loss.
115
+ seerattn_sparsity_method (`str`, *optional*, defaults to 'threshold'):
116
+ Sparsity method used in gate. 'threshold' or 'nz_ratio'.
117
+ seerattn_threshold (`float`, *optional*, defaults to 2e-3):
118
+ The threhold to mask out attention weight if using "threshold" as sparsity method.
119
+ seerattn_nz_ratio (`float`, *optional*, defaults to 1.0):
120
+ The ratio of non-zero attention weights uf using "nz_ratio" as sparsity method. topk for each row in attention weight.
121
+ seerattn_gate_type (`str`, *optional*, defaults to 'Qavg_Kmaxmin'):
122
+ The pooling method for the attention gate. Can be one of ['Qmax_Kmax', 'Qmax_Kmin', 'Qmax_Kavg',...]
123
+ seerattn_gate_block_size (`int`, *optional*, defaults to 64):
124
+ The block size for the gate.
125
+ seerattn_gate_hidden_size (`int`, *optional*, defaults to 128):
126
+ The hidden size for the gate.
127
+ seerattn_last_block_dense (`bool`, *optional*, defaults to True):
128
+ Use dense attention for the last 2 row of blocks (Usually the question of prompt).
129
+ ```python
130
+ >>> from transformers import LlamaModel, LlamaConfig
131
+
132
+ >>> # Initializing a LLaMA llama-7b style configuration
133
+ >>> configuration = LlamaConfig()
134
+
135
+ >>> # Initializing a model from the llama-7b style configuration
136
+ >>> model = LlamaModel(configuration)
137
+
138
+ >>> # Accessing the model configuration
139
+ >>> configuration = model.config
140
+ ```"""
141
+
142
+ model_type = "llama"
143
+ keys_to_ignore_at_inference = ["past_key_values"]
144
+ # Default tensor parallel plan for base model `LlamaModel`
145
+ base_model_tp_plan = {
146
+ "layers.*.self_attn.q_proj": "colwise",
147
+ "layers.*.self_attn.k_proj": "colwise",
148
+ "layers.*.self_attn.v_proj": "colwise",
149
+ "layers.*.self_attn.o_proj": "rowwise",
150
+ "layers.*.mlp.gate_proj": "colwise",
151
+ "layers.*.mlp.up_proj": "colwise",
152
+ "layers.*.mlp.down_proj": "rowwise",
153
+ }
154
+
155
+ def __init__(
156
+ self,
157
+ vocab_size=32000,
158
+ hidden_size=4096,
159
+ intermediate_size=11008,
160
+ num_hidden_layers=32,
161
+ num_attention_heads=32,
162
+ num_key_value_heads=None,
163
+ hidden_act="silu",
164
+ max_position_embeddings=2048,
165
+ initializer_range=0.02,
166
+ rms_norm_eps=1e-6,
167
+ use_cache=True,
168
+ pad_token_id=None,
169
+ bos_token_id=1,
170
+ eos_token_id=2,
171
+ pretraining_tp=1,
172
+ tie_word_embeddings=False,
173
+ rope_theta=10000.0,
174
+ rope_scaling=None,
175
+ attention_bias=False,
176
+ attention_dropout=0.0,
177
+ mlp_bias=False,
178
+ head_dim=None,
179
+ seerattn_sparsity_method='threshold', ## or nz_ratio
180
+ seerattn_threshold=0.0,
181
+ seerattn_nz_ratio=1.0,
182
+ seerattn_gate_type='Qavg_Kmaxminavg',
183
+ seerattn_gate_block_size=64,
184
+ seerattn_gate_hidden_size=128,
185
+ seerattn_last_block_dense=True,
186
+ **kwargs,
187
+ ):
188
+ self.vocab_size = vocab_size
189
+ self.max_position_embeddings = max_position_embeddings
190
+ self.hidden_size = hidden_size
191
+ self.intermediate_size = intermediate_size
192
+ self.num_hidden_layers = num_hidden_layers
193
+ self.num_attention_heads = num_attention_heads
194
+
195
+ # for backward compatibility
196
+ if num_key_value_heads is None:
197
+ num_key_value_heads = num_attention_heads
198
+
199
+ self.num_key_value_heads = num_key_value_heads
200
+ self.hidden_act = hidden_act
201
+ self.initializer_range = initializer_range
202
+ self.rms_norm_eps = rms_norm_eps
203
+ self.pretraining_tp = pretraining_tp
204
+ self.use_cache = use_cache
205
+ self.rope_theta = rope_theta
206
+ self.rope_scaling = rope_scaling
207
+ self.attention_bias = attention_bias
208
+ self.attention_dropout = attention_dropout
209
+ self.mlp_bias = mlp_bias
210
+ self.head_dim = head_dim if head_dim is not None else self.hidden_size // self.num_attention_heads
211
+ # Validate the correctness of rotary position embeddings parameters
212
+ # BC: if there is a 'type' field, copy it it to 'rope_type'.
213
+
214
+ self.seerattn_sparsity_method = seerattn_sparsity_method
215
+ self.seerattn_threshold = seerattn_threshold
216
+ self.seerattn_nz_ratio = seerattn_nz_ratio
217
+ self.seerattn_gate_type = seerattn_gate_type
218
+ self.seerattn_gate_block_size = seerattn_gate_block_size
219
+ self.seerattn_gate_hidden_size = seerattn_gate_hidden_size
220
+ self.seerattn_last_block_dense = seerattn_last_block_dense
221
+
222
+ assert self.seerattn_sparsity_method in ['threshold', 'nz_ratio']
223
+
224
+ #assert for each stage,type
225
+
226
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
227
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
228
+ rope_config_validation(self)
229
+
230
+ super().__init__(
231
+ pad_token_id=pad_token_id,
232
+ bos_token_id=bos_token_id,
233
+ eos_token_id=eos_token_id,
234
+ tie_word_embeddings=tie_word_embeddings,
235
+ **kwargs,
236
+ )
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74200700660dd0f5524fba75534e9dd68fd4d825ea2a52ebf0e254ced1f5746c
3
+ size 4887570576
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8420949ada36e85940885be2f2591f3b59bbfc7a3bb3e3096df0d2141cf847e2
3
+ size 4992480552
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:734407e32bfbc5320aaee6e0354b5b1497bb1dfab2c2458a6760a0366dfb0a99
3
+ size 4995609816
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e6ab9eec2c90d2a824769e5112c235c9d99c4e794aa914716658ba065730dee
3
+ size 1285595816
model.safetensors.index.json ADDED
@@ -0,0 +1,330 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 16161218560
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00004-of-00004.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00004.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
28
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
29
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
30
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
31
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
32
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
33
+ "model.layers.10.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
34
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
35
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
36
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
37
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
38
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
39
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
40
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
41
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
42
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
43
+ "model.layers.11.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
44
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
45
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
46
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
47
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
48
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
49
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
50
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
51
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
53
+ "model.layers.12.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
54
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
55
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
56
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
57
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
58
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
59
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
61
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
63
+ "model.layers.13.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
64
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
65
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
66
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
67
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
68
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
69
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
70
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.14.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
78
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
80
+ "model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
82
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
83
+ "model.layers.15.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
86
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
92
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.16.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
97
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
98
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
99
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
100
+ "model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.17.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.18.input_layernorm.weight": "model-00002-of-00004.safetensors",
109
+ "model.layers.18.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
110
+ "model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
111
+ "model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
112
+ "model.layers.18.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.18.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
114
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.19.input_layernorm.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.19.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.19.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.19.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.19.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
123
+ "model.layers.19.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
124
+ "model.layers.19.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
125
+ "model.layers.19.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
126
+ "model.layers.19.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.19.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
128
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
129
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
130
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
131
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
132
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
133
+ "model.layers.2.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
134
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
135
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
136
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
137
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
138
+ "model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
139
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
140
+ "model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
141
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
142
+ "model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
143
+ "model.layers.20.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
144
+ "model.layers.20.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
145
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
146
+ "model.layers.20.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
147
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
148
+ "model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
149
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
150
+ "model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
151
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
152
+ "model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
153
+ "model.layers.21.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
154
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
155
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
156
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
157
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
158
+ "model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
159
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
160
+ "model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
161
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
162
+ "model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
163
+ "model.layers.22.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
164
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
165
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
166
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
167
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
168
+ "model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
169
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
170
+ "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
171
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
172
+ "model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
173
+ "model.layers.23.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
174
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
175
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
176
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
177
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
178
+ "model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
179
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
180
+ "model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
181
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
182
+ "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
183
+ "model.layers.24.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
184
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
185
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
186
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
187
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
188
+ "model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
189
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
190
+ "model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
191
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
193
+ "model.layers.25.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
194
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
195
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
196
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
197
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
198
+ "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
200
+ "model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
201
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
202
+ "model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
203
+ "model.layers.26.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
204
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
205
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
207
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
208
+ "model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
209
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
210
+ "model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
211
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
212
+ "model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.27.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
218
+ "model.layers.28.input_layernorm.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.28.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.28.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
221
+ "model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
222
+ "model.layers.28.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
223
+ "model.layers.28.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
224
+ "model.layers.28.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
225
+ "model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
226
+ "model.layers.28.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.29.input_layernorm.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.29.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.29.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
231
+ "model.layers.29.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
232
+ "model.layers.29.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.29.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
234
+ "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
235
+ "model.layers.29.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
236
+ "model.layers.29.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
237
+ "model.layers.29.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
238
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
239
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
240
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
241
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
242
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
243
+ "model.layers.3.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
244
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
245
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
246
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
247
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
248
+ "model.layers.30.input_layernorm.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.30.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
250
+ "model.layers.30.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
251
+ "model.layers.30.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.30.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.30.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
254
+ "model.layers.30.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.30.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.30.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.30.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.31.input_layernorm.weight": "model-00004-of-00004.safetensors",
259
+ "model.layers.31.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
260
+ "model.layers.31.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.31.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
262
+ "model.layers.31.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
263
+ "model.layers.31.self_attn.attn_gate.mask_linear_k.weight": "model-00003-of-00004.safetensors",
264
+ "model.layers.31.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
265
+ "model.layers.31.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
266
+ "model.layers.31.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
267
+ "model.layers.31.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
268
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
269
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
270
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
271
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
272
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
273
+ "model.layers.4.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
274
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
275
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
276
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
277
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
278
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
279
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
280
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
281
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
282
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
283
+ "model.layers.5.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
284
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
285
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
286
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
287
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
288
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
289
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
290
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
291
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
292
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
293
+ "model.layers.6.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
294
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
295
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
296
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
297
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
298
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
299
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
300
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
301
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
302
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
303
+ "model.layers.7.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
304
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
305
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
306
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
307
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
308
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
309
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
310
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
311
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
312
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
313
+ "model.layers.8.self_attn.attn_gate.mask_linear_k.weight": "model-00001-of-00004.safetensors",
314
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
315
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
316
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
317
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
318
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
319
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
320
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
321
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
322
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
323
+ "model.layers.9.self_attn.attn_gate.mask_linear_k.weight": "model-00002-of-00004.safetensors",
324
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
325
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
326
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
327
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
328
+ "model.norm.weight": "model-00004-of-00004.safetensors"
329
+ }
330
+ }
modeling_llama_seerattn.py ADDED
@@ -0,0 +1,1199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+
21
+ # Modified by Yizhao Gao from huggingface llama implementation
22
+
23
+ from typing import Callable, List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ import torch.utils.checkpoint
27
+ from torch import nn
28
+ import torch.nn.functional as F
29
+ from torch.nn import init
30
+
31
+ from transformers.activations import ACT2FN
32
+ from transformers.cache_utils import Cache, DynamicCache, StaticCache
33
+ from transformers.generation import GenerationMixin
34
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
35
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS
36
+ from transformers.modeling_utils import PreTrainedModel
37
+ from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
38
+ from transformers.utils import (
39
+ add_code_sample_docstrings,
40
+ add_start_docstrings,
41
+ add_start_docstrings_to_model_forward,
42
+ logging,
43
+ replace_return_docstrings,
44
+ )
45
+ from .configuration_llama_seerattn import SeerAttnLlamaConfig
46
+ from .utils import BaseModelOutputWithPastAndSeer, CausalLMOutputWithPastAndSeer
47
+ from .attn_pooling_kernel import attn_with_pooling
48
+ from .block_sparse_attn import get_sparse_attn_mask_from_topk, get_sparse_attn_mask_from_threshold, sparse_attention_factory
49
+ import copy, math, os
50
+
51
+ logger = logging.get_logger(__name__)
52
+ from itertools import combinations
53
+
54
+
55
+
56
+ def min_pool2d(input, kernel_size, stride=None, padding=0, dilation=1, ceil_mode=False):
57
+ return -F.max_pool2d(-input, kernel_size=kernel_size, stride=stride, padding=padding, dilation=dilation, ceil_mode=ceil_mode)
58
+
59
+
60
+
61
+ class MultiHeadLinear(nn.Module):
62
+ def __init__(self, in_channel_size, hidden_size, num_head):
63
+ super(MultiHeadLinear, self).__init__()
64
+ self.in_channel = in_channel_size
65
+ self.hidden_size = hidden_size
66
+ self.num_head = num_head
67
+ self.weight = nn.Parameter(torch.Tensor(self.num_head, self.in_channel, self.hidden_size))
68
+ self._init_weight()
69
+
70
+
71
+ def _init_weight(self):
72
+ init.xavier_uniform_(self.weight)
73
+
74
+ def forward(self, x): # x shape (batch_size, head, seq_length, channel_size)
75
+ if x.shape[1] < self.num_head:
76
+ x = repeat_kv(x, self.num_head // x.shape[1])
77
+ return torch.matmul(x, self.weight) # torch.einsum('bhsi,hio->bhso', x, self.weight)
78
+
79
+
80
+ class AttnGate(nn.Module):
81
+ def __init__(self, block_size, in_channel_size, hidden_size, num_k_head, num_q_head, q_pooling_funcs, k_pooling_funcs):
82
+ super(AttnGate, self).__init__()
83
+ self.block_size = block_size
84
+ self.in_channel = in_channel_size
85
+ self.hidden_size = hidden_size
86
+ self.num_k_head = num_k_head
87
+ self.num_q_head = num_q_head
88
+
89
+ self.q_pooling_funcs = q_pooling_funcs
90
+ self.k_pooling_funcs = k_pooling_funcs
91
+
92
+
93
+ self.q_dup_size = len(q_pooling_funcs)
94
+ self.k_dup_size = len(k_pooling_funcs)
95
+
96
+ q_in_channel_size = in_channel_size * self.q_dup_size
97
+ k_in_channel_size = in_channel_size * self.k_dup_size
98
+
99
+
100
+ if self.q_dup_size > 1 or self.hidden_size != in_channel_size:
101
+ self.mask_linear_q = MultiHeadLinear(q_in_channel_size, self.hidden_size, self.num_q_head)
102
+ self.mask_linear_k = MultiHeadLinear(k_in_channel_size, self.hidden_size, self.num_k_head)
103
+ else: # Can use a single linear layer if hidden_size = in_channel_size
104
+ self.mask_linear_q = None
105
+ self.mask_linear_k = MultiHeadLinear(k_in_channel_size, self.hidden_size, self.num_q_head)
106
+
107
+ # q shape (batch_size, num_q_head, seq_length, channel_size)
108
+ # k shape (batch_size, num_k_head, seq_length, channel_size)
109
+ def forward(self, q, k, attention_mask, position_embeddings=None, use_softmax=True):
110
+ q, k, attention_mask = q.contiguous(), k.contiguous(), attention_mask.contiguous()
111
+
112
+ q_pooled = [pool_func(q, kernel_size=[self.block_size, 1], stride=[self.block_size, 1], ceil_mode=True) for pool_func in self.q_pooling_funcs]
113
+ q = torch.cat(q_pooled, dim=-1)
114
+ if self.mask_linear_q is not None:
115
+ q = self.mask_linear_q(q)
116
+
117
+ k_pooled = [pool_func(k, kernel_size=[self.block_size, 1], stride=[self.block_size, 1], ceil_mode=True) for pool_func in self.k_pooling_funcs]
118
+ k = torch.cat(k_pooled, dim=-1)
119
+ k = self.mask_linear_k(k)
120
+
121
+ if position_embeddings is not None:
122
+ cos, sin = position_embeddings
123
+ q, k = apply_rotary_pos_emb(q, k, cos, sin, unsqueeze_dim=1)
124
+
125
+ if k.shape[1] < self.num_q_head:
126
+ k = repeat_kv(k, self.num_q_head // k.shape[1])
127
+
128
+ attn = torch.matmul(q, k.transpose(-1, -2)) / torch.sqrt(torch.tensor(self.hidden_size).float())
129
+ if attention_mask.dtype == torch.bool:
130
+ attn = attn.masked_fill(~attention_mask, -1e9)
131
+ else:
132
+ attn = attn + attention_mask
133
+ if use_softmax:
134
+ attn = F.softmax(attn, dim=-1)
135
+ return attn
136
+
137
+
138
+ POOL_FUNCS = {
139
+ 'max': F.max_pool2d,
140
+ 'min': min_pool2d,
141
+ 'avg': F.avg_pool2d
142
+ }
143
+
144
+
145
+ def _create_generic_attngate_class(base_class, suffix, q_pooling_names, k_pooling_names):
146
+ q_pooling_funcs = [POOL_FUNCS[name] for name in q_pooling_names]
147
+ k_pooling_funcs = [POOL_FUNCS[name] for name in k_pooling_names]
148
+ class_name = f"Q{''.join(q_pooling_names)}_K{''.join(k_pooling_names)}{suffix}"
149
+
150
+ class NewAttnGate(base_class):
151
+ def __init__(self, block_size, in_channel_size, hidden_size, num_k_head, num_q_head):
152
+ super(NewAttnGate, self).__init__(
153
+ block_size=block_size,
154
+ in_channel_size=in_channel_size,
155
+ hidden_size=hidden_size,
156
+ num_k_head=num_k_head,
157
+ num_q_head=num_q_head,
158
+ q_pooling_funcs=q_pooling_funcs,
159
+ k_pooling_funcs=k_pooling_funcs
160
+ )
161
+ NewAttnGate.__name__ = class_name
162
+ return class_name, NewAttnGate
163
+
164
+
165
+ def generate_combinations():
166
+ new_classes = {}
167
+ pool_types = ['max', 'min', 'avg']
168
+
169
+ for q_comb in range(1, 4):
170
+ for k_comb in range(1, 4):
171
+ for q_pooling_comb in combinations(pool_types, q_comb):
172
+ for k_pooling_comb in combinations(pool_types, k_comb):
173
+ class_name, new_class = _create_generic_attngate_class(AttnGate, '', q_pooling_comb, k_pooling_comb)
174
+ new_classes[class_name] = new_class
175
+ return new_classes
176
+
177
+
178
+ ATTNGATE_CLASSES = generate_combinations()
179
+
180
+
181
+ class LlamaRMSNorm(nn.Module):
182
+ def __init__(self, hidden_size, eps=1e-6):
183
+ """
184
+ LlamaRMSNorm is equivalent to T5LayerNorm
185
+ """
186
+ super().__init__()
187
+ self.weight = nn.Parameter(torch.ones(hidden_size))
188
+ self.variance_epsilon = eps
189
+
190
+ def forward(self, hidden_states):
191
+ input_dtype = hidden_states.dtype
192
+ hidden_states = hidden_states.to(torch.float32)
193
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
194
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
195
+ return self.weight * hidden_states.to(input_dtype)
196
+
197
+ def extra_repr(self):
198
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
199
+
200
+
201
+ ALL_LAYERNORM_LAYERS.append(LlamaRMSNorm)
202
+
203
+
204
+ class LlamaRotaryEmbedding(nn.Module):
205
+ def __init__(
206
+ self,
207
+ config: SeerAttnLlamaConfig,
208
+ device=None,
209
+ ):
210
+ super().__init__()
211
+ self.rope_kwargs = {}
212
+ # BC: "rope_type" was originally "type"
213
+ if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
214
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
215
+ else:
216
+ self.rope_type = "default"
217
+ self.max_seq_len_cached = config.max_position_embeddings
218
+ self.original_max_seq_len = config.max_position_embeddings
219
+
220
+ self.config = config
221
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
222
+
223
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device, **self.rope_kwargs)
224
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
225
+ self.original_inv_freq = self.inv_freq
226
+
227
+ def _dynamic_frequency_update(self, position_ids, device):
228
+ """
229
+ dynamic RoPE layers should recompute `inv_freq` in the following situations:
230
+ 1 - growing beyond the cached sequence length (allow scaling)
231
+ 2 - the current sequence length is in the original scale (avoid losing precision with small sequences)
232
+ """
233
+ seq_len = torch.max(position_ids) + 1
234
+ if seq_len > self.max_seq_len_cached: # growth
235
+ inv_freq, self.attention_scaling = self.rope_init_fn(
236
+ self.config, device, seq_len=seq_len, **self.rope_kwargs
237
+ )
238
+ self.register_buffer("inv_freq", inv_freq, persistent=False) # TODO joao: may break with compilation
239
+ self.max_seq_len_cached = seq_len
240
+
241
+ if seq_len < self.original_max_seq_len and self.max_seq_len_cached > self.original_max_seq_len: # reset
242
+ self.register_buffer("inv_freq", self.original_inv_freq, persistent=False)
243
+ self.max_seq_len_cached = self.original_max_seq_len
244
+
245
+ @torch.no_grad()
246
+ def forward(self, x, position_ids):
247
+ if "dynamic" in self.rope_type:
248
+ self._dynamic_frequency_update(position_ids, device=x.device)
249
+
250
+ # Core RoPE block
251
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1)
252
+ position_ids_expanded = position_ids[:, None, :].float()
253
+ # Force float32 (see https://github.com/huggingface/transformers/pull/29285)
254
+ device_type = x.device.type
255
+ device_type = device_type if isinstance(device_type, str) and device_type != "mps" else "cpu"
256
+ with torch.autocast(device_type=device_type, enabled=False):
257
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
258
+ emb = torch.cat((freqs, freqs), dim=-1)
259
+ cos = emb.cos()
260
+ sin = emb.sin()
261
+
262
+ # Advanced RoPE types (e.g. yarn) apply a post-processing scaling factor, equivalent to scaling attention
263
+ cos = cos * self.attention_scaling
264
+ sin = sin * self.attention_scaling
265
+
266
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
267
+
268
+
269
+ def rotate_half(x):
270
+ """Rotates half the hidden dims of the input."""
271
+ x1 = x[..., : x.shape[-1] // 2]
272
+ x2 = x[..., x.shape[-1] // 2 :]
273
+ return torch.cat((-x2, x1), dim=-1)
274
+
275
+
276
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
277
+ """Applies Rotary Position Embedding to the query and key tensors.
278
+
279
+ Args:
280
+ q (`torch.Tensor`): The query tensor.
281
+ k (`torch.Tensor`): The key tensor.
282
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
283
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
284
+ position_ids (`torch.Tensor`, *optional*):
285
+ Deprecated and unused.
286
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
287
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
288
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
289
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
290
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
291
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
292
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
293
+ Returns:
294
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
295
+ """
296
+ cos = cos.unsqueeze(unsqueeze_dim)
297
+ sin = sin.unsqueeze(unsqueeze_dim)
298
+ q_embed = (q * cos) + (rotate_half(q) * sin)
299
+ k_embed = (k * cos) + (rotate_half(k) * sin)
300
+ return q_embed, k_embed
301
+
302
+
303
+ class LlamaMLP(nn.Module):
304
+ def __init__(self, config):
305
+ super().__init__()
306
+ self.config = config
307
+ self.hidden_size = config.hidden_size
308
+ self.intermediate_size = config.intermediate_size
309
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
310
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
311
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=config.mlp_bias)
312
+ self.act_fn = ACT2FN[config.hidden_act]
313
+
314
+ def forward(self, x):
315
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
316
+ return down_proj
317
+
318
+
319
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
320
+ """
321
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
322
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
323
+ """
324
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
325
+ if n_rep == 1:
326
+ return hidden_states
327
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
328
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
329
+
330
+
331
+ def eager_attention_forward(
332
+ module: nn.Module,
333
+ query: torch.Tensor,
334
+ key: torch.Tensor,
335
+ value: torch.Tensor,
336
+ attention_mask: Optional[torch.Tensor],
337
+ scaling: float,
338
+ dropout: float = 0.0,
339
+ **kwargs,
340
+ ):
341
+ key_states = repeat_kv(key, module.num_key_value_groups)
342
+ value_states = repeat_kv(value, module.num_key_value_groups)
343
+
344
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
345
+ if attention_mask is not None:
346
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
347
+ attn_weights = attn_weights + causal_mask
348
+
349
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
350
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
351
+ attn_output = torch.matmul(attn_weights, value_states)
352
+ attn_output = attn_output.transpose(1, 2).contiguous()
353
+
354
+ return attn_output, attn_weights
355
+
356
+
357
+
358
+ class LlamaSeerAttention(nn.Module):
359
+ """SeerAttention: Learning Sparse Attention for Transformers"""
360
+
361
+ def __init__(self, config: SeerAttnLlamaConfig, layer_idx: int):
362
+ super().__init__()
363
+ self.config = config
364
+ self.layer_idx = layer_idx
365
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
366
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
367
+ self.scaling = self.head_dim**-0.5
368
+ self.attention_dropout = config.attention_dropout
369
+ self.is_causal = True
370
+
371
+ self.q_proj = nn.Linear(
372
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
373
+ )
374
+ self.k_proj = nn.Linear(
375
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
376
+ )
377
+ self.v_proj = nn.Linear(
378
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
379
+ )
380
+ self.o_proj = nn.Linear(
381
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
382
+ )
383
+
384
+
385
+ self.attn_gate = ATTNGATE_CLASSES[config.seerattn_gate_type](
386
+ config.seerattn_gate_block_size,
387
+ self.head_dim,
388
+ config.seerattn_gate_hidden_size,
389
+ num_k_head=config.num_key_value_heads,
390
+ num_q_head=config.num_attention_heads
391
+ )
392
+
393
+ self.attn_func = sparse_attention_factory(config.seerattn_gate_block_size, config.seerattn_gate_block_size)
394
+ self.mask_loss_func = torch.nn.KLDivLoss()
395
+ self.profile_file = os.environ.get("PROFILE_FILE", None)
396
+
397
+ def forward(
398
+ self,
399
+ hidden_states: torch.Tensor,
400
+ position_embeddings: Tuple[torch.Tensor, torch.Tensor],
401
+ attention_mask: Optional[torch.Tensor],
402
+ past_key_value: Optional[Cache] = None,
403
+ cache_position: Optional[torch.LongTensor] = None,
404
+ block_position_embeddings: Tuple[torch.Tensor, torch.Tensor] = None,
405
+ block_attention_mask: Optional[torch.Tensor] = None,
406
+ **kwargs,
407
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
408
+ input_shape = hidden_states.shape[:-1]
409
+ hidden_shape = (*input_shape, -1, self.head_dim)
410
+
411
+ query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
412
+ key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
413
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
414
+
415
+ q_len = query_states.shape[-2]
416
+
417
+ # get the block mask prediction from gate [before ROPE]
418
+ if q_len > 1:
419
+ use_softmax = not self.training and self.config.seerattn_sparsity_method == "threshold"
420
+ mask_gate_prediction = self.attn_gate(query_states, key_states, block_attention_mask, block_position_embeddings, use_softmax)
421
+
422
+ cos, sin = position_embeddings
423
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
424
+
425
+ if past_key_value is not None:
426
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
427
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
428
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
429
+
430
+ k_len = query_states.shape[-2]
431
+ if not self.training and q_len > 1 and q_len == k_len:
432
+ # get the sparse mask
433
+ if self.config.seerattn_sparsity_method == "nz_ratio":
434
+ downsampled_len = math.ceil(key_states.shape[-2] / self.config.seerattn_gate_block_size)
435
+ topk_nz_ratio = 1 - math.sqrt(1 - self.config.seerattn_nz_ratio)
436
+ topk = int(topk_nz_ratio * downsampled_len)
437
+ topk = 1 if topk == 0 else topk
438
+ ## This attention mask actually a bool type block sparse attention
439
+ sparse_attn_mask = get_sparse_attn_mask_from_topk(mask_gate_prediction, topk, self.config.seerattn_last_block_dense)
440
+ elif self.config.seerattn_sparsity_method == "threshold":
441
+ sparse_attn_mask = get_sparse_attn_mask_from_threshold(mask_gate_prediction, self.config.seerattn_threshold, self.config.seerattn_last_block_dense)
442
+ downsampled_len = sparse_attn_mask.shape[-1]
443
+ total_causal_size = ((1 + downsampled_len) * downsampled_len / 2) * sparse_attn_mask.shape[0] * sparse_attn_mask.shape[1]
444
+ if self.profile_file is not None:
445
+ with open(self.profile_file, "a") as f:
446
+ f.write(f"{hidden_states.shape[1]}: {sparse_attn_mask.sum().item() / total_causal_size}\n")
447
+
448
+ else:
449
+ raise NotImplementedError("The sparsity method is not implemented")
450
+
451
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
452
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
453
+
454
+ query_states = query_states.contiguous()
455
+ key_states = key_states.contiguous()
456
+ value_states = value_states.contiguous()
457
+
458
+ mask_loss = 0
459
+ attn_weights = None
460
+ mask_ground_truth = None
461
+
462
+ if self.training:
463
+ # get the block (pooled) mask ground truth
464
+ attn_output, mask_ground_truth = attn_with_pooling(
465
+ query_states,
466
+ key_states,
467
+ value_states,
468
+ True,
469
+ 1.0 / math.sqrt(self.head_dim),
470
+ self.config.seerattn_gate_block_size,
471
+ )
472
+ elif q_len > 1 and q_len == k_len: ## prefill inference
473
+ attn_output = self.attn_func(
474
+ query_states,
475
+ key_states,
476
+ value_states,
477
+ sparse_attn_mask,
478
+ 1.0 / math.sqrt(self.head_dim),
479
+ )
480
+ else:
481
+ causal_mask = attention_mask
482
+ if attention_mask is not None:
483
+ causal_mask = causal_mask[:, :, :, : key_states.shape[-2]]
484
+
485
+ is_causal = True if causal_mask is None and q_len > 1 else False
486
+
487
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
488
+ query_states,
489
+ key_states,
490
+ value_states,
491
+ attn_mask=causal_mask,
492
+ dropout_p=self.attention_dropout if self.training else 0.0,
493
+ is_causal=is_causal,
494
+ )
495
+
496
+
497
+ attn_output = attn_output.transpose(1, 2).contiguous()
498
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
499
+ attn_output = self.o_proj(attn_output)
500
+
501
+
502
+ if self.training:
503
+ # remove the first quarter of the data for training stability
504
+ mask_ground_truth = mask_ground_truth[:, :, mask_ground_truth.shape[2]//4:].to(torch.float32)
505
+ mask_gate_prediction = mask_gate_prediction[:, :, mask_gate_prediction.shape[2]//4:].to(torch.float32)
506
+ mask_gate_prediction = F.log_softmax(mask_gate_prediction, dim=-1)
507
+ mask_loss = self.mask_loss_func(mask_gate_prediction, mask_ground_truth)
508
+
509
+ # In SeerAttention, output_attentions also means output mask_gate_prediction and mask_ground_truth
510
+ if not kwargs.get("output_attentions", False):
511
+ attn_weights = None
512
+ mask_gate_prediction = None
513
+ mask_ground_truth = None
514
+ return attn_output, mask_loss, attn_weights, mask_gate_prediction, mask_ground_truth
515
+
516
+
517
+ class SeerAttnLlamaDecoderLayer(nn.Module):
518
+ def __init__(self, config: SeerAttnLlamaConfig, layer_idx: int):
519
+ super().__init__()
520
+ self.hidden_size = config.hidden_size
521
+ self.self_attn = LlamaSeerAttention(config=config, layer_idx=layer_idx)
522
+
523
+ self.mlp = LlamaMLP(config)
524
+ self.input_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
525
+ self.post_attention_layernorm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
526
+
527
+ def forward(
528
+ self,
529
+ hidden_states: torch.Tensor,
530
+ attention_mask: Optional[torch.Tensor] = None,
531
+ position_ids: Optional[torch.LongTensor] = None,
532
+ past_key_value: Optional[Cache] = None,
533
+ output_attentions: Optional[bool] = False,
534
+ use_cache: Optional[bool] = False,
535
+ cache_position: Optional[torch.LongTensor] = None,
536
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
537
+ block_position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
538
+ block_attention_mask: Optional[torch.Tensor] = None,
539
+ **kwargs,
540
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
541
+ residual = hidden_states
542
+
543
+ hidden_states = self.input_layernorm(hidden_states)
544
+
545
+ # Self Attention
546
+ hidden_states, seerattn_mask_loss, self_attn_weights, mask_gate_prediction, mask_ground_truth = self.self_attn(
547
+ hidden_states=hidden_states,
548
+ attention_mask=attention_mask,
549
+ position_ids=position_ids,
550
+ past_key_value=past_key_value,
551
+ output_attentions=output_attentions,
552
+ use_cache=use_cache,
553
+ cache_position=cache_position,
554
+ position_embeddings=position_embeddings,
555
+ block_position_embeddings=block_position_embeddings,
556
+ block_attention_mask=block_attention_mask,
557
+ **kwargs,
558
+ )
559
+ hidden_states = residual + hidden_states
560
+
561
+ # Fully Connected
562
+ residual = hidden_states
563
+ hidden_states = self.post_attention_layernorm(hidden_states)
564
+ hidden_states = self.mlp(hidden_states)
565
+ hidden_states = residual + hidden_states
566
+
567
+ outputs = (hidden_states, seerattn_mask_loss)
568
+ if output_attentions:
569
+ outputs += (self_attn_weights, mask_gate_prediction, mask_ground_truth)
570
+
571
+ return outputs
572
+
573
+
574
+
575
+ LLAMA_START_DOCSTRING = r"""
576
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
577
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
578
+ etc.)
579
+
580
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
581
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
582
+ and behavior.
583
+
584
+ Parameters:
585
+ config ([`LlamaConfig`]):
586
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
587
+ load the weights associated with the model, only the configuration. Check out the
588
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
589
+ """
590
+
591
+
592
+ @add_start_docstrings(
593
+ "The bare LLaMA Model outputting raw hidden-states without any specific head on top.",
594
+ LLAMA_START_DOCSTRING,
595
+ )
596
+ class SeerAttnLlamaPreTrainedModel(PreTrainedModel):
597
+ config_class = SeerAttnLlamaConfig
598
+ base_model_prefix = "model"
599
+ supports_gradient_checkpointing = True
600
+ _no_split_modules = ["SeerAttnLlamaDecoderLayer"]
601
+ _skip_keys_device_placement = ["past_key_values"]
602
+ _supports_flash_attn_2 = True
603
+ _supports_sdpa = True
604
+ _supports_cache_class = True
605
+ _supports_quantized_cache = True
606
+ _supports_static_cache = True
607
+
608
+ def _init_weights(self, module):
609
+ std = self.config.initializer_range
610
+ if isinstance(module, nn.Linear):
611
+ module.weight.data.normal_(mean=0.0, std=std)
612
+ if module.bias is not None:
613
+ module.bias.data.zero_()
614
+ elif isinstance(module, nn.Embedding):
615
+ module.weight.data.normal_(mean=0.0, std=std)
616
+ if module.padding_idx is not None:
617
+ module.weight.data[module.padding_idx].zero_()
618
+
619
+
620
+
621
+
622
+ LLAMA_INPUTS_DOCSTRING = r"""
623
+ Args:
624
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
625
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
626
+ it.
627
+
628
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
629
+ [`PreTrainedTokenizer.__call__`] for details.
630
+
631
+ [What are input IDs?](../glossary#input-ids)
632
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
633
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
634
+
635
+ - 1 for tokens that are **not masked**,
636
+ - 0 for tokens that are **masked**.
637
+
638
+ [What are attention masks?](../glossary#attention-mask)
639
+
640
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
641
+ [`PreTrainedTokenizer.__call__`] for details.
642
+
643
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
644
+ `past_key_values`).
645
+
646
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
647
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
648
+ information on the default strategy.
649
+
650
+ - 1 indicates the head is **not masked**,
651
+ - 0 indicates the head is **masked**.
652
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
653
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
654
+ config.n_positions - 1]`.
655
+
656
+ [What are position IDs?](../glossary#position-ids)
657
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
658
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
659
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
660
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
661
+
662
+ Two formats are allowed:
663
+ - a [`~cache_utils.Cache`] instance, see our
664
+ [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache);
665
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
666
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
667
+ cache format.
668
+
669
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
670
+ legacy cache format will be returned.
671
+
672
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
673
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
674
+ of shape `(batch_size, sequence_length)`.
675
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
676
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
677
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
678
+ model's internal embedding lookup matrix.
679
+ use_cache (`bool`, *optional*):
680
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
681
+ `past_key_values`).
682
+ output_attentions (`bool`, *optional*):
683
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
684
+ tensors for more detail.
685
+ output_hidden_states (`bool`, *optional*):
686
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
687
+ more detail.
688
+ return_dict (`bool`, *optional*):
689
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
690
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
691
+ Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
692
+ this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
693
+ the complete sequence length.
694
+ """
695
+
696
+
697
+ @add_start_docstrings(
698
+ "The bare LLaMA Model outputting raw hidden-states without any specific head on top.",
699
+ LLAMA_START_DOCSTRING,
700
+ )
701
+ class SeerAttnLlamaModel(SeerAttnLlamaPreTrainedModel):
702
+ """
703
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`SeerAttnLlamaDecoderLayer`]
704
+
705
+ Args:
706
+ config: SeerAttnLlamaConfig
707
+ """
708
+
709
+ def __init__(self, config: SeerAttnLlamaConfig):
710
+ super().__init__(config)
711
+ self.padding_idx = config.pad_token_id
712
+ self.vocab_size = config.vocab_size
713
+
714
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
715
+ self.layers = nn.ModuleList(
716
+ [SeerAttnLlamaDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
717
+ )
718
+ self.norm = LlamaRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
719
+ self.rotary_emb = LlamaRotaryEmbedding(config=config)
720
+
721
+ #Added for seerattn, block rotary embedding
722
+ block_config = copy.deepcopy(config)
723
+ block_config.hidden_size = config.seerattn_gate_hidden_size * config.num_attention_heads
724
+ self.block_rotary_emb = LlamaRotaryEmbedding(config=block_config)
725
+
726
+ self.gradient_checkpointing = False
727
+
728
+ # Initialize weights and apply final processing
729
+ self.post_init()
730
+
731
+ def get_input_embeddings(self):
732
+ return self.embed_tokens
733
+
734
+ def set_input_embeddings(self, value):
735
+ self.embed_tokens = value
736
+
737
+ @add_start_docstrings_to_model_forward(LLAMA_INPUTS_DOCSTRING)
738
+ def forward(
739
+ self,
740
+ input_ids: torch.LongTensor = None,
741
+ attention_mask: Optional[torch.Tensor] = None,
742
+ position_ids: Optional[torch.LongTensor] = None,
743
+ past_key_values: Optional[Cache] = None,
744
+ inputs_embeds: Optional[torch.FloatTensor] = None,
745
+ use_cache: Optional[bool] = None,
746
+ output_attentions: Optional[bool] = None,
747
+ output_hidden_states: Optional[bool] = None,
748
+ return_dict: Optional[bool] = None,
749
+ cache_position: Optional[torch.LongTensor] = None,
750
+ ) -> Union[Tuple, BaseModelOutputWithPastAndSeer]:
751
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
752
+ output_hidden_states = (
753
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
754
+ )
755
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
756
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
757
+
758
+ if (input_ids is None) ^ (inputs_embeds is not None):
759
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
760
+
761
+ if self.gradient_checkpointing and self.training and use_cache:
762
+ logger.warning_once(
763
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
764
+ )
765
+ use_cache = False
766
+
767
+ if inputs_embeds is None:
768
+ inputs_embeds = self.embed_tokens(input_ids)
769
+
770
+ if use_cache and past_key_values is None:
771
+ past_key_values = DynamicCache()
772
+
773
+ if cache_position is None:
774
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
775
+ cache_position = torch.arange(
776
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
777
+ )
778
+
779
+ if position_ids is None:
780
+ position_ids = cache_position.unsqueeze(0)
781
+
782
+ causal_mask = self._update_causal_mask(
783
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
784
+ )
785
+
786
+
787
+ block_attention_mask = self._seerattn_update_causal_mask(
788
+ inputs_embeds, causal_mask,
789
+ )
790
+
791
+ hidden_states = inputs_embeds
792
+
793
+ # create position embeddings to be shared across the decoder layers
794
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
795
+
796
+ #Added for seerattn
797
+ block_position_ids = position_ids[:, 0::self.config.seerattn_gate_block_size] ## downsampled position ids
798
+ block_position_embeddings = self.block_rotary_emb(hidden_states, block_position_ids) # downsampled position embeddings
799
+
800
+
801
+ # decoder layers
802
+ all_hidden_states = () if output_hidden_states else None
803
+ all_self_attns = () if output_attentions else None
804
+ all_mask_gate_predictions = () if output_attentions else None
805
+ all_mask_ground_truths = () if output_attentions else None
806
+
807
+ # added for seerattn
808
+ total_mask_loss = 0.0
809
+
810
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
811
+ if output_hidden_states:
812
+ all_hidden_states += (hidden_states,)
813
+
814
+ if self.gradient_checkpointing and self.training:
815
+ layer_outputs = self._gradient_checkpointing_func(
816
+ decoder_layer.__call__,
817
+ hidden_states,
818
+ causal_mask,
819
+ position_ids,
820
+ past_key_values,
821
+ output_attentions,
822
+ use_cache,
823
+ cache_position,
824
+ position_embeddings,
825
+ block_position_embeddings,
826
+ block_attention_mask,
827
+ )
828
+ else:
829
+ layer_outputs = decoder_layer(
830
+ hidden_states,
831
+ attention_mask=causal_mask,
832
+ position_ids=position_ids,
833
+ past_key_value=past_key_values,
834
+ output_attentions=output_attentions,
835
+ use_cache=use_cache,
836
+ cache_position=cache_position,
837
+ position_embeddings=position_embeddings,
838
+ block_position_embeddings=block_position_embeddings,
839
+ block_attention_mask=block_attention_mask,
840
+ )
841
+
842
+ hidden_states = layer_outputs[0]
843
+
844
+ mask_loss = layer_outputs[1]
845
+ total_mask_loss += mask_loss
846
+
847
+ if output_attentions:
848
+ all_self_attns += (layer_outputs[2],)
849
+ all_mask_gate_predictions += (layer_outputs[3],)
850
+ all_mask_ground_truths += (layer_outputs[4],)
851
+
852
+ hidden_states = self.norm(hidden_states)
853
+
854
+ # add hidden states from the last decoder layer
855
+ if output_hidden_states:
856
+ all_hidden_states += (hidden_states,)
857
+
858
+ output = BaseModelOutputWithPastAndSeer(
859
+ last_hidden_state=hidden_states,
860
+ past_key_values=past_key_values if use_cache else None,
861
+ hidden_states=all_hidden_states,
862
+ attentions=all_self_attns,
863
+ mask_gate_predictions=all_mask_gate_predictions,
864
+ mask_ground_truths=all_mask_ground_truths,
865
+ mask_loss=total_mask_loss,
866
+ )
867
+ return output if return_dict else output.to_tuple()
868
+
869
+ def _update_causal_mask(
870
+ self,
871
+ attention_mask: torch.Tensor,
872
+ input_tensor: torch.Tensor,
873
+ cache_position: torch.Tensor,
874
+ past_key_values: Cache,
875
+ output_attentions: bool,
876
+ ):
877
+ if self.config._attn_implementation == "flash_attention_2":
878
+ if attention_mask is not None and (attention_mask == 0.0).any():
879
+ return attention_mask
880
+ return None
881
+
882
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
883
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
884
+ # to infer the attention mask.
885
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
886
+ using_static_cache = isinstance(past_key_values, StaticCache)
887
+
888
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
889
+ if self.config._attn_implementation == "sdpa" and not using_static_cache and not output_attentions:
890
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
891
+ attention_mask,
892
+ inputs_embeds=input_tensor,
893
+ past_key_values_length=past_seen_tokens,
894
+ is_training=self.training,
895
+ ):
896
+ return None
897
+
898
+ dtype, device = input_tensor.dtype, input_tensor.device
899
+ sequence_length = input_tensor.shape[1]
900
+ if using_static_cache:
901
+ target_length = past_key_values.get_max_cache_shape()
902
+ else:
903
+ target_length = (
904
+ attention_mask.shape[-1]
905
+ if isinstance(attention_mask, torch.Tensor)
906
+ else past_seen_tokens + sequence_length + 1
907
+ )
908
+
909
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
910
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
911
+ attention_mask,
912
+ sequence_length=sequence_length,
913
+ target_length=target_length,
914
+ dtype=dtype,
915
+ device=device,
916
+ cache_position=cache_position,
917
+ batch_size=input_tensor.shape[0],
918
+ )
919
+
920
+ if (
921
+ self.config._attn_implementation == "sdpa"
922
+ and attention_mask is not None
923
+ and attention_mask.device.type == "cuda"
924
+ and not output_attentions
925
+ ):
926
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
927
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
928
+ # Details: https://github.com/pytorch/pytorch/issues/110213
929
+ min_dtype = torch.finfo(dtype).min
930
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
931
+
932
+ return causal_mask
933
+
934
+ def _seerattn_update_causal_mask(
935
+ self,
936
+ input_tensor: torch.Tensor,
937
+ attention_mask: torch.Tensor,
938
+ ):
939
+ """
940
+ Currently our kernel only supports causal masking, which does not cover the cases when batching inputs with attention masks.
941
+ """
942
+
943
+ def gen_attn_mask(seq_len):
944
+ attention_mask = torch.full((seq_len, seq_len), -1e20)
945
+ attention_mask = torch.triu(attention_mask, diagonal=1)
946
+ return attention_mask
947
+
948
+ def gen_attn_mask_bool(seq_len):
949
+ attention_mask = torch.full((seq_len, seq_len), True, dtype=torch.bool)
950
+ attention_mask.triu_(diagonal=1)
951
+ attention_mask.bitwise_not_()
952
+ return attention_mask
953
+
954
+ if attention_mask is not None:
955
+ gate_mask = torch.nn.functional.max_pool2d(attention_mask, (self.config.seerattn_gate_block_size, self.config.seerattn_gate_block_size), stride=(self.config.seerattn_gate_block_size, self.config.seerattn_gate_block_size), ceil_mode=True)
956
+ else:
957
+ downsample_len = math.ceil(input_tensor.shape[1] / self.config.seerattn_gate_block_size)
958
+ gate_mask = gen_attn_mask(downsample_len).to(device=input_tensor.device)
959
+ return gate_mask
960
+
961
+ @staticmethod
962
+ def _prepare_4d_causal_attention_mask_with_cache_position(
963
+ attention_mask: torch.Tensor,
964
+ sequence_length: int,
965
+ target_length: int,
966
+ dtype: torch.dtype,
967
+ device: torch.device,
968
+ cache_position: torch.Tensor,
969
+ batch_size: int,
970
+ **kwargs,
971
+ ):
972
+ """
973
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
974
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
975
+
976
+ Args:
977
+ attention_mask (`torch.Tensor`):
978
+ A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape
979
+ `(batch_size, 1, query_length, key_value_length)`.
980
+ sequence_length (`int`):
981
+ The sequence length being processed.
982
+ target_length (`int`):
983
+ The target length: when generating with static cache, the mask should be as long as the static cache,
984
+ to account for the 0 padding, the part of the cache that is not filled yet.
985
+ dtype (`torch.dtype`):
986
+ The dtype to use for the 4D attention mask.
987
+ device (`torch.device`):
988
+ The device to plcae the 4D attention mask on.
989
+ cache_position (`torch.Tensor`):
990
+ Indices depicting the position of the input sequence tokens in the sequence.
991
+ batch_size (`torch.Tensor`):
992
+ Batch size.
993
+ """
994
+ if attention_mask is not None and attention_mask.dim() == 4:
995
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
996
+ causal_mask = attention_mask
997
+ else:
998
+ min_dtype = torch.finfo(dtype).min
999
+ causal_mask = torch.full(
1000
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
1001
+ )
1002
+ if sequence_length != 1:
1003
+ causal_mask = torch.triu(causal_mask, diagonal=1)
1004
+ causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
1005
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
1006
+ if attention_mask is not None:
1007
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
1008
+ mask_length = attention_mask.shape[-1]
1009
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :]
1010
+ padding_mask = padding_mask == 0
1011
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
1012
+ padding_mask, min_dtype
1013
+ )
1014
+
1015
+ return causal_mask
1016
+
1017
+
1018
+ class SeerAttnLlamaForCausalLM(SeerAttnLlamaPreTrainedModel, GenerationMixin):
1019
+ _tied_weights_keys = ["lm_head.weight"]
1020
+ _tp_plan = {"lm_head": "colwise_rep"}
1021
+
1022
+ def __init__(self, config):
1023
+ super().__init__(config)
1024
+ self.model = SeerAttnLlamaModel(config)
1025
+ self.vocab_size = config.vocab_size
1026
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1027
+
1028
+ # Initialize weights and apply final processing
1029
+ self.post_init()
1030
+
1031
+ def get_input_embeddings(self):
1032
+ return self.model.embed_tokens
1033
+
1034
+ def set_input_embeddings(self, value):
1035
+ self.model.embed_tokens = value
1036
+
1037
+ def get_output_embeddings(self):
1038
+ return self.lm_head
1039
+
1040
+ def set_output_embeddings(self, new_embeddings):
1041
+ self.lm_head = new_embeddings
1042
+
1043
+ def set_decoder(self, decoder):
1044
+ self.model = decoder
1045
+
1046
+ def get_decoder(self):
1047
+ return self.model
1048
+
1049
+ #@add_start_docstrings_to_model_forward(LLAMA_INPUTS_DOCSTRING)
1050
+ #@replace_return_docstrings(output_type=CausalLMOutputWithPastAndSeer, config_class=_CONFIG_FOR_DOC)
1051
+ def forward(
1052
+ self,
1053
+ input_ids: torch.LongTensor = None,
1054
+ attention_mask: Optional[torch.Tensor] = None,
1055
+ position_ids: Optional[torch.LongTensor] = None,
1056
+ past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
1057
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1058
+ labels: Optional[torch.LongTensor] = None,
1059
+ use_cache: Optional[bool] = None,
1060
+ output_attentions: Optional[bool] = None,
1061
+ output_hidden_states: Optional[bool] = None,
1062
+ return_dict: Optional[bool] = None,
1063
+ cache_position: Optional[torch.LongTensor] = None,
1064
+ num_logits_to_keep: int = 1,
1065
+ **kwargs,
1066
+ ) -> Union[Tuple, CausalLMOutputWithPastAndSeer]:
1067
+ r"""
1068
+ Args:
1069
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1070
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1071
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1072
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1073
+
1074
+ num_logits_to_keep (`int`, *optional*):
1075
+ Calculate logits for the last `num_logits_to_keep` tokens. If `0`, calculate logits for all
1076
+ `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
1077
+ token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
1078
+
1079
+ Returns:
1080
+
1081
+ Example:
1082
+
1083
+ ```python
1084
+ >>> from transformers import AutoTokenizer, SeerAttnLlamaForCausalLM
1085
+
1086
+ >>> model = SeerAttnLlamaForCausalLM.from_pretrained("meta-llama/Llama-2-7b-hf")
1087
+ >>> tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-2-7b-hf")
1088
+
1089
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1090
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1091
+
1092
+ >>> # Generate
1093
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1094
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1095
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1096
+ ```"""
1097
+
1098
+ if attention_mask!= None and torch.any(attention_mask == False):
1099
+ raise ValueError("Batched inference with Attention mask not supported yet")
1100
+
1101
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1102
+ output_hidden_states = (
1103
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1104
+ )
1105
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1106
+
1107
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1108
+ outputs = self.model(
1109
+ input_ids=input_ids,
1110
+ attention_mask=attention_mask,
1111
+ position_ids=position_ids,
1112
+ past_key_values=past_key_values,
1113
+ inputs_embeds=inputs_embeds,
1114
+ use_cache=use_cache,
1115
+ output_attentions=output_attentions,
1116
+ output_hidden_states=output_hidden_states,
1117
+ return_dict=return_dict,
1118
+ cache_position=cache_position,
1119
+ **kwargs,
1120
+ )
1121
+ hidden_states = outputs[0]
1122
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
1123
+ logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :])
1124
+
1125
+ loss = None
1126
+ if labels is not None:
1127
+ loss_fct = torch.nn.CrossEntropyLoss(reduction='sum')
1128
+ valid_seq_len = input_ids.shape[-1] - 1
1129
+ valid_seq_len_slide_win = torch.sum(labels[:, 1:] >= 0).item()
1130
+ loss = 0.0
1131
+ for start_idx in range(0, valid_seq_len, 16384):
1132
+ end_idx = min(start_idx + 16384, valid_seq_len)
1133
+ shift_logits = self.lm_head(hidden_states[..., start_idx:end_idx, :]).float()
1134
+ shift_labels = labels[..., start_idx + 1:end_idx + 1].contiguous()
1135
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1136
+ shift_labels = shift_labels.view(-1)
1137
+ shift_labels = shift_labels.to(shift_logits.device)
1138
+ loss += loss_fct(shift_logits, shift_labels)
1139
+ loss /= valid_seq_len_slide_win
1140
+ #print("loss:", loss)
1141
+ if not return_dict:
1142
+ output = (logits,) + outputs[1:]
1143
+ return (loss,) + output if loss is not None else output
1144
+
1145
+ return CausalLMOutputWithPastAndSeer(
1146
+ loss=loss,
1147
+ logits=logits,
1148
+ past_key_values=outputs.past_key_values,
1149
+ hidden_states=outputs.hidden_states,
1150
+ attentions=outputs.attentions,
1151
+ mask_gate_predictions=outputs.mask_gate_predictions,
1152
+ mask_ground_truths=outputs.mask_ground_truths,
1153
+ mask_loss=outputs.mask_loss,
1154
+ )
1155
+
1156
+ def prepare_inputs_for_generation(
1157
+ self,
1158
+ input_ids,
1159
+ past_key_values=None,
1160
+ attention_mask=None,
1161
+ inputs_embeds=None,
1162
+ cache_position=None,
1163
+ position_ids=None,
1164
+ use_cache=True,
1165
+ **kwargs,
1166
+ ):
1167
+ # If we have cache: let's slice `input_ids` through `cache_position`, to keep only the unprocessed tokens
1168
+ # Exception 1: when passing input_embeds, input_ids may be missing entries
1169
+ # Exception 2: some generation methods do special slicing of input_ids, so we don't need to do it here
1170
+ if past_key_values is not None:
1171
+ if inputs_embeds is not None: # Exception 1
1172
+ input_ids = input_ids[:, -cache_position.shape[0] :]
1173
+ elif input_ids.shape[1] != cache_position.shape[0]: # Default case (the "else", a no op, is Exception 2)
1174
+ input_ids = input_ids[:, cache_position]
1175
+
1176
+ if attention_mask is not None and position_ids is None:
1177
+ # create position_ids on the fly for batch generation
1178
+ position_ids = attention_mask.long().cumsum(-1) - 1
1179
+ position_ids.masked_fill_(attention_mask == 0, 1)
1180
+ if past_key_values:
1181
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1182
+
1183
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1184
+ if inputs_embeds is not None and cache_position[0] == 0:
1185
+ model_inputs = {"inputs_embeds": inputs_embeds}
1186
+ else:
1187
+ model_inputs = {"input_ids": input_ids.contiguous()} # `contiguous()` needed for compilation use cases
1188
+
1189
+ model_inputs.update(
1190
+ {
1191
+ "position_ids": position_ids,
1192
+ "cache_position": cache_position,
1193
+ "past_key_values": past_key_values,
1194
+ "use_cache": use_cache,
1195
+ "attention_mask": attention_mask,
1196
+ }
1197
+ )
1198
+ return model_inputs
1199
+
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|begin_of_text|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|eot_id|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,2081 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "128000": {
4
+ "content": "<|begin_of_text|>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "128001": {
12
+ "content": "<|end_of_text|>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "128002": {
20
+ "content": "<|reserved_special_token_0|>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "128003": {
28
+ "content": "<|reserved_special_token_1|>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "128004": {
36
+ "content": "<|finetune_right_pad_id|>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "128005": {
44
+ "content": "<|reserved_special_token_2|>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "128006": {
52
+ "content": "<|start_header_id|>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "128007": {
60
+ "content": "<|end_header_id|>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ },
67
+ "128008": {
68
+ "content": "<|eom_id|>",
69
+ "lstrip": false,
70
+ "normalized": false,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": true
74
+ },
75
+ "128009": {
76
+ "content": "<|eot_id|>",
77
+ "lstrip": false,
78
+ "normalized": false,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": true
82
+ },
83
+ "128010": {
84
+ "content": "<|python_tag|>",
85
+ "lstrip": false,
86
+ "normalized": false,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": true
90
+ },
91
+ "128011": {
92
+ "content": "<|reserved_special_token_3|>",
93
+ "lstrip": false,
94
+ "normalized": false,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": true
98
+ },
99
+ "128012": {
100
+ "content": "<|reserved_special_token_4|>",
101
+ "lstrip": false,
102
+ "normalized": false,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": true
106
+ },
107
+ "128013": {
108
+ "content": "<|reserved_special_token_5|>",
109
+ "lstrip": false,
110
+ "normalized": false,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": true
114
+ },
115
+ "128014": {
116
+ "content": "<|reserved_special_token_6|>",
117
+ "lstrip": false,
118
+ "normalized": false,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": true
122
+ },
123
+ "128015": {
124
+ "content": "<|reserved_special_token_7|>",
125
+ "lstrip": false,
126
+ "normalized": false,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": true
130
+ },
131
+ "128016": {
132
+ "content": "<|reserved_special_token_8|>",
133
+ "lstrip": false,
134
+ "normalized": false,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": true
138
+ },
139
+ "128017": {
140
+ "content": "<|reserved_special_token_9|>",
141
+ "lstrip": false,
142
+ "normalized": false,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": true
146
+ },
147
+ "128018": {
148
+ "content": "<|reserved_special_token_10|>",
149
+ "lstrip": false,
150
+ "normalized": false,
151
+ "rstrip": false,
152
+ "single_word": false,
153
+ "special": true
154
+ },
155
+ "128019": {
156
+ "content": "<|reserved_special_token_11|>",
157
+ "lstrip": false,
158
+ "normalized": false,
159
+ "rstrip": false,
160
+ "single_word": false,
161
+ "special": true
162
+ },
163
+ "128020": {
164
+ "content": "<|reserved_special_token_12|>",
165
+ "lstrip": false,
166
+ "normalized": false,
167
+ "rstrip": false,
168
+ "single_word": false,
169
+ "special": true
170
+ },
171
+ "128021": {
172
+ "content": "<|reserved_special_token_13|>",
173
+ "lstrip": false,
174
+ "normalized": false,
175
+ "rstrip": false,
176
+ "single_word": false,
177
+ "special": true
178
+ },
179
+ "128022": {
180
+ "content": "<|reserved_special_token_14|>",
181
+ "lstrip": false,
182
+ "normalized": false,
183
+ "rstrip": false,
184
+ "single_word": false,
185
+ "special": true
186
+ },
187
+ "128023": {
188
+ "content": "<|reserved_special_token_15|>",
189
+ "lstrip": false,
190
+ "normalized": false,
191
+ "rstrip": false,
192
+ "single_word": false,
193
+ "special": true
194
+ },
195
+ "128024": {
196
+ "content": "<|reserved_special_token_16|>",
197
+ "lstrip": false,
198
+ "normalized": false,
199
+ "rstrip": false,
200
+ "single_word": false,
201
+ "special": true
202
+ },
203
+ "128025": {
204
+ "content": "<|reserved_special_token_17|>",
205
+ "lstrip": false,
206
+ "normalized": false,
207
+ "rstrip": false,
208
+ "single_word": false,
209
+ "special": true
210
+ },
211
+ "128026": {
212
+ "content": "<|reserved_special_token_18|>",
213
+ "lstrip": false,
214
+ "normalized": false,
215
+ "rstrip": false,
216
+ "single_word": false,
217
+ "special": true
218
+ },
219
+ "128027": {
220
+ "content": "<|reserved_special_token_19|>",
221
+ "lstrip": false,
222
+ "normalized": false,
223
+ "rstrip": false,
224
+ "single_word": false,
225
+ "special": true
226
+ },
227
+ "128028": {
228
+ "content": "<|reserved_special_token_20|>",
229
+ "lstrip": false,
230
+ "normalized": false,
231
+ "rstrip": false,
232
+ "single_word": false,
233
+ "special": true
234
+ },
235
+ "128029": {
236
+ "content": "<|reserved_special_token_21|>",
237
+ "lstrip": false,
238
+ "normalized": false,
239
+ "rstrip": false,
240
+ "single_word": false,
241
+ "special": true
242
+ },
243
+ "128030": {
244
+ "content": "<|reserved_special_token_22|>",
245
+ "lstrip": false,
246
+ "normalized": false,
247
+ "rstrip": false,
248
+ "single_word": false,
249
+ "special": true
250
+ },
251
+ "128031": {
252
+ "content": "<|reserved_special_token_23|>",
253
+ "lstrip": false,
254
+ "normalized": false,
255
+ "rstrip": false,
256
+ "single_word": false,
257
+ "special": true
258
+ },
259
+ "128032": {
260
+ "content": "<|reserved_special_token_24|>",
261
+ "lstrip": false,
262
+ "normalized": false,
263
+ "rstrip": false,
264
+ "single_word": false,
265
+ "special": true
266
+ },
267
+ "128033": {
268
+ "content": "<|reserved_special_token_25|>",
269
+ "lstrip": false,
270
+ "normalized": false,
271
+ "rstrip": false,
272
+ "single_word": false,
273
+ "special": true
274
+ },
275
+ "128034": {
276
+ "content": "<|reserved_special_token_26|>",
277
+ "lstrip": false,
278
+ "normalized": false,
279
+ "rstrip": false,
280
+ "single_word": false,
281
+ "special": true
282
+ },
283
+ "128035": {
284
+ "content": "<|reserved_special_token_27|>",
285
+ "lstrip": false,
286
+ "normalized": false,
287
+ "rstrip": false,
288
+ "single_word": false,
289
+ "special": true
290
+ },
291
+ "128036": {
292
+ "content": "<|reserved_special_token_28|>",
293
+ "lstrip": false,
294
+ "normalized": false,
295
+ "rstrip": false,
296
+ "single_word": false,
297
+ "special": true
298
+ },
299
+ "128037": {
300
+ "content": "<|reserved_special_token_29|>",
301
+ "lstrip": false,
302
+ "normalized": false,
303
+ "rstrip": false,
304
+ "single_word": false,
305
+ "special": true
306
+ },
307
+ "128038": {
308
+ "content": "<|reserved_special_token_30|>",
309
+ "lstrip": false,
310
+ "normalized": false,
311
+ "rstrip": false,
312
+ "single_word": false,
313
+ "special": true
314
+ },
315
+ "128039": {
316
+ "content": "<|reserved_special_token_31|>",
317
+ "lstrip": false,
318
+ "normalized": false,
319
+ "rstrip": false,
320
+ "single_word": false,
321
+ "special": true
322
+ },
323
+ "128040": {
324
+ "content": "<|reserved_special_token_32|>",
325
+ "lstrip": false,
326
+ "normalized": false,
327
+ "rstrip": false,
328
+ "single_word": false,
329
+ "special": true
330
+ },
331
+ "128041": {
332
+ "content": "<|reserved_special_token_33|>",
333
+ "lstrip": false,
334
+ "normalized": false,
335
+ "rstrip": false,
336
+ "single_word": false,
337
+ "special": true
338
+ },
339
+ "128042": {
340
+ "content": "<|reserved_special_token_34|>",
341
+ "lstrip": false,
342
+ "normalized": false,
343
+ "rstrip": false,
344
+ "single_word": false,
345
+ "special": true
346
+ },
347
+ "128043": {
348
+ "content": "<|reserved_special_token_35|>",
349
+ "lstrip": false,
350
+ "normalized": false,
351
+ "rstrip": false,
352
+ "single_word": false,
353
+ "special": true
354
+ },
355
+ "128044": {
356
+ "content": "<|reserved_special_token_36|>",
357
+ "lstrip": false,
358
+ "normalized": false,
359
+ "rstrip": false,
360
+ "single_word": false,
361
+ "special": true
362
+ },
363
+ "128045": {
364
+ "content": "<|reserved_special_token_37|>",
365
+ "lstrip": false,
366
+ "normalized": false,
367
+ "rstrip": false,
368
+ "single_word": false,
369
+ "special": true
370
+ },
371
+ "128046": {
372
+ "content": "<|reserved_special_token_38|>",
373
+ "lstrip": false,
374
+ "normalized": false,
375
+ "rstrip": false,
376
+ "single_word": false,
377
+ "special": true
378
+ },
379
+ "128047": {
380
+ "content": "<|reserved_special_token_39|>",
381
+ "lstrip": false,
382
+ "normalized": false,
383
+ "rstrip": false,
384
+ "single_word": false,
385
+ "special": true
386
+ },
387
+ "128048": {
388
+ "content": "<|reserved_special_token_40|>",
389
+ "lstrip": false,
390
+ "normalized": false,
391
+ "rstrip": false,
392
+ "single_word": false,
393
+ "special": true
394
+ },
395
+ "128049": {
396
+ "content": "<|reserved_special_token_41|>",
397
+ "lstrip": false,
398
+ "normalized": false,
399
+ "rstrip": false,
400
+ "single_word": false,
401
+ "special": true
402
+ },
403
+ "128050": {
404
+ "content": "<|reserved_special_token_42|>",
405
+ "lstrip": false,
406
+ "normalized": false,
407
+ "rstrip": false,
408
+ "single_word": false,
409
+ "special": true
410
+ },
411
+ "128051": {
412
+ "content": "<|reserved_special_token_43|>",
413
+ "lstrip": false,
414
+ "normalized": false,
415
+ "rstrip": false,
416
+ "single_word": false,
417
+ "special": true
418
+ },
419
+ "128052": {
420
+ "content": "<|reserved_special_token_44|>",
421
+ "lstrip": false,
422
+ "normalized": false,
423
+ "rstrip": false,
424
+ "single_word": false,
425
+ "special": true
426
+ },
427
+ "128053": {
428
+ "content": "<|reserved_special_token_45|>",
429
+ "lstrip": false,
430
+ "normalized": false,
431
+ "rstrip": false,
432
+ "single_word": false,
433
+ "special": true
434
+ },
435
+ "128054": {
436
+ "content": "<|reserved_special_token_46|>",
437
+ "lstrip": false,
438
+ "normalized": false,
439
+ "rstrip": false,
440
+ "single_word": false,
441
+ "special": true
442
+ },
443
+ "128055": {
444
+ "content": "<|reserved_special_token_47|>",
445
+ "lstrip": false,
446
+ "normalized": false,
447
+ "rstrip": false,
448
+ "single_word": false,
449
+ "special": true
450
+ },
451
+ "128056": {
452
+ "content": "<|reserved_special_token_48|>",
453
+ "lstrip": false,
454
+ "normalized": false,
455
+ "rstrip": false,
456
+ "single_word": false,
457
+ "special": true
458
+ },
459
+ "128057": {
460
+ "content": "<|reserved_special_token_49|>",
461
+ "lstrip": false,
462
+ "normalized": false,
463
+ "rstrip": false,
464
+ "single_word": false,
465
+ "special": true
466
+ },
467
+ "128058": {
468
+ "content": "<|reserved_special_token_50|>",
469
+ "lstrip": false,
470
+ "normalized": false,
471
+ "rstrip": false,
472
+ "single_word": false,
473
+ "special": true
474
+ },
475
+ "128059": {
476
+ "content": "<|reserved_special_token_51|>",
477
+ "lstrip": false,
478
+ "normalized": false,
479
+ "rstrip": false,
480
+ "single_word": false,
481
+ "special": true
482
+ },
483
+ "128060": {
484
+ "content": "<|reserved_special_token_52|>",
485
+ "lstrip": false,
486
+ "normalized": false,
487
+ "rstrip": false,
488
+ "single_word": false,
489
+ "special": true
490
+ },
491
+ "128061": {
492
+ "content": "<|reserved_special_token_53|>",
493
+ "lstrip": false,
494
+ "normalized": false,
495
+ "rstrip": false,
496
+ "single_word": false,
497
+ "special": true
498
+ },
499
+ "128062": {
500
+ "content": "<|reserved_special_token_54|>",
501
+ "lstrip": false,
502
+ "normalized": false,
503
+ "rstrip": false,
504
+ "single_word": false,
505
+ "special": true
506
+ },
507
+ "128063": {
508
+ "content": "<|reserved_special_token_55|>",
509
+ "lstrip": false,
510
+ "normalized": false,
511
+ "rstrip": false,
512
+ "single_word": false,
513
+ "special": true
514
+ },
515
+ "128064": {
516
+ "content": "<|reserved_special_token_56|>",
517
+ "lstrip": false,
518
+ "normalized": false,
519
+ "rstrip": false,
520
+ "single_word": false,
521
+ "special": true
522
+ },
523
+ "128065": {
524
+ "content": "<|reserved_special_token_57|>",
525
+ "lstrip": false,
526
+ "normalized": false,
527
+ "rstrip": false,
528
+ "single_word": false,
529
+ "special": true
530
+ },
531
+ "128066": {
532
+ "content": "<|reserved_special_token_58|>",
533
+ "lstrip": false,
534
+ "normalized": false,
535
+ "rstrip": false,
536
+ "single_word": false,
537
+ "special": true
538
+ },
539
+ "128067": {
540
+ "content": "<|reserved_special_token_59|>",
541
+ "lstrip": false,
542
+ "normalized": false,
543
+ "rstrip": false,
544
+ "single_word": false,
545
+ "special": true
546
+ },
547
+ "128068": {
548
+ "content": "<|reserved_special_token_60|>",
549
+ "lstrip": false,
550
+ "normalized": false,
551
+ "rstrip": false,
552
+ "single_word": false,
553
+ "special": true
554
+ },
555
+ "128069": {
556
+ "content": "<|reserved_special_token_61|>",
557
+ "lstrip": false,
558
+ "normalized": false,
559
+ "rstrip": false,
560
+ "single_word": false,
561
+ "special": true
562
+ },
563
+ "128070": {
564
+ "content": "<|reserved_special_token_62|>",
565
+ "lstrip": false,
566
+ "normalized": false,
567
+ "rstrip": false,
568
+ "single_word": false,
569
+ "special": true
570
+ },
571
+ "128071": {
572
+ "content": "<|reserved_special_token_63|>",
573
+ "lstrip": false,
574
+ "normalized": false,
575
+ "rstrip": false,
576
+ "single_word": false,
577
+ "special": true
578
+ },
579
+ "128072": {
580
+ "content": "<|reserved_special_token_64|>",
581
+ "lstrip": false,
582
+ "normalized": false,
583
+ "rstrip": false,
584
+ "single_word": false,
585
+ "special": true
586
+ },
587
+ "128073": {
588
+ "content": "<|reserved_special_token_65|>",
589
+ "lstrip": false,
590
+ "normalized": false,
591
+ "rstrip": false,
592
+ "single_word": false,
593
+ "special": true
594
+ },
595
+ "128074": {
596
+ "content": "<|reserved_special_token_66|>",
597
+ "lstrip": false,
598
+ "normalized": false,
599
+ "rstrip": false,
600
+ "single_word": false,
601
+ "special": true
602
+ },
603
+ "128075": {
604
+ "content": "<|reserved_special_token_67|>",
605
+ "lstrip": false,
606
+ "normalized": false,
607
+ "rstrip": false,
608
+ "single_word": false,
609
+ "special": true
610
+ },
611
+ "128076": {
612
+ "content": "<|reserved_special_token_68|>",
613
+ "lstrip": false,
614
+ "normalized": false,
615
+ "rstrip": false,
616
+ "single_word": false,
617
+ "special": true
618
+ },
619
+ "128077": {
620
+ "content": "<|reserved_special_token_69|>",
621
+ "lstrip": false,
622
+ "normalized": false,
623
+ "rstrip": false,
624
+ "single_word": false,
625
+ "special": true
626
+ },
627
+ "128078": {
628
+ "content": "<|reserved_special_token_70|>",
629
+ "lstrip": false,
630
+ "normalized": false,
631
+ "rstrip": false,
632
+ "single_word": false,
633
+ "special": true
634
+ },
635
+ "128079": {
636
+ "content": "<|reserved_special_token_71|>",
637
+ "lstrip": false,
638
+ "normalized": false,
639
+ "rstrip": false,
640
+ "single_word": false,
641
+ "special": true
642
+ },
643
+ "128080": {
644
+ "content": "<|reserved_special_token_72|>",
645
+ "lstrip": false,
646
+ "normalized": false,
647
+ "rstrip": false,
648
+ "single_word": false,
649
+ "special": true
650
+ },
651
+ "128081": {
652
+ "content": "<|reserved_special_token_73|>",
653
+ "lstrip": false,
654
+ "normalized": false,
655
+ "rstrip": false,
656
+ "single_word": false,
657
+ "special": true
658
+ },
659
+ "128082": {
660
+ "content": "<|reserved_special_token_74|>",
661
+ "lstrip": false,
662
+ "normalized": false,
663
+ "rstrip": false,
664
+ "single_word": false,
665
+ "special": true
666
+ },
667
+ "128083": {
668
+ "content": "<|reserved_special_token_75|>",
669
+ "lstrip": false,
670
+ "normalized": false,
671
+ "rstrip": false,
672
+ "single_word": false,
673
+ "special": true
674
+ },
675
+ "128084": {
676
+ "content": "<|reserved_special_token_76|>",
677
+ "lstrip": false,
678
+ "normalized": false,
679
+ "rstrip": false,
680
+ "single_word": false,
681
+ "special": true
682
+ },
683
+ "128085": {
684
+ "content": "<|reserved_special_token_77|>",
685
+ "lstrip": false,
686
+ "normalized": false,
687
+ "rstrip": false,
688
+ "single_word": false,
689
+ "special": true
690
+ },
691
+ "128086": {
692
+ "content": "<|reserved_special_token_78|>",
693
+ "lstrip": false,
694
+ "normalized": false,
695
+ "rstrip": false,
696
+ "single_word": false,
697
+ "special": true
698
+ },
699
+ "128087": {
700
+ "content": "<|reserved_special_token_79|>",
701
+ "lstrip": false,
702
+ "normalized": false,
703
+ "rstrip": false,
704
+ "single_word": false,
705
+ "special": true
706
+ },
707
+ "128088": {
708
+ "content": "<|reserved_special_token_80|>",
709
+ "lstrip": false,
710
+ "normalized": false,
711
+ "rstrip": false,
712
+ "single_word": false,
713
+ "special": true
714
+ },
715
+ "128089": {
716
+ "content": "<|reserved_special_token_81|>",
717
+ "lstrip": false,
718
+ "normalized": false,
719
+ "rstrip": false,
720
+ "single_word": false,
721
+ "special": true
722
+ },
723
+ "128090": {
724
+ "content": "<|reserved_special_token_82|>",
725
+ "lstrip": false,
726
+ "normalized": false,
727
+ "rstrip": false,
728
+ "single_word": false,
729
+ "special": true
730
+ },
731
+ "128091": {
732
+ "content": "<|reserved_special_token_83|>",
733
+ "lstrip": false,
734
+ "normalized": false,
735
+ "rstrip": false,
736
+ "single_word": false,
737
+ "special": true
738
+ },
739
+ "128092": {
740
+ "content": "<|reserved_special_token_84|>",
741
+ "lstrip": false,
742
+ "normalized": false,
743
+ "rstrip": false,
744
+ "single_word": false,
745
+ "special": true
746
+ },
747
+ "128093": {
748
+ "content": "<|reserved_special_token_85|>",
749
+ "lstrip": false,
750
+ "normalized": false,
751
+ "rstrip": false,
752
+ "single_word": false,
753
+ "special": true
754
+ },
755
+ "128094": {
756
+ "content": "<|reserved_special_token_86|>",
757
+ "lstrip": false,
758
+ "normalized": false,
759
+ "rstrip": false,
760
+ "single_word": false,
761
+ "special": true
762
+ },
763
+ "128095": {
764
+ "content": "<|reserved_special_token_87|>",
765
+ "lstrip": false,
766
+ "normalized": false,
767
+ "rstrip": false,
768
+ "single_word": false,
769
+ "special": true
770
+ },
771
+ "128096": {
772
+ "content": "<|reserved_special_token_88|>",
773
+ "lstrip": false,
774
+ "normalized": false,
775
+ "rstrip": false,
776
+ "single_word": false,
777
+ "special": true
778
+ },
779
+ "128097": {
780
+ "content": "<|reserved_special_token_89|>",
781
+ "lstrip": false,
782
+ "normalized": false,
783
+ "rstrip": false,
784
+ "single_word": false,
785
+ "special": true
786
+ },
787
+ "128098": {
788
+ "content": "<|reserved_special_token_90|>",
789
+ "lstrip": false,
790
+ "normalized": false,
791
+ "rstrip": false,
792
+ "single_word": false,
793
+ "special": true
794
+ },
795
+ "128099": {
796
+ "content": "<|reserved_special_token_91|>",
797
+ "lstrip": false,
798
+ "normalized": false,
799
+ "rstrip": false,
800
+ "single_word": false,
801
+ "special": true
802
+ },
803
+ "128100": {
804
+ "content": "<|reserved_special_token_92|>",
805
+ "lstrip": false,
806
+ "normalized": false,
807
+ "rstrip": false,
808
+ "single_word": false,
809
+ "special": true
810
+ },
811
+ "128101": {
812
+ "content": "<|reserved_special_token_93|>",
813
+ "lstrip": false,
814
+ "normalized": false,
815
+ "rstrip": false,
816
+ "single_word": false,
817
+ "special": true
818
+ },
819
+ "128102": {
820
+ "content": "<|reserved_special_token_94|>",
821
+ "lstrip": false,
822
+ "normalized": false,
823
+ "rstrip": false,
824
+ "single_word": false,
825
+ "special": true
826
+ },
827
+ "128103": {
828
+ "content": "<|reserved_special_token_95|>",
829
+ "lstrip": false,
830
+ "normalized": false,
831
+ "rstrip": false,
832
+ "single_word": false,
833
+ "special": true
834
+ },
835
+ "128104": {
836
+ "content": "<|reserved_special_token_96|>",
837
+ "lstrip": false,
838
+ "normalized": false,
839
+ "rstrip": false,
840
+ "single_word": false,
841
+ "special": true
842
+ },
843
+ "128105": {
844
+ "content": "<|reserved_special_token_97|>",
845
+ "lstrip": false,
846
+ "normalized": false,
847
+ "rstrip": false,
848
+ "single_word": false,
849
+ "special": true
850
+ },
851
+ "128106": {
852
+ "content": "<|reserved_special_token_98|>",
853
+ "lstrip": false,
854
+ "normalized": false,
855
+ "rstrip": false,
856
+ "single_word": false,
857
+ "special": true
858
+ },
859
+ "128107": {
860
+ "content": "<|reserved_special_token_99|>",
861
+ "lstrip": false,
862
+ "normalized": false,
863
+ "rstrip": false,
864
+ "single_word": false,
865
+ "special": true
866
+ },
867
+ "128108": {
868
+ "content": "<|reserved_special_token_100|>",
869
+ "lstrip": false,
870
+ "normalized": false,
871
+ "rstrip": false,
872
+ "single_word": false,
873
+ "special": true
874
+ },
875
+ "128109": {
876
+ "content": "<|reserved_special_token_101|>",
877
+ "lstrip": false,
878
+ "normalized": false,
879
+ "rstrip": false,
880
+ "single_word": false,
881
+ "special": true
882
+ },
883
+ "128110": {
884
+ "content": "<|reserved_special_token_102|>",
885
+ "lstrip": false,
886
+ "normalized": false,
887
+ "rstrip": false,
888
+ "single_word": false,
889
+ "special": true
890
+ },
891
+ "128111": {
892
+ "content": "<|reserved_special_token_103|>",
893
+ "lstrip": false,
894
+ "normalized": false,
895
+ "rstrip": false,
896
+ "single_word": false,
897
+ "special": true
898
+ },
899
+ "128112": {
900
+ "content": "<|reserved_special_token_104|>",
901
+ "lstrip": false,
902
+ "normalized": false,
903
+ "rstrip": false,
904
+ "single_word": false,
905
+ "special": true
906
+ },
907
+ "128113": {
908
+ "content": "<|reserved_special_token_105|>",
909
+ "lstrip": false,
910
+ "normalized": false,
911
+ "rstrip": false,
912
+ "single_word": false,
913
+ "special": true
914
+ },
915
+ "128114": {
916
+ "content": "<|reserved_special_token_106|>",
917
+ "lstrip": false,
918
+ "normalized": false,
919
+ "rstrip": false,
920
+ "single_word": false,
921
+ "special": true
922
+ },
923
+ "128115": {
924
+ "content": "<|reserved_special_token_107|>",
925
+ "lstrip": false,
926
+ "normalized": false,
927
+ "rstrip": false,
928
+ "single_word": false,
929
+ "special": true
930
+ },
931
+ "128116": {
932
+ "content": "<|reserved_special_token_108|>",
933
+ "lstrip": false,
934
+ "normalized": false,
935
+ "rstrip": false,
936
+ "single_word": false,
937
+ "special": true
938
+ },
939
+ "128117": {
940
+ "content": "<|reserved_special_token_109|>",
941
+ "lstrip": false,
942
+ "normalized": false,
943
+ "rstrip": false,
944
+ "single_word": false,
945
+ "special": true
946
+ },
947
+ "128118": {
948
+ "content": "<|reserved_special_token_110|>",
949
+ "lstrip": false,
950
+ "normalized": false,
951
+ "rstrip": false,
952
+ "single_word": false,
953
+ "special": true
954
+ },
955
+ "128119": {
956
+ "content": "<|reserved_special_token_111|>",
957
+ "lstrip": false,
958
+ "normalized": false,
959
+ "rstrip": false,
960
+ "single_word": false,
961
+ "special": true
962
+ },
963
+ "128120": {
964
+ "content": "<|reserved_special_token_112|>",
965
+ "lstrip": false,
966
+ "normalized": false,
967
+ "rstrip": false,
968
+ "single_word": false,
969
+ "special": true
970
+ },
971
+ "128121": {
972
+ "content": "<|reserved_special_token_113|>",
973
+ "lstrip": false,
974
+ "normalized": false,
975
+ "rstrip": false,
976
+ "single_word": false,
977
+ "special": true
978
+ },
979
+ "128122": {
980
+ "content": "<|reserved_special_token_114|>",
981
+ "lstrip": false,
982
+ "normalized": false,
983
+ "rstrip": false,
984
+ "single_word": false,
985
+ "special": true
986
+ },
987
+ "128123": {
988
+ "content": "<|reserved_special_token_115|>",
989
+ "lstrip": false,
990
+ "normalized": false,
991
+ "rstrip": false,
992
+ "single_word": false,
993
+ "special": true
994
+ },
995
+ "128124": {
996
+ "content": "<|reserved_special_token_116|>",
997
+ "lstrip": false,
998
+ "normalized": false,
999
+ "rstrip": false,
1000
+ "single_word": false,
1001
+ "special": true
1002
+ },
1003
+ "128125": {
1004
+ "content": "<|reserved_special_token_117|>",
1005
+ "lstrip": false,
1006
+ "normalized": false,
1007
+ "rstrip": false,
1008
+ "single_word": false,
1009
+ "special": true
1010
+ },
1011
+ "128126": {
1012
+ "content": "<|reserved_special_token_118|>",
1013
+ "lstrip": false,
1014
+ "normalized": false,
1015
+ "rstrip": false,
1016
+ "single_word": false,
1017
+ "special": true
1018
+ },
1019
+ "128127": {
1020
+ "content": "<|reserved_special_token_119|>",
1021
+ "lstrip": false,
1022
+ "normalized": false,
1023
+ "rstrip": false,
1024
+ "single_word": false,
1025
+ "special": true
1026
+ },
1027
+ "128128": {
1028
+ "content": "<|reserved_special_token_120|>",
1029
+ "lstrip": false,
1030
+ "normalized": false,
1031
+ "rstrip": false,
1032
+ "single_word": false,
1033
+ "special": true
1034
+ },
1035
+ "128129": {
1036
+ "content": "<|reserved_special_token_121|>",
1037
+ "lstrip": false,
1038
+ "normalized": false,
1039
+ "rstrip": false,
1040
+ "single_word": false,
1041
+ "special": true
1042
+ },
1043
+ "128130": {
1044
+ "content": "<|reserved_special_token_122|>",
1045
+ "lstrip": false,
1046
+ "normalized": false,
1047
+ "rstrip": false,
1048
+ "single_word": false,
1049
+ "special": true
1050
+ },
1051
+ "128131": {
1052
+ "content": "<|reserved_special_token_123|>",
1053
+ "lstrip": false,
1054
+ "normalized": false,
1055
+ "rstrip": false,
1056
+ "single_word": false,
1057
+ "special": true
1058
+ },
1059
+ "128132": {
1060
+ "content": "<|reserved_special_token_124|>",
1061
+ "lstrip": false,
1062
+ "normalized": false,
1063
+ "rstrip": false,
1064
+ "single_word": false,
1065
+ "special": true
1066
+ },
1067
+ "128133": {
1068
+ "content": "<|reserved_special_token_125|>",
1069
+ "lstrip": false,
1070
+ "normalized": false,
1071
+ "rstrip": false,
1072
+ "single_word": false,
1073
+ "special": true
1074
+ },
1075
+ "128134": {
1076
+ "content": "<|reserved_special_token_126|>",
1077
+ "lstrip": false,
1078
+ "normalized": false,
1079
+ "rstrip": false,
1080
+ "single_word": false,
1081
+ "special": true
1082
+ },
1083
+ "128135": {
1084
+ "content": "<|reserved_special_token_127|>",
1085
+ "lstrip": false,
1086
+ "normalized": false,
1087
+ "rstrip": false,
1088
+ "single_word": false,
1089
+ "special": true
1090
+ },
1091
+ "128136": {
1092
+ "content": "<|reserved_special_token_128|>",
1093
+ "lstrip": false,
1094
+ "normalized": false,
1095
+ "rstrip": false,
1096
+ "single_word": false,
1097
+ "special": true
1098
+ },
1099
+ "128137": {
1100
+ "content": "<|reserved_special_token_129|>",
1101
+ "lstrip": false,
1102
+ "normalized": false,
1103
+ "rstrip": false,
1104
+ "single_word": false,
1105
+ "special": true
1106
+ },
1107
+ "128138": {
1108
+ "content": "<|reserved_special_token_130|>",
1109
+ "lstrip": false,
1110
+ "normalized": false,
1111
+ "rstrip": false,
1112
+ "single_word": false,
1113
+ "special": true
1114
+ },
1115
+ "128139": {
1116
+ "content": "<|reserved_special_token_131|>",
1117
+ "lstrip": false,
1118
+ "normalized": false,
1119
+ "rstrip": false,
1120
+ "single_word": false,
1121
+ "special": true
1122
+ },
1123
+ "128140": {
1124
+ "content": "<|reserved_special_token_132|>",
1125
+ "lstrip": false,
1126
+ "normalized": false,
1127
+ "rstrip": false,
1128
+ "single_word": false,
1129
+ "special": true
1130
+ },
1131
+ "128141": {
1132
+ "content": "<|reserved_special_token_133|>",
1133
+ "lstrip": false,
1134
+ "normalized": false,
1135
+ "rstrip": false,
1136
+ "single_word": false,
1137
+ "special": true
1138
+ },
1139
+ "128142": {
1140
+ "content": "<|reserved_special_token_134|>",
1141
+ "lstrip": false,
1142
+ "normalized": false,
1143
+ "rstrip": false,
1144
+ "single_word": false,
1145
+ "special": true
1146
+ },
1147
+ "128143": {
1148
+ "content": "<|reserved_special_token_135|>",
1149
+ "lstrip": false,
1150
+ "normalized": false,
1151
+ "rstrip": false,
1152
+ "single_word": false,
1153
+ "special": true
1154
+ },
1155
+ "128144": {
1156
+ "content": "<|reserved_special_token_136|>",
1157
+ "lstrip": false,
1158
+ "normalized": false,
1159
+ "rstrip": false,
1160
+ "single_word": false,
1161
+ "special": true
1162
+ },
1163
+ "128145": {
1164
+ "content": "<|reserved_special_token_137|>",
1165
+ "lstrip": false,
1166
+ "normalized": false,
1167
+ "rstrip": false,
1168
+ "single_word": false,
1169
+ "special": true
1170
+ },
1171
+ "128146": {
1172
+ "content": "<|reserved_special_token_138|>",
1173
+ "lstrip": false,
1174
+ "normalized": false,
1175
+ "rstrip": false,
1176
+ "single_word": false,
1177
+ "special": true
1178
+ },
1179
+ "128147": {
1180
+ "content": "<|reserved_special_token_139|>",
1181
+ "lstrip": false,
1182
+ "normalized": false,
1183
+ "rstrip": false,
1184
+ "single_word": false,
1185
+ "special": true
1186
+ },
1187
+ "128148": {
1188
+ "content": "<|reserved_special_token_140|>",
1189
+ "lstrip": false,
1190
+ "normalized": false,
1191
+ "rstrip": false,
1192
+ "single_word": false,
1193
+ "special": true
1194
+ },
1195
+ "128149": {
1196
+ "content": "<|reserved_special_token_141|>",
1197
+ "lstrip": false,
1198
+ "normalized": false,
1199
+ "rstrip": false,
1200
+ "single_word": false,
1201
+ "special": true
1202
+ },
1203
+ "128150": {
1204
+ "content": "<|reserved_special_token_142|>",
1205
+ "lstrip": false,
1206
+ "normalized": false,
1207
+ "rstrip": false,
1208
+ "single_word": false,
1209
+ "special": true
1210
+ },
1211
+ "128151": {
1212
+ "content": "<|reserved_special_token_143|>",
1213
+ "lstrip": false,
1214
+ "normalized": false,
1215
+ "rstrip": false,
1216
+ "single_word": false,
1217
+ "special": true
1218
+ },
1219
+ "128152": {
1220
+ "content": "<|reserved_special_token_144|>",
1221
+ "lstrip": false,
1222
+ "normalized": false,
1223
+ "rstrip": false,
1224
+ "single_word": false,
1225
+ "special": true
1226
+ },
1227
+ "128153": {
1228
+ "content": "<|reserved_special_token_145|>",
1229
+ "lstrip": false,
1230
+ "normalized": false,
1231
+ "rstrip": false,
1232
+ "single_word": false,
1233
+ "special": true
1234
+ },
1235
+ "128154": {
1236
+ "content": "<|reserved_special_token_146|>",
1237
+ "lstrip": false,
1238
+ "normalized": false,
1239
+ "rstrip": false,
1240
+ "single_word": false,
1241
+ "special": true
1242
+ },
1243
+ "128155": {
1244
+ "content": "<|reserved_special_token_147|>",
1245
+ "lstrip": false,
1246
+ "normalized": false,
1247
+ "rstrip": false,
1248
+ "single_word": false,
1249
+ "special": true
1250
+ },
1251
+ "128156": {
1252
+ "content": "<|reserved_special_token_148|>",
1253
+ "lstrip": false,
1254
+ "normalized": false,
1255
+ "rstrip": false,
1256
+ "single_word": false,
1257
+ "special": true
1258
+ },
1259
+ "128157": {
1260
+ "content": "<|reserved_special_token_149|>",
1261
+ "lstrip": false,
1262
+ "normalized": false,
1263
+ "rstrip": false,
1264
+ "single_word": false,
1265
+ "special": true
1266
+ },
1267
+ "128158": {
1268
+ "content": "<|reserved_special_token_150|>",
1269
+ "lstrip": false,
1270
+ "normalized": false,
1271
+ "rstrip": false,
1272
+ "single_word": false,
1273
+ "special": true
1274
+ },
1275
+ "128159": {
1276
+ "content": "<|reserved_special_token_151|>",
1277
+ "lstrip": false,
1278
+ "normalized": false,
1279
+ "rstrip": false,
1280
+ "single_word": false,
1281
+ "special": true
1282
+ },
1283
+ "128160": {
1284
+ "content": "<|reserved_special_token_152|>",
1285
+ "lstrip": false,
1286
+ "normalized": false,
1287
+ "rstrip": false,
1288
+ "single_word": false,
1289
+ "special": true
1290
+ },
1291
+ "128161": {
1292
+ "content": "<|reserved_special_token_153|>",
1293
+ "lstrip": false,
1294
+ "normalized": false,
1295
+ "rstrip": false,
1296
+ "single_word": false,
1297
+ "special": true
1298
+ },
1299
+ "128162": {
1300
+ "content": "<|reserved_special_token_154|>",
1301
+ "lstrip": false,
1302
+ "normalized": false,
1303
+ "rstrip": false,
1304
+ "single_word": false,
1305
+ "special": true
1306
+ },
1307
+ "128163": {
1308
+ "content": "<|reserved_special_token_155|>",
1309
+ "lstrip": false,
1310
+ "normalized": false,
1311
+ "rstrip": false,
1312
+ "single_word": false,
1313
+ "special": true
1314
+ },
1315
+ "128164": {
1316
+ "content": "<|reserved_special_token_156|>",
1317
+ "lstrip": false,
1318
+ "normalized": false,
1319
+ "rstrip": false,
1320
+ "single_word": false,
1321
+ "special": true
1322
+ },
1323
+ "128165": {
1324
+ "content": "<|reserved_special_token_157|>",
1325
+ "lstrip": false,
1326
+ "normalized": false,
1327
+ "rstrip": false,
1328
+ "single_word": false,
1329
+ "special": true
1330
+ },
1331
+ "128166": {
1332
+ "content": "<|reserved_special_token_158|>",
1333
+ "lstrip": false,
1334
+ "normalized": false,
1335
+ "rstrip": false,
1336
+ "single_word": false,
1337
+ "special": true
1338
+ },
1339
+ "128167": {
1340
+ "content": "<|reserved_special_token_159|>",
1341
+ "lstrip": false,
1342
+ "normalized": false,
1343
+ "rstrip": false,
1344
+ "single_word": false,
1345
+ "special": true
1346
+ },
1347
+ "128168": {
1348
+ "content": "<|reserved_special_token_160|>",
1349
+ "lstrip": false,
1350
+ "normalized": false,
1351
+ "rstrip": false,
1352
+ "single_word": false,
1353
+ "special": true
1354
+ },
1355
+ "128169": {
1356
+ "content": "<|reserved_special_token_161|>",
1357
+ "lstrip": false,
1358
+ "normalized": false,
1359
+ "rstrip": false,
1360
+ "single_word": false,
1361
+ "special": true
1362
+ },
1363
+ "128170": {
1364
+ "content": "<|reserved_special_token_162|>",
1365
+ "lstrip": false,
1366
+ "normalized": false,
1367
+ "rstrip": false,
1368
+ "single_word": false,
1369
+ "special": true
1370
+ },
1371
+ "128171": {
1372
+ "content": "<|reserved_special_token_163|>",
1373
+ "lstrip": false,
1374
+ "normalized": false,
1375
+ "rstrip": false,
1376
+ "single_word": false,
1377
+ "special": true
1378
+ },
1379
+ "128172": {
1380
+ "content": "<|reserved_special_token_164|>",
1381
+ "lstrip": false,
1382
+ "normalized": false,
1383
+ "rstrip": false,
1384
+ "single_word": false,
1385
+ "special": true
1386
+ },
1387
+ "128173": {
1388
+ "content": "<|reserved_special_token_165|>",
1389
+ "lstrip": false,
1390
+ "normalized": false,
1391
+ "rstrip": false,
1392
+ "single_word": false,
1393
+ "special": true
1394
+ },
1395
+ "128174": {
1396
+ "content": "<|reserved_special_token_166|>",
1397
+ "lstrip": false,
1398
+ "normalized": false,
1399
+ "rstrip": false,
1400
+ "single_word": false,
1401
+ "special": true
1402
+ },
1403
+ "128175": {
1404
+ "content": "<|reserved_special_token_167|>",
1405
+ "lstrip": false,
1406
+ "normalized": false,
1407
+ "rstrip": false,
1408
+ "single_word": false,
1409
+ "special": true
1410
+ },
1411
+ "128176": {
1412
+ "content": "<|reserved_special_token_168|>",
1413
+ "lstrip": false,
1414
+ "normalized": false,
1415
+ "rstrip": false,
1416
+ "single_word": false,
1417
+ "special": true
1418
+ },
1419
+ "128177": {
1420
+ "content": "<|reserved_special_token_169|>",
1421
+ "lstrip": false,
1422
+ "normalized": false,
1423
+ "rstrip": false,
1424
+ "single_word": false,
1425
+ "special": true
1426
+ },
1427
+ "128178": {
1428
+ "content": "<|reserved_special_token_170|>",
1429
+ "lstrip": false,
1430
+ "normalized": false,
1431
+ "rstrip": false,
1432
+ "single_word": false,
1433
+ "special": true
1434
+ },
1435
+ "128179": {
1436
+ "content": "<|reserved_special_token_171|>",
1437
+ "lstrip": false,
1438
+ "normalized": false,
1439
+ "rstrip": false,
1440
+ "single_word": false,
1441
+ "special": true
1442
+ },
1443
+ "128180": {
1444
+ "content": "<|reserved_special_token_172|>",
1445
+ "lstrip": false,
1446
+ "normalized": false,
1447
+ "rstrip": false,
1448
+ "single_word": false,
1449
+ "special": true
1450
+ },
1451
+ "128181": {
1452
+ "content": "<|reserved_special_token_173|>",
1453
+ "lstrip": false,
1454
+ "normalized": false,
1455
+ "rstrip": false,
1456
+ "single_word": false,
1457
+ "special": true
1458
+ },
1459
+ "128182": {
1460
+ "content": "<|reserved_special_token_174|>",
1461
+ "lstrip": false,
1462
+ "normalized": false,
1463
+ "rstrip": false,
1464
+ "single_word": false,
1465
+ "special": true
1466
+ },
1467
+ "128183": {
1468
+ "content": "<|reserved_special_token_175|>",
1469
+ "lstrip": false,
1470
+ "normalized": false,
1471
+ "rstrip": false,
1472
+ "single_word": false,
1473
+ "special": true
1474
+ },
1475
+ "128184": {
1476
+ "content": "<|reserved_special_token_176|>",
1477
+ "lstrip": false,
1478
+ "normalized": false,
1479
+ "rstrip": false,
1480
+ "single_word": false,
1481
+ "special": true
1482
+ },
1483
+ "128185": {
1484
+ "content": "<|reserved_special_token_177|>",
1485
+ "lstrip": false,
1486
+ "normalized": false,
1487
+ "rstrip": false,
1488
+ "single_word": false,
1489
+ "special": true
1490
+ },
1491
+ "128186": {
1492
+ "content": "<|reserved_special_token_178|>",
1493
+ "lstrip": false,
1494
+ "normalized": false,
1495
+ "rstrip": false,
1496
+ "single_word": false,
1497
+ "special": true
1498
+ },
1499
+ "128187": {
1500
+ "content": "<|reserved_special_token_179|>",
1501
+ "lstrip": false,
1502
+ "normalized": false,
1503
+ "rstrip": false,
1504
+ "single_word": false,
1505
+ "special": true
1506
+ },
1507
+ "128188": {
1508
+ "content": "<|reserved_special_token_180|>",
1509
+ "lstrip": false,
1510
+ "normalized": false,
1511
+ "rstrip": false,
1512
+ "single_word": false,
1513
+ "special": true
1514
+ },
1515
+ "128189": {
1516
+ "content": "<|reserved_special_token_181|>",
1517
+ "lstrip": false,
1518
+ "normalized": false,
1519
+ "rstrip": false,
1520
+ "single_word": false,
1521
+ "special": true
1522
+ },
1523
+ "128190": {
1524
+ "content": "<|reserved_special_token_182|>",
1525
+ "lstrip": false,
1526
+ "normalized": false,
1527
+ "rstrip": false,
1528
+ "single_word": false,
1529
+ "special": true
1530
+ },
1531
+ "128191": {
1532
+ "content": "<|reserved_special_token_183|>",
1533
+ "lstrip": false,
1534
+ "normalized": false,
1535
+ "rstrip": false,
1536
+ "single_word": false,
1537
+ "special": true
1538
+ },
1539
+ "128192": {
1540
+ "content": "<|reserved_special_token_184|>",
1541
+ "lstrip": false,
1542
+ "normalized": false,
1543
+ "rstrip": false,
1544
+ "single_word": false,
1545
+ "special": true
1546
+ },
1547
+ "128193": {
1548
+ "content": "<|reserved_special_token_185|>",
1549
+ "lstrip": false,
1550
+ "normalized": false,
1551
+ "rstrip": false,
1552
+ "single_word": false,
1553
+ "special": true
1554
+ },
1555
+ "128194": {
1556
+ "content": "<|reserved_special_token_186|>",
1557
+ "lstrip": false,
1558
+ "normalized": false,
1559
+ "rstrip": false,
1560
+ "single_word": false,
1561
+ "special": true
1562
+ },
1563
+ "128195": {
1564
+ "content": "<|reserved_special_token_187|>",
1565
+ "lstrip": false,
1566
+ "normalized": false,
1567
+ "rstrip": false,
1568
+ "single_word": false,
1569
+ "special": true
1570
+ },
1571
+ "128196": {
1572
+ "content": "<|reserved_special_token_188|>",
1573
+ "lstrip": false,
1574
+ "normalized": false,
1575
+ "rstrip": false,
1576
+ "single_word": false,
1577
+ "special": true
1578
+ },
1579
+ "128197": {
1580
+ "content": "<|reserved_special_token_189|>",
1581
+ "lstrip": false,
1582
+ "normalized": false,
1583
+ "rstrip": false,
1584
+ "single_word": false,
1585
+ "special": true
1586
+ },
1587
+ "128198": {
1588
+ "content": "<|reserved_special_token_190|>",
1589
+ "lstrip": false,
1590
+ "normalized": false,
1591
+ "rstrip": false,
1592
+ "single_word": false,
1593
+ "special": true
1594
+ },
1595
+ "128199": {
1596
+ "content": "<|reserved_special_token_191|>",
1597
+ "lstrip": false,
1598
+ "normalized": false,
1599
+ "rstrip": false,
1600
+ "single_word": false,
1601
+ "special": true
1602
+ },
1603
+ "128200": {
1604
+ "content": "<|reserved_special_token_192|>",
1605
+ "lstrip": false,
1606
+ "normalized": false,
1607
+ "rstrip": false,
1608
+ "single_word": false,
1609
+ "special": true
1610
+ },
1611
+ "128201": {
1612
+ "content": "<|reserved_special_token_193|>",
1613
+ "lstrip": false,
1614
+ "normalized": false,
1615
+ "rstrip": false,
1616
+ "single_word": false,
1617
+ "special": true
1618
+ },
1619
+ "128202": {
1620
+ "content": "<|reserved_special_token_194|>",
1621
+ "lstrip": false,
1622
+ "normalized": false,
1623
+ "rstrip": false,
1624
+ "single_word": false,
1625
+ "special": true
1626
+ },
1627
+ "128203": {
1628
+ "content": "<|reserved_special_token_195|>",
1629
+ "lstrip": false,
1630
+ "normalized": false,
1631
+ "rstrip": false,
1632
+ "single_word": false,
1633
+ "special": true
1634
+ },
1635
+ "128204": {
1636
+ "content": "<|reserved_special_token_196|>",
1637
+ "lstrip": false,
1638
+ "normalized": false,
1639
+ "rstrip": false,
1640
+ "single_word": false,
1641
+ "special": true
1642
+ },
1643
+ "128205": {
1644
+ "content": "<|reserved_special_token_197|>",
1645
+ "lstrip": false,
1646
+ "normalized": false,
1647
+ "rstrip": false,
1648
+ "single_word": false,
1649
+ "special": true
1650
+ },
1651
+ "128206": {
1652
+ "content": "<|reserved_special_token_198|>",
1653
+ "lstrip": false,
1654
+ "normalized": false,
1655
+ "rstrip": false,
1656
+ "single_word": false,
1657
+ "special": true
1658
+ },
1659
+ "128207": {
1660
+ "content": "<|reserved_special_token_199|>",
1661
+ "lstrip": false,
1662
+ "normalized": false,
1663
+ "rstrip": false,
1664
+ "single_word": false,
1665
+ "special": true
1666
+ },
1667
+ "128208": {
1668
+ "content": "<|reserved_special_token_200|>",
1669
+ "lstrip": false,
1670
+ "normalized": false,
1671
+ "rstrip": false,
1672
+ "single_word": false,
1673
+ "special": true
1674
+ },
1675
+ "128209": {
1676
+ "content": "<|reserved_special_token_201|>",
1677
+ "lstrip": false,
1678
+ "normalized": false,
1679
+ "rstrip": false,
1680
+ "single_word": false,
1681
+ "special": true
1682
+ },
1683
+ "128210": {
1684
+ "content": "<|reserved_special_token_202|>",
1685
+ "lstrip": false,
1686
+ "normalized": false,
1687
+ "rstrip": false,
1688
+ "single_word": false,
1689
+ "special": true
1690
+ },
1691
+ "128211": {
1692
+ "content": "<|reserved_special_token_203|>",
1693
+ "lstrip": false,
1694
+ "normalized": false,
1695
+ "rstrip": false,
1696
+ "single_word": false,
1697
+ "special": true
1698
+ },
1699
+ "128212": {
1700
+ "content": "<|reserved_special_token_204|>",
1701
+ "lstrip": false,
1702
+ "normalized": false,
1703
+ "rstrip": false,
1704
+ "single_word": false,
1705
+ "special": true
1706
+ },
1707
+ "128213": {
1708
+ "content": "<|reserved_special_token_205|>",
1709
+ "lstrip": false,
1710
+ "normalized": false,
1711
+ "rstrip": false,
1712
+ "single_word": false,
1713
+ "special": true
1714
+ },
1715
+ "128214": {
1716
+ "content": "<|reserved_special_token_206|>",
1717
+ "lstrip": false,
1718
+ "normalized": false,
1719
+ "rstrip": false,
1720
+ "single_word": false,
1721
+ "special": true
1722
+ },
1723
+ "128215": {
1724
+ "content": "<|reserved_special_token_207|>",
1725
+ "lstrip": false,
1726
+ "normalized": false,
1727
+ "rstrip": false,
1728
+ "single_word": false,
1729
+ "special": true
1730
+ },
1731
+ "128216": {
1732
+ "content": "<|reserved_special_token_208|>",
1733
+ "lstrip": false,
1734
+ "normalized": false,
1735
+ "rstrip": false,
1736
+ "single_word": false,
1737
+ "special": true
1738
+ },
1739
+ "128217": {
1740
+ "content": "<|reserved_special_token_209|>",
1741
+ "lstrip": false,
1742
+ "normalized": false,
1743
+ "rstrip": false,
1744
+ "single_word": false,
1745
+ "special": true
1746
+ },
1747
+ "128218": {
1748
+ "content": "<|reserved_special_token_210|>",
1749
+ "lstrip": false,
1750
+ "normalized": false,
1751
+ "rstrip": false,
1752
+ "single_word": false,
1753
+ "special": true
1754
+ },
1755
+ "128219": {
1756
+ "content": "<|reserved_special_token_211|>",
1757
+ "lstrip": false,
1758
+ "normalized": false,
1759
+ "rstrip": false,
1760
+ "single_word": false,
1761
+ "special": true
1762
+ },
1763
+ "128220": {
1764
+ "content": "<|reserved_special_token_212|>",
1765
+ "lstrip": false,
1766
+ "normalized": false,
1767
+ "rstrip": false,
1768
+ "single_word": false,
1769
+ "special": true
1770
+ },
1771
+ "128221": {
1772
+ "content": "<|reserved_special_token_213|>",
1773
+ "lstrip": false,
1774
+ "normalized": false,
1775
+ "rstrip": false,
1776
+ "single_word": false,
1777
+ "special": true
1778
+ },
1779
+ "128222": {
1780
+ "content": "<|reserved_special_token_214|>",
1781
+ "lstrip": false,
1782
+ "normalized": false,
1783
+ "rstrip": false,
1784
+ "single_word": false,
1785
+ "special": true
1786
+ },
1787
+ "128223": {
1788
+ "content": "<|reserved_special_token_215|>",
1789
+ "lstrip": false,
1790
+ "normalized": false,
1791
+ "rstrip": false,
1792
+ "single_word": false,
1793
+ "special": true
1794
+ },
1795
+ "128224": {
1796
+ "content": "<|reserved_special_token_216|>",
1797
+ "lstrip": false,
1798
+ "normalized": false,
1799
+ "rstrip": false,
1800
+ "single_word": false,
1801
+ "special": true
1802
+ },
1803
+ "128225": {
1804
+ "content": "<|reserved_special_token_217|>",
1805
+ "lstrip": false,
1806
+ "normalized": false,
1807
+ "rstrip": false,
1808
+ "single_word": false,
1809
+ "special": true
1810
+ },
1811
+ "128226": {
1812
+ "content": "<|reserved_special_token_218|>",
1813
+ "lstrip": false,
1814
+ "normalized": false,
1815
+ "rstrip": false,
1816
+ "single_word": false,
1817
+ "special": true
1818
+ },
1819
+ "128227": {
1820
+ "content": "<|reserved_special_token_219|>",
1821
+ "lstrip": false,
1822
+ "normalized": false,
1823
+ "rstrip": false,
1824
+ "single_word": false,
1825
+ "special": true
1826
+ },
1827
+ "128228": {
1828
+ "content": "<|reserved_special_token_220|>",
1829
+ "lstrip": false,
1830
+ "normalized": false,
1831
+ "rstrip": false,
1832
+ "single_word": false,
1833
+ "special": true
1834
+ },
1835
+ "128229": {
1836
+ "content": "<|reserved_special_token_221|>",
1837
+ "lstrip": false,
1838
+ "normalized": false,
1839
+ "rstrip": false,
1840
+ "single_word": false,
1841
+ "special": true
1842
+ },
1843
+ "128230": {
1844
+ "content": "<|reserved_special_token_222|>",
1845
+ "lstrip": false,
1846
+ "normalized": false,
1847
+ "rstrip": false,
1848
+ "single_word": false,
1849
+ "special": true
1850
+ },
1851
+ "128231": {
1852
+ "content": "<|reserved_special_token_223|>",
1853
+ "lstrip": false,
1854
+ "normalized": false,
1855
+ "rstrip": false,
1856
+ "single_word": false,
1857
+ "special": true
1858
+ },
1859
+ "128232": {
1860
+ "content": "<|reserved_special_token_224|>",
1861
+ "lstrip": false,
1862
+ "normalized": false,
1863
+ "rstrip": false,
1864
+ "single_word": false,
1865
+ "special": true
1866
+ },
1867
+ "128233": {
1868
+ "content": "<|reserved_special_token_225|>",
1869
+ "lstrip": false,
1870
+ "normalized": false,
1871
+ "rstrip": false,
1872
+ "single_word": false,
1873
+ "special": true
1874
+ },
1875
+ "128234": {
1876
+ "content": "<|reserved_special_token_226|>",
1877
+ "lstrip": false,
1878
+ "normalized": false,
1879
+ "rstrip": false,
1880
+ "single_word": false,
1881
+ "special": true
1882
+ },
1883
+ "128235": {
1884
+ "content": "<|reserved_special_token_227|>",
1885
+ "lstrip": false,
1886
+ "normalized": false,
1887
+ "rstrip": false,
1888
+ "single_word": false,
1889
+ "special": true
1890
+ },
1891
+ "128236": {
1892
+ "content": "<|reserved_special_token_228|>",
1893
+ "lstrip": false,
1894
+ "normalized": false,
1895
+ "rstrip": false,
1896
+ "single_word": false,
1897
+ "special": true
1898
+ },
1899
+ "128237": {
1900
+ "content": "<|reserved_special_token_229|>",
1901
+ "lstrip": false,
1902
+ "normalized": false,
1903
+ "rstrip": false,
1904
+ "single_word": false,
1905
+ "special": true
1906
+ },
1907
+ "128238": {
1908
+ "content": "<|reserved_special_token_230|>",
1909
+ "lstrip": false,
1910
+ "normalized": false,
1911
+ "rstrip": false,
1912
+ "single_word": false,
1913
+ "special": true
1914
+ },
1915
+ "128239": {
1916
+ "content": "<|reserved_special_token_231|>",
1917
+ "lstrip": false,
1918
+ "normalized": false,
1919
+ "rstrip": false,
1920
+ "single_word": false,
1921
+ "special": true
1922
+ },
1923
+ "128240": {
1924
+ "content": "<|reserved_special_token_232|>",
1925
+ "lstrip": false,
1926
+ "normalized": false,
1927
+ "rstrip": false,
1928
+ "single_word": false,
1929
+ "special": true
1930
+ },
1931
+ "128241": {
1932
+ "content": "<|reserved_special_token_233|>",
1933
+ "lstrip": false,
1934
+ "normalized": false,
1935
+ "rstrip": false,
1936
+ "single_word": false,
1937
+ "special": true
1938
+ },
1939
+ "128242": {
1940
+ "content": "<|reserved_special_token_234|>",
1941
+ "lstrip": false,
1942
+ "normalized": false,
1943
+ "rstrip": false,
1944
+ "single_word": false,
1945
+ "special": true
1946
+ },
1947
+ "128243": {
1948
+ "content": "<|reserved_special_token_235|>",
1949
+ "lstrip": false,
1950
+ "normalized": false,
1951
+ "rstrip": false,
1952
+ "single_word": false,
1953
+ "special": true
1954
+ },
1955
+ "128244": {
1956
+ "content": "<|reserved_special_token_236|>",
1957
+ "lstrip": false,
1958
+ "normalized": false,
1959
+ "rstrip": false,
1960
+ "single_word": false,
1961
+ "special": true
1962
+ },
1963
+ "128245": {
1964
+ "content": "<|reserved_special_token_237|>",
1965
+ "lstrip": false,
1966
+ "normalized": false,
1967
+ "rstrip": false,
1968
+ "single_word": false,
1969
+ "special": true
1970
+ },
1971
+ "128246": {
1972
+ "content": "<|reserved_special_token_238|>",
1973
+ "lstrip": false,
1974
+ "normalized": false,
1975
+ "rstrip": false,
1976
+ "single_word": false,
1977
+ "special": true
1978
+ },
1979
+ "128247": {
1980
+ "content": "<|reserved_special_token_239|>",
1981
+ "lstrip": false,
1982
+ "normalized": false,
1983
+ "rstrip": false,
1984
+ "single_word": false,
1985
+ "special": true
1986
+ },
1987
+ "128248": {
1988
+ "content": "<|reserved_special_token_240|>",
1989
+ "lstrip": false,
1990
+ "normalized": false,
1991
+ "rstrip": false,
1992
+ "single_word": false,
1993
+ "special": true
1994
+ },
1995
+ "128249": {
1996
+ "content": "<|reserved_special_token_241|>",
1997
+ "lstrip": false,
1998
+ "normalized": false,
1999
+ "rstrip": false,
2000
+ "single_word": false,
2001
+ "special": true
2002
+ },
2003
+ "128250": {
2004
+ "content": "<|reserved_special_token_242|>",
2005
+ "lstrip": false,
2006
+ "normalized": false,
2007
+ "rstrip": false,
2008
+ "single_word": false,
2009
+ "special": true
2010
+ },
2011
+ "128251": {
2012
+ "content": "<|reserved_special_token_243|>",
2013
+ "lstrip": false,
2014
+ "normalized": false,
2015
+ "rstrip": false,
2016
+ "single_word": false,
2017
+ "special": true
2018
+ },
2019
+ "128252": {
2020
+ "content": "<|reserved_special_token_244|>",
2021
+ "lstrip": false,
2022
+ "normalized": false,
2023
+ "rstrip": false,
2024
+ "single_word": false,
2025
+ "special": true
2026
+ },
2027
+ "128253": {
2028
+ "content": "<|reserved_special_token_245|>",
2029
+ "lstrip": false,
2030
+ "normalized": false,
2031
+ "rstrip": false,
2032
+ "single_word": false,
2033
+ "special": true
2034
+ },
2035
+ "128254": {
2036
+ "content": "<|reserved_special_token_246|>",
2037
+ "lstrip": false,
2038
+ "normalized": false,
2039
+ "rstrip": false,
2040
+ "single_word": false,
2041
+ "special": true
2042
+ },
2043
+ "128255": {
2044
+ "content": "<|reserved_special_token_247|>",
2045
+ "lstrip": false,
2046
+ "normalized": false,
2047
+ "rstrip": false,
2048
+ "single_word": false,
2049
+ "special": true
2050
+ },
2051
+ "128256": {
2052
+ "content": "[PAD]",
2053
+ "lstrip": false,
2054
+ "normalized": false,
2055
+ "rstrip": false,
2056
+ "single_word": false,
2057
+ "special": true
2058
+ },
2059
+ "128257": {
2060
+ "content": "<unk>",
2061
+ "lstrip": false,
2062
+ "normalized": false,
2063
+ "rstrip": false,
2064
+ "single_word": false,
2065
+ "special": true
2066
+ }
2067
+ },
2068
+ "bos_token": "<|begin_of_text|>",
2069
+ "chat_template": "{{- bos_token }}\n{%- if custom_tools is defined %}\n {%- set tools = custom_tools %}\n{%- endif %}\n{%- if not tools_in_user_message is defined %}\n {%- set tools_in_user_message = true %}\n{%- endif %}\n{%- if not date_string is defined %}\n {%- set date_string = \"26 Jul 2024\" %}\n{%- endif %}\n{%- if not tools is defined %}\n {%- set tools = none %}\n{%- endif %}\n\n{#- This block extracts the system message, so we can slot it into the right place. #}\n{%- if messages[0]['role'] == 'system' %}\n {%- set system_message = messages[0]['content']|trim %}\n {%- set messages = messages[1:] %}\n{%- else %}\n {%- set system_message = \"\" %}\n{%- endif %}\n\n{#- System message + builtin tools #}\n{{- \"<|start_header_id|>system<|end_header_id|>\\n\\n\" }}\n{%- if builtin_tools is defined or tools is not none %}\n {{- \"Environment: ipython\\n\" }}\n{%- endif %}\n{%- if builtin_tools is defined %}\n {{- \"Tools: \" + builtin_tools | reject('equalto', 'code_interpreter') | join(\", \") + \"\\n\\n\"}}\n{%- endif %}\n{{- \"Cutting Knowledge Date: December 2023\\n\" }}\n{{- \"Today Date: \" + date_string + \"\\n\\n\" }}\n{%- if tools is not none and not tools_in_user_message %}\n {{- \"You have access to the following functions. To call a function, please respond with JSON for a function call.\" }}\n {{- 'Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.' }}\n {{- \"Do not use variables.\\n\\n\" }}\n {%- for t in tools %}\n {{- t | tojson(indent=4) }}\n {{- \"\\n\\n\" }}\n {%- endfor %}\n{%- endif %}\n{{- system_message }}\n{{- \"<|eot_id|>\" }}\n\n{#- Custom tools are passed in a user message with some extra guidance #}\n{%- if tools_in_user_message and not tools is none %}\n {#- Extract the first user message so we can plug it in here #}\n {%- if messages | length != 0 %}\n {%- set first_user_message = messages[0]['content']|trim %}\n {%- set messages = messages[1:] %}\n {%- else %}\n {{- raise_exception(\"Cannot put tools in the first user message when there's no first user message!\") }}\n{%- endif %}\n {{- '<|start_header_id|>user<|end_header_id|>\\n\\n' -}}\n {{- \"Given the following functions, please respond with a JSON for a function call \" }}\n {{- \"with its proper arguments that best answers the given prompt.\\n\\n\" }}\n {{- 'Respond in the format {\"name\": function name, \"parameters\": dictionary of argument name and its value}.' }}\n {{- \"Do not use variables.\\n\\n\" }}\n {%- for t in tools %}\n {{- t | tojson(indent=4) }}\n {{- \"\\n\\n\" }}\n {%- endfor %}\n {{- first_user_message + \"<|eot_id|>\"}}\n{%- endif %}\n\n{%- for message in messages %}\n {%- if not (message.role == 'ipython' or message.role == 'tool' or 'tool_calls' in message) %}\n {{- '<|start_header_id|>' + message['role'] + '<|end_header_id|>\\n\\n'+ message['content'] | trim + '<|eot_id|>' }}\n {%- elif 'tool_calls' in message %}\n {%- if not message.tool_calls|length == 1 %}\n {{- raise_exception(\"This model only supports single tool-calls at once!\") }}\n {%- endif %}\n {%- set tool_call = message.tool_calls[0].function %}\n {%- if builtin_tools is defined and tool_call.name in builtin_tools %}\n {{- '<|start_header_id|>assistant<|end_header_id|>\\n\\n' -}}\n {{- \"<|python_tag|>\" + tool_call.name + \".call(\" }}\n {%- for arg_name, arg_val in tool_call.arguments | items %}\n {{- arg_name + '=\"' + arg_val + '\"' }}\n {%- if not loop.last %}\n {{- \", \" }}\n {%- endif %}\n {%- endfor %}\n {{- \")\" }}\n {%- else %}\n {{- '<|start_header_id|>assistant<|end_header_id|>\\n\\n' -}}\n {{- '{\"name\": \"' + tool_call.name + '\", ' }}\n {{- '\"parameters\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- \"}\" }}\n {%- endif %}\n {%- if builtin_tools is defined %}\n {#- This means we're in ipython mode #}\n {{- \"<|eom_id|>\" }}\n {%- else %}\n {{- \"<|eot_id|>\" }}\n {%- endif %}\n {%- elif message.role == \"tool\" or message.role == \"ipython\" %}\n {{- \"<|start_header_id|>ipython<|end_header_id|>\\n\\n\" }}\n {%- if message.content is mapping or message.content is iterable %}\n {{- message.content | tojson }}\n {%- else %}\n {{- message.content }}\n {%- endif %}\n {{- \"<|eot_id|>\" }}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|start_header_id|>assistant<|end_header_id|>\\n\\n' }}\n{%- endif %}\n",
2070
+ "clean_up_tokenization_spaces": true,
2071
+ "eos_token": "<|eot_id|>",
2072
+ "model_input_names": [
2073
+ "input_ids",
2074
+ "attention_mask"
2075
+ ],
2076
+ "model_max_length": 131072,
2077
+ "pad_token": "[PAD]",
2078
+ "padding_side": "right",
2079
+ "tokenizer_class": "PreTrainedTokenizerFast",
2080
+ "unk_token": "<unk>"
2081
+ }
utils.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import warnings
2
+ from dataclasses import dataclass
3
+ from typing import Optional, Tuple
4
+
5
+ import torch
6
+
7
+ from transformers.utils import ModelOutput
8
+
9
+ @dataclass
10
+ class BaseModelOutputWithPastAndSeer(ModelOutput):
11
+ last_hidden_state: torch.FloatTensor = None
12
+ past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None
13
+ hidden_states: Optional[Tuple[torch.FloatTensor, ...]] = None
14
+ attentions: Optional[Tuple[torch.FloatTensor, ...]] = None
15
+ mask_gate_predictions: Optional[Tuple[torch.FloatTensor, ...]] = None
16
+ mask_ground_truths: Optional[Tuple[torch.FloatTensor, ...]] = None
17
+ mask_loss: torch.FloatTensor = None
18
+
19
+
20
+ @dataclass
21
+ class CausalLMOutputWithPastAndSeer(ModelOutput):
22
+ loss: Optional[torch.FloatTensor] = None
23
+ logits: torch.FloatTensor = None
24
+ past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None
25
+ hidden_states: Optional[Tuple[torch.FloatTensor, ...]] = None
26
+ attentions: Optional[Tuple[torch.FloatTensor, ...]] = None
27
+ mask_gate_predictions: Optional[Tuple[torch.FloatTensor, ...]] = None
28
+ mask_ground_truths: Optional[Tuple[torch.FloatTensor, ...]] = None
29
+ mask_loss: torch.FloatTensor = None
30
+