mkurman commited on
Commit
e689d6b
·
verified ·
1 Parent(s): b9847e3

Upload 9 files

Browse files
__init__.py ADDED
File without changes
chat_template.jinja ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% for message in messages %}
2
+ {% if message['role'] == 'assistant' %}
3
+ {{ '<|im_start|>assistant\n' }}
4
+ {% generation %}
5
+ {{ message['content'] }}
6
+ {% endgeneration %}
7
+ {{ '<|im_end|>' }}
8
+ {% else %}
9
+ {{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>'}}
10
+ {% endif %}
11
+ {% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}
config.json ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "NeuroBLASTForCausalLM"
4
+ ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_neuroblast.NeuroBLASTConfig",
7
+ "AutoModelForCausalLM": "modeling_neuroblast.NeuroBLASTForCausalLM"
8
+ },
9
+ "attention_bias": false,
10
+ "attention_dropout": 0.0,
11
+ "attention_every": 0,
12
+ "dropout": 0.0,
13
+ "dtype": "float32",
14
+ "hidden_act": "silu",
15
+ "hidden_size": 512,
16
+ "initializer_range": 0.02,
17
+ "intermediate_size": 3072,
18
+ "kernel_size": 5,
19
+ "layer_types": [
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention",
52
+ "full_attention",
53
+ "full_attention",
54
+ "full_attention",
55
+ "full_attention",
56
+ "full_attention",
57
+ "full_attention",
58
+ "full_attention",
59
+ "full_attention",
60
+ "full_attention",
61
+ "full_attention",
62
+ "full_attention",
63
+ "full_attention",
64
+ "full_attention",
65
+ "full_attention",
66
+ "full_attention",
67
+ "full_attention",
68
+ "full_attention",
69
+ "full_attention",
70
+ "full_attention",
71
+ "full_attention",
72
+ "full_attention",
73
+ "full_attention",
74
+ "full_attention",
75
+ "full_attention",
76
+ "full_attention",
77
+ "full_attention",
78
+ "full_attention",
79
+ "full_attention",
80
+ "full_attention",
81
+ "full_attention",
82
+ "full_attention",
83
+ "full_attention",
84
+ "full_attention",
85
+ "full_attention",
86
+ "full_attention",
87
+ "full_attention",
88
+ "full_attention",
89
+ "full_attention",
90
+ "full_attention",
91
+ "full_attention"
92
+ ],
93
+ "max_position_embeddings": 32768,
94
+ "model_type": "neuroblast",
95
+ "num_associative_layers": 32,
96
+ "num_attention_heads": 16,
97
+ "num_hidden_layers": 72,
98
+ "num_key_value_heads": 8,
99
+ "num_motor_layers": 16,
100
+ "num_sensory_layers": 24,
101
+ "pad_token_id": 65537,
102
+ "rms_norm_eps": 1e-06,
103
+ "rope_scaling": null,
104
+ "rope_theta": 10000.0,
105
+ "scale": 1.0,
106
+ "sliding_window": null,
107
+ "temporal_kernel_size": 5,
108
+ "tie_word_embeddings": false,
109
+ "transformers_version": "4.57.1",
110
+ "use_cache": true,
111
+ "use_sliding_window": false,
112
+ "vocab_size": 65538
113
+ }
configuration_neuroblast_jax.py ADDED
@@ -0,0 +1,322 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """NeuroBLASTConfig model configuration"""
16
+
17
+ from transformers.configuration_utils import PretrainedConfig
18
+ from transformers.utils import logging
19
+
20
+ logger = logging.get_logger(__name__)
21
+
22
+
23
+ class NeuroBLASTConfig(PretrainedConfig):
24
+ r"""
25
+ This is the configuration class to store the configuration of a [`Qwen3Model`]. It is used to instantiate a
26
+ Qwen3 model according to the specified arguments, defining the model architecture. Instantiating a configuration
27
+ with the defaults will yield a similar configuration to that of
28
+ Qwen3-8B [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B).
29
+
30
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
31
+ documentation from [`PretrainedConfig`] for more information.
32
+
33
+
34
+ Args:
35
+ vocab_size (`int`, *optional*, defaults to 151936):
36
+ Vocabulary size of the Qwen3 model. Defines the number of different tokens that can be represented by the
37
+ `inputs_ids` passed when calling [`Qwen3Model`]
38
+ hidden_size (`int`, *optional*, defaults to 4096):
39
+ Dimension of the hidden representations.
40
+ intermediate_size (`int`, *optional*, defaults to 22016):
41
+ Dimension of the MLP representations.
42
+ num_hidden_layers (`int`, *optional*, defaults to 32):
43
+ Number of hidden layers in the Transformer encoder.
44
+ num_attention_heads (`int`, *optional*, defaults to 32):
45
+ Number of attention heads for each attention layer in the Transformer encoder.
46
+ num_key_value_heads (`int`, *optional*, defaults to 32):
47
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
48
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
49
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
50
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
51
+ by meanpooling all the original heads within that group. For more details, check out [this
52
+ paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to `32`.
53
+ head_dim (`int`, *optional*, defaults to 128):
54
+ The attention head dimension.
55
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
56
+ The non-linear activation function (function or string) in the decoder.
57
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
58
+ The maximum sequence length that this model might ever be used with.
59
+ initializer_range (`float`, *optional*, defaults to 0.02):
60
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
61
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
62
+ The epsilon used by the rms normalization layers.
63
+ use_cache (`bool`, *optional*, defaults to `True`):
64
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
65
+ relevant if `config.is_decoder=True`.
66
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
67
+ Whether the model's input and output word embeddings should be tied.
68
+ rope_theta (`float`, *optional*, defaults to 10000.0):
69
+ The base period of the RoPE embeddings.
70
+ rope_scaling (`Dict`, *optional*):
71
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
72
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
73
+ accordingly.
74
+ Expected contents:
75
+ `rope_type` (`str`):
76
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
77
+ 'llama3'], with 'default' being the original RoPE implementation.
78
+ `factor` (`float`, *optional*):
79
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
80
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
81
+ original maximum pre-trained length.
82
+ `original_max_position_embeddings` (`int`, *optional*):
83
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
84
+ pretraining.
85
+ `attention_factor` (`float`, *optional*):
86
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
87
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
88
+ `factor` field to infer the suggested value.
89
+ `beta_fast` (`float`, *optional*):
90
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
91
+ ramp function. If unspecified, it defaults to 32.
92
+ `beta_slow` (`float`, *optional*):
93
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
94
+ ramp function. If unspecified, it defaults to 1.
95
+ `short_factor` (`list[float]`, *optional*):
96
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
97
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
98
+ size divided by the number of attention heads divided by 2
99
+ `long_factor` (`list[float]`, *optional*):
100
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
101
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
102
+ size divided by the number of attention heads divided by 2
103
+ `low_freq_factor` (`float`, *optional*):
104
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
105
+ `high_freq_factor` (`float`, *optional*):
106
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
107
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
108
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
109
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
110
+ Whether to use sliding window attention.
111
+ sliding_window (`int`, *optional*, defaults to 4096):
112
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
113
+ max_window_layers (`int`, *optional*, defaults to 28):
114
+ The number of layers using full attention. The first `max_window_layers` layers will use full attention, while any
115
+ additional layer afterwards will use SWA (Sliding Window Attention).
116
+ layer_types (`list`, *optional*):
117
+ Attention pattern for each layer.
118
+ attention_dropout (`float`, *optional*, defaults to 0.0):
119
+ The dropout ratio for the attention probabilities.
120
+
121
+ ```python
122
+ >>> from transformers import Qwen3Model, Qwen3Config
123
+
124
+ >>> # Initializing a Qwen3 style configuration
125
+ >>> configuration = Qwen3Config()
126
+
127
+ >>> # Initializing a model from the Qwen3-8B style configuration
128
+ >>> model = Qwen3Model(configuration)
129
+
130
+ >>> # Accessing the model configuration
131
+ >>> configuration = model.config
132
+ ```"""
133
+
134
+ model_type = "frankqwenstein"
135
+ keys_to_ignore_at_inference = ["past_key_values"]
136
+
137
+ # Default tensor parallel plan for base model `Qwen3`
138
+ base_model_tp_plan = {
139
+ "layers.*.self_attn.q_proj": "colwise",
140
+ "layers.*.self_attn.k_proj": "colwise",
141
+ "layers.*.self_attn.v_proj": "colwise",
142
+ "layers.*.self_attn.o_proj": "rowwise",
143
+ "layers.*.mlp.gate_proj": "colwise",
144
+ "layers.*.mlp.up_proj": "colwise",
145
+ "layers.*.mlp.down_proj": "rowwise",
146
+ }
147
+ base_model_pp_plan = {
148
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
149
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
150
+ "norm": (["hidden_states"], ["hidden_states"]),
151
+ }
152
+
153
+ def __init__(
154
+ self,
155
+ vocab_size=151936,
156
+ hidden_size=4096,
157
+ energy_dim=128,
158
+ intermediate_size=22016,
159
+ num_hidden_layers=32,
160
+ num_associative_layers=16,
161
+ num_sensory_layers=8,
162
+ num_motor_layers=8,
163
+ num_attention_heads=32,
164
+ num_key_value_heads=32,
165
+ head_dim=128,
166
+ hidden_act="silu",
167
+ max_position_embeddings=32768,
168
+ initializer_range=0.02,
169
+ rms_norm_eps=1e-6,
170
+ use_cache=True,
171
+ tie_word_embeddings=False,
172
+ rope_theta=10000.0,
173
+ rope_scaling=None,
174
+ attention_bias=False,
175
+ use_sliding_window=False,
176
+ sliding_window=4096,
177
+ max_window_layers=28,
178
+ layer_types=None,
179
+ attention_dropout=0.0,
180
+ attention_every=0,
181
+ moe_topk=1,
182
+ moe_experts=1,
183
+ scale=1.0,
184
+ chunk_height=1,
185
+ chunk_top_k=2,
186
+ kernel_size=5,
187
+ temporal_kernel_size=5, # New parameter for temporal convolution kernel size
188
+ dropout=0.0,
189
+ attn_dropout=0.0,
190
+ num_blocks=3,
191
+ conv_stride=1, # New parameter for convolution stride
192
+ yarn_original_max_position_embeddings=8192, # Original max position for YaRN
193
+ yarn_extrapolation_factor=1.0, # YaRN extrapolation factor
194
+ yarn_attention_factor=1.0, # YaRN attention factor
195
+ yarn_beta_fast=32, # YaRN beta fast parameter
196
+ yarn_beta_slow=1, # YaRN beta slow parameter
197
+ bidirectional_training=False, # Enable bidirectional token prediction training
198
+ # Standard MoE parameters
199
+ use_moe=False,
200
+ num_experts=8,
201
+ num_experts_per_tok=2,
202
+ moe_intermediate_size=2048,
203
+ norm_topk_prob=True,
204
+ # Optimization parameters
205
+ capacity_factor=1.25,
206
+ eval_capacity_factor=2.0,
207
+ load_balancing_loss_coef=0.01,
208
+ expert_dropout=0.1,
209
+ routing_noise_std=0.1,
210
+ # Advanced features
211
+ num_gate_heads=1,
212
+ gating_strategy="standard",
213
+ expert_parallel=False,
214
+ track_expert_usage=True,
215
+ # Hierarchical MoE
216
+ num_expert_groups=4,
217
+ use_silu_after_blocks=False,
218
+ query_feature_map: str = "relu_squared",
219
+ kv_feature_map: str = "softplus",
220
+ **kwargs,
221
+ ):
222
+ self.vocab_size = vocab_size
223
+ self.max_position_embeddings = max_position_embeddings
224
+ self.hidden_size = hidden_size
225
+ self.energy_dim = energy_dim
226
+ self.intermediate_size = intermediate_size
227
+ self.num_hidden_layers = num_hidden_layers
228
+
229
+ self.num_associative_layers = num_associative_layers
230
+ self.num_sensory_layers = num_sensory_layers
231
+
232
+ self.num_motor_layers = num_motor_layers
233
+
234
+ if (
235
+ num_hidden_layers
236
+ != num_associative_layers + num_sensory_layers + num_motor_layers
237
+ ):
238
+ self.num_hidden_layers = (
239
+ num_associative_layers + num_sensory_layers + num_motor_layers
240
+ )
241
+ self.num_attention_heads = num_attention_heads
242
+ self.use_sliding_window = use_sliding_window
243
+ self.sliding_window = sliding_window if self.use_sliding_window else None
244
+ self.max_window_layers = max_window_layers
245
+
246
+ # for backward compatibility
247
+ if num_key_value_heads is None:
248
+ num_key_value_heads = num_attention_heads
249
+
250
+ self.num_key_value_heads = num_key_value_heads
251
+ self.head_dim = head_dim
252
+ self.hidden_act = hidden_act
253
+ self.initializer_range = initializer_range
254
+ self.rms_norm_eps = rms_norm_eps
255
+ self.use_cache = use_cache
256
+ self.rope_theta = rope_theta
257
+ self.rope_scaling = rope_scaling
258
+ self.attention_bias = attention_bias
259
+ self.attention_dropout = attention_dropout
260
+ self.attention_every = attention_every
261
+ self.scale = scale
262
+ self.chunk_height = chunk_height
263
+ self.chunk_top_k = chunk_top_k
264
+ self.kernel_size = kernel_size
265
+ self.temporal_kernel_size = temporal_kernel_size
266
+ self.num_blocks = num_blocks
267
+ self.dropout = dropout
268
+ self.attn_dropout = attn_dropout
269
+ self.conv_stride = conv_stride
270
+ self.yarn_original_max_position_embeddings = (
271
+ yarn_original_max_position_embeddings
272
+ )
273
+ self.yarn_extrapolation_factor = yarn_extrapolation_factor
274
+ self.yarn_attention_factor = yarn_attention_factor
275
+ self.yarn_beta_fast = yarn_beta_fast
276
+ self.yarn_beta_slow = yarn_beta_slow
277
+ self.bidirectional_training = bidirectional_training
278
+ self.moe_topk = moe_topk
279
+ self.moe_experts = moe_experts
280
+
281
+ self.use_moe = use_moe
282
+ self.num_experts = num_experts
283
+ self.num_experts_per_tok = num_experts_per_tok
284
+ self.moe_intermediate_size = moe_intermediate_size
285
+ self.norm_topk_prob = norm_topk_prob
286
+
287
+ # Optimization parameters
288
+ self.capacity_factor = capacity_factor
289
+ self.eval_capacity_factor = eval_capacity_factor
290
+ self.load_balancing_loss_coef = load_balancing_loss_coef
291
+ self.expert_dropout = expert_dropout
292
+ self.routing_noise_std = routing_noise_std
293
+
294
+ # Advanced features
295
+ self.num_gate_heads = num_gate_heads
296
+ self.gating_strategy = gating_strategy
297
+ self.expert_parallel = expert_parallel
298
+ self.track_expert_usage = track_expert_usage
299
+ self.use_silu_after_blocks = use_silu_after_blocks
300
+
301
+ # Hierarchical MoE
302
+ self.num_expert_groups = num_expert_groups
303
+
304
+ # Linear Attention Feature Maps
305
+ self.query_feature_map = query_feature_map
306
+ self.kv_feature_map = kv_feature_map
307
+
308
+ # Validate the correctness of rotary position embeddings parameters
309
+ # BC: if there is a 'type' field, move it to 'rope_type'.
310
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
311
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
312
+
313
+ self.layer_types = layer_types
314
+ if self.layer_types is None:
315
+ self.layer_types = [
316
+ ("full_attention") for i in range(self.num_hidden_layers)
317
+ ]
318
+
319
+ super().__init__(
320
+ tie_word_embeddings=tie_word_embeddings,
321
+ **kwargs,
322
+ )
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8d85fd3448ffeb9bce6bea7672865f6cec4e0e224400a1c38de97199c8359dd7
3
+ size 2386809408
modeling_neuroblast_jax.py ADDED
@@ -0,0 +1,691 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ from typing import Optional, Tuple, Any, Callable
3
+
4
+ import jax
5
+ import jax.numpy as jnp
6
+ from flax import linen as nn
7
+ from flax.core.frozen_dict import FrozenDict
8
+ from flax.linen.attention import dot_product_attention
9
+ from flax.traverse_util import flatten_dict, unflatten_dict
10
+ from transformers.modeling_flax_utils import FlaxPreTrainedModel
11
+ from transformers.utils import logging
12
+
13
+ from .configuration_neuroblast_jax import NeuroBLASTConfig
14
+
15
+ logger = logging.get_logger(__name__)
16
+
17
+
18
+ class NeuroBLASTRMSNorm(nn.Module):
19
+ hidden_size: int = 0
20
+ eps: float = 1e-6
21
+ dtype: Any = jnp.float32
22
+
23
+ def setup(self):
24
+ self.weight = self.param(
25
+ "weight",
26
+ lambda rng, shape: jnp.ones(shape, dtype=self.dtype),
27
+ (self.hidden_size,),
28
+ )
29
+
30
+ def __call__(self, hidden_states):
31
+ variance = jnp.mean(jnp.square(hidden_states), axis=-1, keepdims=True)
32
+ hidden_states = hidden_states * jax.lax.rsqrt(variance + self.eps)
33
+ return self.weight * hidden_states
34
+
35
+
36
+ class NeuroBLASTMLP(nn.Module):
37
+ config: Optional[NeuroBLASTConfig] = None
38
+ dtype: Any = jnp.float32
39
+
40
+ def setup(self):
41
+ self.hidden_size = self.config.hidden_size
42
+ self.intermediate_size = self.config.intermediate_size
43
+
44
+ self.gate_proj = nn.Dense(self.intermediate_size, use_bias=False, dtype=self.dtype)
45
+ self.up_proj = nn.Dense(self.intermediate_size, use_bias=False, dtype=self.dtype)
46
+ self.down_proj = nn.Dense(self.hidden_size, use_bias=False, dtype=self.dtype)
47
+
48
+ # Activation function
49
+ if self.config.hidden_act == "silu":
50
+ self.act_fn = nn.silu
51
+ elif self.config.hidden_act == "gelu":
52
+ self.act_fn = nn.gelu
53
+ elif self.config.hidden_act == "relu":
54
+ self.act_fn = nn.relu
55
+ else:
56
+ raise ValueError(f"Unsupported activation: {self.config.hidden_act}")
57
+
58
+ def __call__(self, x):
59
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
60
+
61
+
62
+ def rotate_half(x):
63
+ x1 = x[..., : x.shape[-1] // 2]
64
+ x2 = x[..., x.shape[-1] // 2 :]
65
+ return jnp.concatenate((-x2, x1), axis=-1)
66
+
67
+
68
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None):
69
+
70
+ q_embed = (q * cos) + (rotate_half(q) * sin)
71
+ k_embed = (k * cos) + (rotate_half(k) * sin)
72
+ return q_embed, k_embed
73
+
74
+
75
+ class NeuroBLASTAttention(nn.Module):
76
+ config: Optional[NeuroBLASTConfig] = None
77
+ layer_idx: int = 0
78
+ use_rope: bool = True
79
+ dtype: Any = jnp.float32
80
+
81
+ def setup(self):
82
+ self.hidden_size = self.config.hidden_size
83
+ self.num_heads = self.config.num_attention_heads
84
+ self.head_dim = getattr(
85
+ self.config, "head_dim", self.hidden_size // self.num_heads
86
+ )
87
+ self.num_key_value_heads = self.config.num_key_value_heads
88
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
89
+ self.scaling = self.head_dim**-0.5
90
+ self.attn_output_dim = self.num_heads * self.head_dim
91
+
92
+ self.q_proj = nn.Dense(
93
+ self.attn_output_dim,
94
+ use_bias=self.config.attention_bias,
95
+ dtype=self.dtype
96
+ )
97
+ self.k_proj = nn.Dense(
98
+ self.num_key_value_heads * self.head_dim,
99
+ use_bias=self.config.attention_bias,
100
+ dtype=self.dtype
101
+ )
102
+ self.v_proj = nn.Dense(
103
+ self.num_key_value_heads * self.head_dim,
104
+ use_bias=self.config.attention_bias,
105
+ dtype=self.dtype
106
+ )
107
+ self.o_proj = nn.Dense(
108
+ self.hidden_size,
109
+ use_bias=self.config.attention_bias,
110
+ dtype=self.dtype
111
+ )
112
+
113
+ self.q_norm = NeuroBLASTRMSNorm(self.head_dim, eps=self.config.rms_norm_eps, dtype=self.dtype)
114
+ self.k_norm = NeuroBLASTRMSNorm(self.head_dim, eps=self.config.rms_norm_eps, dtype=self.dtype)
115
+
116
+ def __call__(
117
+ self,
118
+ hidden_states,
119
+ attention_mask=None,
120
+ position_embeddings=None,
121
+ deterministic: bool = True,
122
+ ):
123
+ batch_size, seq_len, _ = hidden_states.shape
124
+
125
+ # Projection
126
+ query_states = self.q_proj(hidden_states)
127
+ key_states = self.k_proj(hidden_states)
128
+ value_states = self.v_proj(hidden_states)
129
+
130
+ # Reshape
131
+ query_states = query_states.reshape(batch_size, seq_len, self.num_heads, self.head_dim)
132
+ key_states = key_states.reshape(batch_size, seq_len, self.num_key_value_heads, self.head_dim)
133
+ value_states = value_states.reshape(batch_size, seq_len, self.num_key_value_heads, self.head_dim)
134
+
135
+ # Norm
136
+ query_states = self.q_norm(query_states)
137
+ key_states = self.k_norm(key_states)
138
+
139
+ # RoPE
140
+ if self.use_rope and position_embeddings is not None:
141
+ cos, sin = position_embeddings
142
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
143
+
144
+ if self.num_key_value_groups > 1:
145
+ key_states = jnp.repeat(key_states, self.num_key_value_groups, axis=2)
146
+ value_states = jnp.repeat(value_states, self.num_key_value_groups, axis=2)
147
+
148
+ query_states = jnp.transpose(query_states, (0, 2, 1, 3))
149
+ key_states = jnp.transpose(key_states, (0, 2, 1, 3))
150
+ value_states = jnp.transpose(value_states, (0, 2, 1, 3))
151
+
152
+ scale = 1.0 / jnp.sqrt(self.head_dim)
153
+ attn_weights = jnp.einsum("...qd,...kd->...qk", query_states, key_states) * scale
154
+
155
+ if attention_mask is not None:
156
+ attn_weights = attn_weights + attention_mask
157
+
158
+ attn_weights = nn.softmax(attn_weights, axis=-1)
159
+
160
+ if self.config.attention_dropout > 0.0 and not deterministic:
161
+ attn_weights = nn.dropout(
162
+ nn.make_rng(),
163
+ attn_weights,
164
+ deterministic=deterministic,
165
+ rate=self.config.attention_dropout
166
+ )
167
+
168
+ attn_output = jnp.einsum("...qk,...kd->...qd", attn_weights, value_states)
169
+
170
+ attn_output = jnp.transpose(attn_output, (0, 2, 1, 3))
171
+ attn_output = attn_output.reshape(batch_size, seq_len, self.attn_output_dim)
172
+
173
+ attn_output = self.o_proj(attn_output)
174
+
175
+ return attn_output
176
+
177
+
178
+
179
+ class NeuroBLASTRMSNorm2d(nn.Module):
180
+ dim: int = 0
181
+ eps: float = 1e-6
182
+ dtype: Any = jnp.float32
183
+
184
+ def setup(self):
185
+ self.weight = self.param(
186
+ "weight",
187
+ lambda rng, shape: jnp.ones(shape, dtype=self.dtype),
188
+ (self.dim,),
189
+ )
190
+
191
+ def __call__(self, x):
192
+ variance = jnp.mean(jnp.square(x), axis=-1, keepdims=True)
193
+ x_norm = x * jax.lax.rsqrt(variance + self.eps)
194
+ return self.weight * x_norm
195
+
196
+
197
+ class NeuroBLASTCausalConv2DBlock(nn.Module):
198
+ config: Optional[NeuroBLASTConfig] = None
199
+ dilation: int = 1
200
+ layer_idx: int = 0
201
+ dtype: Any = jnp.float32
202
+
203
+ def setup(self):
204
+ k = self.config.kernel_size
205
+ d = self.config.hidden_size
206
+ s = self.config.scale
207
+
208
+ if s == 1:
209
+ self.conv = nn.Conv(
210
+ features=d,
211
+ kernel_size=(k, k),
212
+ kernel_dilation=(1, self.dilation),
213
+ padding=(k // 2, 0),
214
+ use_bias=False,
215
+ dtype=self.dtype,
216
+ )
217
+ self.use_gating = False
218
+ self.use_projection = False
219
+ elif s > 1:
220
+ internal_dim = int(d * s)
221
+ self.conv = nn.Conv(
222
+ features=internal_dim,
223
+ kernel_size=(k, k),
224
+ kernel_dilation=(1, self.dilation),
225
+ padding=(k // 2, 0),
226
+ use_bias=False,
227
+ dtype=self.dtype,
228
+ )
229
+ self.use_gating = True
230
+ self.use_projection = False
231
+ else:
232
+ internal_dim = max(int(d * s), d // 4)
233
+ self.conv = nn.Conv(
234
+ features=internal_dim,
235
+ kernel_size=(k, k),
236
+ kernel_dilation=(1, self.dilation),
237
+ padding=(k // 2, 0),
238
+ use_bias=False,
239
+ dtype=self.dtype,
240
+ )
241
+ self.use_gating = False
242
+ self.use_projection = True
243
+ self.proj_back = nn.Conv(features=d, kernel_size=(1, 1), use_bias=False, dtype=self.dtype)
244
+
245
+ self.norm_in = NeuroBLASTRMSNorm2d(d, eps=self.config.rms_norm_eps, dtype=self.dtype)
246
+ self.norm_out = NeuroBLASTRMSNorm2d(d, eps=self.config.rms_norm_eps, dtype=self.dtype)
247
+ self.dropout = nn.Dropout(self.config.dropout)
248
+
249
+ def __call__(self, x, deterministic: bool = True):
250
+ B, H, W, C = x.shape # Store original W for cropping!
251
+ residual = x
252
+ y = self.norm_in(x)
253
+
254
+ k = self.config.kernel_size
255
+ pad_w = (k - 1) * self.dilation
256
+
257
+ y_pad = jnp.pad(y, ((0, 0), (0, 0), (pad_w, 0), (0, 0)), mode='constant')
258
+
259
+ y = self.conv(y_pad)
260
+
261
+ y = y[:, :, -W:, :]
262
+
263
+ if self.use_gating:
264
+ gate, val = jnp.split(y, 2, axis=-1)
265
+ y = val * nn.softmax(gate, axis=-1)
266
+ elif self.use_projection:
267
+ y = self.proj_back(y)
268
+
269
+ y = self.norm_out(y)
270
+
271
+ x = residual + self.dropout(y, deterministic=deterministic)
272
+ return x
273
+
274
+
275
+ class NeuroBLASTDecoderLayer(nn.Module):
276
+ config: Optional[NeuroBLASTConfig] = None
277
+ layer_idx: int = 0
278
+ attention_type: str = "full_attention"
279
+ dtype: Any = jnp.float32
280
+
281
+ def setup(self):
282
+ self.hidden_size = self.config.hidden_size
283
+
284
+ if self.attention_type == "linear_attention":
285
+ self.self_attn = NeuroBLASTLinearAttention(
286
+ config=self.config,
287
+ layer_idx=self.layer_idx,
288
+ query_feature_map_name=self.config.query_feature_map,
289
+ kv_feature_map_name=self.config.kv_feature_map,
290
+ dtype=self.dtype,
291
+ )
292
+ else:
293
+ self.self_attn = NeuroBLASTAttention(
294
+ config=self.config,
295
+ layer_idx=self.layer_idx,
296
+ use_rope=(self.attention_type != "no_rope"),
297
+ dtype=self.dtype,
298
+ )
299
+
300
+ self.mlp = NeuroBLASTMLP(self.config, dtype=self.dtype)
301
+ self.input_layernorm = NeuroBLASTRMSNorm(self.hidden_size, eps=self.config.rms_norm_eps, dtype=self.dtype)
302
+ self.post_attention_layernorm = NeuroBLASTRMSNorm(self.hidden_size, eps=self.config.rms_norm_eps, dtype=self.dtype)
303
+
304
+ def __call__(
305
+ self,
306
+ hidden_states,
307
+ attention_mask=None,
308
+ position_embeddings=None,
309
+ deterministic: bool = True,
310
+ ):
311
+ residual = hidden_states
312
+ hidden_states = self.input_layernorm(hidden_states)
313
+
314
+ hidden_states = self.self_attn(
315
+ hidden_states,
316
+ attention_mask=attention_mask,
317
+ position_embeddings=position_embeddings,
318
+ deterministic=deterministic,
319
+ )
320
+
321
+ hidden_states = residual + hidden_states
322
+
323
+ residual = hidden_states
324
+ hidden_states = self.post_attention_layernorm(hidden_states)
325
+ hidden_states = self.mlp(hidden_states)
326
+ hidden_states = residual + hidden_states
327
+
328
+ return hidden_states
329
+
330
+
331
+ class NeuroBLASTToken2D(nn.Module):
332
+ dtype: Any = jnp.float32
333
+
334
+ def __call__(self, x, mode="seq_to_2d"):
335
+ if mode == "seq_to_2d":
336
+ # x: (B, L, C) → (B, H, W, C) where H=1, W=L
337
+ # PyTorch: x.view(B, L, 1, C).permute(0, 3, 2, 1) → (B, C, 1, L)
338
+ # In Flax channels-last: (B, H=1, W=L, C)
339
+ B, L, C = x.shape
340
+ x = x.reshape(B, 1, L, C) # (B, H=1, W=L, C)
341
+ return x
342
+ else:
343
+ # x: (B, H, W, C) → (B, L, C) where L = W*H
344
+ # PyTorch: x.permute(0, 3, 2, 1).view(B, W * H, C)
345
+ # Permute (B,C,H,W) → (B,W,H,C), then flatten to (B,W*H,C)
346
+ # This means W varies first (causal ordering)
347
+ #
348
+ # Flax: transpose (B, H, W, C) → (B, W, H, C), then flatten
349
+ B, H, W, C = x.shape
350
+ x = x.transpose(0, 2, 1, 3) # (B, H, W, C) → (B, W, H, C)
351
+ x = x.reshape(B, W * H, C) # (B, W, H, C) → (B, W*H, C)
352
+ return x
353
+
354
+
355
+ class NeuroBLASTRotaryEmbedding(nn.Module):
356
+ config: Optional[NeuroBLASTConfig] = None
357
+ dtype: Any = jnp.float32
358
+
359
+ def setup(self):
360
+ self.dim = self.config.head_dim
361
+ self.max_position_embeddings = self.config.max_position_embeddings
362
+ self.base = self.config.rope_theta
363
+
364
+ # Precompute freqs
365
+ inv_freq = 1.0 / (self.base ** (jnp.arange(0, self.dim, 2, dtype=jnp.float32) / self.dim))
366
+ self.inv_freq = inv_freq
367
+
368
+ def __call__(self, x, position_ids):
369
+ # x: (B, L, H, D)
370
+ # position_ids: (B, L) or (1, L)
371
+
372
+ inv_freq_expanded = self.inv_freq[None, :, None] # (1, D/2, 1)
373
+
374
+ # position_ids: (B, L)
375
+ # We want (B, L, D/2)
376
+
377
+ position_ids_expanded = position_ids[:, :, None] # (B, L, 1)
378
+
379
+ # freqs: (B, L, D/2)
380
+ freqs = jnp.matmul(position_ids_expanded.astype(jnp.float32), self.inv_freq[None, None, :])
381
+
382
+ # emb: (B, L, D)
383
+ emb = jnp.concatenate((freqs, freqs), axis=-1)
384
+
385
+ cos = jnp.cos(emb)
386
+ sin = jnp.sin(emb)
387
+
388
+ # Expand for heads: (B, L, 1, D)
389
+ cos = cos[:, :, None, :]
390
+ sin = sin[:, :, None, :]
391
+
392
+ return cos, sin
393
+
394
+
395
+ class NeuroBLASTModel(nn.Module):
396
+ config: Optional[NeuroBLASTConfig] = None
397
+ dtype: Any = jnp.float32
398
+
399
+ def setup(self):
400
+ self.embed_tokens = nn.Embed(
401
+ self.config.vocab_size,
402
+ self.config.hidden_size,
403
+ embedding_init=jax.nn.initializers.normal(stddev=self.config.initializer_range),
404
+ dtype=self.dtype,
405
+ )
406
+
407
+ self.token2d = NeuroBLASTToken2D(dtype=self.dtype)
408
+
409
+ sensory_layers = []
410
+ dilatation_step = 1
411
+ for i in range(self.config.num_sensory_layers):
412
+ if i % 2 == 0:
413
+ layer = NeuroBLASTDecoderLayer(
414
+ self.config, layer_idx=i, attention_type="full_attention", dtype=self.dtype, name=f"sensory_layers_{i}"
415
+ )
416
+ else:
417
+ dilation = min(2 ** ((i - 1) // dilatation_step), 8)
418
+ layer = NeuroBLASTCausalConv2DBlock(
419
+ self.config, dilation=dilation, layer_idx=i, dtype=self.dtype, name=f"sensory_layers_{i}"
420
+ )
421
+ sensory_layers.append(layer)
422
+ self.sensory_layers = sensory_layers
423
+
424
+ self.sensory_to_associative = NeuroBLASTRMSNorm(self.config.hidden_size, eps=self.config.rms_norm_eps, dtype=self.dtype)
425
+
426
+ associative_layers = []
427
+ next_layer_type = "full_attention"
428
+ for i in range(self.config.num_associative_layers):
429
+ idx = i + self.config.num_sensory_layers
430
+ if i % 2 == 0:
431
+ layer = NeuroBLASTDecoderLayer(
432
+ self.config, layer_idx=idx, attention_type=next_layer_type, dtype=self.dtype, name=f"associative_layers_{i}"
433
+ )
434
+ if next_layer_type == "full_attention":
435
+ next_layer_type = "no_rope"
436
+ else:
437
+ next_layer_type = "full_attention"
438
+ else:
439
+ dilation = min(2 ** ((i - 1) // dilatation_step), 8)
440
+ layer = NeuroBLASTCausalConv2DBlock(
441
+ self.config, dilation=dilation, layer_idx=idx, dtype=self.dtype, name=f"associative_layers_{i}"
442
+ )
443
+ associative_layers.append(layer)
444
+ self.associative_layers = associative_layers
445
+
446
+ self.sensory_to_motor = NeuroBLASTRMSNorm(self.config.hidden_size, eps=self.config.rms_norm_eps, dtype=self.dtype)
447
+
448
+ motor_layers = []
449
+ next_layer_type = "full_attention"
450
+ for i in range(self.config.num_motor_layers):
451
+ idx = i + self.config.num_sensory_layers + self.config.num_associative_layers
452
+ layer = NeuroBLASTDecoderLayer(
453
+ self.config, layer_idx=idx, attention_type=next_layer_type, dtype=self.dtype, name=f"motor_layers_{i}"
454
+ )
455
+ if next_layer_type == "full_attention":
456
+ next_layer_type = "no_rope"
457
+ else:
458
+ next_layer_type = "full_attention"
459
+ motor_layers.append(layer)
460
+ self.motor_layers = motor_layers
461
+
462
+ self.norm = NeuroBLASTRMSNorm(self.config.hidden_size, eps=self.config.rms_norm_eps, dtype=self.dtype)
463
+ self.rotary_emb = NeuroBLASTRotaryEmbedding(self.config, dtype=self.dtype)
464
+
465
+ def __call__(
466
+ self,
467
+ input_ids,
468
+ attention_mask=None,
469
+ position_ids=None,
470
+ deterministic: bool = True,
471
+ output_attentions: bool = False,
472
+ output_hidden_states: bool = False,
473
+ return_dict: bool = True,
474
+ ):
475
+ batch_size, seq_len = input_ids.shape
476
+
477
+ if position_ids is None:
478
+ position_ids = jnp.arange(seq_len, dtype="i4")[None, :]
479
+
480
+ # Create attention mask
481
+ if attention_mask is None:
482
+ attention_mask = jnp.ones((batch_size, seq_len), dtype="i4")
483
+
484
+ # Build a boolean mask that enforces both padding and causality, then turn it
485
+ # into an additive bias for the attention logits.
486
+ attention_mask_bool = attention_mask.astype(bool)
487
+ causal_mask = nn.make_causal_mask(attention_mask_bool)
488
+ padding_mask = nn.make_attention_mask(attention_mask_bool, attention_mask_bool)
489
+ combined_mask = nn.combine_masks(causal_mask, padding_mask)
490
+ attention_bias = jnp.where(
491
+ combined_mask,
492
+ jnp.array(0.0, dtype=self.dtype),
493
+ jnp.array(jnp.finfo(self.dtype).min, dtype=self.dtype),
494
+ )
495
+
496
+ # Embedding lookup
497
+ inputs_embeds = self.embed_tokens(input_ids)
498
+
499
+ # Zero out padding token embeddings (equivalent to PyTorch's padding_idx)
500
+ # attention_mask is (B, L) with 1 for real tokens, 0 for padding
501
+ # Expand to (B, L, 1) to broadcast across hidden_size dimension
502
+ embedding_mask = attention_mask[:, :, None].astype(inputs_embeds.dtype)
503
+ inputs_embeds = inputs_embeds * embedding_mask
504
+
505
+ hidden_states = inputs_embeds
506
+
507
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
508
+
509
+ all_hidden_states = () if output_hidden_states else None
510
+ all_attentions = () if output_attentions else None
511
+
512
+ residual = hidden_states
513
+
514
+ # Sensory
515
+ for i, layer in enumerate(self.sensory_layers):
516
+ if output_hidden_states:
517
+ all_hidden_states += (hidden_states,)
518
+
519
+ if i % 2 == 1:
520
+ hidden_states = self.token2d(hidden_states, mode="seq_to_2d")
521
+ hidden_states = layer(hidden_states, deterministic=deterministic)
522
+ hidden_states = self.token2d(hidden_states, mode="d2_to_seq")
523
+ else:
524
+ hidden_states = layer(
525
+ hidden_states,
526
+ attention_mask=attention_bias,
527
+ position_embeddings=position_embeddings,
528
+ deterministic=deterministic,
529
+ )
530
+
531
+ hidden_states = hidden_states + self.sensory_to_associative(nn.silu(residual))
532
+
533
+ # Associative
534
+ for i, layer in enumerate(self.associative_layers):
535
+ if output_hidden_states:
536
+ all_hidden_states += (hidden_states,)
537
+
538
+ if i % 2 == 1:
539
+ hidden_states = self.token2d(hidden_states, mode="seq_to_2d")
540
+ hidden_states = layer(hidden_states, deterministic=deterministic)
541
+ hidden_states = self.token2d(hidden_states, mode="d2_to_seq")
542
+ else:
543
+ hidden_states = layer(
544
+ hidden_states,
545
+ attention_mask=attention_bias,
546
+ position_embeddings=position_embeddings,
547
+ deterministic=deterministic,
548
+ )
549
+
550
+ hidden_states = hidden_states + self.sensory_to_motor(nn.silu(-residual))
551
+
552
+ # Motor
553
+ for i, layer in enumerate(self.motor_layers):
554
+ if output_hidden_states:
555
+ all_hidden_states += (hidden_states,)
556
+
557
+ hidden_states = layer(
558
+ hidden_states,
559
+ attention_mask=attention_bias,
560
+ position_embeddings=position_embeddings,
561
+ deterministic=deterministic,
562
+ )
563
+
564
+ hidden_states = self.norm(hidden_states)
565
+
566
+ if output_hidden_states:
567
+ all_hidden_states += (hidden_states,)
568
+
569
+ if not return_dict:
570
+ return tuple(v for v in [hidden_states, all_hidden_states, all_attentions] if v is not None)
571
+
572
+ return FlaxBaseModelOutput(
573
+ last_hidden_state=hidden_states,
574
+ hidden_states=all_hidden_states,
575
+ attentions=all_attentions,
576
+ )
577
+
578
+
579
+ class NeuroBLASTForCausalLMModule(nn.Module):
580
+ config: Optional[NeuroBLASTConfig] = None
581
+ dtype: Any = jnp.float32
582
+
583
+ def setup(self):
584
+ self.model = NeuroBLASTModel(self.config, dtype=self.dtype)
585
+ self.lm_head = nn.Dense(self.config.vocab_size, use_bias=False, dtype=self.dtype)
586
+
587
+ def __call__(
588
+ self,
589
+ input_ids,
590
+ attention_mask=None,
591
+ position_ids=None,
592
+ deterministic: bool = True,
593
+ output_attentions: bool = False,
594
+ output_hidden_states: bool = False,
595
+ return_dict: bool = True,
596
+ ):
597
+ outputs = self.model(
598
+ input_ids,
599
+ attention_mask=attention_mask,
600
+ position_ids=position_ids,
601
+ deterministic=deterministic,
602
+ output_attentions=output_attentions,
603
+ output_hidden_states=output_hidden_states,
604
+ return_dict=return_dict,
605
+ )
606
+
607
+ hidden_states = outputs[0] if not return_dict else outputs.last_hidden_state
608
+ logits = self.lm_head(hidden_states)
609
+
610
+ if not return_dict:
611
+ return (logits,) + outputs[1:]
612
+
613
+ return FlaxCausalLMOutput(
614
+ logits=logits,
615
+ hidden_states=outputs.hidden_states,
616
+ attentions=outputs.attentions,
617
+ )
618
+
619
+ class NeuroBLASTForCausalLM(FlaxPreTrainedModel):
620
+ module_class = NeuroBLASTForCausalLMModule
621
+ config_class = NeuroBLASTConfig
622
+
623
+ def __init__(
624
+ self,
625
+ config: NeuroBLASTConfig,
626
+ input_shape: Tuple = (1, 1),
627
+ seed: int = 0,
628
+ dtype: jnp.dtype = jnp.float32,
629
+ _do_init: bool = True,
630
+ **kwargs,
631
+ ):
632
+ module = NeuroBLASTForCausalLMModule(config=config, dtype=dtype, **kwargs)
633
+ super().__init__(config, module, input_shape=input_shape, seed=seed, dtype=dtype, _do_init=_do_init)
634
+
635
+ def init_weights(self, rng: jax.random.PRNGKey, input_shape: Tuple, params: FrozenDict = None) -> FrozenDict:
636
+ # init input tensors
637
+ input_ids = jnp.zeros(input_shape, dtype="i4")
638
+ attention_mask = jnp.ones_like(input_ids)
639
+ position_ids = jnp.broadcast_to(jnp.arange(jnp.atleast_2d(input_ids).shape[-1]), input_shape)
640
+ params_rng, dropout_rng = jax.random.split(rng)
641
+ rngs = {"params": params_rng, "dropout": dropout_rng}
642
+
643
+ module_init_outputs = self.module.init(rngs, input_ids, attention_mask, position_ids, return_dict=False)
644
+
645
+ random_params = module_init_outputs["params"]
646
+
647
+ if params is not None:
648
+ random_params = flatten_dict(unflatten_dict(random_params) | unflatten_dict(params))
649
+ return FrozenDict(random_params)
650
+ return random_params
651
+
652
+ def __call__(
653
+ self,
654
+ input_ids,
655
+ attention_mask=None,
656
+ position_ids=None,
657
+ params: dict = None,
658
+ dropout_rng: jax.random.PRNGKey = None,
659
+ train: bool = False,
660
+ output_attentions: bool = None,
661
+ output_hidden_states: bool = None,
662
+ return_dict: bool = None,
663
+ ):
664
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
665
+ output_hidden_states = (
666
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
667
+ )
668
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
669
+
670
+ if params is None:
671
+ params = self.params
672
+
673
+ rngs = {}
674
+ if dropout_rng is not None:
675
+ rngs["dropout"] = dropout_rng
676
+
677
+ return self.module.apply(
678
+ {"params": params or self.params},
679
+ input_ids=jnp.array(input_ids),
680
+ attention_mask=jnp.array(attention_mask) if attention_mask is not None else None,
681
+ position_ids=jnp.array(position_ids) if position_ids is not None else None,
682
+ deterministic=not train,
683
+ output_attentions=output_attentions,
684
+ output_hidden_states=output_hidden_states,
685
+ return_dict=return_dict,
686
+ rngs=rngs,
687
+ )
688
+
689
+ from transformers.modeling_flax_outputs import FlaxBaseModelOutput, FlaxCausalLMOutput
690
+
691
+
special_tokens_map.json ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<think>",
6
+ "</think>",
7
+ "source_1",
8
+ "source_2",
9
+ "source_3",
10
+ "source_4",
11
+ "source_5",
12
+ "source_6",
13
+ "source_7",
14
+ "source_8",
15
+ "source_9",
16
+ "source_10",
17
+ "<ref",
18
+ "</ref>",
19
+ "→",
20
+ "↺",
21
+ "※",
22
+ "?maybe?",
23
+ "●",
24
+ "◐",
25
+ "○",
26
+ "⚠",
27
+ "☐",
28
+ "☑",
29
+ "✓",
30
+ "⟨H≈0.1⟩",
31
+ "⟨H≈0.2⟩",
32
+ "⟨H≈0.3⟩",
33
+ "⟨H≈0.4⟩",
34
+ "⟨H≈0.5⟩",
35
+ "⟨H≈0.6⟩",
36
+ "⟨H≈0.7⟩",
37
+ "⟨H≈0.8⟩",
38
+ "⟨H≈0.9⟩",
39
+ "⟨H≈1.0⟩",
40
+ "⟨H≈1.1⟩",
41
+ "⟨H≈1.2⟩",
42
+ "⟨H≈1.3⟩",
43
+ "⟨H≈1.4⟩",
44
+ "⟨H≈1.5⟩",
45
+ "⟨H≈1.6⟩",
46
+ "⟨H≈1.7⟩",
47
+ "⟨H≈1.8⟩"
48
+ ],
49
+ "bos_token": {
50
+ "content": "<|im_start|>",
51
+ "lstrip": false,
52
+ "normalized": false,
53
+ "rstrip": false,
54
+ "single_word": false
55
+ },
56
+ "eos_token": {
57
+ "content": "<|im_end|>",
58
+ "lstrip": false,
59
+ "normalized": false,
60
+ "rstrip": false,
61
+ "single_word": false
62
+ },
63
+ "mask_token": {
64
+ "content": "<|mask|>",
65
+ "lstrip": false,
66
+ "normalized": false,
67
+ "rstrip": false,
68
+ "single_word": false
69
+ },
70
+ "pad_token": {
71
+ "content": "<|pad|>",
72
+ "lstrip": false,
73
+ "normalized": false,
74
+ "rstrip": false,
75
+ "single_word": false
76
+ }
77
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,474 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[UNK]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<|begin_of_text|>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "<|end_of_text|>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[PAD]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "65491": {
36
+ "content": "<|im_start|>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "65492": {
44
+ "content": "<|im_end|>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "65493": {
52
+ "content": "<think>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "65494": {
60
+ "content": "</think>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ },
67
+ "65495": {
68
+ "content": "source_1",
69
+ "lstrip": false,
70
+ "normalized": false,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": true
74
+ },
75
+ "65496": {
76
+ "content": "source_2",
77
+ "lstrip": false,
78
+ "normalized": false,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": true
82
+ },
83
+ "65497": {
84
+ "content": "source_3",
85
+ "lstrip": false,
86
+ "normalized": false,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": true
90
+ },
91
+ "65498": {
92
+ "content": "source_4",
93
+ "lstrip": false,
94
+ "normalized": false,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": true
98
+ },
99
+ "65499": {
100
+ "content": "source_5",
101
+ "lstrip": false,
102
+ "normalized": false,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": true
106
+ },
107
+ "65500": {
108
+ "content": "source_6",
109
+ "lstrip": false,
110
+ "normalized": false,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": true
114
+ },
115
+ "65501": {
116
+ "content": "source_7",
117
+ "lstrip": false,
118
+ "normalized": false,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": true
122
+ },
123
+ "65502": {
124
+ "content": "source_8",
125
+ "lstrip": false,
126
+ "normalized": false,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": true
130
+ },
131
+ "65503": {
132
+ "content": "source_9",
133
+ "lstrip": false,
134
+ "normalized": false,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": true
138
+ },
139
+ "65504": {
140
+ "content": "source_10",
141
+ "lstrip": false,
142
+ "normalized": false,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": true
146
+ },
147
+ "65505": {
148
+ "content": "<ref",
149
+ "lstrip": false,
150
+ "normalized": false,
151
+ "rstrip": false,
152
+ "single_word": false,
153
+ "special": true
154
+ },
155
+ "65506": {
156
+ "content": "</ref>",
157
+ "lstrip": false,
158
+ "normalized": false,
159
+ "rstrip": false,
160
+ "single_word": false,
161
+ "special": true
162
+ },
163
+ "65507": {
164
+ "content": "→",
165
+ "lstrip": false,
166
+ "normalized": false,
167
+ "rstrip": false,
168
+ "single_word": false,
169
+ "special": true
170
+ },
171
+ "65508": {
172
+ "content": "↺",
173
+ "lstrip": false,
174
+ "normalized": false,
175
+ "rstrip": false,
176
+ "single_word": false,
177
+ "special": true
178
+ },
179
+ "65509": {
180
+ "content": "※",
181
+ "lstrip": false,
182
+ "normalized": false,
183
+ "rstrip": false,
184
+ "single_word": false,
185
+ "special": true
186
+ },
187
+ "65510": {
188
+ "content": "?maybe?",
189
+ "lstrip": false,
190
+ "normalized": false,
191
+ "rstrip": false,
192
+ "single_word": false,
193
+ "special": true
194
+ },
195
+ "65511": {
196
+ "content": "●",
197
+ "lstrip": false,
198
+ "normalized": false,
199
+ "rstrip": false,
200
+ "single_word": false,
201
+ "special": true
202
+ },
203
+ "65512": {
204
+ "content": "◐",
205
+ "lstrip": false,
206
+ "normalized": false,
207
+ "rstrip": false,
208
+ "single_word": false,
209
+ "special": true
210
+ },
211
+ "65513": {
212
+ "content": "○",
213
+ "lstrip": false,
214
+ "normalized": false,
215
+ "rstrip": false,
216
+ "single_word": false,
217
+ "special": true
218
+ },
219
+ "65514": {
220
+ "content": "⚠",
221
+ "lstrip": false,
222
+ "normalized": false,
223
+ "rstrip": false,
224
+ "single_word": false,
225
+ "special": true
226
+ },
227
+ "65515": {
228
+ "content": "☐",
229
+ "lstrip": false,
230
+ "normalized": false,
231
+ "rstrip": false,
232
+ "single_word": false,
233
+ "special": true
234
+ },
235
+ "65516": {
236
+ "content": "☑",
237
+ "lstrip": false,
238
+ "normalized": false,
239
+ "rstrip": false,
240
+ "single_word": false,
241
+ "special": true
242
+ },
243
+ "65517": {
244
+ "content": "✓",
245
+ "lstrip": false,
246
+ "normalized": false,
247
+ "rstrip": false,
248
+ "single_word": false,
249
+ "special": true
250
+ },
251
+ "65518": {
252
+ "content": "⟨H≈0.1⟩",
253
+ "lstrip": false,
254
+ "normalized": false,
255
+ "rstrip": false,
256
+ "single_word": false,
257
+ "special": true
258
+ },
259
+ "65519": {
260
+ "content": "⟨H≈0.2⟩",
261
+ "lstrip": false,
262
+ "normalized": false,
263
+ "rstrip": false,
264
+ "single_word": false,
265
+ "special": true
266
+ },
267
+ "65520": {
268
+ "content": "⟨H≈0.3⟩",
269
+ "lstrip": false,
270
+ "normalized": false,
271
+ "rstrip": false,
272
+ "single_word": false,
273
+ "special": true
274
+ },
275
+ "65521": {
276
+ "content": "⟨H≈0.4⟩",
277
+ "lstrip": false,
278
+ "normalized": false,
279
+ "rstrip": false,
280
+ "single_word": false,
281
+ "special": true
282
+ },
283
+ "65522": {
284
+ "content": "⟨H≈0.5⟩",
285
+ "lstrip": false,
286
+ "normalized": false,
287
+ "rstrip": false,
288
+ "single_word": false,
289
+ "special": true
290
+ },
291
+ "65523": {
292
+ "content": "⟨H≈0.6⟩",
293
+ "lstrip": false,
294
+ "normalized": false,
295
+ "rstrip": false,
296
+ "single_word": false,
297
+ "special": true
298
+ },
299
+ "65524": {
300
+ "content": "⟨H≈0.7⟩",
301
+ "lstrip": false,
302
+ "normalized": false,
303
+ "rstrip": false,
304
+ "single_word": false,
305
+ "special": true
306
+ },
307
+ "65525": {
308
+ "content": "⟨H≈0.8⟩",
309
+ "lstrip": false,
310
+ "normalized": false,
311
+ "rstrip": false,
312
+ "single_word": false,
313
+ "special": true
314
+ },
315
+ "65526": {
316
+ "content": "⟨H≈0.9⟩",
317
+ "lstrip": false,
318
+ "normalized": false,
319
+ "rstrip": false,
320
+ "single_word": false,
321
+ "special": true
322
+ },
323
+ "65527": {
324
+ "content": "⟨H≈1.0⟩",
325
+ "lstrip": false,
326
+ "normalized": false,
327
+ "rstrip": false,
328
+ "single_word": false,
329
+ "special": true
330
+ },
331
+ "65528": {
332
+ "content": "⟨H≈1.1⟩",
333
+ "lstrip": false,
334
+ "normalized": false,
335
+ "rstrip": false,
336
+ "single_word": false,
337
+ "special": true
338
+ },
339
+ "65529": {
340
+ "content": "⟨H≈1.2⟩",
341
+ "lstrip": false,
342
+ "normalized": false,
343
+ "rstrip": false,
344
+ "single_word": false,
345
+ "special": true
346
+ },
347
+ "65530": {
348
+ "content": "⟨H≈1.3⟩",
349
+ "lstrip": false,
350
+ "normalized": false,
351
+ "rstrip": false,
352
+ "single_word": false,
353
+ "special": true
354
+ },
355
+ "65531": {
356
+ "content": "⟨H≈1.4⟩",
357
+ "lstrip": false,
358
+ "normalized": false,
359
+ "rstrip": false,
360
+ "single_word": false,
361
+ "special": true
362
+ },
363
+ "65532": {
364
+ "content": "⟨H≈1.5⟩",
365
+ "lstrip": false,
366
+ "normalized": false,
367
+ "rstrip": false,
368
+ "single_word": false,
369
+ "special": true
370
+ },
371
+ "65533": {
372
+ "content": "⟨H≈1.6⟩",
373
+ "lstrip": false,
374
+ "normalized": false,
375
+ "rstrip": false,
376
+ "single_word": false,
377
+ "special": true
378
+ },
379
+ "65534": {
380
+ "content": "⟨H≈1.7⟩",
381
+ "lstrip": false,
382
+ "normalized": false,
383
+ "rstrip": false,
384
+ "single_word": false,
385
+ "special": true
386
+ },
387
+ "65535": {
388
+ "content": "⟨H≈1.8⟩",
389
+ "lstrip": false,
390
+ "normalized": false,
391
+ "rstrip": false,
392
+ "single_word": false,
393
+ "special": true
394
+ },
395
+ "65536": {
396
+ "content": "<|mask|>",
397
+ "lstrip": false,
398
+ "normalized": false,
399
+ "rstrip": false,
400
+ "single_word": false,
401
+ "special": true
402
+ },
403
+ "65537": {
404
+ "content": "<|pad|>",
405
+ "lstrip": false,
406
+ "normalized": false,
407
+ "rstrip": false,
408
+ "single_word": false,
409
+ "special": true
410
+ }
411
+ },
412
+ "additional_special_tokens": [
413
+ "<|im_start|>",
414
+ "<|im_end|>",
415
+ "<think>",
416
+ "</think>",
417
+ "source_1",
418
+ "source_2",
419
+ "source_3",
420
+ "source_4",
421
+ "source_5",
422
+ "source_6",
423
+ "source_7",
424
+ "source_8",
425
+ "source_9",
426
+ "source_10",
427
+ "<ref",
428
+ "</ref>",
429
+ "→",
430
+ "↺",
431
+ "※",
432
+ "?maybe?",
433
+ "●",
434
+ "◐",
435
+ "○",
436
+ "⚠",
437
+ "☐",
438
+ "☑",
439
+ "✓",
440
+ "⟨H≈0.1⟩",
441
+ "⟨H≈0.2⟩",
442
+ "⟨H≈0.3⟩",
443
+ "⟨H≈0.4⟩",
444
+ "⟨H≈0.5⟩",
445
+ "⟨H≈0.6⟩",
446
+ "⟨H≈0.7⟩",
447
+ "⟨H≈0.8⟩",
448
+ "⟨H≈0.9⟩",
449
+ "⟨H≈1.0⟩",
450
+ "⟨H≈1.1⟩",
451
+ "⟨H≈1.2⟩",
452
+ "⟨H≈1.3⟩",
453
+ "⟨H≈1.4⟩",
454
+ "⟨H≈1.5⟩",
455
+ "⟨H≈1.6⟩",
456
+ "⟨H≈1.7⟩",
457
+ "⟨H≈1.8⟩"
458
+ ],
459
+ "bos_token": "<|im_start|>",
460
+ "clean_up_tokenization_spaces": true,
461
+ "eos_token": "<|im_end|>",
462
+ "extra_special_tokens": {},
463
+ "mask_token": "<|mask|>",
464
+ "max_length": 256,
465
+ "model_max_length": 1000000000000000019884624838656,
466
+ "pad_to_multiple_of": null,
467
+ "pad_token": "<|pad|>",
468
+ "pad_token_type_id": 0,
469
+ "padding_side": "right",
470
+ "stride": 0,
471
+ "tokenizer_class": "PreTrainedTokenizerFast",
472
+ "truncation_side": "right",
473
+ "truncation_strategy": "longest_first"
474
+ }