ToastyPigeon commited on
Commit
7b88703
·
verified ·
1 Parent(s): e3c1cba

Training in progress, step 63

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
added_tokens.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "<image_soft_token>": 262144
3
+ }
chat_template.jinja ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {{ bos_token }}{% for message in messages %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '<start_of_turn>' + role + '
2
+ ' + message['content'] | trim + '<end_of_turn>
3
+ ' }}{% endfor %}{% if add_generation_prompt %}{{'<start_of_turn>model
4
+ '}}{% endif %}
config.json ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_sliding_window_pattern": 6,
3
+ "architectures": [
4
+ "GemmagainForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "attn_logit_softcapping": null,
9
+ "auto_map": {
10
+ "AutoConfig": "configuration_gemmagain.GemmagainConfig",
11
+ "AutoModelForCausalLM": "modeling_gemmagain.GemmagainForCausalLM"
12
+ },
13
+ "bos_token_id": 2,
14
+ "cache_implementation": "hybrid",
15
+ "dtype": "float32",
16
+ "eos_token_id": 106,
17
+ "final_logit_softcapping": null,
18
+ "head_dim": 256,
19
+ "hidden_activation": "gelu_pytorch_tanh",
20
+ "hidden_size": 2560,
21
+ "initializer_range": 0.02,
22
+ "intermediate_size": 10240,
23
+ "layer_sequence": [
24
+ [
25
+ 0,
26
+ 34
27
+ ]
28
+ ],
29
+ "layer_types": [
30
+ "sliding_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "sliding_attention",
34
+ "sliding_attention",
35
+ "full_attention",
36
+ "sliding_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "sliding_attention",
40
+ "sliding_attention",
41
+ "full_attention",
42
+ "sliding_attention",
43
+ "sliding_attention",
44
+ "sliding_attention",
45
+ "sliding_attention",
46
+ "sliding_attention",
47
+ "full_attention",
48
+ "sliding_attention",
49
+ "sliding_attention",
50
+ "sliding_attention",
51
+ "sliding_attention",
52
+ "sliding_attention",
53
+ "full_attention",
54
+ "sliding_attention",
55
+ "sliding_attention",
56
+ "sliding_attention",
57
+ "sliding_attention",
58
+ "sliding_attention",
59
+ "full_attention",
60
+ "sliding_attention",
61
+ "sliding_attention",
62
+ "sliding_attention",
63
+ "sliding_attention"
64
+ ],
65
+ "max_position_embeddings": 131072,
66
+ "model_type": "gemma3",
67
+ "num_attention_heads": 8,
68
+ "num_hidden_layers": 34,
69
+ "num_key_value_heads": 4,
70
+ "pad_token_id": 0,
71
+ "query_pre_attn_scalar": 256,
72
+ "rms_norm_eps": 1e-06,
73
+ "rope_local_base_freq": 10000.0,
74
+ "rope_scaling": {
75
+ "factor": 8.0,
76
+ "rope_type": "linear"
77
+ },
78
+ "rope_theta": 1000000.0,
79
+ "sliding_window": 1024,
80
+ "sliding_window_pattern": 6,
81
+ "transformers_version": "4.57.1",
82
+ "use_bidirectional_attention": false,
83
+ "use_cache": false,
84
+ "vocab_size": 262208
85
+ }
configuration_gemmagain.py ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 Google Inc. HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Gemmagain model configuration - Gemma3 with layer looping support"""
16
+
17
+ from transformers.configuration_utils import PretrainedConfig, layer_type_validation
18
+ from transformers.modeling_rope_utils import rope_config_validation
19
+ from transformers.utils import logging
20
+
21
+
22
+ logger = logging.get_logger(__name__)
23
+
24
+
25
+ class GemmagainConfig(PretrainedConfig):
26
+ r"""
27
+ Configuration class for Gemmagain - a Gemma3 text model with layer looping support.
28
+
29
+ This extends Gemma3TextConfig to add the `layer_sequence` parameter which controls
30
+ how layers are executed, allowing layers to be repeated multiple times.
31
+
32
+ Args:
33
+ vocab_size (`int`, *optional*, defaults to 262208):
34
+ Vocabulary size of the model.
35
+ hidden_size (`int`, *optional*, defaults to 2560):
36
+ Dimension of the hidden representations.
37
+ intermediate_size (`int`, *optional*, defaults to 10240):
38
+ Dimension of the MLP representations.
39
+ num_hidden_layers (`int`, *optional*, defaults to 34):
40
+ Number of hidden layers in the Transformer decoder.
41
+ num_attention_heads (`int`, *optional*, defaults to 8):
42
+ Number of attention heads for each attention layer.
43
+ num_key_value_heads (`int`, *optional*, defaults to 4):
44
+ Number of key_value heads for GQA.
45
+ head_dim (`int`, *optional*, defaults to 256):
46
+ The attention head dimension.
47
+ hidden_activation (`str`, *optional*, defaults to `"gelu_pytorch_tanh"`):
48
+ The activation function.
49
+ max_position_embeddings (`int`, *optional*, defaults to 131072):
50
+ Maximum sequence length.
51
+ layer_sequence (`list`, *optional*):
52
+ Order to execute layers. Defaults to all layers once.
53
+ Flexible format - each item can be:
54
+ - An integer: single layer index (e.g., 5 means layer 5)
55
+ - A 2-element list [start, end]: range of layers (e.g., [4, 20] means layers 4-19)
56
+ - A 3-element list [start, end, repeats]: range repeated N times
57
+ Examples:
58
+ - [[0, 34, 1]]: all 34 layers once
59
+ - [[0, 10], [10, 28, 2], [28, 34]]: layers 0-9, then 10-27 twice, then 28-33
60
+ layer_types (`list`, *optional*):
61
+ Attention pattern for each layer ("sliding_attention" or "full_attention").
62
+ sliding_window (`int`, *optional*, defaults to 1024):
63
+ Size of the sliding window for sliding attention layers.
64
+ rope_theta (`float`, *optional*, defaults to 1000000.0):
65
+ Base period for RoPE embeddings (global attention).
66
+ rope_local_base_freq (`float`, *optional*, defaults to 10000.0):
67
+ Base period for RoPE embeddings (local/sliding attention).
68
+ query_pre_attn_scalar (`float`, *optional*, defaults to 256):
69
+ Scaling factor for attention scores.
70
+ rms_norm_eps (`float`, *optional*, defaults to 1e-6):
71
+ Epsilon for RMS normalization.
72
+ attention_bias (`bool`, *optional*, defaults to False):
73
+ Whether to use bias in attention projections.
74
+ attention_dropout (`float`, *optional*, defaults to 0.0):
75
+ Dropout ratio for attention.
76
+ final_logit_softcapping (`float`, *optional*):
77
+ Softcapping for final logits.
78
+ attn_logit_softcapping (`float`, *optional*):
79
+ Softcapping for attention logits.
80
+ rope_scaling (`dict`, *optional*):
81
+ RoPE scaling configuration.
82
+ use_bidirectional_attention (`bool`, *optional*, defaults to False):
83
+ If True, use bidirectional attention instead of causal.
84
+ """
85
+
86
+ model_type = "gemma3"
87
+ keys_to_ignore_at_inference = ["past_key_values"]
88
+ base_model_tp_plan = {
89
+ "layers.*.self_attn.q_proj": "colwise",
90
+ "layers.*.self_attn.k_proj": "colwise",
91
+ "layers.*.self_attn.v_proj": "colwise",
92
+ "layers.*.self_attn.o_proj": "rowwise",
93
+ "layers.*.mlp.gate_proj": "colwise",
94
+ "layers.*.mlp.up_proj": "colwise",
95
+ "layers.*.mlp.down_proj": "rowwise",
96
+ }
97
+ base_model_pp_plan = {
98
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
99
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
100
+ "norm": (["hidden_states"], ["hidden_states"]),
101
+ }
102
+
103
+ def __init__(
104
+ self,
105
+ vocab_size=262_208,
106
+ hidden_size=2560,
107
+ intermediate_size=10240,
108
+ num_hidden_layers=34,
109
+ num_attention_heads=8,
110
+ num_key_value_heads=4,
111
+ head_dim=256,
112
+ hidden_activation="gelu_pytorch_tanh",
113
+ max_position_embeddings=131_072,
114
+ initializer_range=0.02,
115
+ rms_norm_eps=1e-6,
116
+ use_cache=True,
117
+ pad_token_id=0,
118
+ eos_token_id=1,
119
+ bos_token_id=2,
120
+ tie_word_embeddings=True,
121
+ rope_theta=1_000_000.0,
122
+ attention_bias=False,
123
+ attention_dropout=0.0,
124
+ query_pre_attn_scalar=256,
125
+ sliding_window=1024,
126
+ layer_types=None,
127
+ layer_sequence=None,
128
+ final_logit_softcapping=None,
129
+ attn_logit_softcapping=None,
130
+ rope_scaling=None,
131
+ rope_local_base_freq=10_000.0,
132
+ use_bidirectional_attention=False,
133
+ **kwargs,
134
+ ):
135
+ super().__init__(
136
+ pad_token_id=pad_token_id,
137
+ bos_token_id=bos_token_id,
138
+ eos_token_id=eos_token_id,
139
+ tie_word_embeddings=tie_word_embeddings,
140
+ **kwargs,
141
+ )
142
+ self.vocab_size = vocab_size
143
+ self.max_position_embeddings = max_position_embeddings
144
+ self.hidden_size = hidden_size
145
+ self.intermediate_size = intermediate_size
146
+ self.num_hidden_layers = num_hidden_layers
147
+ self.num_attention_heads = num_attention_heads
148
+ self.head_dim = head_dim
149
+ self.num_key_value_heads = num_key_value_heads
150
+ self.initializer_range = initializer_range
151
+ self.rms_norm_eps = rms_norm_eps
152
+ self.use_cache = use_cache
153
+ self.rope_theta = rope_theta
154
+ self.attention_bias = attention_bias
155
+ self.attention_dropout = attention_dropout
156
+ self.hidden_activation = hidden_activation
157
+ self.query_pre_attn_scalar = query_pre_attn_scalar
158
+ self.sliding_window = sliding_window
159
+ self.final_logit_softcapping = final_logit_softcapping
160
+ self.attn_logit_softcapping = attn_logit_softcapping
161
+ self.use_bidirectional_attention = use_bidirectional_attention
162
+
163
+ if use_bidirectional_attention:
164
+ self.sliding_window = (self.sliding_window // 2) + 1
165
+
166
+ self.rope_local_base_freq = rope_local_base_freq
167
+ self.rope_scaling = rope_scaling
168
+ rope_config_validation(self)
169
+
170
+ # Layer sequence for looping - defaults to all layers once
171
+ if layer_sequence is None:
172
+ layer_sequence = [[0, num_hidden_layers, 1]]
173
+ self.layer_sequence = layer_sequence
174
+
175
+ # Layer types (sliding vs full attention)
176
+ self._sliding_window_pattern = kwargs.get("sliding_window_pattern", 6)
177
+ self.layer_types = layer_types
178
+ if self.layer_types is None:
179
+ self.layer_types = [
180
+ "sliding_attention" if bool((i + 1) % self._sliding_window_pattern) else "full_attention"
181
+ for i in range(self.num_hidden_layers)
182
+ ]
183
+ layer_type_validation(self.layer_types, self.num_hidden_layers)
184
+
185
+
186
+ __all__ = ["GemmagainConfig"]
debug.log ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+
2
+ [2026-01-07 04:29:01,441] [WARNING] [axolotl.monkeypatch.multipack.patch_remote:85] [PID:48541] Failed to load model for multipack patching: Parameter.__new__() got an unexpected keyword argument '_is_hf_initialized'. Multipack _get_unpad_data patching will be skipped.
3
+
4
+ [2026-01-07 04:33:39,857] [WARNING] [py.warnings._showwarnmsg:110] [PID:48541] /workspace/venv/lib/python3.12/site-packages/torch/distributed/fsdp/fully_sharded_data_parallel.py:675: FutureWarning: FSDP.state_dict_type() and FSDP.set_state_dict_type() are being deprecated. Please use APIs, get_state_dict() and set_state_dict(), which can support different parallelisms, FSDP1, FSDP2, DDP. API doc: https://pytorch.org/docs/stable/distributed.checkpoint.html#torch.distributed.checkpoint.state_dict.get_state_dict .Tutorial: https://pytorch.org/tutorials/recipes/distributed_checkpoint_recipe.html .
5
+ warnings.warn(
6
+
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 2,
3
+ "cache_implementation": "hybrid",
4
+ "do_sample": true,
5
+ "eos_token_id": [
6
+ 1,
7
+ 106
8
+ ],
9
+ "pad_token_id": 0,
10
+ "top_k": 64,
11
+ "top_p": 0.95,
12
+ "transformers_version": "4.57.1"
13
+ }
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f7657727224e5150e5592f23b14efb0a221f38dcb0350c5b57bb4c03342b6797
3
+ size 4992144616
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f331d95a0abc2caa329bfabba99148ee1176572dec817c447f6b9e3d39f94699
3
+ size 4928888200
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:799dcce25f96c1a136afc4ef209ef63de16bb735e9bc6baa0837ee652641a6cb
3
+ size 4907914352
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56a7dfd21f4e779884180918b53dacdb5761ceef770bf39708ee436aabdf9cf7
3
+ size 3377166832
model.safetensors.index.json ADDED
@@ -0,0 +1,453 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 1940131584,
4
+ "total_size": 18206062592
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.input_layernorm.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.post_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.pre_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.post_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
28
+ "model.layers.1.pre_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
30
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
31
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
32
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
33
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
34
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
35
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
36
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
37
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
38
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
39
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
40
+ "model.layers.10.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
41
+ "model.layers.10.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
42
+ "model.layers.10.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
43
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
44
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
45
+ "model.layers.10.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
46
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
47
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
48
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
49
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
50
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
51
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
53
+ "model.layers.11.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
54
+ "model.layers.11.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
55
+ "model.layers.11.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
56
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
57
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
58
+ "model.layers.11.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
59
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
61
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
63
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
64
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
65
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
66
+ "model.layers.12.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
67
+ "model.layers.12.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
68
+ "model.layers.12.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
69
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
70
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.12.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
78
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.13.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
80
+ "model.layers.13.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.13.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
82
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
83
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.13.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
86
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
92
+ "model.layers.14.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.14.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.14.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
97
+ "model.layers.14.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
98
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
99
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
100
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.15.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.15.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.15.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
109
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
110
+ "model.layers.15.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
111
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
112
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
114
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.16.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.16.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.16.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
123
+ "model.layers.16.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
124
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
125
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
126
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
128
+ "model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
130
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
131
+ "model.layers.17.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.17.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
133
+ "model.layers.17.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
134
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
135
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
136
+ "model.layers.17.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
137
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
138
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
139
+ "model.layers.18.input_layernorm.weight": "model-00002-of-00004.safetensors",
140
+ "model.layers.18.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
141
+ "model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
142
+ "model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
143
+ "model.layers.18.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
144
+ "model.layers.18.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
145
+ "model.layers.18.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
146
+ "model.layers.18.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
147
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
148
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
149
+ "model.layers.18.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
150
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
151
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
152
+ "model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
153
+ "model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
154
+ "model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
155
+ "model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
156
+ "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
157
+ "model.layers.19.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
158
+ "model.layers.19.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
159
+ "model.layers.19.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
160
+ "model.layers.19.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
161
+ "model.layers.19.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
162
+ "model.layers.19.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
163
+ "model.layers.19.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
164
+ "model.layers.19.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
165
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
166
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
167
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
168
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
169
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
170
+ "model.layers.2.post_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
171
+ "model.layers.2.pre_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
172
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
173
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
174
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
175
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
176
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
177
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
178
+ "model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
179
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
180
+ "model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
181
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
182
+ "model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
183
+ "model.layers.20.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
184
+ "model.layers.20.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
185
+ "model.layers.20.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
186
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
187
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
188
+ "model.layers.20.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
189
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
190
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
191
+ "model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
193
+ "model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
194
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
195
+ "model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
196
+ "model.layers.21.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
197
+ "model.layers.21.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
198
+ "model.layers.21.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
200
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
201
+ "model.layers.21.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
202
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
203
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
204
+ "model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
205
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
207
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
208
+ "model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
209
+ "model.layers.22.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
210
+ "model.layers.22.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
211
+ "model.layers.22.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
212
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.22.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
218
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
221
+ "model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
222
+ "model.layers.23.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
223
+ "model.layers.23.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
224
+ "model.layers.23.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
225
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
226
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.23.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
231
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
232
+ "model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
234
+ "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
235
+ "model.layers.24.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
236
+ "model.layers.24.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
237
+ "model.layers.24.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
238
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
239
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
240
+ "model.layers.24.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
243
+ "model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
245
+ "model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
246
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
247
+ "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
248
+ "model.layers.25.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.25.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
250
+ "model.layers.25.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
251
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.25.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
254
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
259
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
260
+ "model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.26.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
262
+ "model.layers.26.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
263
+ "model.layers.26.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
264
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
265
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
266
+ "model.layers.26.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
267
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
268
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
269
+ "model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
270
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
271
+ "model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
272
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
273
+ "model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
274
+ "model.layers.27.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
275
+ "model.layers.27.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
276
+ "model.layers.27.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
277
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
278
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
279
+ "model.layers.27.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
280
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
281
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
282
+ "model.layers.28.input_layernorm.weight": "model-00003-of-00004.safetensors",
283
+ "model.layers.28.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
284
+ "model.layers.28.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
285
+ "model.layers.28.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
286
+ "model.layers.28.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
287
+ "model.layers.28.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
288
+ "model.layers.28.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
289
+ "model.layers.28.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
290
+ "model.layers.28.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
291
+ "model.layers.28.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
292
+ "model.layers.28.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
293
+ "model.layers.28.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
294
+ "model.layers.28.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
295
+ "model.layers.29.input_layernorm.weight": "model-00003-of-00004.safetensors",
296
+ "model.layers.29.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
297
+ "model.layers.29.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
298
+ "model.layers.29.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
299
+ "model.layers.29.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
300
+ "model.layers.29.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
301
+ "model.layers.29.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
302
+ "model.layers.29.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
303
+ "model.layers.29.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
304
+ "model.layers.29.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
305
+ "model.layers.29.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
306
+ "model.layers.29.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
307
+ "model.layers.29.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
308
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
309
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
310
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
311
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
312
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
313
+ "model.layers.3.post_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
314
+ "model.layers.3.pre_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
315
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
316
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
317
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
318
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
319
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
320
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
321
+ "model.layers.30.input_layernorm.weight": "model-00003-of-00004.safetensors",
322
+ "model.layers.30.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
323
+ "model.layers.30.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
324
+ "model.layers.30.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
325
+ "model.layers.30.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
326
+ "model.layers.30.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
327
+ "model.layers.30.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
328
+ "model.layers.30.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
329
+ "model.layers.30.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
330
+ "model.layers.30.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
331
+ "model.layers.30.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
332
+ "model.layers.30.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
333
+ "model.layers.30.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
334
+ "model.layers.31.input_layernorm.weight": "model-00003-of-00004.safetensors",
335
+ "model.layers.31.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
336
+ "model.layers.31.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
337
+ "model.layers.31.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
338
+ "model.layers.31.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
339
+ "model.layers.31.post_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
340
+ "model.layers.31.pre_feedforward_layernorm.weight": "model-00003-of-00004.safetensors",
341
+ "model.layers.31.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
342
+ "model.layers.31.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
343
+ "model.layers.31.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
344
+ "model.layers.31.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
345
+ "model.layers.31.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
346
+ "model.layers.31.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
347
+ "model.layers.32.input_layernorm.weight": "model-00004-of-00004.safetensors",
348
+ "model.layers.32.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
349
+ "model.layers.32.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
350
+ "model.layers.32.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
351
+ "model.layers.32.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
352
+ "model.layers.32.post_feedforward_layernorm.weight": "model-00004-of-00004.safetensors",
353
+ "model.layers.32.pre_feedforward_layernorm.weight": "model-00004-of-00004.safetensors",
354
+ "model.layers.32.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
355
+ "model.layers.32.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
356
+ "model.layers.32.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
357
+ "model.layers.32.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
358
+ "model.layers.32.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
359
+ "model.layers.32.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
360
+ "model.layers.33.input_layernorm.weight": "model-00004-of-00004.safetensors",
361
+ "model.layers.33.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
362
+ "model.layers.33.mlp.gate_proj.weight": "model-00004-of-00004.safetensors",
363
+ "model.layers.33.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
364
+ "model.layers.33.post_attention_layernorm.weight": "model-00004-of-00004.safetensors",
365
+ "model.layers.33.post_feedforward_layernorm.weight": "model-00004-of-00004.safetensors",
366
+ "model.layers.33.pre_feedforward_layernorm.weight": "model-00004-of-00004.safetensors",
367
+ "model.layers.33.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
368
+ "model.layers.33.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
369
+ "model.layers.33.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
370
+ "model.layers.33.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
371
+ "model.layers.33.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
372
+ "model.layers.33.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
373
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
374
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
375
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
376
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
377
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
378
+ "model.layers.4.post_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
379
+ "model.layers.4.pre_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
380
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
381
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
382
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
383
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
384
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
385
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
386
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
387
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
388
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
389
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
390
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
391
+ "model.layers.5.post_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
392
+ "model.layers.5.pre_feedforward_layernorm.weight": "model-00001-of-00004.safetensors",
393
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
394
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
395
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
396
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
397
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
398
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
399
+ "model.layers.6.input_layernorm.weight": "model-00002-of-00004.safetensors",
400
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
401
+ "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
402
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
403
+ "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
404
+ "model.layers.6.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
405
+ "model.layers.6.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
406
+ "model.layers.6.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
407
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
408
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
409
+ "model.layers.6.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
410
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
411
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
412
+ "model.layers.7.input_layernorm.weight": "model-00002-of-00004.safetensors",
413
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
414
+ "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
415
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
416
+ "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
417
+ "model.layers.7.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
418
+ "model.layers.7.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
419
+ "model.layers.7.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
420
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
421
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
422
+ "model.layers.7.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
423
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
424
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
425
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
426
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
427
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
428
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
429
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
430
+ "model.layers.8.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
431
+ "model.layers.8.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
432
+ "model.layers.8.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
433
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
434
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
435
+ "model.layers.8.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
436
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
437
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
438
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
439
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
440
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
441
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
442
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
443
+ "model.layers.9.post_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
444
+ "model.layers.9.pre_feedforward_layernorm.weight": "model-00002-of-00004.safetensors",
445
+ "model.layers.9.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
446
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
447
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
448
+ "model.layers.9.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
449
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
450
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
451
+ "model.norm.weight": "model-00004-of-00004.safetensors"
452
+ }
453
+ }
modeling_gemmagain.py ADDED
@@ -0,0 +1,589 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2025 Google Inc. HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """
16
+ Gemmagain - Gemma3 text model with layer looping support (wrapper approach).
17
+
18
+ This model allows running the same physical layers multiple times in sequence,
19
+ enabling parameter-efficient deep networks. Compatible with standard Gemma3 weights.
20
+
21
+ This version uses wrapper layers that pass the virtual layer index at runtime,
22
+ giving each virtual layer position unique RoPE encodings and cache slots.
23
+ """
24
+ import copy
25
+ from typing import Callable, Optional, Union
26
+
27
+ import torch
28
+ import torch.nn as nn
29
+ from torch.nn import CrossEntropyLoss
30
+
31
+ from transformers.activations import ACT2FN
32
+ from transformers.cache_utils import Cache, DynamicCache, DynamicLayer
33
+ from transformers.generation import GenerationMixin
34
+ from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
35
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
36
+ from transformers.modeling_layers import GradientCheckpointingLayer
37
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
38
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
39
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
40
+ from transformers.processing_utils import Unpack
41
+ from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple, logging
42
+ from transformers.utils.deprecation import deprecate_kwarg
43
+
44
+ try:
45
+ from .configuration_gemmagain import GemmagainConfig
46
+ except ImportError:
47
+ from configuration_gemmagain import GemmagainConfig
48
+
49
+
50
+ logger = logging.get_logger(__name__)
51
+
52
+
53
+ class Gemma3TextScaledWordEmbedding(nn.Embedding):
54
+ """
55
+ This module overrides nn.Embeddings' forward by multiplying with embeddings scale.
56
+ """
57
+
58
+ def __init__(self, num_embeddings: int, embedding_dim: int, padding_idx: int, embed_scale: float = 1.0):
59
+ super().__init__(num_embeddings, embedding_dim, padding_idx)
60
+ self.register_buffer("embed_scale", torch.tensor(embed_scale), persistent=False)
61
+
62
+ def forward(self, input_ids: torch.Tensor):
63
+ return super().forward(input_ids) * self.embed_scale.to(self.weight.dtype)
64
+
65
+
66
+ class Gemma3MLP(nn.Module):
67
+ def __init__(self, config: GemmagainConfig):
68
+ super().__init__()
69
+ self.config = config
70
+ self.hidden_size = config.hidden_size
71
+ self.intermediate_size = config.intermediate_size
72
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
73
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
74
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
75
+ self.act_fn = ACT2FN[config.hidden_activation]
76
+
77
+ def forward(self, x):
78
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
79
+ return down_proj
80
+
81
+
82
+ class Gemma3RMSNorm(nn.Module):
83
+ def __init__(self, dim: int, eps: float = 1e-6):
84
+ super().__init__()
85
+ self.eps = eps
86
+ self.weight = nn.Parameter(torch.zeros(dim))
87
+
88
+ def _norm(self, x):
89
+ return x * torch.rsqrt(x.pow(2).mean(-1, keepdim=True) + self.eps)
90
+
91
+ def forward(self, x):
92
+ output = self._norm(x.float())
93
+ # Gemma3 uses (x * w).to(dtype) instead of x.to(dtype) * w
94
+ output = output * (1.0 + self.weight.float())
95
+ return output.type_as(x)
96
+
97
+ def extra_repr(self):
98
+ return f"{tuple(self.weight.shape)}, eps={self.eps}"
99
+
100
+
101
+ class Gemma3RotaryEmbedding(nn.Module):
102
+ inv_freq: torch.Tensor
103
+
104
+ def __init__(self, config: GemmagainConfig, device=None):
105
+ super().__init__()
106
+ if hasattr(config, "rope_scaling") and isinstance(config.rope_scaling, dict):
107
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
108
+ else:
109
+ self.rope_type = "default"
110
+ self.max_seq_len_cached = config.max_position_embeddings
111
+ self.original_max_seq_len = config.max_position_embeddings
112
+
113
+ self.config = config
114
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
115
+
116
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
117
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
118
+ self.original_inv_freq = self.inv_freq
119
+
120
+ @torch.no_grad()
121
+ @dynamic_rope_update
122
+ def forward(self, x, position_ids):
123
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
124
+ position_ids_expanded = position_ids[:, None, :].float()
125
+
126
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
127
+ with torch.autocast(device_type=device_type, enabled=False):
128
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
129
+ emb = torch.cat((freqs, freqs), dim=-1)
130
+ cos = emb.cos() * self.attention_scaling
131
+ sin = emb.sin() * self.attention_scaling
132
+
133
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
134
+
135
+
136
+ def rotate_half(x):
137
+ """Rotates half the hidden dims of the input."""
138
+ x1 = x[..., : x.shape[-1] // 2]
139
+ x2 = x[..., x.shape[-1] // 2 :]
140
+ return torch.cat((-x2, x1), dim=-1)
141
+
142
+
143
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
144
+ """Applies Rotary Position Embedding to the query and key tensors."""
145
+ cos = cos.unsqueeze(unsqueeze_dim)
146
+ sin = sin.unsqueeze(unsqueeze_dim)
147
+ q_embed = (q * cos) + (rotate_half(q) * sin)
148
+ k_embed = (k * cos) + (rotate_half(k) * sin)
149
+ return q_embed, k_embed
150
+
151
+
152
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
153
+ """Repeat KV heads for GQA."""
154
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
155
+ if n_rep == 1:
156
+ return hidden_states
157
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
158
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
159
+
160
+
161
+ def eager_attention_forward(
162
+ module: nn.Module,
163
+ query: torch.Tensor,
164
+ key: torch.Tensor,
165
+ value: torch.Tensor,
166
+ attention_mask: Optional[torch.Tensor],
167
+ dropout: float = 0.0,
168
+ scaling: Optional[float] = None,
169
+ softcap: Optional[float] = None,
170
+ **kwargs,
171
+ ) -> tuple[torch.Tensor, torch.Tensor]:
172
+ if scaling is None:
173
+ scaling = module.head_dim**-0.5
174
+
175
+ key_states = repeat_kv(key, module.num_key_value_groups)
176
+ value_states = repeat_kv(value, module.num_key_value_groups)
177
+
178
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
179
+
180
+ if softcap is not None:
181
+ attn_weights = attn_weights / softcap
182
+ attn_weights = torch.tanh(attn_weights)
183
+ attn_weights = attn_weights * softcap
184
+ if attention_mask is not None:
185
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
186
+ attn_weights = attn_weights + causal_mask
187
+
188
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
189
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
190
+ attn_output = torch.matmul(attn_weights, value_states)
191
+ attn_output = attn_output.transpose(1, 2).contiguous()
192
+ return attn_output, attn_weights
193
+
194
+
195
+ class Gemma3Attention(nn.Module):
196
+ """Multi-headed attention with support for virtual layer index."""
197
+
198
+ def __init__(self, config: GemmagainConfig, layer_idx: int):
199
+ super().__init__()
200
+ self.is_sliding = config.layer_types[layer_idx] == "sliding_attention"
201
+ self.config = config
202
+ self.layer_idx = layer_idx
203
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
204
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
205
+ self.scaling = config.query_pre_attn_scalar**-0.5
206
+ self.attention_dropout = self.config.attention_dropout
207
+ self.is_causal = not self.config.use_bidirectional_attention
208
+
209
+ self.q_proj = nn.Linear(
210
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
211
+ )
212
+ self.k_proj = nn.Linear(
213
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
214
+ )
215
+ self.v_proj = nn.Linear(
216
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
217
+ )
218
+ self.o_proj = nn.Linear(
219
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
220
+ )
221
+ self.attn_logit_softcapping = self.config.attn_logit_softcapping
222
+ self.sliding_window = config.sliding_window if self.is_sliding else None
223
+
224
+ self.q_norm = Gemma3RMSNorm(dim=config.head_dim, eps=config.rms_norm_eps)
225
+ self.k_norm = Gemma3RMSNorm(dim=config.head_dim, eps=config.rms_norm_eps)
226
+
227
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
228
+ def forward(
229
+ self,
230
+ hidden_states: torch.Tensor,
231
+ position_embeddings: torch.Tensor,
232
+ attention_mask: Optional[torch.Tensor],
233
+ past_key_values: Optional[Cache] = None,
234
+ cache_position: Optional[torch.LongTensor] = None,
235
+ real_layer_idx: Optional[int] = None,
236
+ **kwargs: Unpack[FlashAttentionKwargs],
237
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
238
+ input_shape = hidden_states.shape[:-1]
239
+ hidden_shape = (*input_shape, -1, self.head_dim)
240
+
241
+ query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
242
+ key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
243
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
244
+
245
+ query_states = self.q_norm(query_states)
246
+ key_states = self.k_norm(key_states)
247
+
248
+ cos, sin = position_embeddings
249
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
250
+
251
+ if past_key_values is not None:
252
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
253
+ # Use real_layer_idx for cache slot - each virtual layer gets its own slot
254
+ slot_idx = real_layer_idx if real_layer_idx is not None else self.layer_idx
255
+ key_states, value_states = past_key_values.update(key_states, value_states, slot_idx, cache_kwargs)
256
+
257
+ attention_interface: Callable = eager_attention_forward
258
+ if self.config._attn_implementation != "eager":
259
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
260
+
261
+ attn_output, attn_weights = attention_interface(
262
+ self,
263
+ query_states,
264
+ key_states,
265
+ value_states,
266
+ attention_mask,
267
+ dropout=self.attention_dropout if self.training else 0.0,
268
+ scaling=self.scaling,
269
+ sliding_window=self.sliding_window,
270
+ **kwargs,
271
+ )
272
+
273
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
274
+ attn_output = self.o_proj(attn_output)
275
+ return attn_output, attn_weights
276
+
277
+
278
+ class Gemma3DecoderLayer(GradientCheckpointingLayer):
279
+ def __init__(self, config: GemmagainConfig, layer_idx: int):
280
+ super().__init__()
281
+ self.config = config
282
+ self.hidden_size = config.hidden_size
283
+ self.layer_idx = layer_idx
284
+ self.attention_type = config.layer_types[layer_idx]
285
+ self.self_attn = Gemma3Attention(config=config, layer_idx=layer_idx)
286
+ self.mlp = Gemma3MLP(config)
287
+ self.input_layernorm = Gemma3RMSNorm(self.hidden_size, eps=config.rms_norm_eps)
288
+ self.post_attention_layernorm = Gemma3RMSNorm(self.hidden_size, eps=config.rms_norm_eps)
289
+ self.pre_feedforward_layernorm = Gemma3RMSNorm(self.hidden_size, eps=config.rms_norm_eps)
290
+ self.post_feedforward_layernorm = Gemma3RMSNorm(self.hidden_size, eps=config.rms_norm_eps)
291
+
292
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
293
+ def forward(
294
+ self,
295
+ hidden_states: torch.Tensor,
296
+ position_embeddings_global: torch.Tensor,
297
+ position_embeddings_local: torch.Tensor,
298
+ attention_mask: Optional[torch.Tensor] = None,
299
+ position_ids: Optional[torch.LongTensor] = None,
300
+ past_key_values: Optional[Cache] = None,
301
+ use_cache: Optional[bool] = False,
302
+ cache_position: Optional[torch.LongTensor] = None,
303
+ real_layer_idx: Optional[int] = None,
304
+ **kwargs,
305
+ ) -> torch.Tensor:
306
+ residual = hidden_states
307
+
308
+ hidden_states = self.input_layernorm(hidden_states)
309
+
310
+ # Apply global RoPE to non-sliding layers, local RoPE to sliding layers
311
+ if self.self_attn.is_sliding:
312
+ position_embeddings = position_embeddings_local
313
+ else:
314
+ position_embeddings = position_embeddings_global
315
+
316
+ hidden_states, _ = self.self_attn(
317
+ hidden_states=hidden_states,
318
+ position_embeddings=position_embeddings,
319
+ attention_mask=attention_mask,
320
+ position_ids=position_ids,
321
+ past_key_values=past_key_values,
322
+ use_cache=use_cache,
323
+ cache_position=cache_position,
324
+ real_layer_idx=real_layer_idx,
325
+ **kwargs,
326
+ )
327
+ hidden_states = self.post_attention_layernorm(hidden_states)
328
+ hidden_states = residual + hidden_states
329
+
330
+ residual = hidden_states
331
+ hidden_states = self.pre_feedforward_layernorm(hidden_states)
332
+ hidden_states = self.mlp(hidden_states)
333
+ hidden_states = self.post_feedforward_layernorm(hidden_states)
334
+ hidden_states = residual + hidden_states
335
+
336
+ return hidden_states
337
+
338
+
339
+ @auto_docstring
340
+ class GemmagainPreTrainedModel(PreTrainedModel):
341
+ config_class = GemmagainConfig
342
+ base_model_prefix = "model"
343
+ supports_gradient_checkpointing = True
344
+ _no_split_modules = ["Gemma3DecoderLayer"]
345
+ _skip_keys_device_placement = ["past_key_values"]
346
+ _supports_flash_attn = True
347
+ _supports_sdpa = True
348
+ _supports_flex_attn = True
349
+ _can_compile_fullgraph = True
350
+ _supports_attention_backend = True
351
+ _can_record_outputs = {
352
+ "hidden_states": Gemma3DecoderLayer,
353
+ "attentions": Gemma3Attention,
354
+ }
355
+
356
+ def _init_weights(self, module):
357
+ super()._init_weights(module)
358
+ # Initialize RMSNorm weights to 0 (Gemma3 uses 1 + weight)
359
+ if "RMSNorm" in module.__class__.__name__:
360
+ module.weight.data.zero_()
361
+
362
+
363
+ def _expand_layer_sequence(layer_sequence, num_hidden_layers):
364
+ """Expand layer_sequence config into a flat list of layer indices."""
365
+ l_seq = []
366
+ for item in layer_sequence:
367
+ if isinstance(item, int):
368
+ l_seq.append(item)
369
+ elif isinstance(item, list):
370
+ if len(item) == 2:
371
+ start, end = item
372
+ l_seq += list(range(start, min(end, num_hidden_layers)))
373
+ elif len(item) == 3:
374
+ start, end, repeats = item
375
+ l_seq += list(range(start, min(end, num_hidden_layers))) * repeats
376
+ else:
377
+ raise ValueError(f"Invalid layer_sequence item: {item}")
378
+ else:
379
+ raise ValueError(f"Invalid layer_sequence item type: {type(item)}")
380
+ return l_seq
381
+
382
+
383
+ def _bidirectional_window_overlay(sliding_window: int) -> Callable[[int, int, int, int], bool]:
384
+ """Enables a bidirectional mask within the sliding window."""
385
+ def inner_mask(batch_idx: int, head_idx: int, q_idx: int, kv_idx: int) -> bool:
386
+ return abs(q_idx - kv_idx) < sliding_window
387
+ return inner_mask
388
+
389
+
390
+ @auto_docstring
391
+ class GemmagainModel(GemmagainPreTrainedModel):
392
+ def __init__(self, config: GemmagainConfig):
393
+ super().__init__(config)
394
+ self.padding_idx = config.pad_token_id
395
+ self.vocab_size = config.vocab_size
396
+
397
+ self.embed_tokens = Gemma3TextScaledWordEmbedding(
398
+ config.vocab_size, config.hidden_size, self.padding_idx, embed_scale=config.hidden_size**0.5
399
+ )
400
+ # Physical layers - the actual parameters
401
+ self.layers = nn.ModuleList(
402
+ [Gemma3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
403
+ )
404
+ self.norm = Gemma3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
405
+ self.rotary_emb = Gemma3RotaryEmbedding(config=config)
406
+ self.gradient_checkpointing = False
407
+
408
+ # Create local RoPE with different theta
409
+ local_config = copy.deepcopy(config)
410
+ local_config.rope_theta = config.rope_local_base_freq
411
+ local_config.rope_scaling = {"rope_type": "default"}
412
+ self.rotary_emb_local = Gemma3RotaryEmbedding(config=local_config)
413
+
414
+ # Build the virtual layer execution schedule as plain data (FSDP-compatible)
415
+ # Each entry is (physical_layer_idx, virtual_layer_idx)
416
+ layer_indices = _expand_layer_sequence(config.layer_sequence, config.num_hidden_layers)
417
+ self._execution_schedule = [(phys_idx, virt_idx) for virt_idx, phys_idx in enumerate(layer_indices)]
418
+
419
+ # For compatibility, expose the layer sequence info
420
+ self._layer_sequence = layer_indices
421
+ self._num_cache_slots = len(self._execution_schedule)
422
+
423
+ self.post_init()
424
+
425
+ @auto_docstring
426
+ def forward(
427
+ self,
428
+ input_ids: Optional[torch.LongTensor] = None,
429
+ attention_mask: Optional[torch.Tensor] = None,
430
+ position_ids: Optional[torch.LongTensor] = None,
431
+ past_key_values: Optional[Cache] = None,
432
+ inputs_embeds: Optional[torch.FloatTensor] = None,
433
+ use_cache: Optional[bool] = None,
434
+ cache_position: Optional[torch.LongTensor] = None,
435
+ **kwargs: Unpack[TransformersKwargs],
436
+ ) -> BaseModelOutputWithPast:
437
+ if (input_ids is None) ^ (inputs_embeds is not None):
438
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
439
+
440
+ if inputs_embeds is None:
441
+ inputs_embeds = self.embed_tokens(input_ids)
442
+
443
+ # Handle use_cache default
444
+ effective_use_cache = use_cache if use_cache is not None else self.config.use_cache
445
+
446
+ if effective_use_cache and not self.training:
447
+ if past_key_values is None:
448
+ # Create cache with enough slots for the full virtual layer sequence
449
+ # DynamicCache doesn't pre-allocate layers, so we need to do it manually
450
+ past_key_values = DynamicCache()
451
+ for _ in range(self._num_cache_slots):
452
+ past_key_values.layers.append(DynamicLayer())
453
+ elif isinstance(past_key_values, DynamicCache) and len(past_key_values.layers) < self._num_cache_slots:
454
+ # Extend cache if created externally with fewer slots
455
+ while len(past_key_values.layers) < self._num_cache_slots:
456
+ past_key_values.layers.append(DynamicLayer())
457
+
458
+ if cache_position is None:
459
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
460
+ cache_position = torch.arange(
461
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
462
+ )
463
+
464
+ if position_ids is None:
465
+ position_ids = cache_position.unsqueeze(0)
466
+
467
+ # Prepare attention masks
468
+ if not isinstance(causal_mask_mapping := attention_mask, dict):
469
+ mask_kwargs = {
470
+ "config": self.config,
471
+ "input_embeds": inputs_embeds,
472
+ "attention_mask": attention_mask,
473
+ "cache_position": cache_position,
474
+ "past_key_values": past_key_values,
475
+ "position_ids": position_ids,
476
+ }
477
+ sliding_mask_kwargs = mask_kwargs.copy()
478
+
479
+ if self.config.use_bidirectional_attention:
480
+ mask_kwargs["or_mask_function"] = lambda *args: torch.tensor(True, dtype=torch.bool)
481
+ sliding_mask_kwargs["or_mask_function"] = _bidirectional_window_overlay(self.config.sliding_window)
482
+
483
+ causal_mask_mapping = {
484
+ "full_attention": create_causal_mask(**mask_kwargs),
485
+ "sliding_attention": create_sliding_window_causal_mask(**sliding_mask_kwargs),
486
+ }
487
+
488
+ hidden_states = inputs_embeds
489
+ position_embeddings_global = self.rotary_emb(hidden_states, position_ids)
490
+ position_embeddings_local = self.rotary_emb_local(hidden_states, position_ids)
491
+
492
+ # Execute virtual layers using the schedule (FSDP-compatible)
493
+ for physical_idx, virtual_idx in self._execution_schedule:
494
+ layer = self.layers[physical_idx]
495
+ hidden_states = layer(
496
+ hidden_states,
497
+ position_embeddings_global=position_embeddings_global,
498
+ position_embeddings_local=position_embeddings_local,
499
+ attention_mask=causal_mask_mapping[layer.attention_type],
500
+ position_ids=position_ids,
501
+ past_key_values=past_key_values,
502
+ use_cache=use_cache,
503
+ cache_position=cache_position,
504
+ real_layer_idx=virtual_idx,
505
+ **kwargs,
506
+ )
507
+
508
+ hidden_states = self.norm(hidden_states)
509
+
510
+ return BaseModelOutputWithPast(
511
+ last_hidden_state=hidden_states,
512
+ past_key_values=past_key_values if use_cache else None,
513
+ )
514
+
515
+
516
+ @auto_docstring
517
+ class GemmagainForCausalLM(GemmagainPreTrainedModel, GenerationMixin):
518
+ _tied_weights_keys = ["lm_head.weight"]
519
+ _tp_plan = {"lm_head": "colwise_rep"}
520
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
521
+
522
+ def __init__(self, config: GemmagainConfig):
523
+ super().__init__(config)
524
+ self.model = GemmagainModel(config)
525
+ self.vocab_size = config.vocab_size
526
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
527
+
528
+ self.post_init()
529
+
530
+ @can_return_tuple
531
+ @auto_docstring
532
+ def forward(
533
+ self,
534
+ input_ids: Optional[torch.LongTensor] = None,
535
+ attention_mask: Optional[torch.Tensor] = None,
536
+ position_ids: Optional[torch.LongTensor] = None,
537
+ past_key_values: Optional[Cache] = None,
538
+ inputs_embeds: Optional[torch.FloatTensor] = None,
539
+ labels: Optional[torch.LongTensor] = None,
540
+ use_cache: Optional[bool] = None,
541
+ cache_position: Optional[torch.LongTensor] = None,
542
+ logits_to_keep: Union[int, torch.Tensor] = 0,
543
+ **kwargs: Unpack[TransformersKwargs],
544
+ ) -> CausalLMOutputWithPast:
545
+ outputs: BaseModelOutputWithPast = self.model(
546
+ input_ids=input_ids,
547
+ attention_mask=attention_mask,
548
+ position_ids=position_ids,
549
+ past_key_values=past_key_values,
550
+ inputs_embeds=inputs_embeds,
551
+ use_cache=use_cache,
552
+ cache_position=cache_position,
553
+ **kwargs,
554
+ )
555
+
556
+ hidden_states = outputs.last_hidden_state
557
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
558
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
559
+
560
+ if self.config.final_logit_softcapping is not None:
561
+ logits = logits / self.config.final_logit_softcapping
562
+ logits = torch.tanh(logits)
563
+ logits = logits * self.config.final_logit_softcapping
564
+
565
+ loss = None
566
+ if labels is not None:
567
+ # Standard loss calculation
568
+ shift_logits = logits[..., :-1, :].contiguous()
569
+ shift_labels = labels[..., 1:].contiguous()
570
+ loss_fct = CrossEntropyLoss()
571
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
572
+ shift_labels = shift_labels.view(-1)
573
+ shift_labels = shift_labels.to(shift_logits.device)
574
+ loss = loss_fct(shift_logits, shift_labels)
575
+
576
+ return CausalLMOutputWithPast(
577
+ loss=loss,
578
+ logits=logits,
579
+ past_key_values=outputs.past_key_values,
580
+ hidden_states=outputs.hidden_states,
581
+ attentions=outputs.attentions,
582
+ )
583
+
584
+
585
+ __all__ = [
586
+ "GemmagainForCausalLM",
587
+ "GemmagainModel",
588
+ "GemmagainPreTrainedModel",
589
+ ]
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "boi_token": "<start_of_image>",
3
+ "bos_token": {
4
+ "content": "<bos>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false
9
+ },
10
+ "eoi_token": "<end_of_image>",
11
+ "eos_token": {
12
+ "content": "<end_of_turn>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false
17
+ },
18
+ "image_token": "<image_soft_token>",
19
+ "pad_token": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4667f2089529e8e7657cfb6d1c19910ae71ff5f28aa7ab2ff2763330affad795
3
+ size 33384568
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1299c11d7cf632ef3b4e11937501358ada021bbdf7c47638d13c0ee982f2e79c
3
+ size 4689074
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff
 
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:04e32973ed0a4482704cef72eedef53f3916e564f45e15ee23be29a1bc0064a0
3
+ size 8209