nexaai 1.0.19rc6__cp310-cp310-macosx_14_0_universal2.whl → 1.0.19rc8__cp310-cp310-macosx_14_0_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of nexaai might be problematic. Click here for more details.
- nexaai/_stub.cpython-310-darwin.so +0 -0
- nexaai/_version.py +1 -1
- nexaai/binds/libnexa_bridge.dylib +0 -0
- nexaai/binds/nexa_llama_cpp/libggml-base.dylib +0 -0
- nexaai/binds/nexa_llama_cpp/libggml-cpu.so +0 -0
- nexaai/binds/nexa_llama_cpp/libggml-metal.so +0 -0
- nexaai/binds/nexa_llama_cpp/libggml.dylib +0 -0
- nexaai/binds/nexa_llama_cpp/libllama.dylib +0 -0
- nexaai/binds/nexa_llama_cpp/libmtmd.dylib +0 -0
- nexaai/binds/nexa_llama_cpp/libnexa_plugin.dylib +0 -0
- nexaai/binds/nexa_mlx/libnexa_plugin.dylib +0 -0
- nexaai/binds/nexa_nexaml/libggml-base.dylib +0 -0
- nexaai/binds/nexa_nexaml/libggml-cpu.so +0 -0
- nexaai/binds/nexa_nexaml/libggml-metal.so +0 -0
- nexaai/binds/nexa_nexaml/libggml.dylib +0 -0
- nexaai/mlx_backend/vlm/generate_qwen3_vl_moe.py +276 -0
- nexaai/mlx_backend/vlm/interface.py +21 -4
- nexaai/mlx_backend/vlm/main.py +6 -2
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/__init__.py +0 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/base.py +117 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/cache.py +531 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/generate.py +701 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/rope_utils.py +255 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/sample_utils.py +303 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/llm_common/tokenizer_utils.py +407 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/processor.py +476 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/qwen3vl_moe.py +1309 -0
- nexaai/mlx_backend/vlm/modeling/models/qwen3vl_moe/switch_layers.py +210 -0
- nexaai/utils/manifest_utils.py +222 -15
- nexaai/utils/model_manager.py +83 -7
- nexaai/utils/model_types.py +2 -0
- {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc8.dist-info}/METADATA +1 -1
- {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc8.dist-info}/RECORD +35 -24
- {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc8.dist-info}/WHEEL +0 -0
- {nexaai-1.0.19rc6.dist-info → nexaai-1.0.19rc8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from functools import partial
|
|
3
|
+
from json import JSONDecodeError
|
|
4
|
+
from typing import List
|
|
5
|
+
|
|
6
|
+
from transformers import AutoTokenizer, PreTrainedTokenizerFast
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class StreamingDetokenizer:
|
|
10
|
+
"""The streaming detokenizer interface so that we can detokenize one token at a time.
|
|
11
|
+
|
|
12
|
+
Example usage is as follows:
|
|
13
|
+
|
|
14
|
+
detokenizer = ...
|
|
15
|
+
|
|
16
|
+
# Reset the tokenizer state
|
|
17
|
+
detokenizer.reset()
|
|
18
|
+
|
|
19
|
+
for token in generate(...):
|
|
20
|
+
detokenizer.add_token(token.item())
|
|
21
|
+
|
|
22
|
+
# Contains the whole text so far. Some tokens may not be included
|
|
23
|
+
# since it contains whole words usually.
|
|
24
|
+
detokenizer.text
|
|
25
|
+
|
|
26
|
+
# Contains the printable segment (usually a word) since the last
|
|
27
|
+
# time it was accessed
|
|
28
|
+
detokenizer.last_segment
|
|
29
|
+
|
|
30
|
+
# Contains all the tokens added so far
|
|
31
|
+
detokenizer.tokens
|
|
32
|
+
|
|
33
|
+
# Make sure that we detokenize any remaining tokens
|
|
34
|
+
detokenizer.finalize()
|
|
35
|
+
|
|
36
|
+
# Now detokenizer.text should match tokenizer.decode(detokenizer.tokens)
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
__slots__ = ("text", "tokens", "offset")
|
|
40
|
+
|
|
41
|
+
def reset(self):
|
|
42
|
+
raise NotImplementedError()
|
|
43
|
+
|
|
44
|
+
def add_token(self, token):
|
|
45
|
+
raise NotImplementedError()
|
|
46
|
+
|
|
47
|
+
def finalize(self):
|
|
48
|
+
raise NotImplementedError()
|
|
49
|
+
|
|
50
|
+
@property
|
|
51
|
+
def last_segment(self):
|
|
52
|
+
"""Return the last segment of readable text since last time this property was accessed."""
|
|
53
|
+
text = self.text
|
|
54
|
+
segment = text[self.offset :]
|
|
55
|
+
self.offset = len(text)
|
|
56
|
+
return segment
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class NaiveStreamingDetokenizer(StreamingDetokenizer):
|
|
60
|
+
"""NaiveStreamingDetokenizer relies on the underlying tokenizer
|
|
61
|
+
implementation and should work with every tokenizer.
|
|
62
|
+
|
|
63
|
+
Its complexity is O(T^2) where T is the longest line since it will
|
|
64
|
+
repeatedly detokenize the same tokens until a new line is generated.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def __init__(self, tokenizer):
|
|
68
|
+
self._tokenizer = tokenizer
|
|
69
|
+
self._tokenizer.decode([0])
|
|
70
|
+
self.reset()
|
|
71
|
+
|
|
72
|
+
def reset(self):
|
|
73
|
+
self.offset = 0
|
|
74
|
+
self.tokens = []
|
|
75
|
+
self._text = ""
|
|
76
|
+
self._current_tokens = []
|
|
77
|
+
self._current_text = ""
|
|
78
|
+
|
|
79
|
+
def add_token(self, token):
|
|
80
|
+
self._current_tokens.append(token)
|
|
81
|
+
self.tokens.append(token)
|
|
82
|
+
|
|
83
|
+
def finalize(self):
|
|
84
|
+
self._text += self._tokenizer.decode(self._current_tokens)
|
|
85
|
+
self._current_tokens = []
|
|
86
|
+
self._current_text = ""
|
|
87
|
+
|
|
88
|
+
@property
|
|
89
|
+
def text(self):
|
|
90
|
+
if self._current_tokens:
|
|
91
|
+
self._current_text = self._tokenizer.decode(self._current_tokens)
|
|
92
|
+
if self._tokenizer.clean_up_tokenization_spaces and self._current_text[-1] == " ":
|
|
93
|
+
self._current_text = self._current_text[:-1]
|
|
94
|
+
if self._current_text and self._current_text[-1] == "\n":
|
|
95
|
+
self._text += self._current_text
|
|
96
|
+
self._current_tokens.clear()
|
|
97
|
+
self._current_text = ""
|
|
98
|
+
return self._text + self._current_text
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class SPMStreamingDetokenizer(StreamingDetokenizer):
|
|
102
|
+
"""A streaming detokenizer for SPM models.
|
|
103
|
+
|
|
104
|
+
It adds tokens to the text if the next token starts with the special SPM
|
|
105
|
+
underscore which results in linear complexity.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
def __init__(self, tokenizer, trim_space=True):
|
|
109
|
+
self.trim_space = trim_space
|
|
110
|
+
self._sep = "\u2581".encode()
|
|
111
|
+
|
|
112
|
+
# Extract the tokens in a list from id to text
|
|
113
|
+
self.tokenmap = [""] * (max(tokenizer.vocab.values()) + 1)
|
|
114
|
+
for value, tokenid in tokenizer.vocab.items():
|
|
115
|
+
if value.startswith("<0x"):
|
|
116
|
+
# Replace bytes with their value
|
|
117
|
+
self.tokenmap[tokenid] = bytes([int(value[3:5], 16)])
|
|
118
|
+
else:
|
|
119
|
+
self.tokenmap[tokenid] = value.encode()
|
|
120
|
+
|
|
121
|
+
self.reset()
|
|
122
|
+
|
|
123
|
+
def reset(self):
|
|
124
|
+
self.offset = 0
|
|
125
|
+
self._unflushed = b""
|
|
126
|
+
self.text = ""
|
|
127
|
+
self.tokens = []
|
|
128
|
+
|
|
129
|
+
def _try_flush(self, force=False):
|
|
130
|
+
text = self._unflushed.replace(self._sep, b" ").decode("utf-8", "replace")
|
|
131
|
+
if not force and text.endswith("\ufffd"):
|
|
132
|
+
return
|
|
133
|
+
if not self.text and self.trim_space and text and text[0] == " ":
|
|
134
|
+
text = text[1:]
|
|
135
|
+
self.text += text
|
|
136
|
+
self._unflushed = b""
|
|
137
|
+
|
|
138
|
+
def add_token(self, token):
|
|
139
|
+
self.tokens.append(token)
|
|
140
|
+
v = self.tokenmap[token]
|
|
141
|
+
self._unflushed += v
|
|
142
|
+
self._try_flush()
|
|
143
|
+
|
|
144
|
+
def finalize(self):
|
|
145
|
+
self._try_flush(force=True)
|
|
146
|
+
self._unflushed = b""
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class BPEStreamingDetokenizer(StreamingDetokenizer):
|
|
150
|
+
"""A streaming detokenizer for OpenAI style BPE models.
|
|
151
|
+
|
|
152
|
+
It adds tokens to the text if the next token starts with a space similar to
|
|
153
|
+
the SPM detokenizer.
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
_byte_decoder = None
|
|
157
|
+
_space_matches = (".", "?", "!", ",", "n't", "'m", "'s", "'ve", "'re")
|
|
158
|
+
|
|
159
|
+
def __init__(self, tokenizer):
|
|
160
|
+
self.clean_spaces = tokenizer.clean_up_tokenization_spaces
|
|
161
|
+
|
|
162
|
+
# Extract the tokens in a list from id to text
|
|
163
|
+
self.tokenmap = [None] * len(tokenizer.vocab)
|
|
164
|
+
for value, tokenid in tokenizer.vocab.items():
|
|
165
|
+
self.tokenmap[tokenid] = value
|
|
166
|
+
|
|
167
|
+
self.reset()
|
|
168
|
+
|
|
169
|
+
# Make the BPE byte decoder from
|
|
170
|
+
# https://github.com/openai/gpt-2/blob/master/src/encoder.py
|
|
171
|
+
self.make_byte_decoder()
|
|
172
|
+
|
|
173
|
+
def reset(self):
|
|
174
|
+
self.offset = 0
|
|
175
|
+
self._unflushed = ""
|
|
176
|
+
self.text = ""
|
|
177
|
+
self.tokens = []
|
|
178
|
+
|
|
179
|
+
def _decode_bytes(self, seq):
|
|
180
|
+
barr = bytearray()
|
|
181
|
+
for c in seq:
|
|
182
|
+
res = self._byte_decoder.get(c, False)
|
|
183
|
+
if res:
|
|
184
|
+
barr.append(res)
|
|
185
|
+
else:
|
|
186
|
+
barr.extend(bytes(c, "utf-8"))
|
|
187
|
+
return barr.decode("utf-8", "replace")
|
|
188
|
+
|
|
189
|
+
def _maybe_trim_space(self, current_text):
|
|
190
|
+
if len(current_text) == 0:
|
|
191
|
+
return current_text
|
|
192
|
+
elif current_text[0] != " ":
|
|
193
|
+
return current_text
|
|
194
|
+
elif not self.text:
|
|
195
|
+
return current_text[1:]
|
|
196
|
+
elif self.clean_spaces and current_text[1:].startswith(self._space_matches):
|
|
197
|
+
return current_text[1:]
|
|
198
|
+
return current_text
|
|
199
|
+
|
|
200
|
+
def add_token(self, token):
|
|
201
|
+
self.tokens.append(token)
|
|
202
|
+
v = self.tokenmap[token]
|
|
203
|
+
self._unflushed += v
|
|
204
|
+
text = self._decode_bytes(self._unflushed)
|
|
205
|
+
|
|
206
|
+
# For multi-byte utf-8 wait until they are complete
|
|
207
|
+
# For single spaces wait until the next token to clean it if needed
|
|
208
|
+
if not text.endswith("\ufffd") and not (len(v) == 1 and self._byte_decoder[v[0]] == 32):
|
|
209
|
+
self.text += self._maybe_trim_space(text)
|
|
210
|
+
self._unflushed = ""
|
|
211
|
+
|
|
212
|
+
def finalize(self):
|
|
213
|
+
current_text = bytearray(self._byte_decoder[c] for c in self._unflushed).decode(
|
|
214
|
+
"utf-8",
|
|
215
|
+
"replace",
|
|
216
|
+
)
|
|
217
|
+
self.text += self._maybe_trim_space(current_text)
|
|
218
|
+
self._unflushed = ""
|
|
219
|
+
|
|
220
|
+
@classmethod
|
|
221
|
+
def make_byte_decoder(cls):
|
|
222
|
+
"""See https://github.com/openai/gpt-2/blob/master/src/encoder.py for the rationale."""
|
|
223
|
+
if cls._byte_decoder is not None:
|
|
224
|
+
return
|
|
225
|
+
|
|
226
|
+
char_to_bytes = {}
|
|
227
|
+
limits = [
|
|
228
|
+
0,
|
|
229
|
+
ord("!"),
|
|
230
|
+
ord("~") + 1,
|
|
231
|
+
ord("¡"),
|
|
232
|
+
ord("¬") + 1,
|
|
233
|
+
ord("®"),
|
|
234
|
+
ord("ÿ") + 1,
|
|
235
|
+
]
|
|
236
|
+
n = 0
|
|
237
|
+
for i, (start, stop) in enumerate(zip(limits, limits[1:])):
|
|
238
|
+
if i % 2 == 0:
|
|
239
|
+
for b in range(start, stop):
|
|
240
|
+
char_to_bytes[chr(2**8 + n)] = b
|
|
241
|
+
n += 1
|
|
242
|
+
else:
|
|
243
|
+
for b in range(start, stop):
|
|
244
|
+
char_to_bytes[chr(b)] = b
|
|
245
|
+
cls._byte_decoder = char_to_bytes
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
class TokenizerWrapper:
|
|
249
|
+
"""A wrapper that combines an HF tokenizer and a detokenizer.
|
|
250
|
+
|
|
251
|
+
Accessing any attribute other than the ``detokenizer`` is forwarded to the
|
|
252
|
+
huggingface tokenizer.
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
def __init__(self, tokenizer, detokenizer_class=NaiveStreamingDetokenizer, eos_token_ids=None):
|
|
256
|
+
self._tokenizer = tokenizer
|
|
257
|
+
self._detokenizer = detokenizer_class(tokenizer)
|
|
258
|
+
self._eos_token_ids = (
|
|
259
|
+
set(eos_token_ids) if eos_token_ids is not None else {tokenizer.eos_token_id}
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
def add_eos_token(self, token: str):
|
|
263
|
+
token_id = None
|
|
264
|
+
try:
|
|
265
|
+
token_id = int(token)
|
|
266
|
+
except ValueError:
|
|
267
|
+
token_id = self._tokenizer.convert_tokens_to_ids(token)
|
|
268
|
+
|
|
269
|
+
if token_id is None:
|
|
270
|
+
raise ValueError(f"'{token}' is not a token for this tokenizer")
|
|
271
|
+
|
|
272
|
+
self._eos_token_ids.add(token_id)
|
|
273
|
+
|
|
274
|
+
def __getattr__(self, attr):
|
|
275
|
+
if attr == "detokenizer":
|
|
276
|
+
return self._detokenizer
|
|
277
|
+
elif attr == "eos_token_ids":
|
|
278
|
+
return self._eos_token_ids
|
|
279
|
+
elif attr.startswith("_"):
|
|
280
|
+
return self.__getattribute__(attr)
|
|
281
|
+
else:
|
|
282
|
+
return getattr(self._tokenizer, attr)
|
|
283
|
+
|
|
284
|
+
def __setattr__(self, attr, value):
|
|
285
|
+
if attr in {"detokenizer", "eos_token_ids"}:
|
|
286
|
+
if attr == "detokenizer":
|
|
287
|
+
raise AttributeError("Cannot set the detokenizer.")
|
|
288
|
+
elif attr == "eos_token_ids":
|
|
289
|
+
self._eos_token_ids = set(value) if value is not None else set()
|
|
290
|
+
elif attr.startswith("_"):
|
|
291
|
+
super().__setattr__(attr, value)
|
|
292
|
+
else:
|
|
293
|
+
setattr(self._tokenizer, attr, value)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
class NewlineTokenizer(PreTrainedTokenizerFast):
|
|
297
|
+
"""A tokenizer that replaces newlines with <n> and <n> with new line."""
|
|
298
|
+
|
|
299
|
+
def __init__(self, *args, **kwargs):
|
|
300
|
+
super().__init__(*args, **kwargs)
|
|
301
|
+
|
|
302
|
+
def _preprocess_text(self, text):
|
|
303
|
+
return text.replace("\n", "<n>")
|
|
304
|
+
|
|
305
|
+
def _postprocess_text(self, text):
|
|
306
|
+
return text.replace("<n>", "\n")
|
|
307
|
+
|
|
308
|
+
def encode(self, text, **kwargs):
|
|
309
|
+
return super().encode(self._preprocess_text(text), **kwargs)
|
|
310
|
+
|
|
311
|
+
def encode_batch(self, texts, **kwargs):
|
|
312
|
+
return super().encode_batch([self._preprocess_text(t) for t in texts], **kwargs)
|
|
313
|
+
|
|
314
|
+
def decode(self, *args, **kwargs):
|
|
315
|
+
return self._postprocess_text(super().decode(*args, **kwargs))
|
|
316
|
+
|
|
317
|
+
def batch_decode(self, *args, **kwargs):
|
|
318
|
+
decoded = super().batch_decode(*args, **kwargs)
|
|
319
|
+
return [self._postprocess_text(d) for d in decoded]
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
AutoTokenizer.register("NewlineTokenizer", fast_tokenizer_class=NewlineTokenizer)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def _match(a, b):
|
|
326
|
+
if type(a) != type(b):
|
|
327
|
+
return False
|
|
328
|
+
if isinstance(a, dict):
|
|
329
|
+
return len(a) == len(b) and all(k in b and _match(a[k], b[k]) for k in a)
|
|
330
|
+
if isinstance(a, list):
|
|
331
|
+
return len(a) == len(b) and all(_match(ai, bi) for ai, bi in zip(a, b))
|
|
332
|
+
|
|
333
|
+
return a == b
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def _is_spm_decoder(decoder):
|
|
337
|
+
_target_description = {
|
|
338
|
+
"type": "Sequence",
|
|
339
|
+
"decoders": [
|
|
340
|
+
{"type": "Replace", "pattern": {"String": "▁"}, "content": " "},
|
|
341
|
+
{"type": "ByteFallback"},
|
|
342
|
+
{"type": "Fuse"},
|
|
343
|
+
{"type": "Strip", "content": " ", "start": 1, "stop": 0},
|
|
344
|
+
],
|
|
345
|
+
}
|
|
346
|
+
return _match(_target_description, decoder)
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def _is_spm_decoder_no_space(decoder):
|
|
350
|
+
_target_description = {
|
|
351
|
+
"type": "Sequence",
|
|
352
|
+
"decoders": [
|
|
353
|
+
{"type": "Replace", "pattern": {"String": "▁"}, "content": " "},
|
|
354
|
+
{"type": "ByteFallback"},
|
|
355
|
+
{"type": "Fuse"},
|
|
356
|
+
],
|
|
357
|
+
}
|
|
358
|
+
return _match(_target_description, decoder)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _is_bpe_decoder(decoder):
|
|
362
|
+
return isinstance(decoder, dict) and decoder.get("type", None) == "ByteLevel"
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def load_tokenizer(
|
|
366
|
+
model_path, tokenizer_config_extra={}, return_tokenizer=True, eos_token_ids=None
|
|
367
|
+
):
|
|
368
|
+
"""Load a huggingface tokenizer and try to infer the type of streaming
|
|
369
|
+
detokenizer to use.
|
|
370
|
+
|
|
371
|
+
Note, to use a fast streaming tokenizer, pass a local file path rather than
|
|
372
|
+
a Hugging Face repo ID.
|
|
373
|
+
"""
|
|
374
|
+
detokenizer_class = NaiveStreamingDetokenizer
|
|
375
|
+
|
|
376
|
+
tokenizer_file = model_path / "tokenizer.json"
|
|
377
|
+
if tokenizer_file.exists():
|
|
378
|
+
with open(tokenizer_file, "r", encoding="utf-8") as fid:
|
|
379
|
+
try:
|
|
380
|
+
tokenizer_content = json.load(fid)
|
|
381
|
+
except JSONDecodeError as e:
|
|
382
|
+
raise JSONDecodeError("Failed to parse tokenizer.json", e.doc, e.pos)
|
|
383
|
+
|
|
384
|
+
if "decoder" in tokenizer_content:
|
|
385
|
+
if _is_spm_decoder(tokenizer_content["decoder"]):
|
|
386
|
+
detokenizer_class = SPMStreamingDetokenizer
|
|
387
|
+
elif _is_spm_decoder_no_space(tokenizer_content["decoder"]):
|
|
388
|
+
detokenizer_class = partial(SPMStreamingDetokenizer, trim_space=False)
|
|
389
|
+
elif _is_bpe_decoder(tokenizer_content["decoder"]):
|
|
390
|
+
detokenizer_class = BPEStreamingDetokenizer
|
|
391
|
+
|
|
392
|
+
if isinstance(eos_token_ids, int):
|
|
393
|
+
eos_token_ids = [eos_token_ids]
|
|
394
|
+
|
|
395
|
+
if return_tokenizer:
|
|
396
|
+
return TokenizerWrapper(
|
|
397
|
+
AutoTokenizer.from_pretrained(model_path, **tokenizer_config_extra),
|
|
398
|
+
detokenizer_class,
|
|
399
|
+
eos_token_ids=eos_token_ids,
|
|
400
|
+
)
|
|
401
|
+
else:
|
|
402
|
+
return detokenizer_class
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
def no_bos_or_eos(sequence: List, bos: int, eos: int) -> List:
|
|
406
|
+
removed_bos = sequence if sequence[0] != bos else sequence[1:]
|
|
407
|
+
return removed_bos[:-1] if removed_bos[-1] == eos else removed_bos
|