mkurman commited on
Commit
25597f5
·
verified ·
1 Parent(s): 7f15acd

Upload 9 files

Browse files
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.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 Mariusz Kurman, MedIT Solutions Sp. z o.o, Poland. 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
+
16
+ """NeuroBLASTConfig model configuration"""
17
+
18
+ from transformers.configuration_utils import PretrainedConfig, layer_type_validation
19
+ from transformers.modeling_rope_utils import rope_config_validation
20
+ from transformers.utils import logging
21
+
22
+ import math
23
+ import warnings
24
+
25
+ logger = logging.get_logger(__name__)
26
+
27
+
28
+ class NeuroBLASTConfig(PretrainedConfig):
29
+ model_type = "neuroblast"
30
+ keys_to_ignore_at_inference = ["past_key_values"]
31
+
32
+ # Default tensor parallel plan for base model `Qwen3`
33
+ base_model_tp_plan = {
34
+ "layers.*.self_attn.q_proj": "colwise",
35
+ "layers.*.self_attn.k_proj": "colwise",
36
+ "layers.*.self_attn.v_proj": "colwise",
37
+ "layers.*.self_attn.o_proj": "rowwise",
38
+ "layers.*.mlp.gate_proj": "colwise",
39
+ "layers.*.mlp.up_proj": "colwise",
40
+ "layers.*.mlp.down_proj": "rowwise",
41
+ }
42
+ base_model_pp_plan = {
43
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
44
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
45
+ "norm": (["hidden_states"], ["hidden_states"]),
46
+ }
47
+
48
+ def __init__(
49
+ self,
50
+ vocab_size=151936,
51
+ hidden_size=4096,
52
+ energy_dim=128,
53
+ intermediate_size=22016,
54
+ num_hidden_layers=32,
55
+ num_associative_layers=16,
56
+ num_sensory_layers=8,
57
+ num_motor_layers=8,
58
+ num_attention_heads=32,
59
+ num_key_value_heads=32,
60
+ head_dim=128,
61
+ hidden_act="silu",
62
+ max_position_embeddings=32768,
63
+ initializer_range=0.02,
64
+ rms_norm_eps=1e-6,
65
+ use_cache=True,
66
+ tie_word_embeddings=False,
67
+ rope_theta=10000.0,
68
+ rope_scaling=None,
69
+ attention_bias=False,
70
+ use_sliding_window=False,
71
+ sliding_window=4096,
72
+ max_window_layers=28,
73
+ layer_types=None,
74
+ attention_dropout=0.0,
75
+ attention_every=0,
76
+ dropout=0.0,
77
+ scale=1.0,
78
+ kernel_size=5,
79
+ temporal_kernel_size=5,
80
+ **kwargs,
81
+ ):
82
+ self.vocab_size = vocab_size
83
+ self.max_position_embeddings = max_position_embeddings
84
+ self.hidden_size = hidden_size
85
+ self.energy_dim = energy_dim
86
+ self.intermediate_size = intermediate_size
87
+ self.num_hidden_layers = num_hidden_layers
88
+
89
+ self.num_associative_layers = num_associative_layers
90
+ self.num_sensory_layers = num_sensory_layers
91
+
92
+ self.num_motor_layers = num_motor_layers
93
+
94
+ if (
95
+ num_hidden_layers
96
+ != num_associative_layers + num_sensory_layers + num_motor_layers
97
+ ):
98
+ self.num_hidden_layers = (
99
+ num_associative_layers + num_sensory_layers + num_motor_layers
100
+ )
101
+ warnings.warn(
102
+ f"num_hidden_layers ({num_hidden_layers}) is not equal to num_associative_layers ({num_associative_layers}) + num_sensory_layers ({num_sensory_layers}) + num_motor_layers ({num_motor_layers}). Setting num_hidden_layers to {num_associative_layers + num_sensory_layers + num_motor_layers}."
103
+ )
104
+ self.num_attention_heads = num_attention_heads
105
+ self.use_sliding_window = use_sliding_window
106
+ self.sliding_window = sliding_window if self.use_sliding_window else None
107
+ self.max_window_layers = max_window_layers
108
+
109
+ # for backward compatibility
110
+ if num_key_value_heads is None:
111
+ num_key_value_heads = num_attention_heads
112
+
113
+ self.num_key_value_heads = num_key_value_heads
114
+ self.head_dim = head_dim
115
+ self.hidden_act = hidden_act
116
+ self.initializer_range = initializer_range
117
+ self.rms_norm_eps = rms_norm_eps
118
+ self.use_cache = use_cache
119
+ self.rope_theta = rope_theta
120
+ self.rope_scaling = rope_scaling
121
+ self.attention_bias = attention_bias
122
+ self.attention_dropout = attention_dropout
123
+ self.attention_every = attention_every
124
+ self.scale = scale
125
+ self.kernel_size = kernel_size
126
+ self.temporal_kernel_size = temporal_kernel_size
127
+ self.dropout = dropout
128
+
129
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
130
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
131
+ rope_config_validation(self)
132
+
133
+ self.layer_types = layer_types
134
+ if self.layer_types is None:
135
+ self.layer_types = [
136
+ ("full_attention") for i in range(self.num_hidden_layers)
137
+ ]
138
+ layer_type_validation(self.layer_types)
139
+
140
+ super().__init__(
141
+ tie_word_embeddings=tie_word_embeddings,
142
+ **kwargs,
143
+ )
144
+
145
+
146
+ __all__ = ["NeuroBLASTConfig"]
generation_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "pad_token_id": 65537,
4
+ "transformers_version": "4.57.1"
5
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fa14abdfa73bff6af64994e22d00b80796f5d7eb02a4084d7897fded10cf710
3
+ size 2386982048
modeling_neuroblast.py ADDED
@@ -0,0 +1,738 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 Mariusz Kurman, MedIT Solutions Sp. z o.o, Poland. 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
+
16
+ """PyTorch NeuroBLAST model."""
17
+
18
+ import math
19
+ from typing import List, Optional, Tuple, Union
20
+
21
+ import torch
22
+ import torch.nn.functional as F
23
+ import torch.utils.checkpoint
24
+ from torch import nn
25
+ from torch.nn import CrossEntropyLoss
26
+
27
+ from transformers.activations import ACT2FN
28
+ from transformers.cache_utils import Cache, DynamicCache
29
+ from transformers.modeling_outputs import (
30
+ BaseModelOutputWithPast,
31
+ CausalLMOutputWithPast,
32
+ )
33
+ from transformers.modeling_utils import PreTrainedModel
34
+ from transformers import GenerationMixin
35
+ from transformers.utils import (
36
+ add_start_docstrings,
37
+ add_start_docstrings_to_model_forward,
38
+ logging,
39
+ replace_return_docstrings,
40
+ )
41
+ from .configuration_neuroblast import NeuroBLASTConfig
42
+
43
+
44
+ logger = logging.get_logger(__name__)
45
+
46
+ _CONFIG_FOR_DOC = "NeuroBLASTConfig"
47
+
48
+
49
+ class NeuroBLASTRMSNorm(nn.Module):
50
+ def __init__(self, hidden_size, eps=1e-6):
51
+ super().__init__()
52
+ self.weight = nn.Parameter(torch.ones(hidden_size))
53
+ self.variance_epsilon = eps
54
+
55
+ def forward(self, hidden_states):
56
+ input_dtype = hidden_states.dtype
57
+ hidden_states = hidden_states.to(torch.float32)
58
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
59
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
60
+ return self.weight * hidden_states.to(input_dtype)
61
+
62
+
63
+ class NeuroBLASTMLP(nn.Module):
64
+ def __init__(self, config):
65
+ super().__init__()
66
+ self.config = config
67
+ self.hidden_size = config.hidden_size
68
+ self.intermediate_size = config.intermediate_size
69
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
70
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
71
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
72
+ self.act_fn = ACT2FN[config.hidden_act]
73
+
74
+ def forward(self, x):
75
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
76
+
77
+
78
+ def rotate_half(x):
79
+ x1 = x[..., : x.shape[-1] // 2]
80
+ x2 = x[..., x.shape[-1] // 2 :]
81
+ return torch.cat((-x2, x1), dim=-1)
82
+
83
+
84
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
85
+ cos = cos.unsqueeze(unsqueeze_dim)
86
+ sin = sin.unsqueeze(unsqueeze_dim)
87
+ q_embed = (q * cos) + (rotate_half(q) * sin)
88
+ k_embed = (k * cos) + (rotate_half(k) * sin)
89
+ return q_embed.to(q.dtype), k_embed.to(q.dtype)
90
+
91
+
92
+ class NeuroBLASTAttention(nn.Module):
93
+ def __init__(self, config: NeuroBLASTConfig, layer_idx: Optional[int] = None, use_rope: bool = True):
94
+ super().__init__()
95
+ self.config = config
96
+ self.layer_idx = layer_idx
97
+ self.use_rope = use_rope
98
+ if layer_idx is None:
99
+ logger.warning_once(
100
+ f"Instantiating {self.__class__.__name__} without passing a `layer_idx` is not recommended and will "
101
+ "lead to errors during the forward call if caching is used. Please make sure to provide a `layer_idx` "
102
+ "when creating this class."
103
+ )
104
+
105
+ self.hidden_size = config.hidden_size
106
+ self.num_heads = config.num_attention_heads
107
+ self.head_dim = getattr(config, "head_dim", self.hidden_size // self.num_heads)
108
+ self.num_key_value_heads = config.num_key_value_heads
109
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
110
+ self.max_position_embeddings = config.max_position_embeddings
111
+ self.rope_theta = config.rope_theta
112
+ self.is_causal = True
113
+
114
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias)
115
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
116
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=config.attention_bias)
117
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=config.attention_bias)
118
+
119
+ self.q_norm = NeuroBLASTRMSNorm(self.head_dim, eps=config.rms_norm_eps)
120
+ self.k_norm = NeuroBLASTRMSNorm(self.head_dim, eps=config.rms_norm_eps)
121
+
122
+ def forward(
123
+ self,
124
+ hidden_states: torch.Tensor,
125
+ attention_mask: Optional[torch.Tensor] = None,
126
+ position_ids: Optional[torch.LongTensor] = None,
127
+ past_key_value: Optional[Cache] = None,
128
+ output_attentions: bool = False,
129
+ use_cache: bool = False,
130
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
131
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
132
+ bsz, q_len, _ = hidden_states.size()
133
+
134
+ query_states = self.q_proj(hidden_states)
135
+ key_states = self.k_proj(hidden_states)
136
+ value_states = self.v_proj(hidden_states)
137
+
138
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim)
139
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim)
140
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim)
141
+
142
+ # Norm
143
+ query_states = self.q_norm(query_states)
144
+ key_states = self.k_norm(key_states)
145
+
146
+ query_states = query_states.transpose(1, 2)
147
+ key_states = key_states.transpose(1, 2)
148
+ value_states = value_states.transpose(1, 2)
149
+
150
+ kv_seq_len = key_states.shape[-2]
151
+ if past_key_value is not None:
152
+ if self.layer_idx is None:
153
+ raise ValueError(
154
+ f"The `layer_idx` should be defined when calling the forward function of {self.__class__.__name__}. "
155
+ "Please make sure to pass a `layer_idx` when creating this class."
156
+ )
157
+ kv_seq_len += past_key_value.get_seq_length(self.layer_idx)
158
+
159
+ if self.use_rope and position_embeddings is not None:
160
+ cos, sin = position_embeddings
161
+ cos = cos.squeeze(2)
162
+ sin = sin.squeeze(2)
163
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, unsqueeze_dim=1)
164
+ else:
165
+ cos = None
166
+ sin = None
167
+
168
+ if past_key_value is not None:
169
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs={"cos": cos, "sin": sin})
170
+
171
+ # repeat k/v heads if n_kv_heads < n_heads
172
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
173
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
174
+
175
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
176
+
177
+ if attention_mask is not None:
178
+ attn_weights = attn_weights + attention_mask
179
+
180
+ # upcast attention to fp32
181
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
182
+ attn_weights = nn.functional.dropout(attn_weights, p=self.config.attention_dropout, training=self.training)
183
+ attn_output = torch.matmul(attn_weights, value_states)
184
+
185
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
186
+ raise ValueError(
187
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
188
+ f" {attn_output.size()}"
189
+ )
190
+
191
+ attn_output = attn_output.transpose(1, 2).contiguous()
192
+ attn_output = attn_output.reshape(bsz, q_len, self.num_heads * self.head_dim)
193
+
194
+ attn_output = self.o_proj(attn_output)
195
+
196
+ if not output_attentions:
197
+ attn_weights = None
198
+
199
+ return attn_output, attn_weights, past_key_value
200
+
201
+
202
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
203
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
204
+ if n_rep == 1:
205
+ return hidden_states
206
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
207
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
208
+
209
+
210
+ class NeuroBLASTRMSNorm2d(nn.Module):
211
+ def __init__(self, dim, eps=1e-6):
212
+ super().__init__()
213
+ self.weight = nn.Parameter(torch.ones(dim))
214
+ self.variance_epsilon = eps
215
+
216
+ def forward(self, x):
217
+ # x: (B, C, H, W)
218
+ input_dtype = x.dtype
219
+ x = x.to(torch.float32)
220
+ variance = x.pow(2).mean(dim=1, keepdim=True)
221
+ x_norm = x * torch.rsqrt(variance + self.variance_epsilon)
222
+ return self.weight.view(1, -1, 1, 1) * x_norm.to(input_dtype)
223
+
224
+
225
+ class NeuroBLASTCausalConv2DBlock(nn.Module):
226
+ def __init__(self, config, dilation=1, layer_idx=0):
227
+ super().__init__()
228
+ self.config = config
229
+ self.dilation = dilation
230
+ self.layer_idx = layer_idx
231
+
232
+ k = config.kernel_size
233
+ d = config.hidden_size
234
+ s = config.scale
235
+
236
+ self.conv_padding = (k // 2, 0)
237
+
238
+ if s == 1:
239
+ self.conv = nn.Conv2d(
240
+ d, d,
241
+ kernel_size=(k, k),
242
+ dilation=(1, dilation),
243
+ padding=self.conv_padding,
244
+ bias=False
245
+ )
246
+ self.use_gating = False
247
+ self.use_projection = False
248
+ elif s > 1:
249
+ internal_dim = int(d * s)
250
+ self.conv = nn.Conv2d(
251
+ d, internal_dim,
252
+ kernel_size=(k, k),
253
+ dilation=(1, dilation),
254
+ padding=self.conv_padding,
255
+ bias=False
256
+ )
257
+ self.use_gating = True
258
+ self.use_projection = False
259
+ else:
260
+ internal_dim = max(int(d * s), d // 4)
261
+ self.conv = nn.Conv2d(
262
+ d, internal_dim,
263
+ kernel_size=(k, k),
264
+ dilation=(1, dilation),
265
+ padding=self.conv_padding,
266
+ bias=False
267
+ )
268
+ self.use_gating = False
269
+ self.use_projection = True
270
+ self.proj_back = nn.Conv2d(internal_dim, d, kernel_size=(1, 1), bias=False)
271
+
272
+ self.norm_in = NeuroBLASTRMSNorm2d(d, eps=config.rms_norm_eps)
273
+ self.norm_out = NeuroBLASTRMSNorm2d(d, eps=config.rms_norm_eps)
274
+ self.dropout = nn.Dropout(config.dropout)
275
+
276
+ def forward(self, x):
277
+ # x: (B, C, H, W)
278
+ B, C, H, W = x.shape
279
+ residual = x
280
+ y = self.norm_in(x)
281
+
282
+ k = self.config.kernel_size
283
+ pad_w = (k - 1) * self.dilation
284
+
285
+ # Pad W on the left
286
+ y_pad = F.pad(y, (pad_w, 0, 0, 0))
287
+
288
+ y = self.conv(y_pad)
289
+
290
+ if self.use_gating:
291
+ gate, val = torch.chunk(y, 2, dim=1)
292
+ y = val * F.softmax(gate, dim=1)
293
+ elif self.use_projection:
294
+ y = self.proj_back(y)
295
+
296
+ y = self.norm_out(y)
297
+
298
+ x = residual + self.dropout(y)
299
+ return x
300
+
301
+
302
+ class NeuroBLASTDecoderLayer(nn.Module):
303
+ def __init__(self, config: NeuroBLASTConfig, layer_idx: int, attention_type: str = "full_attention"):
304
+ super().__init__()
305
+ self.hidden_size = config.hidden_size
306
+ self.self_attn = NeuroBLASTAttention(
307
+ config=config,
308
+ layer_idx=layer_idx,
309
+ use_rope=(attention_type != "no_rope"),
310
+ )
311
+ self.mlp = NeuroBLASTMLP(config)
312
+ self.input_layernorm = NeuroBLASTRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
313
+ self.post_attention_layernorm = NeuroBLASTRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
314
+
315
+ def forward(
316
+ self,
317
+ hidden_states: torch.Tensor,
318
+ attention_mask: Optional[torch.Tensor] = None,
319
+ position_ids: Optional[torch.LongTensor] = None,
320
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
321
+ output_attentions: Optional[bool] = False,
322
+ use_cache: Optional[bool] = False,
323
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
324
+ ) -> Tuple[torch.Tensor, Optional[Tuple[torch.Tensor, torch.Tensor]]]:
325
+
326
+ residual = hidden_states
327
+ hidden_states = self.input_layernorm(hidden_states)
328
+
329
+ # Self Attention
330
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
331
+ hidden_states=hidden_states,
332
+ attention_mask=attention_mask,
333
+ position_ids=position_ids,
334
+ past_key_value=past_key_value,
335
+ output_attentions=output_attentions,
336
+ use_cache=use_cache,
337
+ position_embeddings=position_embeddings,
338
+ )
339
+ hidden_states = residual + hidden_states
340
+
341
+ # MLP
342
+ residual = hidden_states
343
+ hidden_states = self.post_attention_layernorm(hidden_states)
344
+ hidden_states = self.mlp(hidden_states)
345
+ hidden_states = residual + hidden_states
346
+
347
+ outputs = (hidden_states,)
348
+
349
+ if output_attentions:
350
+ outputs += (self_attn_weights,)
351
+
352
+ if use_cache:
353
+ outputs += (present_key_value,)
354
+
355
+ return outputs
356
+
357
+
358
+ class NeuroBLASTToken2D(nn.Module):
359
+ def forward(self, x, mode="seq_to_2d"):
360
+ if mode == "seq_to_2d":
361
+ return x.permute(0, 2, 1).unsqueeze(2)
362
+ else:
363
+ return x.squeeze(2).permute(0, 2, 1)
364
+
365
+
366
+ class NeuroBLASTRotaryEmbedding(nn.Module):
367
+ def __init__(self, config):
368
+ super().__init__()
369
+ self.dim = config.head_dim
370
+ self.max_position_embeddings = config.max_position_embeddings
371
+ self.base = config.rope_theta
372
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float() / self.dim))
373
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
374
+
375
+ def forward(self, x, position_ids):
376
+ # x: (B, L, H, D) or similar. Not used for shape here.
377
+ # position_ids: (B, L)
378
+
379
+ inv_freq_expanded = self.inv_freq[None, :, None]
380
+ position_ids_expanded = position_ids[:, :, None].float()
381
+ freqs = torch.matmul(position_ids_expanded, self.inv_freq[None, None, :])
382
+ emb = torch.cat((freqs, freqs), dim=-1)
383
+ cos = emb.cos()
384
+ sin = emb.sin()
385
+
386
+ # Output: (B, L, 1, D)
387
+ return cos[:, :, None, :], sin[:, :, None, :]
388
+
389
+
390
+ class NeuroBLASTPreTrainedModel(PreTrainedModel):
391
+ config_class = NeuroBLASTConfig
392
+ base_model_prefix = "model"
393
+ supports_gradient_checkpointing = True
394
+ _no_split_modules = ["NeuroBLASTDecoderLayer", "NeuroBLASTCausalConv2DBlock"]
395
+ _skip_keys_device_placement = "past_key_values"
396
+
397
+ def _init_weights(self, module):
398
+ std = self.config.initializer_range
399
+ if isinstance(module, nn.Linear):
400
+ module.weight.data.normal_(mean=0.0, std=std)
401
+ if module.bias is not None:
402
+ module.bias.data.zero_()
403
+ elif isinstance(module, nn.Embedding):
404
+ module.weight.data.normal_(mean=0.0, std=std)
405
+ if module.padding_idx is not None:
406
+ module.weight.data[module.padding_idx].zero_()
407
+
408
+
409
+ class NeuroBLASTModel(NeuroBLASTPreTrainedModel):
410
+ def __init__(self, config: NeuroBLASTConfig):
411
+ super().__init__(config)
412
+ self.padding_idx = config.pad_token_id
413
+ self.vocab_size = config.vocab_size
414
+
415
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
416
+ self.token2d = NeuroBLASTToken2D()
417
+
418
+ self.sensory_layers = nn.ModuleList()
419
+ dilatation_step = 1
420
+ for i in range(config.num_sensory_layers):
421
+ if i % 2 == 0:
422
+ layer = NeuroBLASTDecoderLayer(config, layer_idx=i, attention_type="full_attention")
423
+ else:
424
+ dilation = min(2 ** ((i - 1) // dilatation_step), 8)
425
+ layer = NeuroBLASTCausalConv2DBlock(config, dilation=dilation, layer_idx=i)
426
+ self.sensory_layers.append(layer)
427
+
428
+ self.sensory_to_associative = NeuroBLASTRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
429
+
430
+ self.associative_layers = nn.ModuleList()
431
+ next_layer_type = "full_attention"
432
+ for i in range(config.num_associative_layers):
433
+ idx = i + config.num_sensory_layers
434
+ if i % 2 == 0:
435
+ layer = NeuroBLASTDecoderLayer(config, layer_idx=idx, attention_type=next_layer_type)
436
+ if next_layer_type == "full_attention":
437
+ next_layer_type = "no_rope"
438
+ else:
439
+ next_layer_type = "full_attention"
440
+ else:
441
+ dilation = min(2 ** ((i - 1) // dilatation_step), 8)
442
+ layer = NeuroBLASTCausalConv2DBlock(config, dilation=dilation, layer_idx=idx)
443
+ self.associative_layers.append(layer)
444
+
445
+ self.sensory_to_motor = NeuroBLASTRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
446
+
447
+ self.motor_layers = nn.ModuleList()
448
+ next_layer_type = "full_attention"
449
+ for i in range(config.num_motor_layers):
450
+ idx = i + config.num_sensory_layers + config.num_associative_layers
451
+ layer = NeuroBLASTDecoderLayer(config, layer_idx=idx, attention_type=next_layer_type)
452
+ if next_layer_type == "full_attention":
453
+ next_layer_type = "no_rope"
454
+ else:
455
+ next_layer_type = "full_attention"
456
+ self.motor_layers.append(layer)
457
+
458
+ self.norm = NeuroBLASTRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
459
+ self.rotary_emb = NeuroBLASTRotaryEmbedding(config)
460
+
461
+ self.gradient_checkpointing = False
462
+ self.post_init()
463
+
464
+ def forward(
465
+ self,
466
+ input_ids: torch.LongTensor = None,
467
+ attention_mask: Optional[torch.Tensor] = None,
468
+ position_ids: Optional[torch.LongTensor] = None,
469
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
470
+ inputs_embeds: Optional[torch.FloatTensor] = None,
471
+ use_cache: Optional[bool] = None,
472
+ output_attentions: Optional[bool] = None,
473
+ output_hidden_states: Optional[bool] = None,
474
+ cache_position: Optional[torch.LongTensor] = None,
475
+ return_dict: Optional[bool] = None,
476
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
477
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
478
+ output_hidden_states = (
479
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
480
+ )
481
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
482
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
483
+
484
+ if input_ids is not None and inputs_embeds is not None:
485
+ raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
486
+ elif input_ids is not None:
487
+ batch_size, seq_length = input_ids.shape
488
+ elif inputs_embeds is not None:
489
+ batch_size, seq_length, _ = inputs_embeds.shape
490
+ else:
491
+ raise ValueError("You have to specify either input_ids or inputs_embeds")
492
+
493
+ if position_ids is None:
494
+ device = input_ids.device if input_ids is not None else inputs_embeds.device
495
+ past_length = 0
496
+ if past_key_values is not None:
497
+ if isinstance(past_key_values, DynamicCache):
498
+ past_length = past_key_values.get_seq_length()
499
+ elif isinstance(past_key_values, (tuple, list)):
500
+ past_length = past_key_values[0][0].shape[-2]
501
+
502
+ position_ids = torch.arange(past_length, past_length + seq_length, dtype=torch.long, device=device)
503
+ position_ids = position_ids.unsqueeze(0).view(-1, seq_length)
504
+ else:
505
+ position_ids = position_ids.view(-1, seq_length).long()
506
+
507
+ if inputs_embeds is None:
508
+ inputs_embeds = self.embed_tokens(input_ids)
509
+
510
+ if attention_mask is None:
511
+ attention_mask = torch.ones(
512
+ (batch_size, seq_length), dtype=torch.bool, device=inputs_embeds.device
513
+ )
514
+
515
+ # Create causal mask
516
+ min_dtype = torch.finfo(inputs_embeds.dtype).min
517
+ causal_mask = torch.full((seq_length, seq_length), min_dtype, device=inputs_embeds.device)
518
+ causal_mask = torch.triu(causal_mask, diagonal=1)
519
+ causal_mask = causal_mask[None, None, :, :] # (1, 1, L, L)
520
+
521
+ # Expand attention_mask
522
+ # attention_mask: (B, L) -> (B, 1, 1, L)
523
+ padding_mask = attention_mask[:, None, None, :].to(inputs_embeds.dtype)
524
+ padding_mask = (1.0 - padding_mask) * min_dtype
525
+
526
+ combined_mask = causal_mask + padding_mask
527
+
528
+ # Initialize cache if needed
529
+ if use_cache and past_key_values is None:
530
+ past_key_values = DynamicCache()
531
+
532
+ hidden_states = inputs_embeds
533
+
534
+ # RoPE
535
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
536
+
537
+ all_hidden_states = () if output_hidden_states else None
538
+ all_self_attns = () if output_attentions else None
539
+
540
+ residual = hidden_states
541
+
542
+ # Sensory
543
+ for i, layer in enumerate(self.sensory_layers):
544
+ if output_hidden_states:
545
+ all_hidden_states += (hidden_states,)
546
+
547
+ if i % 2 == 1:
548
+ # Conv layer
549
+ hidden_states = self.token2d(hidden_states, mode="seq_to_2d")
550
+ hidden_states = layer(hidden_states)
551
+ hidden_states = self.token2d(hidden_states, mode="d2_to_seq")
552
+ else:
553
+ # Attention layer
554
+ layer_outputs = layer(
555
+ hidden_states,
556
+ attention_mask=combined_mask,
557
+ position_ids=position_ids,
558
+ past_key_value=past_key_values,
559
+ output_attentions=output_attentions,
560
+ use_cache=use_cache,
561
+ position_embeddings=position_embeddings,
562
+ )
563
+ hidden_states = layer_outputs[0]
564
+ if output_attentions:
565
+ all_self_attns += (layer_outputs[1],)
566
+
567
+ hidden_states = hidden_states + self.sensory_to_associative(F.silu(residual))
568
+
569
+ # Associative
570
+ for i, layer in enumerate(self.associative_layers):
571
+ if output_hidden_states:
572
+ all_hidden_states += (hidden_states,)
573
+
574
+ if i % 2 == 1:
575
+ hidden_states = self.token2d(hidden_states, mode="seq_to_2d")
576
+ hidden_states = layer(hidden_states)
577
+ hidden_states = self.token2d(hidden_states, mode="d2_to_seq")
578
+ else:
579
+ layer_outputs = layer(
580
+ hidden_states,
581
+ attention_mask=combined_mask,
582
+ position_ids=position_ids,
583
+ past_key_value=past_key_values,
584
+ output_attentions=output_attentions,
585
+ use_cache=use_cache,
586
+ position_embeddings=position_embeddings,
587
+ )
588
+ hidden_states = layer_outputs[0]
589
+ if output_attentions:
590
+ all_self_attns += (layer_outputs[1],)
591
+
592
+ hidden_states = hidden_states + self.sensory_to_motor(F.silu(-residual))
593
+
594
+ # Motor
595
+ for i, layer in enumerate(self.motor_layers):
596
+ if output_hidden_states:
597
+ all_hidden_states += (hidden_states,)
598
+
599
+ layer_outputs = layer(
600
+ hidden_states,
601
+ attention_mask=combined_mask,
602
+ position_ids=position_ids,
603
+ past_key_value=past_key_values,
604
+ output_attentions=output_attentions,
605
+ use_cache=use_cache,
606
+ position_embeddings=position_embeddings,
607
+ )
608
+ hidden_states = layer_outputs[0]
609
+ if output_attentions:
610
+ all_self_attns += (layer_outputs[1],)
611
+
612
+ hidden_states = self.norm(hidden_states)
613
+
614
+ if output_hidden_states:
615
+ all_hidden_states += (hidden_states,)
616
+
617
+ if not return_dict:
618
+ return tuple(v for v in [hidden_states, past_key_values, all_hidden_states, all_self_attns] if v is not None)
619
+
620
+ return BaseModelOutputWithPast(
621
+ last_hidden_state=hidden_states,
622
+ past_key_values=past_key_values,
623
+ hidden_states=all_hidden_states,
624
+ attentions=all_self_attns,
625
+ )
626
+ class NeuroBLASTPreTrainedModel(PreTrainedModel):
627
+ config_class = NeuroBLASTConfig
628
+ base_model_prefix = "model"
629
+ supports_gradient_checkpointing = True
630
+ _no_split_modules = ["NeuroBLASTBlock"]
631
+ _skip_keys_device_placement = "past_key_values"
632
+
633
+ def _init_weights(self, module):
634
+ std = self.config.initializer_range
635
+ if isinstance(module, nn.Linear):
636
+ module.weight.data.normal_(mean=0.0, std=std)
637
+ if module.bias is not None:
638
+ module.bias.data.zero_()
639
+ elif isinstance(module, nn.Embedding):
640
+ module.weight.data.normal_(mean=0.0, std=std)
641
+ if module.padding_idx is not None:
642
+ module.weight.data[module.padding_idx].zero_()
643
+
644
+ class NeuroBLASTForCausalLM(NeuroBLASTPreTrainedModel, GenerationMixin):
645
+ _tied_weights_keys = ["lm_head.weight"]
646
+
647
+ def __init__(self, config):
648
+ super().__init__(config)
649
+ self.model = NeuroBLASTModel(config)
650
+ self.vocab_size = config.vocab_size
651
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
652
+
653
+ # Initialize weights and apply final processing
654
+ self.post_init()
655
+
656
+ def get_input_embeddings(self):
657
+ return self.model.embed_tokens
658
+
659
+ def set_input_embeddings(self, value):
660
+ self.model.embed_tokens = value
661
+
662
+ def get_output_embeddings(self):
663
+ return self.lm_head
664
+
665
+ def set_output_embeddings(self, new_embeddings):
666
+ self.lm_head = new_embeddings
667
+
668
+ def set_decoder(self, decoder):
669
+ self.model = decoder
670
+
671
+ def get_decoder(self):
672
+ return self.model
673
+
674
+ def forward(
675
+ self,
676
+ input_ids: Optional[torch.LongTensor] = None,
677
+ attention_mask: Optional[torch.Tensor] = None,
678
+ position_ids: Optional[torch.LongTensor] = None,
679
+ past_key_values: Optional[Cache] = None,
680
+ inputs_embeds: Optional[torch.FloatTensor] = None,
681
+ labels: Optional[torch.LongTensor] = None,
682
+ use_cache: Optional[bool] = None,
683
+ output_attentions: Optional[bool] = None,
684
+ output_hidden_states: Optional[bool] = None,
685
+ cache_position: Optional[torch.LongTensor] = None,
686
+ logits_to_keep: Union[int, torch.Tensor] = 0,
687
+ return_dict: Optional[bool] = None,
688
+ **kwargs,
689
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
690
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
691
+ output_hidden_states = (
692
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
693
+ )
694
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
695
+
696
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
697
+ outputs = self.model(
698
+ input_ids=input_ids,
699
+ attention_mask=attention_mask,
700
+ position_ids=position_ids,
701
+ past_key_values=past_key_values,
702
+ inputs_embeds=inputs_embeds,
703
+ use_cache=use_cache,
704
+ output_attentions=output_attentions,
705
+ output_hidden_states=output_hidden_states,
706
+ cache_position=cache_position,
707
+ return_dict=return_dict,
708
+ )
709
+
710
+ hidden_states = outputs[0]
711
+ slice_indices = (
712
+ slice(-logits_to_keep, None)
713
+ if isinstance(logits_to_keep, int)
714
+ else logits_to_keep
715
+ )
716
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
717
+
718
+ loss = None
719
+ if labels is not None:
720
+ loss = self.loss_function(
721
+ logits=logits,
722
+ labels=labels,
723
+ vocab_size=self.config.vocab_size,
724
+ **kwargs,
725
+ )
726
+
727
+ if not return_dict:
728
+ output = (logits,) + outputs[1:]
729
+ return ((loss,) + output) if loss is not None else output
730
+
731
+ return CausalLMOutputWithPast(
732
+ loss=loss,
733
+ logits=logits,
734
+ past_key_values=outputs.past_key_values,
735
+ hidden_states=outputs.hidden_states,
736
+ attentions=outputs.attentions,
737
+ )
738
+
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
+ }