Delta-Vector commited on
Commit
447b1cf
·
verified ·
1 Parent(s): 0d70d0a

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
chat_template.jinja ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ <s>{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '
2
+ ' + message['content'] + '<|im_end|>' + '
3
+ '}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant
4
+ ' }}{% endif %}
config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ApertusForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_apertus.ApertusConfig",
9
+ "AutoModel": "modeling_apertus.ApertusModel",
10
+ "AutoModelForCausalLM": "modeling_apertus.ApertusForCausalLM"
11
+ },
12
+ "bos_token_id": 1,
13
+ "dtype": "bfloat16",
14
+ "eos_token_id": 68,
15
+ "hidden_act": "xielu",
16
+ "hidden_dropout": 0.0,
17
+ "hidden_size": 4096,
18
+ "initializer_range": 0.02,
19
+ "intermediate_size": 21504,
20
+ "max_position_embeddings": 65536,
21
+ "mlp_bias": false,
22
+ "model_type": "apertus",
23
+ "num_attention_heads": 32,
24
+ "num_hidden_layers": 32,
25
+ "num_key_value_heads": 8,
26
+ "pad_token_id": 3,
27
+ "post_norm": false,
28
+ "qk_norm": true,
29
+ "rms_norm_eps": 1e-05,
30
+ "rope_scaling": {
31
+ "factor": 8.0,
32
+ "high_freq_factor": 4.0,
33
+ "low_freq_factor": 1.0,
34
+ "original_max_position_embeddings": 8192,
35
+ "rope_type": "llama3",
36
+ "type": "llama3"
37
+ },
38
+ "rope_theta": 12000000,
39
+ "tie_word_embeddings": false,
40
+ "transformers_version": "4.56.1",
41
+ "use_cache": false,
42
+ "vocab_size": 131072
43
+ }
configuration_apertus.py ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
2
+ # This file was automatically generated from src/transformers/models/apertus/modular_apertus.py.
3
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
4
+ # the file from the modular. If any change should be done, please apply the change to the
5
+ # modular_apertus.py file directly. One of our CI enforces this.
6
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7
+ # coding=utf-8
8
+ # Copyright 2025 the HuggingFace Inc. team and the Swiss AI Initiative. All rights reserved.
9
+ #
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+
23
+ from transformers.configuration_utils import PretrainedConfig
24
+ from transformers.modeling_rope_utils import rope_config_validation
25
+
26
+
27
+ class ApertusConfig(PretrainedConfig):
28
+ r"""
29
+ This is the configuration class to store the configuration of a [`ApertusModel`]. It is used to instantiate a Apertus
30
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
31
+ defaults will yield a similar configuration to that of the Apertus-8B.
32
+ e.g. [swiss-ai/Apertus-8B](https://huggingface.co/swiss-ai/Apertus-8B)
33
+
34
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
35
+ documentation from [`PretrainedConfig`] for more information.
36
+
37
+
38
+ Args:
39
+ vocab_size (`int`, *optional*, defaults to 131072):
40
+ Vocabulary size of the Apertus model. Defines the number of different tokens that can be represented by the
41
+ `inputs_ids` passed when calling [`ApertusModel`]
42
+ hidden_size (`int`, *optional*, defaults to 4096):
43
+ Dimension of the hidden representations.
44
+ intermediate_size (`int`, *optional*, defaults to 14336):
45
+ Dimension of the MLP representations.
46
+ num_hidden_layers (`int`, *optional*, defaults to 32):
47
+ Number of hidden layers in the Transformer decoder.
48
+ num_attention_heads (`int`, *optional*, defaults to 32):
49
+ Number of attention heads for each attention layer in the Transformer decoder.
50
+ num_key_value_heads (`int`, *optional*):
51
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
52
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
53
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
54
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
55
+ by meanpooling all the original heads within that group. For more details, check out [this
56
+ paper](https://huggingface.co/papers/2305.13245). If it is not specified, will default to
57
+ `num_attention_heads`.
58
+ hidden_act (`str` or `function`, *optional*, defaults to `"xielu"`):
59
+ The non-linear activation function (function or string) in the decoder.
60
+ max_position_embeddings (`int`, *optional*, defaults to 65536):
61
+ The maximum sequence length that this model might ever be used with. Apertus supports up to 65536 tokens.
62
+ initializer_range (`float`, *optional*, defaults to 0.02):
63
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
64
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
65
+ The epsilon used by the rms normalization layers.
66
+ use_cache (`bool`, *optional*, defaults to `True`):
67
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
68
+ relevant if `config.is_decoder=True`.
69
+ pad_token_id (`int`, *optional*, defaults to 3):
70
+ Padding token id.
71
+ bos_token_id (`int`, *optional*, defaults to 1):
72
+ Beginning of stream token id.
73
+ eos_token_id (`int`, *optional*, defaults to 2):
74
+ End of stream token id.
75
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
76
+ Whether to tie weight embeddings
77
+ rope_theta (`float`, *optional*, defaults to 12000000.0):
78
+ The base period of the RoPE embeddings.
79
+ rope_scaling (`Dict`, *optional*):
80
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
81
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
82
+ accordingly.
83
+ Expected contents:
84
+ `rope_type` (`str`):
85
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
86
+ 'llama3'], with 'default' being the original RoPE implementation.
87
+ `factor` (`float`, *optional*):
88
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
89
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
90
+ original maximum pre-trained length.
91
+ `original_max_position_embeddings` (`int`, *optional*):
92
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
93
+ pretraining.
94
+ `attention_factor` (`float`, *optional*):
95
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
96
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
97
+ `factor` field to infer the suggested value.
98
+ `beta_fast` (`float`, *optional*):
99
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
100
+ ramp function. If unspecified, it defaults to 32.
101
+ `beta_slow` (`float`, *optional*):
102
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
103
+ ramp function. If unspecified, it defaults to 1.
104
+ `short_factor` (`list[float]`, *optional*):
105
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
106
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
107
+ size divided by the number of attention heads divided by 2
108
+ `long_factor` (`list[float]`, *optional*):
109
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
110
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
111
+ size divided by the number of attention heads divided by 2
112
+ `low_freq_factor` (`float`, *optional*):
113
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
114
+ `high_freq_factor` (`float`, *optional*):
115
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
116
+ attention_bias (`bool`, *optional*, defaults to `False`):
117
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
118
+ attention_dropout (`float`, *optional*, defaults to 0.0):
119
+ The dropout ratio for the attention probabilities.
120
+
121
+ ```python
122
+ >>> from transformers import ApertusModel, ApertusConfig
123
+
124
+ >>> # Initializing a Apertus-8B style configuration
125
+ >>> configuration = ApertusConfig()
126
+
127
+ >>> # Initializing a model from the Apertus-8B style configuration
128
+ >>> model = ApertusModel(configuration)
129
+
130
+ >>> # Accessing the model configuration
131
+ >>> configuration = model.config
132
+ ```"""
133
+
134
+ model_type = "apertus"
135
+ keys_to_ignore_at_inference = ["past_key_values"]
136
+ base_model_tp_plan = {
137
+ "layers.*.self_attn.q_proj": "colwise_rep", # we need to replicate here due to the added norm on q and k
138
+ "layers.*.self_attn.k_proj": "colwise_rep", # we need to replicate here due to the added norm on q and k
139
+ "layers.*.self_attn.v_proj": "colwise_rep", # we need to replicate here due to the added norm on q and k
140
+ "layers.*.self_attn.o_proj": "rowwise_rep", # we need to replicate here due to the added norm on q and k
141
+ "layers.*.mlp.up_proj": "colwise",
142
+ "layers.*.mlp.down_proj": "rowwise",
143
+ "layers.*.mlp.gate_proj": "colwise",
144
+ }
145
+ base_model_pp_plan = {
146
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
147
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
148
+ "norm": (["hidden_states"], ["hidden_states"]),
149
+ }
150
+
151
+ def __init__(
152
+ self,
153
+ vocab_size=131072,
154
+ hidden_size=4096,
155
+ intermediate_size=14336,
156
+ num_hidden_layers=32,
157
+ num_attention_heads=32,
158
+ num_key_value_heads=None,
159
+ hidden_act="xielu",
160
+ max_position_embeddings=65536,
161
+ initializer_range=0.02,
162
+ rms_norm_eps=1e-5,
163
+ use_cache=True,
164
+ pad_token_id=3,
165
+ bos_token_id=1,
166
+ eos_token_id=2,
167
+ tie_word_embeddings=False,
168
+ rope_theta=12000000.0,
169
+ rope_scaling={
170
+ "rope_type": "llama3",
171
+ "factor": 8.0,
172
+ "original_max_position_embeddings": 8192,
173
+ "low_freq_factor": 1.0,
174
+ "high_freq_factor": 4.0,
175
+ },
176
+ attention_bias=False,
177
+ attention_dropout=0.0,
178
+ patches=["liger", "cce"],
179
+ **kwargs,
180
+ ):
181
+ super().__init__(
182
+ pad_token_id=pad_token_id,
183
+ bos_token_id=bos_token_id,
184
+ eos_token_id=eos_token_id,
185
+ tie_word_embeddings=tie_word_embeddings,
186
+ **kwargs,
187
+ )
188
+ self.vocab_size = vocab_size
189
+ self.max_position_embeddings = max_position_embeddings
190
+ self.hidden_size = hidden_size
191
+ self.intermediate_size = intermediate_size
192
+ self.num_hidden_layers = num_hidden_layers
193
+ self.num_attention_heads = num_attention_heads
194
+
195
+ # for backward compatibility
196
+ if num_key_value_heads is None:
197
+ num_key_value_heads = num_attention_heads
198
+
199
+ self.num_key_value_heads = num_key_value_heads
200
+ self.hidden_act = hidden_act
201
+ self.initializer_range = initializer_range
202
+ self.rms_norm_eps = rms_norm_eps
203
+ self.use_cache = use_cache
204
+ self.rope_theta = rope_theta
205
+ self.rope_scaling = rope_scaling
206
+ self.attention_bias = attention_bias
207
+ self.attention_dropout = attention_dropout
208
+ # Validate the correctness of rotary position embeddings parameters
209
+ # BC: if there is a 'type' field, copy it it to 'rope_type'.
210
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
211
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
212
+ rope_config_validation(self)
213
+
214
+ self.patches = patches
215
+
216
+
217
+ __all__ = ["ApertusConfig"]
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 68
7
+ ],
8
+ "pad_token_id": 3,
9
+ "transformers_version": "4.56.1"
10
+ }
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a7c21e1d777d7f5651191f50f3a873345c770fb49e384341d7e8584cd18f1402
3
+ size 4999776656
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:79c2bd751b9c072de6cfeb97cc136d912b9d5cb2dcbbd9e30ed7b9cacb7f2b17
3
+ size 4882374192
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:681c4e64ea0ea9171df8a9e1c283d88253d2a70b7d278ef2d99ab1cd6bcdaf18
3
+ size 4974647808
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a1187bf39f8a7b2045be7e3c142b4a7bd2967668fcfad802800d82d976b9b6d
3
+ size 1249928160
model.safetensors.index.json ADDED
@@ -0,0 +1,459 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 274496,
4
+ "total_size": 16106676480
5
+ },
6
+ "weight_map": {
7
+ "lm_head.weight": "model-00004-of-00004.safetensors",
8
+ "model.embed_tokens.weight": "model-00001-of-00004.safetensors",
9
+ "model.layers.0.attention_layernorm.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.attention_layernorm.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
28
+ "model.layers.1.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
30
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
31
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
32
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
33
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
34
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
35
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
36
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
37
+ "model.layers.10.attention_layernorm.weight": "model-00002-of-00004.safetensors",
38
+ "model.layers.10.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
39
+ "model.layers.10.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
40
+ "model.layers.10.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
41
+ "model.layers.10.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
42
+ "model.layers.10.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
43
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
44
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
45
+ "model.layers.10.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
46
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
47
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
48
+ "model.layers.10.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
49
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
50
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
51
+ "model.layers.11.attention_layernorm.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.11.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
53
+ "model.layers.11.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
54
+ "model.layers.11.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
55
+ "model.layers.11.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
56
+ "model.layers.11.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
57
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
58
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
59
+ "model.layers.11.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
61
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.11.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
63
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
64
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
65
+ "model.layers.12.attention_layernorm.weight": "model-00002-of-00004.safetensors",
66
+ "model.layers.12.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
67
+ "model.layers.12.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
68
+ "model.layers.12.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
69
+ "model.layers.12.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
70
+ "model.layers.12.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
71
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.12.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.12.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
78
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.13.attention_layernorm.weight": "model-00002-of-00004.safetensors",
80
+ "model.layers.13.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.13.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
82
+ "model.layers.13.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
83
+ "model.layers.13.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
84
+ "model.layers.13.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
85
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
86
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.13.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.13.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
92
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.14.attention_layernorm.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.14.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.14.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
96
+ "model.layers.14.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
97
+ "model.layers.14.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
98
+ "model.layers.14.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
99
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
100
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.14.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.14.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.15.attention_layernorm.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.15.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
109
+ "model.layers.15.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
110
+ "model.layers.15.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
111
+ "model.layers.15.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
112
+ "model.layers.15.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
113
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
114
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.15.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.15.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.16.attention_layernorm.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.16.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
123
+ "model.layers.16.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
124
+ "model.layers.16.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
125
+ "model.layers.16.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
126
+ "model.layers.16.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
127
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
128
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.16.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
130
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
131
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.16.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
133
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
134
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
135
+ "model.layers.17.attention_layernorm.weight": "model-00002-of-00004.safetensors",
136
+ "model.layers.17.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
137
+ "model.layers.17.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
138
+ "model.layers.17.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
139
+ "model.layers.17.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
140
+ "model.layers.17.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
141
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
142
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
143
+ "model.layers.17.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
144
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
145
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
146
+ "model.layers.17.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
147
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
148
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
149
+ "model.layers.18.attention_layernorm.weight": "model-00002-of-00004.safetensors",
150
+ "model.layers.18.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
151
+ "model.layers.18.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
152
+ "model.layers.18.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
153
+ "model.layers.18.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
154
+ "model.layers.18.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
155
+ "model.layers.18.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
156
+ "model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
157
+ "model.layers.18.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
158
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
159
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
160
+ "model.layers.18.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
161
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
162
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
163
+ "model.layers.19.attention_layernorm.weight": "model-00002-of-00004.safetensors",
164
+ "model.layers.19.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
165
+ "model.layers.19.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
166
+ "model.layers.19.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
167
+ "model.layers.19.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
168
+ "model.layers.19.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
169
+ "model.layers.19.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
170
+ "model.layers.19.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
171
+ "model.layers.19.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
172
+ "model.layers.19.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
173
+ "model.layers.19.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
174
+ "model.layers.19.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
175
+ "model.layers.19.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
176
+ "model.layers.19.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
177
+ "model.layers.2.attention_layernorm.weight": "model-00001-of-00004.safetensors",
178
+ "model.layers.2.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
179
+ "model.layers.2.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
180
+ "model.layers.2.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
181
+ "model.layers.2.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
182
+ "model.layers.2.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
183
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
184
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
185
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
186
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
187
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
188
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
189
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
190
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
191
+ "model.layers.20.attention_layernorm.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.20.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
193
+ "model.layers.20.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
194
+ "model.layers.20.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
195
+ "model.layers.20.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
196
+ "model.layers.20.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
197
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
198
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.20.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
200
+ "model.layers.20.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
201
+ "model.layers.20.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
202
+ "model.layers.20.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
203
+ "model.layers.20.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
204
+ "model.layers.20.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
205
+ "model.layers.21.attention_layernorm.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.21.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
207
+ "model.layers.21.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
208
+ "model.layers.21.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
209
+ "model.layers.21.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
210
+ "model.layers.21.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
211
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
212
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.21.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.21.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
218
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.22.attention_layernorm.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.22.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
221
+ "model.layers.22.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
222
+ "model.layers.22.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
223
+ "model.layers.22.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
224
+ "model.layers.22.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
225
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
226
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.22.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.22.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
231
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
232
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.23.attention_layernorm.weight": "model-00003-of-00004.safetensors",
234
+ "model.layers.23.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
235
+ "model.layers.23.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
236
+ "model.layers.23.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
237
+ "model.layers.23.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
238
+ "model.layers.23.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
239
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
240
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.23.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
243
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.23.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
245
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
246
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
247
+ "model.layers.24.attention_layernorm.weight": "model-00003-of-00004.safetensors",
248
+ "model.layers.24.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.24.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
250
+ "model.layers.24.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
251
+ "model.layers.24.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
252
+ "model.layers.24.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
253
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
254
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.24.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.24.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
259
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
260
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.25.attention_layernorm.weight": "model-00003-of-00004.safetensors",
262
+ "model.layers.25.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
263
+ "model.layers.25.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
264
+ "model.layers.25.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
265
+ "model.layers.25.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
266
+ "model.layers.25.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
267
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
268
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
269
+ "model.layers.25.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
270
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
271
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
272
+ "model.layers.25.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
273
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
274
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
275
+ "model.layers.26.attention_layernorm.weight": "model-00003-of-00004.safetensors",
276
+ "model.layers.26.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
277
+ "model.layers.26.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
278
+ "model.layers.26.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
279
+ "model.layers.26.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
280
+ "model.layers.26.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
281
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
282
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
283
+ "model.layers.26.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
284
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
285
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
286
+ "model.layers.26.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
287
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
288
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
289
+ "model.layers.27.attention_layernorm.weight": "model-00003-of-00004.safetensors",
290
+ "model.layers.27.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
291
+ "model.layers.27.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
292
+ "model.layers.27.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
293
+ "model.layers.27.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
294
+ "model.layers.27.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
295
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
296
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
297
+ "model.layers.27.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
298
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
299
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
300
+ "model.layers.27.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
301
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
302
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
303
+ "model.layers.28.attention_layernorm.weight": "model-00003-of-00004.safetensors",
304
+ "model.layers.28.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
305
+ "model.layers.28.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
306
+ "model.layers.28.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
307
+ "model.layers.28.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
308
+ "model.layers.28.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
309
+ "model.layers.28.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
310
+ "model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
311
+ "model.layers.28.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
312
+ "model.layers.28.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
313
+ "model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
314
+ "model.layers.28.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
315
+ "model.layers.28.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
316
+ "model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
317
+ "model.layers.29.attention_layernorm.weight": "model-00003-of-00004.safetensors",
318
+ "model.layers.29.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
319
+ "model.layers.29.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
320
+ "model.layers.29.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
321
+ "model.layers.29.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
322
+ "model.layers.29.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
323
+ "model.layers.29.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
324
+ "model.layers.29.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
325
+ "model.layers.29.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
326
+ "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
327
+ "model.layers.29.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
328
+ "model.layers.29.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
329
+ "model.layers.29.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
330
+ "model.layers.29.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
331
+ "model.layers.3.attention_layernorm.weight": "model-00001-of-00004.safetensors",
332
+ "model.layers.3.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
333
+ "model.layers.3.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
334
+ "model.layers.3.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
335
+ "model.layers.3.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
336
+ "model.layers.3.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
337
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
338
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
339
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
340
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
341
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
342
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
343
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
344
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
345
+ "model.layers.30.attention_layernorm.weight": "model-00003-of-00004.safetensors",
346
+ "model.layers.30.feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
347
+ "model.layers.30.mlp.act_fn.alpha_n": "model-00003-of-00004.safetensors",
348
+ "model.layers.30.mlp.act_fn.alpha_p": "model-00003-of-00004.safetensors",
349
+ "model.layers.30.mlp.act_fn.beta": "model-00003-of-00004.safetensors",
350
+ "model.layers.30.mlp.act_fn.eps": "model-00003-of-00004.safetensors",
351
+ "model.layers.30.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
352
+ "model.layers.30.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
353
+ "model.layers.30.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
354
+ "model.layers.30.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
355
+ "model.layers.30.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
356
+ "model.layers.30.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
357
+ "model.layers.30.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
358
+ "model.layers.30.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
359
+ "model.layers.31.attention_layernorm.weight": "model-00004-of-00004.safetensors",
360
+ "model.layers.31.feedforward_layernorm.weight": "model-00004-of-00004.safetensors",
361
+ "model.layers.31.mlp.act_fn.alpha_n": "model-00004-of-00004.safetensors",
362
+ "model.layers.31.mlp.act_fn.alpha_p": "model-00004-of-00004.safetensors",
363
+ "model.layers.31.mlp.act_fn.beta": "model-00004-of-00004.safetensors",
364
+ "model.layers.31.mlp.act_fn.eps": "model-00004-of-00004.safetensors",
365
+ "model.layers.31.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
366
+ "model.layers.31.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
367
+ "model.layers.31.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
368
+ "model.layers.31.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
369
+ "model.layers.31.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
370
+ "model.layers.31.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
371
+ "model.layers.31.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
372
+ "model.layers.31.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
373
+ "model.layers.4.attention_layernorm.weight": "model-00001-of-00004.safetensors",
374
+ "model.layers.4.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
375
+ "model.layers.4.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
376
+ "model.layers.4.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
377
+ "model.layers.4.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
378
+ "model.layers.4.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
379
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
380
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
381
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
382
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
383
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
384
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
385
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
386
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
387
+ "model.layers.5.attention_layernorm.weight": "model-00001-of-00004.safetensors",
388
+ "model.layers.5.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
389
+ "model.layers.5.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
390
+ "model.layers.5.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
391
+ "model.layers.5.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
392
+ "model.layers.5.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
393
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
394
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
395
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
396
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
397
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
398
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
399
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
400
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
401
+ "model.layers.6.attention_layernorm.weight": "model-00001-of-00004.safetensors",
402
+ "model.layers.6.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
403
+ "model.layers.6.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
404
+ "model.layers.6.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
405
+ "model.layers.6.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
406
+ "model.layers.6.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
407
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
408
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
409
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
410
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
411
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
412
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
413
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
414
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
415
+ "model.layers.7.attention_layernorm.weight": "model-00001-of-00004.safetensors",
416
+ "model.layers.7.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
417
+ "model.layers.7.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
418
+ "model.layers.7.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
419
+ "model.layers.7.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
420
+ "model.layers.7.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
421
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
422
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
423
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
424
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
425
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
426
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
427
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
428
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
429
+ "model.layers.8.attention_layernorm.weight": "model-00001-of-00004.safetensors",
430
+ "model.layers.8.feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
431
+ "model.layers.8.mlp.act_fn.alpha_n": "model-00001-of-00004.safetensors",
432
+ "model.layers.8.mlp.act_fn.alpha_p": "model-00001-of-00004.safetensors",
433
+ "model.layers.8.mlp.act_fn.beta": "model-00001-of-00004.safetensors",
434
+ "model.layers.8.mlp.act_fn.eps": "model-00001-of-00004.safetensors",
435
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
436
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
437
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
438
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
439
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
440
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
441
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
442
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
443
+ "model.layers.9.attention_layernorm.weight": "model-00002-of-00004.safetensors",
444
+ "model.layers.9.feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
445
+ "model.layers.9.mlp.act_fn.alpha_n": "model-00002-of-00004.safetensors",
446
+ "model.layers.9.mlp.act_fn.alpha_p": "model-00002-of-00004.safetensors",
447
+ "model.layers.9.mlp.act_fn.beta": "model-00002-of-00004.safetensors",
448
+ "model.layers.9.mlp.act_fn.eps": "model-00002-of-00004.safetensors",
449
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
450
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
451
+ "model.layers.9.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
452
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
453
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
454
+ "model.layers.9.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
455
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
456
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
457
+ "model.norm.weight": "model-00004-of-00004.safetensors"
458
+ }
459
+ }
modeling_apertus.py ADDED
@@ -0,0 +1,666 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
2
+ # This file was automatically generated from src/transformers/models/apertus/modular_apertus.py.
3
+ # Do NOT edit this file manually as any edits will be overwritten by the generation of
4
+ # the file from the modular. If any change should be done, please apply the change to the
5
+ # modular_apertus.py file directly. One of our CI enforces this.
6
+ # 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
7
+ # coding=utf-8
8
+ # Copyright 2025 the HuggingFace Inc. team and the Swiss AI Initiative. All rights reserved.
9
+ #
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ from typing import Callable, Optional, Union
23
+
24
+ import torch
25
+ from torch import nn
26
+
27
+ from transformers.activations import ACT2FN
28
+ from transformers.cache_utils import Cache, DynamicCache
29
+ from transformers.generation import GenerationMixin
30
+ from transformers.integrations import use_kernel_forward_from_hub
31
+ from transformers.masking_utils import create_causal_mask
32
+ from transformers.modeling_layers import GenericForTokenClassification, GradientCheckpointingLayer
33
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
34
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
35
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
36
+ from transformers.processing_utils import Unpack
37
+ from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple
38
+ from transformers.utils.deprecation import deprecate_kwarg
39
+ from transformers.utils.generic import check_model_inputs
40
+ from .configuration_apertus import ApertusConfig
41
+
42
+ try:
43
+ from liger_kernel.ops.rope import LigerRopeFunction
44
+ from liger_kernel.ops.rms_norm import LigerRMSNormFunction
45
+ ENABLE_LIGER = True
46
+ except Exception as e:
47
+ print(f"Warning, could not import Liger packages, force disabling all Liger patches!\n{e}")
48
+ ENABLE_LIGER = False
49
+
50
+ try:
51
+ from cut_cross_entropy import linear_cross_entropy
52
+ from typing import TypedDict
53
+ from dataclasses import dataclass
54
+
55
+ class CCEPreset(TypedDict):
56
+ filter_eps: float | str | None
57
+ accum_e_fp32: bool
58
+ accum_c_fp32: bool
59
+ filter_e_grad: bool
60
+ filter_c_grad: bool
61
+
62
+ class CCEKwargs(CCEPreset):
63
+ impl: str
64
+ reduction: str
65
+
66
+ @dataclass
67
+ class PatchOptions:
68
+ impl: str
69
+ reduction: str
70
+ filter_eps: float | str | None
71
+ accum_e_fp32: bool
72
+ accum_c_fp32: bool
73
+ filter_e_grad: bool
74
+ filter_c_grad: bool
75
+ train_only: bool
76
+
77
+ def to_kwargs(self) -> CCEKwargs:
78
+ return CCEKwargs(
79
+ impl=self.impl,
80
+ reduction=self.reduction,
81
+ filter_eps=self.filter_eps,
82
+ accum_e_fp32=self.accum_e_fp32,
83
+ accum_c_fp32=self.accum_c_fp32,
84
+ filter_e_grad=self.filter_e_grad,
85
+ filter_c_grad=self.filter_c_grad,
86
+ )
87
+
88
+ _PATCH_OPTS = PatchOptions(
89
+ impl="cce",
90
+ reduction="mean",
91
+ filter_eps="auto",
92
+ accum_e_fp32=False,
93
+ accum_c_fp32=False,
94
+ filter_e_grad=True,
95
+ filter_c_grad=True,
96
+ train_only=False,
97
+ )
98
+
99
+ def apply_lce(
100
+ e: torch.Tensor,
101
+ c: torch.Tensor,
102
+ labels: torch.Tensor,
103
+ opts,
104
+ bias: torch.Tensor | None = None,
105
+ **loss_kwargs,
106
+ ) -> torch.Tensor:
107
+ num_items_in_batch = loss_kwargs.get("num_items_in_batch", None)
108
+ cce_kwargs = opts.to_kwargs()
109
+ if num_items_in_batch is not None and cce_kwargs["reduction"] == "mean":
110
+ cce_kwargs["reduction"] = "sum"
111
+ else:
112
+ num_items_in_batch = None
113
+
114
+ loss = linear_cross_entropy(
115
+ e,
116
+ c,
117
+ labels.to(e.device),
118
+ bias=bias,
119
+ shift=True,
120
+ **cce_kwargs,
121
+ )
122
+
123
+ if num_items_in_batch is not None:
124
+ loss = loss / num_items_in_batch
125
+
126
+ return loss
127
+ ENABLE_CCE = True
128
+ except Exception as e:
129
+ print(f"Warning, could not import CCE packages, force disabling all CCE patches!\n{e}")
130
+ ENABLE_CCE = False
131
+
132
+ class ApertusMLP(nn.Module):
133
+ def __init__(self, config):
134
+ super().__init__()
135
+ self.config = config
136
+ self.hidden_size = config.hidden_size
137
+ self.intermediate_size = config.intermediate_size
138
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
139
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
140
+ self.act_fn = ACT2FN[config.hidden_act]
141
+
142
+ def forward(self, x):
143
+ return self.down_proj(self.act_fn(self.up_proj(x)))
144
+
145
+
146
+ @use_kernel_forward_from_hub("RMSNorm")
147
+ class ApertusRMSNorm(nn.Module):
148
+ def __init__(self, hidden_size, eps=1e-6, **kwargs):
149
+ """
150
+ ApertusRMSNorm is equivalent to T5LayerNorm
151
+ """
152
+ super().__init__()
153
+ self.weight = nn.Parameter(torch.ones(hidden_size))
154
+ self.variance_epsilon = eps
155
+
156
+ def forward(self, hidden_states):
157
+ input_dtype = hidden_states.dtype
158
+ hidden_states = hidden_states.to(torch.float32)
159
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
160
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
161
+ return self.weight * hidden_states.to(input_dtype)
162
+
163
+ def extra_repr(self):
164
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
165
+
166
+ class ApertusLigerRMSNorm(nn.Module):
167
+ def __init__(
168
+ self,
169
+ hidden_size,
170
+ eps=1e-6,
171
+ offset=0.0,
172
+ casting_mode="llama",
173
+ in_place=True,
174
+ row_mode=None
175
+ ):
176
+ super().__init__()
177
+ self.weight = nn.Parameter(torch.ones(hidden_size))
178
+ self.variance_epsilon, self.offset, self.casting_mode, self.in_place, self.row_mode = (
179
+ eps,
180
+ offset,
181
+ casting_mode,
182
+ in_place,
183
+ row_mode,
184
+ )
185
+
186
+ def forward(self, hidden_states):
187
+ return LigerRMSNormFunction.apply(
188
+ hidden_states,
189
+ self.weight,
190
+ self.variance_epsilon,
191
+ self.offset,
192
+ self.casting_mode,
193
+ self.in_place,
194
+ self.row_mode,
195
+ )
196
+
197
+ def extra_repr(self):
198
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
199
+
200
+ class ApertusRotaryEmbedding(nn.Module):
201
+ inv_freq: torch.Tensor # fix linting for `register_buffer`
202
+
203
+ def __init__(self, config: ApertusConfig, device=None):
204
+ super().__init__()
205
+ # BC: "rope_type" was originally "type"
206
+ if hasattr(config, "rope_scaling") and isinstance(config.rope_scaling, dict):
207
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
208
+ else:
209
+ self.rope_type = "default"
210
+ self.max_seq_len_cached = config.max_position_embeddings
211
+ self.original_max_seq_len = config.max_position_embeddings
212
+
213
+ self.config = config
214
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
215
+
216
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
217
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
218
+ self.original_inv_freq = self.inv_freq
219
+
220
+ @torch.no_grad()
221
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
222
+ def forward(self, x, position_ids):
223
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
224
+ position_ids_expanded = position_ids[:, None, :].float()
225
+
226
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
227
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
228
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
229
+ emb = torch.cat((freqs, freqs), dim=-1)
230
+ cos = emb.cos() * self.attention_scaling
231
+ sin = emb.sin() * self.attention_scaling
232
+
233
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
234
+
235
+
236
+ def rotate_half(x):
237
+ """Rotates half the hidden dims of the input."""
238
+ x1 = x[..., : x.shape[-1] // 2]
239
+ x2 = x[..., x.shape[-1] // 2 :]
240
+ return torch.cat((-x2, x1), dim=-1)
241
+
242
+
243
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
244
+ """Applies Rotary Position Embedding to the query and key tensors.
245
+
246
+ Args:
247
+ q (`torch.Tensor`): The query tensor.
248
+ k (`torch.Tensor`): The key tensor.
249
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
250
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
251
+ position_ids (`torch.Tensor`, *optional*):
252
+ Deprecated and unused.
253
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
254
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
255
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
256
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
257
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
258
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
259
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
260
+ Returns:
261
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
262
+ """
263
+ cos = cos.unsqueeze(unsqueeze_dim)
264
+ sin = sin.unsqueeze(unsqueeze_dim)
265
+ q_embed = (q * cos) + (rotate_half(q) * sin)
266
+ k_embed = (k * cos) + (rotate_half(k) * sin)
267
+ return q_embed, k_embed
268
+
269
+ def apply_liger_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
270
+ """Applies Rotary Position Embedding to the query and key tensors.
271
+
272
+ Args:
273
+ q (`torch.Tensor`): The query tensor.
274
+ k (`torch.Tensor`): The key tensor.
275
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
276
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
277
+ position_ids (`torch.Tensor`, *optional*):
278
+ Deprecated and unused.
279
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
280
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
281
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
282
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
283
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
284
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
285
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
286
+ Returns:
287
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
288
+ """
289
+ return LigerRopeFunction.apply(q, k, cos, sin, position_ids, unsqueeze_dim)
290
+
291
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
292
+ """
293
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
294
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
295
+ """
296
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
297
+ if n_rep == 1:
298
+ return hidden_states
299
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
300
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
301
+
302
+
303
+ def eager_attention_forward(
304
+ module: nn.Module,
305
+ query: torch.Tensor,
306
+ key: torch.Tensor,
307
+ value: torch.Tensor,
308
+ attention_mask: Optional[torch.Tensor],
309
+ scaling: float,
310
+ dropout: float = 0.0,
311
+ **kwargs: Unpack[TransformersKwargs],
312
+ ):
313
+ key_states = repeat_kv(key, module.num_key_value_groups)
314
+ value_states = repeat_kv(value, module.num_key_value_groups)
315
+
316
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
317
+ if attention_mask is not None:
318
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
319
+ attn_weights = attn_weights + causal_mask
320
+
321
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
322
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
323
+ attn_output = torch.matmul(attn_weights, value_states)
324
+ attn_output = attn_output.transpose(1, 2).contiguous()
325
+
326
+ return attn_output, attn_weights
327
+
328
+
329
+ class ApertusAttention(nn.Module):
330
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
331
+
332
+ def __init__(self, config: ApertusConfig, layer_idx: Optional[int] = None):
333
+ super().__init__()
334
+ self.config = config
335
+ self.layer_idx = layer_idx
336
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
337
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
338
+ self.scaling = self.head_dim**-0.5
339
+ self.attention_dropout = config.attention_dropout
340
+ self.is_causal = True
341
+
342
+ self.q_proj = nn.Linear(
343
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
344
+ )
345
+ self.k_proj = nn.Linear(
346
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
347
+ )
348
+ self.v_proj = nn.Linear(
349
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
350
+ )
351
+ self.o_proj = nn.Linear(
352
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
353
+ )
354
+ if "liger" in config.patches and ENABLE_LIGER:
355
+ self.q_norm = ApertusLigerRMSNorm(self.head_dim, config.rms_norm_eps)
356
+ self.k_norm = ApertusLigerRMSNorm(self.head_dim, config.rms_norm_eps)
357
+ self._ROTARY = apply_liger_pos_emb
358
+ else:
359
+ self.q_norm = ApertusRMSNorm(self.head_dim, config.rms_norm_eps)
360
+ self.k_norm = ApertusRMSNorm(self.head_dim, config.rms_norm_eps)
361
+ self._ROTARY = apply_rotary_pos_emb
362
+
363
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
364
+ def forward(
365
+ self,
366
+ hidden_states: torch.Tensor,
367
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
368
+ attention_mask: Optional[torch.Tensor],
369
+ past_key_values: Optional[Cache] = None,
370
+ cache_position: Optional[torch.LongTensor] = None,
371
+ **kwargs: Unpack[TransformersKwargs],
372
+ ) -> tuple[torch.Tensor, torch.Tensor]:
373
+ input_shape = hidden_states.shape[:-1]
374
+ hidden_shape = (*input_shape, -1, self.head_dim)
375
+
376
+ query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
377
+ key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
378
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
379
+ query_states = self.q_norm(query_states)
380
+ key_states = self.k_norm(key_states)
381
+
382
+ cos, sin = position_embeddings
383
+ query_states, key_states = self._ROTARY(query_states, key_states, cos, sin)
384
+
385
+ if past_key_values is not None:
386
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
387
+ key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_kwargs)
388
+
389
+ attention_interface: Callable = eager_attention_forward
390
+ if self.config._attn_implementation != "eager":
391
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
392
+
393
+ attn_output, attn_weights = attention_interface(
394
+ self,
395
+ query_states,
396
+ key_states,
397
+ value_states,
398
+ attention_mask,
399
+ dropout=0.0 if not self.training else self.attention_dropout,
400
+ scaling=self.scaling,
401
+ **kwargs,
402
+ )
403
+
404
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
405
+ attn_output = self.o_proj(attn_output)
406
+ return attn_output, attn_weights
407
+
408
+
409
+ class ApertusDecoderLayer(GradientCheckpointingLayer):
410
+ def __init__(self, config: ApertusConfig, layer_idx: int):
411
+ super().__init__()
412
+ self.hidden_size = config.hidden_size
413
+
414
+ self.self_attn = ApertusAttention(config=config, layer_idx=layer_idx)
415
+
416
+ self.mlp = ApertusMLP(config)
417
+
418
+ if "liger" in config.patches and ENABLE_LIGER:
419
+ self.attention_layernorm = ApertusLigerRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
420
+ self.feedforward_layernorm = ApertusLigerRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
421
+ else:
422
+ self.attention_layernorm = ApertusRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
423
+ self.feedforward_layernorm = ApertusRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
424
+
425
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
426
+ def forward(
427
+ self,
428
+ hidden_states: torch.Tensor,
429
+ attention_mask: Optional[torch.Tensor] = None,
430
+ position_ids: Optional[torch.LongTensor] = None,
431
+ past_key_values: Optional[Cache] = None,
432
+ use_cache: Optional[bool] = False,
433
+ cache_position: Optional[torch.LongTensor] = None,
434
+ position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None,
435
+ **kwargs: Unpack[TransformersKwargs],
436
+ ) -> tuple[torch.Tensor]:
437
+ residual = hidden_states
438
+ hidden_states = self.attention_layernorm(hidden_states)
439
+ hidden_states, _ = self.self_attn(
440
+ hidden_states=hidden_states,
441
+ attention_mask=attention_mask,
442
+ position_ids=position_ids,
443
+ past_key_values=past_key_values,
444
+ use_cache=use_cache,
445
+ cache_position=cache_position,
446
+ position_embeddings=position_embeddings,
447
+ **kwargs,
448
+ )
449
+ hidden_states = residual + hidden_states
450
+
451
+ # Fully Connected
452
+ residual = hidden_states
453
+ hidden_states = self.feedforward_layernorm(hidden_states)
454
+ hidden_states = self.mlp(hidden_states)
455
+ hidden_states = residual + hidden_states
456
+ return hidden_states
457
+
458
+
459
+ @auto_docstring
460
+ class ApertusPreTrainedModel(PreTrainedModel):
461
+ config: ApertusConfig
462
+ base_model_prefix = "model"
463
+ supports_gradient_checkpointing = True
464
+ _no_split_modules = ["ApertusDecoderLayer"]
465
+ _skip_keys_device_placement = ["past_key_values"]
466
+ _supports_flash_attn = True
467
+ _supports_sdpa = True
468
+ _supports_flex_attn = True
469
+
470
+ _can_compile_fullgraph = True
471
+ _supports_attention_backend = True
472
+ _can_record_outputs = {
473
+ "hidden_states": ApertusDecoderLayer,
474
+ "attentions": ApertusAttention,
475
+ }
476
+
477
+
478
+ @auto_docstring
479
+ class ApertusModel(ApertusPreTrainedModel):
480
+ def __init__(self, config: ApertusConfig):
481
+ super().__init__(config)
482
+ self.padding_idx = config.pad_token_id
483
+ self.vocab_size = config.vocab_size
484
+
485
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
486
+ self.layers = nn.ModuleList(
487
+ [ApertusDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
488
+ )
489
+
490
+ if "liger" in config.patches and ENABLE_LIGER:
491
+ self.norm = ApertusLigerRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
492
+ print("Using Liger RMSNorm!")
493
+ else:
494
+ self.norm = ApertusRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
495
+ self.rotary_emb = ApertusRotaryEmbedding(config=config)
496
+ self.gradient_checkpointing = False
497
+
498
+ # Initialize weights and apply final processing
499
+ self.post_init()
500
+
501
+ @check_model_inputs
502
+ @auto_docstring
503
+ def forward(
504
+ self,
505
+ input_ids: Optional[torch.LongTensor] = None,
506
+ attention_mask: Optional[torch.Tensor] = None,
507
+ position_ids: Optional[torch.LongTensor] = None,
508
+ past_key_values: Optional[Cache] = None,
509
+ inputs_embeds: Optional[torch.FloatTensor] = None,
510
+ cache_position: Optional[torch.LongTensor] = None,
511
+ use_cache: Optional[bool] = None,
512
+ **kwargs: Unpack[TransformersKwargs],
513
+ ) -> BaseModelOutputWithPast:
514
+ if (input_ids is None) ^ (inputs_embeds is not None):
515
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
516
+
517
+ if inputs_embeds is None:
518
+ inputs_embeds: torch.Tensor = self.embed_tokens(input_ids)
519
+
520
+ if use_cache and past_key_values is None:
521
+ past_key_values = DynamicCache(config=self.config)
522
+
523
+ if cache_position is None:
524
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
525
+ cache_position: torch.Tensor = torch.arange(
526
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
527
+ )
528
+
529
+ if position_ids is None:
530
+ position_ids = cache_position.unsqueeze(0)
531
+
532
+ causal_mask = create_causal_mask(
533
+ config=self.config,
534
+ input_embeds=inputs_embeds,
535
+ attention_mask=attention_mask,
536
+ cache_position=cache_position,
537
+ past_key_values=past_key_values,
538
+ position_ids=position_ids,
539
+ )
540
+
541
+ hidden_states = inputs_embeds
542
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
543
+
544
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
545
+ hidden_states = decoder_layer(
546
+ hidden_states,
547
+ attention_mask=causal_mask,
548
+ position_ids=position_ids,
549
+ past_key_values=past_key_values,
550
+ cache_position=cache_position,
551
+ position_embeddings=position_embeddings,
552
+ **kwargs,
553
+ )
554
+
555
+ hidden_states = self.norm(hidden_states)
556
+ return BaseModelOutputWithPast(
557
+ last_hidden_state=hidden_states,
558
+ past_key_values=past_key_values,
559
+ )
560
+
561
+
562
+ @auto_docstring
563
+ class ApertusForCausalLM(ApertusPreTrainedModel, GenerationMixin):
564
+ _tied_weights_keys = ["lm_head.weight"]
565
+ _tp_plan = {"lm_head": "colwise_rep"}
566
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
567
+
568
+ def __init__(self, config):
569
+ super().__init__(config)
570
+ self.config = config
571
+ self.model = ApertusModel(config)
572
+ self.vocab_size = config.vocab_size
573
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
574
+
575
+ # Initialize weights and apply final processing
576
+ self.post_init()
577
+
578
+ @can_return_tuple
579
+ @auto_docstring
580
+ def forward(
581
+ self,
582
+ input_ids: Optional[torch.LongTensor] = None,
583
+ attention_mask: Optional[torch.Tensor] = None,
584
+ position_ids: Optional[torch.LongTensor] = None,
585
+ past_key_values: Optional[Cache] = None,
586
+ inputs_embeds: Optional[torch.FloatTensor] = None,
587
+ labels: Optional[torch.LongTensor] = None,
588
+ use_cache: Optional[bool] = None,
589
+ cache_position: Optional[torch.LongTensor] = None,
590
+ logits_to_keep: Union[int, torch.Tensor] = 0,
591
+ **kwargs: Unpack[TransformersKwargs],
592
+ ) -> CausalLMOutputWithPast:
593
+ r"""
594
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
595
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
596
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
597
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
598
+
599
+ Example:
600
+
601
+ ```python
602
+ >>> from transformers import AutoTokenizer, ApertusForCausalLM
603
+
604
+ >>> model = ApertusForCausalLM.from_pretrained("swiss-ai/Apertus-8B")
605
+ >>> tokenizer = AutoTokenizer.from_pretrained("swiss-ai/Apertus-8B")
606
+
607
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
608
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
609
+
610
+ >>> # Generate
611
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
612
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
613
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
614
+ ```"""
615
+ outputs: BaseModelOutputWithPast = self.model(
616
+ input_ids=input_ids,
617
+ attention_mask=attention_mask,
618
+ position_ids=position_ids,
619
+ past_key_values=past_key_values,
620
+ inputs_embeds=inputs_embeds,
621
+ use_cache=use_cache,
622
+ cache_position=cache_position,
623
+ **kwargs,
624
+ )
625
+ hidden_states = outputs.last_hidden_state
626
+ loss = None
627
+ logits = None
628
+
629
+ if "cce" in self.config.patches and ENABLE_CCE and labels is not None:
630
+ loss = apply_lce(
631
+ hidden_states,
632
+ self.lm_head.weight,
633
+ labels,
634
+ _PATCH_OPTS,
635
+ **kwargs,
636
+ )
637
+
638
+ return CausalLMOutputWithPast(
639
+ loss=loss,
640
+ logits=logits,
641
+ past_key_values=outputs.past_key_values,
642
+ hidden_states=outputs.hidden_states,
643
+ attentions=outputs.attentions,
644
+ )
645
+ else:
646
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
647
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
648
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
649
+
650
+ if labels is not None:
651
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
652
+
653
+ return CausalLMOutputWithPast(
654
+ loss=loss,
655
+ logits=logits,
656
+ past_key_values=outputs.past_key_values,
657
+ hidden_states=outputs.hidden_states,
658
+ attentions=outputs.attentions,
659
+ )
660
+
661
+
662
+ class ApertusForTokenClassification(GenericForTokenClassification, ApertusPreTrainedModel):
663
+ pass
664
+
665
+
666
+ __all__ = ["ApertusModel", "ApertusForCausalLM", "ApertusForTokenClassification", "ApertusPreTrainedModel"]
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|im_end|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "<pad>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3b48362424d6314748c7d8a8d943e4e1a46552647ae9176b08d4f452e7b4313
3
+ size 17078467
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff