TeleAI-AI-Flow commited on
Commit
8452ea7
·
verified ·
1 Parent(s): b30c751

Upload folder using huggingface_hub

Browse files
config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "EEQwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_eeqwen3.EEQwen3Config",
9
+ "AutoModel": "modeling_eeqwen3.EEQwen3Model",
10
+ "AutoModelForCausalLM": "modeling_eeqwen3.EEQwen3ForCausalLM"
11
+ },
12
+ "bos_token_id": 151643,
13
+ "default_early_exit_point": 39,
14
+ "early_exit_points": [
15
+ 2,
16
+ 21,
17
+ 39
18
+ ],
19
+ "eos_token_id": 151643,
20
+ "head_dim": 128,
21
+ "hidden_act": "silu",
22
+ "hidden_size": 5120,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 17408,
25
+ "max_position_embeddings": 32768,
26
+ "max_window_layers": 40,
27
+ "model_type": "ee_qwen3",
28
+ "num_attention_heads": 40,
29
+ "num_hidden_layers": 40,
30
+ "num_key_value_heads": 8,
31
+ "rms_norm_eps": 1e-06,
32
+ "rope_scaling": null,
33
+ "rope_theta": 1000000,
34
+ "shared_heads": false,
35
+ "sliding_window": null,
36
+ "tie_word_embeddings": false,
37
+ "torch_dtype": "bfloat16",
38
+ "transformers_version": "4.52.0",
39
+ "use_cache": true,
40
+ "use_sliding_window": false,
41
+ "vocab_size": 151936
42
+ }
configuration_eeqwen3.py ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # Ref: https://github.com/huggingface/transformers/blob/v4.51.3/src/transformers/models/qwen3/configuration_qwen3.py
3
+ # Copyright (c) TeleAI, R.I. and its affiliates. All Rights Reserved.
4
+ """EEQwen3 model configuration"""
5
+
6
+ import os
7
+ import shutil
8
+
9
+ from transformers.configuration_utils import PretrainedConfig
10
+ from transformers.modeling_rope_utils import rope_config_validation
11
+ from transformers.utils import logging
12
+
13
+
14
+ logger = logging.get_logger(__name__)
15
+
16
+
17
+ class EEQwen3Config(PretrainedConfig):
18
+ r"""
19
+ This is the configuration class to store the configuration of a [`Qwen3Model`]. It is used to instantiate a
20
+ Qwen3 model according to the specified arguments, defining the model architecture. Instantiating a configuration
21
+ with the defaults will yield a similar configuration to that of
22
+ Qwen3-8B [Qwen/Qwen3-8B](https://huggingface.co/Qwen/Qwen3-8B).
23
+
24
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
25
+ documentation from [`PretrainedConfig`] for more information.
26
+
27
+
28
+ Args:
29
+ vocab_size (`int`, *optional*, defaults to 151936):
30
+ Vocabulary size of the Qwen3 model. Defines the number of different tokens that can be represented by the
31
+ `inputs_ids` passed when calling [`Qwen3Model`]
32
+ hidden_size (`int`, *optional*, defaults to 4096):
33
+ Dimension of the hidden representations.
34
+ intermediate_size (`int`, *optional*, defaults to 22016):
35
+ Dimension of the MLP representations.
36
+ num_hidden_layers (`int`, *optional*, defaults to 32):
37
+ Number of hidden layers in the Transformer encoder.
38
+ num_attention_heads (`int`, *optional*, defaults to 32):
39
+ Number of attention heads for each attention layer in the Transformer encoder.
40
+ num_key_value_heads (`int`, *optional*, defaults to 32):
41
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
42
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
43
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
44
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
45
+ by meanpooling all the original heads within that group. For more details checkout [this
46
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
47
+ head_dim (`int`, *optional*, defaults to 128):
48
+ The attention head dimension.
49
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
50
+ The non-linear activation function (function or string) in the decoder.
51
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
52
+ The maximum sequence length that this model might ever be used with.
53
+ initializer_range (`float`, *optional*, defaults to 0.02):
54
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
55
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
56
+ The epsilon used by the rms normalization layers.
57
+ use_cache (`bool`, *optional*, defaults to `True`):
58
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
59
+ relevant if `config.is_decoder=True`.
60
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
61
+ Whether the model's input and output word embeddings should be tied.
62
+ rope_theta (`float`, *optional*, defaults to 10000.0):
63
+ The base period of the RoPE embeddings.
64
+ rope_scaling (`Dict`, *optional*):
65
+ Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
66
+ and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
67
+ accordingly.
68
+ Expected contents:
69
+ `rope_type` (`str`):
70
+ The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
71
+ 'llama3'], with 'default' being the original RoPE implementation.
72
+ `factor` (`float`, *optional*):
73
+ Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
74
+ most scaling types, a `factor` of x will enable the model to handle sequences of length x *
75
+ original maximum pre-trained length.
76
+ `original_max_position_embeddings` (`int`, *optional*):
77
+ Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
78
+ pretraining.
79
+ `attention_factor` (`float`, *optional*):
80
+ Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
81
+ computation. If unspecified, it defaults to value recommended by the implementation, using the
82
+ `factor` field to infer the suggested value.
83
+ `beta_fast` (`float`, *optional*):
84
+ Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
85
+ ramp function. If unspecified, it defaults to 32.
86
+ `beta_slow` (`float`, *optional*):
87
+ Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
88
+ ramp function. If unspecified, it defaults to 1.
89
+ `short_factor` (`List[float]`, *optional*):
90
+ Only used with 'longrope'. The scaling factor to be applied to short contexts (<
91
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
92
+ size divided by the number of attention heads divided by 2
93
+ `long_factor` (`List[float]`, *optional*):
94
+ Only used with 'longrope'. The scaling factor to be applied to long contexts (<
95
+ `original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
96
+ size divided by the number of attention heads divided by 2
97
+ `low_freq_factor` (`float`, *optional*):
98
+ Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
99
+ `high_freq_factor` (`float`, *optional*):
100
+ Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
101
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
102
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
103
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
104
+ Whether to use sliding window attention.
105
+ sliding_window (`int`, *optional*, defaults to 4096):
106
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
107
+ max_window_layers (`int`, *optional*, defaults to 28):
108
+ The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
109
+ attention_dropout (`float`, *optional*, defaults to 0.0):
110
+ The dropout ratio for the attention probabilities.
111
+
112
+ ```python
113
+ >>> from transformers import Qwen3Model, Qwen3Config
114
+
115
+ >>> # Initializing a Qwen3 style configuration
116
+ >>> configuration = Qwen3Config()
117
+
118
+ >>> # Initializing a model from the Qwen3-8B style configuration
119
+ >>> model = Qwen3Model(configuration)
120
+
121
+ >>> # Accessing the model configuration
122
+ >>> configuration = model.config
123
+ ```"""
124
+
125
+ model_type = "ee_qwen3"
126
+ keys_to_ignore_at_inference = ["past_key_values"]
127
+
128
+ # Default tensor parallel plan for base model `Qwen3`
129
+ base_model_tp_plan = {
130
+ "layers.*.self_attn.q_proj": "colwise",
131
+ "layers.*.self_attn.k_proj": "colwise",
132
+ "layers.*.self_attn.v_proj": "colwise",
133
+ "layers.*.self_attn.o_proj": "rowwise",
134
+ "layers.*.mlp.gate_proj": "colwise",
135
+ "layers.*.mlp.up_proj": "colwise",
136
+ "layers.*.mlp.down_proj": "rowwise",
137
+ }
138
+ base_model_pp_plan = {
139
+ "embed_tokens": (["input_ids"], ["inputs_embeds"]),
140
+ "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
141
+ "norm": (["hidden_states"], ["hidden_states"]),
142
+ }
143
+
144
+ def __init__(
145
+ self,
146
+ vocab_size=151936,
147
+ hidden_size=5120,
148
+ intermediate_size=17408,
149
+ num_hidden_layers=40,
150
+ num_attention_heads=40,
151
+ num_key_value_heads=8,
152
+ head_dim=128,
153
+ hidden_act="silu",
154
+ max_position_embeddings=32768,
155
+ initializer_range=0.02,
156
+ rms_norm_eps=1e-6,
157
+ use_cache=True,
158
+ tie_word_embeddings=False,
159
+ rope_theta=1000000.0,
160
+ rope_scaling=None,
161
+ attention_bias=False,
162
+ use_sliding_window=False,
163
+ sliding_window=4096,
164
+ max_window_layers=40,
165
+ attention_dropout=0.0,
166
+
167
+ shared_heads=False,
168
+ default_early_exit_point=-1,
169
+ early_exit_points=[2, 21, 39],
170
+ **kwargs,
171
+ ):
172
+ self.vocab_size = vocab_size
173
+ self.max_position_embeddings = max_position_embeddings
174
+ self.hidden_size = hidden_size
175
+ self.intermediate_size = intermediate_size
176
+ self.num_hidden_layers = num_hidden_layers
177
+ self.num_attention_heads = num_attention_heads
178
+ self.use_sliding_window = use_sliding_window
179
+ self.sliding_window = sliding_window # we check `use_sliding_window` in the modeling code
180
+ self.max_window_layers = max_window_layers
181
+
182
+ # for backward compatibility
183
+ if num_key_value_heads is None:
184
+ num_key_value_heads = num_attention_heads
185
+
186
+ self.num_key_value_heads = num_key_value_heads
187
+ self.head_dim = head_dim
188
+ self.hidden_act = hidden_act
189
+ self.initializer_range = initializer_range
190
+ self.rms_norm_eps = rms_norm_eps
191
+ self.use_cache = use_cache
192
+ self.rope_theta = rope_theta
193
+ self.rope_scaling = rope_scaling
194
+ self.attention_bias = attention_bias
195
+ self.attention_dropout = attention_dropout
196
+ # Validate the correctness of rotary position embeddings parameters
197
+ # BC: if there is a 'type' field, move it to 'rope_type'.
198
+ if self.rope_scaling is not None and "type" in self.rope_scaling:
199
+ self.rope_scaling["rope_type"] = self.rope_scaling["type"]
200
+ rope_config_validation(self)
201
+
202
+ self.shared_heads = shared_heads
203
+ self.default_early_exit_point = default_early_exit_point
204
+ self.early_exit_points = early_exit_points
205
+ self.auto_map = {
206
+ "AutoConfig": "configuration_eeqwen3.EEQwen3Config",
207
+ "AutoModel": "modeling_eeqwen3.EEQwen3Model",
208
+ "AutoModelForCausalLM": "modeling_eeqwen3.EEQwen3ForCausalLM"
209
+ }
210
+
211
+ super().__init__(
212
+ tie_word_embeddings=tie_word_embeddings,
213
+ **kwargs,
214
+ )
215
+
216
+ def save_pretrained(self, save_directory, **kwargs):
217
+ super().save_pretrained(save_directory, **kwargs)
218
+ shutil.copyfile(
219
+ os.path.abspath(__file__),
220
+ os.path.join(save_directory, "configuration_eeqwen3.py")
221
+ )
222
+
223
+
224
+ __all__ = ["EEQwen3Config"]
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 151643,
4
+ "eos_token_id": 151643,
5
+ "transformers_version": "4.52.0"
6
+ }
model-00001-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd64cec2a8a288c9a231b5db42e36f215e1e326b96534596391a8191e8ca96c8
3
+ size 4984780784
model-00002-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fa0b529ee6a3f703f408fde741dc747cdaf136a7e438824800dbc36c96394cf1
3
+ size 4980892048
model-00003-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cafdf070c3668c9e15007de4c656fda72965f4e89151971225f8e1c1376a735a
3
+ size 4928485104
model-00004-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1703de2ddeb7af3ea8eaddd4bb02a5e56c64786c6d2b3e647a2493a2a969963
3
+ size 4980892112
model-00005-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aacf2fc6eeb6e450c045d11c87e1b3b4b029542dc065095d721f21a08196a1bb
3
+ size 4928485104
model-00006-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e26d954b4ad2c24f4f46287ef5cebc71cea7eb74a2ed315c30e40cff4017ec8a
3
+ size 4498576728
model-00007-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:751ba7766464cb717a44876ce63d3482cae7bd3db506ca4663d9852fd893aa8a
3
+ size 4667474248
model.safetensors.index.json ADDED
@@ -0,0 +1,476 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 33969531904
4
+ },
5
+ "weight_map": {
6
+ "lm_head.0.weight": "model-00007-of-00007.safetensors",
7
+ "lm_head.1.weight": "model-00007-of-00007.safetensors",
8
+ "lm_head.2.weight": "model-00007-of-00007.safetensors",
9
+ "model.eelayers.0.input_layernorm.weight": "model-00006-of-00007.safetensors",
10
+ "model.eelayers.0.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
11
+ "model.eelayers.0.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
12
+ "model.eelayers.0.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
13
+ "model.eelayers.0.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
14
+ "model.eelayers.0.self_attn.k_norm.weight": "model-00006-of-00007.safetensors",
15
+ "model.eelayers.0.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
16
+ "model.eelayers.0.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
17
+ "model.eelayers.0.self_attn.q_norm.weight": "model-00006-of-00007.safetensors",
18
+ "model.eelayers.0.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
19
+ "model.eelayers.0.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
20
+ "model.eelayers.1.input_layernorm.weight": "model-00006-of-00007.safetensors",
21
+ "model.eelayers.1.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
22
+ "model.eelayers.1.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
23
+ "model.eelayers.1.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
24
+ "model.eelayers.1.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
25
+ "model.eelayers.1.self_attn.k_norm.weight": "model-00006-of-00007.safetensors",
26
+ "model.eelayers.1.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
27
+ "model.eelayers.1.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
28
+ "model.eelayers.1.self_attn.q_norm.weight": "model-00006-of-00007.safetensors",
29
+ "model.eelayers.1.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
30
+ "model.eelayers.1.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
31
+ "model.embed_tokens.weight": "model-00001-of-00007.safetensors",
32
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00007.safetensors",
33
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
34
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
35
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
36
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
37
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00007.safetensors",
38
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
39
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
40
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00007.safetensors",
41
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
42
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
43
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00007.safetensors",
44
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
45
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
46
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
47
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
48
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00007.safetensors",
49
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
50
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
51
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00007.safetensors",
52
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
53
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
54
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00007.safetensors",
55
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
56
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
57
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
58
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
59
+ "model.layers.10.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
60
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
61
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
62
+ "model.layers.10.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
63
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
64
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
65
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00007.safetensors",
66
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
67
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
68
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
69
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
70
+ "model.layers.11.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
71
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
72
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
73
+ "model.layers.11.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
74
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
75
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
76
+ "model.layers.12.input_layernorm.weight": "model-00003-of-00007.safetensors",
77
+ "model.layers.12.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
78
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
79
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
80
+ "model.layers.12.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
81
+ "model.layers.12.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
82
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
83
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
84
+ "model.layers.12.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
85
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
86
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
87
+ "model.layers.13.input_layernorm.weight": "model-00003-of-00007.safetensors",
88
+ "model.layers.13.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
89
+ "model.layers.13.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
90
+ "model.layers.13.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
91
+ "model.layers.13.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
92
+ "model.layers.13.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
93
+ "model.layers.13.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
94
+ "model.layers.13.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
95
+ "model.layers.13.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
96
+ "model.layers.13.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
97
+ "model.layers.13.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
98
+ "model.layers.14.input_layernorm.weight": "model-00003-of-00007.safetensors",
99
+ "model.layers.14.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
100
+ "model.layers.14.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
101
+ "model.layers.14.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
102
+ "model.layers.14.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
103
+ "model.layers.14.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
104
+ "model.layers.14.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
105
+ "model.layers.14.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
106
+ "model.layers.14.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
107
+ "model.layers.14.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
108
+ "model.layers.14.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
109
+ "model.layers.15.input_layernorm.weight": "model-00003-of-00007.safetensors",
110
+ "model.layers.15.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
111
+ "model.layers.15.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
112
+ "model.layers.15.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
113
+ "model.layers.15.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
114
+ "model.layers.15.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
115
+ "model.layers.15.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
116
+ "model.layers.15.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
117
+ "model.layers.15.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
118
+ "model.layers.15.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
119
+ "model.layers.15.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
120
+ "model.layers.16.input_layernorm.weight": "model-00003-of-00007.safetensors",
121
+ "model.layers.16.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
122
+ "model.layers.16.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
123
+ "model.layers.16.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
124
+ "model.layers.16.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
125
+ "model.layers.16.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
126
+ "model.layers.16.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
127
+ "model.layers.16.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
128
+ "model.layers.16.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
129
+ "model.layers.16.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
130
+ "model.layers.16.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
131
+ "model.layers.17.input_layernorm.weight": "model-00003-of-00007.safetensors",
132
+ "model.layers.17.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
133
+ "model.layers.17.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
134
+ "model.layers.17.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
135
+ "model.layers.17.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
136
+ "model.layers.17.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
137
+ "model.layers.17.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
138
+ "model.layers.17.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
139
+ "model.layers.17.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
140
+ "model.layers.17.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
141
+ "model.layers.17.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
142
+ "model.layers.18.input_layernorm.weight": "model-00003-of-00007.safetensors",
143
+ "model.layers.18.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
144
+ "model.layers.18.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
145
+ "model.layers.18.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
146
+ "model.layers.18.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
147
+ "model.layers.18.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
148
+ "model.layers.18.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
149
+ "model.layers.18.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
150
+ "model.layers.18.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
151
+ "model.layers.18.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
152
+ "model.layers.18.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
153
+ "model.layers.19.input_layernorm.weight": "model-00003-of-00007.safetensors",
154
+ "model.layers.19.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
155
+ "model.layers.19.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
156
+ "model.layers.19.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
157
+ "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
158
+ "model.layers.19.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
159
+ "model.layers.19.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
160
+ "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
161
+ "model.layers.19.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
162
+ "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
163
+ "model.layers.19.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
164
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00007.safetensors",
165
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
166
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
167
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
168
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
169
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00007.safetensors",
170
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
171
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
172
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00007.safetensors",
173
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
174
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
175
+ "model.layers.20.input_layernorm.weight": "model-00004-of-00007.safetensors",
176
+ "model.layers.20.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
177
+ "model.layers.20.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
178
+ "model.layers.20.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
179
+ "model.layers.20.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
180
+ "model.layers.20.self_attn.k_norm.weight": "model-00003-of-00007.safetensors",
181
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
182
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
183
+ "model.layers.20.self_attn.q_norm.weight": "model-00003-of-00007.safetensors",
184
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
185
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
186
+ "model.layers.21.input_layernorm.weight": "model-00004-of-00007.safetensors",
187
+ "model.layers.21.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
188
+ "model.layers.21.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
189
+ "model.layers.21.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
190
+ "model.layers.21.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
191
+ "model.layers.21.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
192
+ "model.layers.21.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
193
+ "model.layers.21.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
194
+ "model.layers.21.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
195
+ "model.layers.21.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
196
+ "model.layers.21.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
197
+ "model.layers.22.input_layernorm.weight": "model-00004-of-00007.safetensors",
198
+ "model.layers.22.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
199
+ "model.layers.22.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
200
+ "model.layers.22.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
201
+ "model.layers.22.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
202
+ "model.layers.22.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
203
+ "model.layers.22.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
204
+ "model.layers.22.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
205
+ "model.layers.22.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
206
+ "model.layers.22.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
207
+ "model.layers.22.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
208
+ "model.layers.23.input_layernorm.weight": "model-00004-of-00007.safetensors",
209
+ "model.layers.23.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
210
+ "model.layers.23.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
211
+ "model.layers.23.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
212
+ "model.layers.23.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
213
+ "model.layers.23.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
214
+ "model.layers.23.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
215
+ "model.layers.23.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
216
+ "model.layers.23.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
217
+ "model.layers.23.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
218
+ "model.layers.23.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
219
+ "model.layers.24.input_layernorm.weight": "model-00004-of-00007.safetensors",
220
+ "model.layers.24.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
221
+ "model.layers.24.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
222
+ "model.layers.24.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
223
+ "model.layers.24.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
224
+ "model.layers.24.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
225
+ "model.layers.24.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
226
+ "model.layers.24.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
227
+ "model.layers.24.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
228
+ "model.layers.24.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
229
+ "model.layers.24.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
230
+ "model.layers.25.input_layernorm.weight": "model-00004-of-00007.safetensors",
231
+ "model.layers.25.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
232
+ "model.layers.25.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
233
+ "model.layers.25.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
234
+ "model.layers.25.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
235
+ "model.layers.25.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
236
+ "model.layers.25.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
237
+ "model.layers.25.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
238
+ "model.layers.25.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
239
+ "model.layers.25.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
240
+ "model.layers.25.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
241
+ "model.layers.26.input_layernorm.weight": "model-00004-of-00007.safetensors",
242
+ "model.layers.26.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
243
+ "model.layers.26.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
244
+ "model.layers.26.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
245
+ "model.layers.26.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
246
+ "model.layers.26.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
247
+ "model.layers.26.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
248
+ "model.layers.26.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
249
+ "model.layers.26.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
250
+ "model.layers.26.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
251
+ "model.layers.26.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
252
+ "model.layers.27.input_layernorm.weight": "model-00005-of-00007.safetensors",
253
+ "model.layers.27.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
254
+ "model.layers.27.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
255
+ "model.layers.27.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
256
+ "model.layers.27.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
257
+ "model.layers.27.self_attn.k_norm.weight": "model-00004-of-00007.safetensors",
258
+ "model.layers.27.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
259
+ "model.layers.27.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
260
+ "model.layers.27.self_attn.q_norm.weight": "model-00004-of-00007.safetensors",
261
+ "model.layers.27.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
262
+ "model.layers.27.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
263
+ "model.layers.28.input_layernorm.weight": "model-00005-of-00007.safetensors",
264
+ "model.layers.28.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
265
+ "model.layers.28.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
266
+ "model.layers.28.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
267
+ "model.layers.28.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
268
+ "model.layers.28.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
269
+ "model.layers.28.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
270
+ "model.layers.28.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
271
+ "model.layers.28.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
272
+ "model.layers.28.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
273
+ "model.layers.28.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
274
+ "model.layers.29.input_layernorm.weight": "model-00005-of-00007.safetensors",
275
+ "model.layers.29.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
276
+ "model.layers.29.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
277
+ "model.layers.29.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
278
+ "model.layers.29.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
279
+ "model.layers.29.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
280
+ "model.layers.29.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
281
+ "model.layers.29.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
282
+ "model.layers.29.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
283
+ "model.layers.29.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
284
+ "model.layers.29.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
285
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00007.safetensors",
286
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
287
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
288
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
289
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
290
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00007.safetensors",
291
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
292
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
293
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00007.safetensors",
294
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
295
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
296
+ "model.layers.30.input_layernorm.weight": "model-00005-of-00007.safetensors",
297
+ "model.layers.30.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
298
+ "model.layers.30.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
299
+ "model.layers.30.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
300
+ "model.layers.30.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
301
+ "model.layers.30.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
302
+ "model.layers.30.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
303
+ "model.layers.30.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
304
+ "model.layers.30.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
305
+ "model.layers.30.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
306
+ "model.layers.30.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
307
+ "model.layers.31.input_layernorm.weight": "model-00005-of-00007.safetensors",
308
+ "model.layers.31.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
309
+ "model.layers.31.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
310
+ "model.layers.31.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
311
+ "model.layers.31.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
312
+ "model.layers.31.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
313
+ "model.layers.31.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
314
+ "model.layers.31.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
315
+ "model.layers.31.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
316
+ "model.layers.31.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
317
+ "model.layers.31.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
318
+ "model.layers.32.input_layernorm.weight": "model-00005-of-00007.safetensors",
319
+ "model.layers.32.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
320
+ "model.layers.32.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
321
+ "model.layers.32.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
322
+ "model.layers.32.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
323
+ "model.layers.32.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
324
+ "model.layers.32.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
325
+ "model.layers.32.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
326
+ "model.layers.32.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
327
+ "model.layers.32.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
328
+ "model.layers.32.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
329
+ "model.layers.33.input_layernorm.weight": "model-00005-of-00007.safetensors",
330
+ "model.layers.33.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
331
+ "model.layers.33.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
332
+ "model.layers.33.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
333
+ "model.layers.33.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
334
+ "model.layers.33.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
335
+ "model.layers.33.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
336
+ "model.layers.33.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
337
+ "model.layers.33.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
338
+ "model.layers.33.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
339
+ "model.layers.33.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
340
+ "model.layers.34.input_layernorm.weight": "model-00005-of-00007.safetensors",
341
+ "model.layers.34.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
342
+ "model.layers.34.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
343
+ "model.layers.34.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
344
+ "model.layers.34.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
345
+ "model.layers.34.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
346
+ "model.layers.34.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
347
+ "model.layers.34.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
348
+ "model.layers.34.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
349
+ "model.layers.34.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
350
+ "model.layers.34.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
351
+ "model.layers.35.input_layernorm.weight": "model-00006-of-00007.safetensors",
352
+ "model.layers.35.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
353
+ "model.layers.35.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
354
+ "model.layers.35.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
355
+ "model.layers.35.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
356
+ "model.layers.35.self_attn.k_norm.weight": "model-00005-of-00007.safetensors",
357
+ "model.layers.35.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
358
+ "model.layers.35.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
359
+ "model.layers.35.self_attn.q_norm.weight": "model-00005-of-00007.safetensors",
360
+ "model.layers.35.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
361
+ "model.layers.35.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
362
+ "model.layers.36.input_layernorm.weight": "model-00006-of-00007.safetensors",
363
+ "model.layers.36.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
364
+ "model.layers.36.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
365
+ "model.layers.36.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
366
+ "model.layers.36.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
367
+ "model.layers.36.self_attn.k_norm.weight": "model-00006-of-00007.safetensors",
368
+ "model.layers.36.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
369
+ "model.layers.36.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
370
+ "model.layers.36.self_attn.q_norm.weight": "model-00006-of-00007.safetensors",
371
+ "model.layers.36.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
372
+ "model.layers.36.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
373
+ "model.layers.37.input_layernorm.weight": "model-00006-of-00007.safetensors",
374
+ "model.layers.37.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
375
+ "model.layers.37.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
376
+ "model.layers.37.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
377
+ "model.layers.37.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
378
+ "model.layers.37.self_attn.k_norm.weight": "model-00006-of-00007.safetensors",
379
+ "model.layers.37.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
380
+ "model.layers.37.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
381
+ "model.layers.37.self_attn.q_norm.weight": "model-00006-of-00007.safetensors",
382
+ "model.layers.37.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
383
+ "model.layers.37.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
384
+ "model.layers.38.input_layernorm.weight": "model-00006-of-00007.safetensors",
385
+ "model.layers.38.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
386
+ "model.layers.38.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
387
+ "model.layers.38.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
388
+ "model.layers.38.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
389
+ "model.layers.38.self_attn.k_norm.weight": "model-00006-of-00007.safetensors",
390
+ "model.layers.38.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
391
+ "model.layers.38.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
392
+ "model.layers.38.self_attn.q_norm.weight": "model-00006-of-00007.safetensors",
393
+ "model.layers.38.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
394
+ "model.layers.38.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
395
+ "model.layers.39.input_layernorm.weight": "model-00006-of-00007.safetensors",
396
+ "model.layers.39.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
397
+ "model.layers.39.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
398
+ "model.layers.39.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
399
+ "model.layers.39.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
400
+ "model.layers.39.self_attn.k_norm.weight": "model-00006-of-00007.safetensors",
401
+ "model.layers.39.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
402
+ "model.layers.39.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
403
+ "model.layers.39.self_attn.q_norm.weight": "model-00006-of-00007.safetensors",
404
+ "model.layers.39.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
405
+ "model.layers.39.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
406
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00007.safetensors",
407
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
408
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
409
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
410
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
411
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00007.safetensors",
412
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
413
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
414
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00007.safetensors",
415
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
416
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
417
+ "model.layers.5.input_layernorm.weight": "model-00002-of-00007.safetensors",
418
+ "model.layers.5.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
419
+ "model.layers.5.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
420
+ "model.layers.5.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
421
+ "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
422
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00007.safetensors",
423
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
424
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
425
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00007.safetensors",
426
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
427
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
428
+ "model.layers.6.input_layernorm.weight": "model-00002-of-00007.safetensors",
429
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
430
+ "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
431
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
432
+ "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
433
+ "model.layers.6.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
434
+ "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
435
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
436
+ "model.layers.6.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
437
+ "model.layers.6.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
438
+ "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
439
+ "model.layers.7.input_layernorm.weight": "model-00002-of-00007.safetensors",
440
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
441
+ "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
442
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
443
+ "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
444
+ "model.layers.7.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
445
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
446
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
447
+ "model.layers.7.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
448
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
449
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
450
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00007.safetensors",
451
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
452
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
453
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
454
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
455
+ "model.layers.8.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
456
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
457
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
458
+ "model.layers.8.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
459
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
460
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
461
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00007.safetensors",
462
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
463
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
464
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
465
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
466
+ "model.layers.9.self_attn.k_norm.weight": "model-00002-of-00007.safetensors",
467
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
468
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
469
+ "model.layers.9.self_attn.q_norm.weight": "model-00002-of-00007.safetensors",
470
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
471
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
472
+ "model.norms.0.weight": "model-00006-of-00007.safetensors",
473
+ "model.norms.1.weight": "model-00006-of-00007.safetensors",
474
+ "model.norms.2.weight": "model-00006-of-00007.safetensors"
475
+ }
476
+ }
modeling_eeqwen3.py ADDED
@@ -0,0 +1,906 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ # Ref: https://github.com/huggingface/transformers/blob/v4.51.3/src/transformers/models/qwen3/modeling_qwen3.py
3
+ """EEQwen3 model"""
4
+
5
+ import os
6
+ import shutil
7
+
8
+ from functools import partial
9
+ from typing import Callable, Optional, Tuple, Union
10
+ from itertools import chain
11
+
12
+ import torch
13
+ from torch import nn
14
+
15
+ from transformers.activations import ACT2FN
16
+ from transformers.cache_utils import Cache, DynamicCache, SlidingWindowCache, StaticCache
17
+ from transformers.generation import GenerationMixin
18
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
19
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
20
+ from transformers.modeling_outputs import (
21
+ BaseModelOutputWithPast,
22
+ CausalLMOutputWithPast,
23
+ QuestionAnsweringModelOutput,
24
+ SequenceClassifierOutputWithPast,
25
+ TokenClassifierOutput,
26
+ )
27
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
28
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
29
+ from transformers.processing_utils import Unpack
30
+ from transformers.utils import (
31
+ LossKwargs,
32
+ add_code_sample_docstrings,
33
+ add_start_docstrings,
34
+ add_start_docstrings_to_model_forward,
35
+ can_return_tuple,
36
+ logging,
37
+ replace_return_docstrings,
38
+ )
39
+ from transformers.utils.deprecation import deprecate_kwarg
40
+ from .configuration_eeqwen3 import EEQwen3Config
41
+
42
+ from eelm.global_var import set_global_val, get_global_val
43
+
44
+
45
+ logger = logging.get_logger(__name__)
46
+
47
+ _CONFIG_FOR_DOC = "EEQwen3Config"
48
+
49
+
50
+ class EEQwen3RMSNorm(nn.Module):
51
+ def __init__(self, hidden_size, eps=1e-6):
52
+ """
53
+ EEQwen3RMSNorm is equivalent to T5LayerNorm
54
+ """
55
+ super().__init__()
56
+ self.weight = nn.Parameter(torch.ones(hidden_size))
57
+ self.variance_epsilon = eps
58
+
59
+ def forward(self, hidden_states):
60
+ input_dtype = hidden_states.dtype
61
+ hidden_states = hidden_states.to(torch.float32)
62
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
63
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
64
+ return self.weight * hidden_states.to(input_dtype)
65
+
66
+ def extra_repr(self):
67
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
68
+
69
+
70
+ class EEQwen3MLP(nn.Module):
71
+ def __init__(self, config):
72
+ super().__init__()
73
+ self.config = config
74
+ self.hidden_size = config.hidden_size
75
+ self.intermediate_size = config.intermediate_size
76
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
77
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
78
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
79
+ self.act_fn = ACT2FN[config.hidden_act]
80
+
81
+ def forward(self, x):
82
+ down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
83
+ return down_proj
84
+
85
+
86
+ def rotate_half(x):
87
+ """Rotates half the hidden dims of the input."""
88
+ x1 = x[..., : x.shape[-1] // 2]
89
+ x2 = x[..., x.shape[-1] // 2 :]
90
+ return torch.cat((-x2, x1), dim=-1)
91
+
92
+
93
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids=None, unsqueeze_dim=1):
94
+ """Applies Rotary Position Embedding to the query and key tensors.
95
+
96
+ Args:
97
+ q (`torch.Tensor`): The query tensor.
98
+ k (`torch.Tensor`): The key tensor.
99
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
100
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
101
+ position_ids (`torch.Tensor`, *optional*):
102
+ Deprecated and unused.
103
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
104
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
105
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
106
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
107
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
108
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
109
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
110
+ Returns:
111
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
112
+ """
113
+ cos = cos.unsqueeze(unsqueeze_dim)
114
+ sin = sin.unsqueeze(unsqueeze_dim)
115
+ q_embed = (q * cos) + (rotate_half(q) * sin)
116
+ k_embed = (k * cos) + (rotate_half(k) * sin)
117
+ return q_embed, k_embed
118
+
119
+
120
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
121
+ """
122
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
123
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
124
+ """
125
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
126
+ if n_rep == 1:
127
+ return hidden_states
128
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
129
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
130
+
131
+
132
+ def eager_attention_forward(
133
+ module: nn.Module,
134
+ query: torch.Tensor,
135
+ key: torch.Tensor,
136
+ value: torch.Tensor,
137
+ attention_mask: Optional[torch.Tensor],
138
+ scaling: float,
139
+ dropout: float = 0.0,
140
+ **kwargs,
141
+ ):
142
+ key_states = repeat_kv(key, module.num_key_value_groups)
143
+ value_states = repeat_kv(value, module.num_key_value_groups)
144
+
145
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
146
+ if attention_mask is not None:
147
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
148
+ attn_weights = attn_weights + causal_mask
149
+
150
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
151
+ attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
152
+ attn_output = torch.matmul(attn_weights, value_states)
153
+ attn_output = attn_output.transpose(1, 2).contiguous()
154
+
155
+ return attn_output, attn_weights
156
+
157
+
158
+ class EEQwen3Attention(nn.Module):
159
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
160
+
161
+ def __init__(self, config: EEQwen3Config, layer_idx: int):
162
+ super().__init__()
163
+ self.config = config
164
+ self.layer_idx = layer_idx
165
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
166
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
167
+ self.scaling = self.head_dim**-0.5
168
+ self.attention_dropout = config.attention_dropout
169
+ self.is_causal = True
170
+
171
+ self.q_proj = nn.Linear(
172
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
173
+ )
174
+ self.k_proj = nn.Linear(
175
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
176
+ )
177
+ self.v_proj = nn.Linear(
178
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
179
+ )
180
+ self.o_proj = nn.Linear(
181
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
182
+ )
183
+ self.q_norm = EEQwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # unlike olmo, only on the head dim!
184
+ self.k_norm = EEQwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps) # thus post q_norm does not need reshape
185
+ self.sliding_window = config.sliding_window
186
+ if not (
187
+ self.config.use_sliding_window
188
+ and getattr(self.config, "sliding_window", None) is not None
189
+ and self.layer_idx >= self.config.max_window_layers
190
+ ):
191
+ self.sliding_window = None
192
+
193
+ def forward(
194
+ self,
195
+ hidden_states: torch.Tensor,
196
+ position_embeddings: Tuple[torch.Tensor, torch.Tensor],
197
+ attention_mask: Optional[torch.Tensor],
198
+ past_key_value: Optional[Cache] = None,
199
+ cache_position: Optional[torch.LongTensor] = None,
200
+ **kwargs: Unpack[FlashAttentionKwargs],
201
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
202
+ input_shape = hidden_states.shape[:-1]
203
+ hidden_shape = (*input_shape, -1, self.head_dim)
204
+
205
+ query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
206
+ key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
207
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
208
+
209
+ cos, sin = position_embeddings
210
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
211
+
212
+ if past_key_value is not None:
213
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
214
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
215
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
216
+
217
+ attention_interface: Callable = eager_attention_forward
218
+ if self.config._attn_implementation != "eager":
219
+ if self.config._attn_implementation == "sdpa" and kwargs.get("output_attentions", False):
220
+ logger.warning_once(
221
+ "`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to "
222
+ 'eager attention. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
223
+ )
224
+ else:
225
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
226
+
227
+ attn_output, attn_weights = attention_interface(
228
+ self,
229
+ query_states,
230
+ key_states,
231
+ value_states,
232
+ attention_mask,
233
+ dropout=0.0 if not self.training else self.attention_dropout,
234
+ scaling=self.scaling,
235
+ sliding_window=self.sliding_window, # diff with Llama
236
+ **kwargs,
237
+ )
238
+
239
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
240
+ attn_output = self.o_proj(attn_output)
241
+ return attn_output, attn_weights
242
+
243
+
244
+ class EEQwen3DecoderLayer(nn.Module):
245
+ def __init__(self, config: EEQwen3Config, layer_idx: int):
246
+ super().__init__()
247
+ self.hidden_size = config.hidden_size
248
+ self.self_attn = EEQwen3Attention(config=config, layer_idx=layer_idx)
249
+ self.mlp = EEQwen3MLP(config)
250
+ self.input_layernorm = EEQwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
251
+ self.post_attention_layernorm = EEQwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
252
+ if (
253
+ config.sliding_window and config._attn_implementation != "flash_attention_2"
254
+ ): # diff with Llama is this warning
255
+ logger.warning_once(
256
+ f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
257
+ "unexpected results may be encountered."
258
+ )
259
+
260
+ def forward(
261
+ self,
262
+ hidden_states: torch.Tensor,
263
+ attention_mask: Optional[torch.Tensor] = None,
264
+ position_ids: Optional[torch.LongTensor] = None,
265
+ past_key_value: Optional[Cache] = None,
266
+ output_attentions: Optional[bool] = False,
267
+ use_cache: Optional[bool] = False,
268
+ cache_position: Optional[torch.LongTensor] = None,
269
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
270
+ **kwargs: Unpack[FlashAttentionKwargs],
271
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
272
+ residual = hidden_states
273
+
274
+ hidden_states = self.input_layernorm(hidden_states)
275
+
276
+ # Self Attention
277
+ hidden_states, self_attn_weights = self.self_attn(
278
+ hidden_states=hidden_states,
279
+ attention_mask=attention_mask,
280
+ position_ids=position_ids,
281
+ past_key_value=past_key_value,
282
+ output_attentions=output_attentions,
283
+ use_cache=use_cache,
284
+ cache_position=cache_position,
285
+ position_embeddings=position_embeddings,
286
+ **kwargs,
287
+ )
288
+ hidden_states = residual + hidden_states
289
+
290
+ # Fully Connected
291
+ residual = hidden_states
292
+ hidden_states = self.post_attention_layernorm(hidden_states)
293
+ hidden_states = self.mlp(hidden_states)
294
+ hidden_states = residual + hidden_states
295
+
296
+ outputs = (hidden_states,)
297
+ if output_attentions:
298
+ outputs += (self_attn_weights,)
299
+
300
+ return outputs
301
+
302
+
303
+ class EEQwen3RotaryEmbedding(nn.Module):
304
+ def __init__(self, config: EEQwen3Config, device=None):
305
+ super().__init__()
306
+ # BC: "rope_type" was originally "type"
307
+ if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
308
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
309
+ else:
310
+ self.rope_type = "default"
311
+ self.max_seq_len_cached = config.max_position_embeddings
312
+ self.original_max_seq_len = config.max_position_embeddings
313
+
314
+ self.config = config
315
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
316
+
317
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
318
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
319
+ self.original_inv_freq = self.inv_freq
320
+
321
+ @torch.no_grad()
322
+ @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
323
+ def forward(self, x, position_ids):
324
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
325
+ position_ids_expanded = position_ids[:, None, :].float()
326
+
327
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
328
+ with torch.autocast(device_type=device_type, enabled=False): # Force float32
329
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
330
+ emb = torch.cat((freqs, freqs), dim=-1)
331
+ cos = emb.cos() * self.attention_scaling
332
+ sin = emb.sin() * self.attention_scaling
333
+
334
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
335
+
336
+ EEQWEN3_START_DOCSTRING = r"""
337
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
338
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
339
+ etc.)
340
+
341
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
342
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
343
+ and behavior.
344
+
345
+ Parameters:
346
+ config ([`EEQwen3Config`]):
347
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
348
+ load the weights associated with the model, only the configuration. Check out the
349
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
350
+ """
351
+
352
+
353
+ @add_start_docstrings(
354
+ "The bare EEQwen3 Model outputting raw hidden-states without any specific head on top.",
355
+ EEQWEN3_START_DOCSTRING,
356
+ )
357
+ class EEQwen3PreTrainedModel(PreTrainedModel):
358
+ config_class = EEQwen3Config
359
+ base_model_prefix = "model"
360
+ supports_gradient_checkpointing = True
361
+ _no_split_modules = ["EEQwen3DecoderLayer"]
362
+ _skip_keys_device_placement = ["past_key_values"]
363
+ _supports_flash_attn_2 = True
364
+ _supports_sdpa = True
365
+ _supports_flex_attn = True
366
+ _supports_cache_class = True
367
+ _supports_quantized_cache = True
368
+ _supports_static_cache = True
369
+ _supports_attention_backend = True
370
+
371
+ def _init_weights(self, module):
372
+ std = self.config.initializer_range
373
+ if isinstance(module, nn.Linear):
374
+ module.weight.data.normal_(mean=0.0, std=std)
375
+ if module.bias is not None:
376
+ module.bias.data.zero_()
377
+ elif isinstance(module, nn.Embedding):
378
+ module.weight.data.normal_(mean=0.0, std=std)
379
+ if module.padding_idx is not None:
380
+ module.weight.data[module.padding_idx].zero_()
381
+
382
+
383
+ EEQWEN3_INPUTS_DOCSTRING = r"""
384
+ Args:
385
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
386
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
387
+ it.
388
+
389
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
390
+ [`PreTrainedTokenizer.__call__`] for details.
391
+
392
+ [What are input IDs?](../glossary#input-ids)
393
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
394
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
395
+
396
+ - 1 for tokens that are **not masked**,
397
+ - 0 for tokens that are **masked**.
398
+
399
+ [What are attention masks?](../glossary#attention-mask)
400
+
401
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
402
+ [`PreTrainedTokenizer.__call__`] for details.
403
+
404
+ If `past_key_values` is used, optionally only the last `input_ids` have to be input (see
405
+ `past_key_values`).
406
+
407
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
408
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
409
+ information on the default strategy.
410
+
411
+ - 1 indicates the head is **not masked**,
412
+ - 0 indicates the head is **masked**.
413
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
414
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
415
+ config.n_positions - 1]`.
416
+
417
+ [What are position IDs?](../glossary#position-ids)
418
+ past_key_values (`Cache`, *optional*):
419
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
420
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
421
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
422
+
423
+ It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
424
+
425
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
426
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
427
+ of shape `(batch_size, sequence_length)`.
428
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
429
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
430
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
431
+ model's internal embedding lookup matrix.
432
+ use_cache (`bool`, *optional*):
433
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
434
+ `past_key_values`).
435
+ output_attentions (`bool`, *optional*):
436
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
437
+ tensors for more detail.
438
+ output_hidden_states (`bool`, *optional*):
439
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
440
+ more detail.
441
+ return_dict (`bool`, *optional*):
442
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
443
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
444
+ Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
445
+ this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
446
+ the complete sequence length.
447
+ """
448
+
449
+
450
+ @add_start_docstrings(
451
+ "The bare EEQwen3 Model outputting raw hidden-states without any specific head on top.",
452
+ EEQWEN3_START_DOCSTRING,
453
+ )
454
+ class EEQwen3Model(EEQwen3PreTrainedModel):
455
+ """
456
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`EEQwen3DecoderLayer`]
457
+
458
+ Args:
459
+ config: EEQwen3Config
460
+ """
461
+
462
+ def __init__(self, config: EEQwen3Config):
463
+ super().__init__(config)
464
+ self.padding_idx = config.pad_token_id
465
+ self.vocab_size = config.vocab_size
466
+
467
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
468
+ self.layers = nn.ModuleList(
469
+ [EEQwen3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
470
+ )
471
+ self.eelayers = nn.ModuleList(
472
+ [EEQwen3DecoderLayer(config, layer_idx) for layer_idx in config.early_exit_points[:-1]]
473
+ )
474
+ self.norms = nn.ModuleList(
475
+ [EEQwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps) for _ in config.early_exit_points]
476
+ )
477
+ self.rotary_emb = EEQwen3RotaryEmbedding(config=config)
478
+ self.gradient_checkpointing = False
479
+
480
+ if config.default_early_exit_point not in config.early_exit_points:
481
+ config.default_early_exit_point = config.early_exit_points[-1]
482
+ set_global_val("early_exit_point", config.default_early_exit_point)
483
+
484
+ # Initialize weights and apply final processing
485
+ self.post_init()
486
+
487
+ def get_input_embeddings(self):
488
+ return self.embed_tokens
489
+
490
+ def set_input_embeddings(self, value):
491
+ self.embed_tokens = value
492
+
493
+ @can_return_tuple
494
+ @add_start_docstrings_to_model_forward(EEQWEN3_INPUTS_DOCSTRING)
495
+ def forward(
496
+ self,
497
+ input_ids: Optional[torch.LongTensor] = None,
498
+ attention_mask: Optional[torch.Tensor] = None,
499
+ position_ids: Optional[torch.LongTensor] = None,
500
+ past_key_values: Optional[Cache] = None,
501
+ inputs_embeds: Optional[torch.FloatTensor] = None,
502
+ use_cache: Optional[bool] = None,
503
+ output_attentions: Optional[bool] = None,
504
+ output_hidden_states: Optional[bool] = None,
505
+ cache_position: Optional[torch.LongTensor] = None,
506
+ **flash_attn_kwargs: Unpack[FlashAttentionKwargs],
507
+ ) -> BaseModelOutputWithPast:
508
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
509
+ output_hidden_states = (
510
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
511
+ )
512
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
513
+
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 self.gradient_checkpointing and self.training and use_cache:
518
+ logger.warning_once(
519
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
520
+ )
521
+ use_cache = False
522
+
523
+ # TODO (joao): remove this exception in v4.56 -- it exists for users that try to pass a legacy cache
524
+ if not isinstance(past_key_values, (type(None), Cache)):
525
+ raise ValueError("The `past_key_values` should be either a `Cache` object or `None`.")
526
+
527
+ if inputs_embeds is None:
528
+ inputs_embeds = self.embed_tokens(input_ids)
529
+
530
+ if use_cache and past_key_values is None:
531
+ past_key_values = DynamicCache()
532
+
533
+ if cache_position is None:
534
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
535
+ cache_position = torch.arange(
536
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
537
+ )
538
+
539
+ if position_ids is None:
540
+ position_ids = cache_position.unsqueeze(0)
541
+
542
+ causal_mask = self._update_causal_mask(
543
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
544
+ )
545
+
546
+ hidden_states = inputs_embeds
547
+
548
+ # create position embeddings to be shared across the decoder layers
549
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
550
+
551
+ # decoder layers
552
+ all_hidden_states = () if output_hidden_states else None
553
+ all_self_attns = () if output_attentions else None
554
+
555
+ early_exit_point = get_global_val("early_exit_point", self.config.early_exit_points[-1])
556
+ for decoder_layer in chain(
557
+ self.layers[:early_exit_point],
558
+ [self.layers[-1] if early_exit_point == self.config.num_hidden_layers - 1 \
559
+ else self.eelayers[self.config.early_exit_points.index(early_exit_point)]]
560
+ ):
561
+ if output_hidden_states:
562
+ all_hidden_states += (hidden_states,)
563
+
564
+ if self.gradient_checkpointing and self.training:
565
+ layer_outputs = self._gradient_checkpointing_func(
566
+ partial(decoder_layer.__call__, **flash_attn_kwargs),
567
+ hidden_states,
568
+ causal_mask,
569
+ position_ids,
570
+ past_key_values,
571
+ output_attentions,
572
+ use_cache,
573
+ cache_position,
574
+ position_embeddings,
575
+ )
576
+ else:
577
+ layer_outputs = decoder_layer(
578
+ hidden_states,
579
+ attention_mask=causal_mask,
580
+ position_ids=position_ids,
581
+ past_key_value=past_key_values,
582
+ output_attentions=output_attentions,
583
+ use_cache=use_cache,
584
+ cache_position=cache_position,
585
+ position_embeddings=position_embeddings,
586
+ **flash_attn_kwargs,
587
+ )
588
+
589
+ if isinstance(layer_outputs, tuple):
590
+ hidden_states = layer_outputs[0]
591
+ else:
592
+ hidden_states = layer_outputs # deepspeed gradient checkpointing
593
+
594
+ if output_attentions:
595
+ all_self_attns += (layer_outputs[1],)
596
+
597
+ hidden_states = self.norms[self.config.early_exit_points.index(early_exit_point)](hidden_states)
598
+
599
+ # add hidden states from the last decoder layer
600
+ if output_hidden_states:
601
+ all_hidden_states += (hidden_states,)
602
+
603
+ return BaseModelOutputWithPast(
604
+ last_hidden_state=hidden_states,
605
+ past_key_values=past_key_values if use_cache else None,
606
+ hidden_states=all_hidden_states,
607
+ attentions=all_self_attns,
608
+ )
609
+
610
+ def _update_causal_mask(
611
+ self,
612
+ attention_mask: torch.Tensor,
613
+ input_tensor: torch.Tensor,
614
+ cache_position: torch.Tensor,
615
+ past_key_values: Cache,
616
+ output_attentions: bool = False,
617
+ ):
618
+ if self.config._attn_implementation == "flash_attention_2":
619
+ if attention_mask is not None and past_key_values is not None:
620
+ is_padding_right = attention_mask[:, -1].sum().item() != input_tensor.size()[0]
621
+ if is_padding_right:
622
+ raise ValueError(
623
+ "You are attempting to perform batched generation with padding_side='right'"
624
+ " this may lead to unexpected behaviour for Flash Attention version of EEQwen3. Make sure to "
625
+ " call `tokenizer.padding_side = 'left'` before tokenizing the input. "
626
+ )
627
+ if attention_mask is not None and 0.0 in attention_mask:
628
+ return attention_mask
629
+ return None
630
+
631
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
632
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
633
+ # to infer the attention mask.
634
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
635
+ using_static_cache = isinstance(past_key_values, StaticCache)
636
+ using_sliding_window_cache = isinstance(past_key_values, SlidingWindowCache)
637
+
638
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
639
+ if (
640
+ self.config._attn_implementation == "sdpa"
641
+ and not (using_static_cache or using_sliding_window_cache)
642
+ and not output_attentions
643
+ ):
644
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
645
+ attention_mask,
646
+ inputs_embeds=input_tensor,
647
+ past_key_values_length=past_seen_tokens,
648
+ sliding_window=self.config.sliding_window,
649
+ is_training=self.training,
650
+ ):
651
+ return None
652
+
653
+ dtype, device = input_tensor.dtype, input_tensor.device
654
+ min_dtype = torch.finfo(dtype).min
655
+ sequence_length = input_tensor.shape[1]
656
+ # SlidingWindowCache or StaticCache
657
+ if using_sliding_window_cache or using_static_cache:
658
+ target_length = past_key_values.get_max_cache_shape()
659
+ # DynamicCache or no cache
660
+ else:
661
+ target_length = (
662
+ attention_mask.shape[-1]
663
+ if isinstance(attention_mask, torch.Tensor)
664
+ else past_seen_tokens + sequence_length + 1
665
+ )
666
+
667
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
668
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
669
+ attention_mask,
670
+ sequence_length=sequence_length,
671
+ target_length=target_length,
672
+ dtype=dtype,
673
+ device=device,
674
+ cache_position=cache_position,
675
+ batch_size=input_tensor.shape[0],
676
+ config=self.config,
677
+ past_key_values=past_key_values,
678
+ )
679
+
680
+ if (
681
+ self.config._attn_implementation == "sdpa"
682
+ and attention_mask is not None
683
+ and attention_mask.device.type in ["cuda", "xpu"]
684
+ and not output_attentions
685
+ ):
686
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
687
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
688
+ # Details: https://github.com/pytorch/pytorch/issues/110213
689
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
690
+
691
+ return causal_mask
692
+
693
+ @staticmethod
694
+ def _prepare_4d_causal_attention_mask_with_cache_position(
695
+ attention_mask: torch.Tensor,
696
+ sequence_length: int,
697
+ target_length: int,
698
+ dtype: torch.dtype,
699
+ device: torch.device,
700
+ cache_position: torch.Tensor,
701
+ batch_size: int,
702
+ config: EEQwen3Config,
703
+ past_key_values: Cache,
704
+ ):
705
+ """
706
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
707
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
708
+
709
+ Args:
710
+ attention_mask (`torch.Tensor`):
711
+ A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape `(batch_size, 1, query_length, key_value_length)`.
712
+ sequence_length (`int`):
713
+ The sequence length being processed.
714
+ target_length (`int`):
715
+ The target length: when generating with static cache, the mask should be as long as the static cache, to account for the 0 padding, the part of the cache that is not filled yet.
716
+ dtype (`torch.dtype`):
717
+ The dtype to use for the 4D attention mask.
718
+ device (`torch.device`):
719
+ The device to place the 4D attention mask on.
720
+ cache_position (`torch.Tensor`):
721
+ Indices depicting the position of the input sequence tokens in the sequence.
722
+ batch_size (`torch.Tensor`):
723
+ Batch size.
724
+ config (`EEQwen3Config`):
725
+ The model's configuration class
726
+ past_key_values (`Cache`):
727
+ The cache class that is being used currently to generate
728
+ """
729
+ if attention_mask is not None and attention_mask.dim() == 4:
730
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
731
+ causal_mask = attention_mask
732
+ else:
733
+ min_dtype = torch.finfo(dtype).min
734
+ causal_mask = torch.full(
735
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device
736
+ )
737
+ diagonal_attend_mask = torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
738
+ if config.sliding_window is not None:
739
+ # if we have sliding window, we should not attend to tokens beyond sliding window length, so we mask them out also
740
+ # the check is needed to verify is current checkpoint was trained with sliding window or not
741
+ if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
742
+ sliding_attend_mask = torch.arange(target_length, device=device) <= (
743
+ cache_position.reshape(-1, 1) - config.sliding_window
744
+ )
745
+ diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
746
+ causal_mask *= diagonal_attend_mask
747
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
748
+ if attention_mask is not None:
749
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
750
+ if attention_mask.shape[-1] > target_length:
751
+ attention_mask = attention_mask[:, :target_length]
752
+ mask_length = attention_mask.shape[-1]
753
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
754
+ causal_mask.device
755
+ )
756
+ padding_mask = padding_mask == 0
757
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
758
+ padding_mask, min_dtype
759
+ )
760
+ return causal_mask
761
+
762
+
763
+ class KwargsForCausalLM(FlashAttentionKwargs, LossKwargs): ...
764
+
765
+
766
+ class EEQwen3ForCausalLM(EEQwen3PreTrainedModel, GenerationMixin):
767
+ _tied_weights_keys = ["lm_head.weight"]
768
+ _tp_plan = {"lm_head": "colwise_rep"}
769
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
770
+
771
+ def __init__(self, config):
772
+ super().__init__(config)
773
+ self.model = EEQwen3Model(config)
774
+ self.vocab_size = config.vocab_size
775
+ self.shared_heads = config.shared_heads
776
+ if self.shared_heads:
777
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
778
+ else:
779
+ self.lm_head = nn.ModuleList(
780
+ [nn.Linear(config.hidden_size, config.vocab_size, bias=False) for _ in config.early_exit_points]
781
+ )
782
+
783
+ # Initialize weights and apply final processing
784
+ self.post_init()
785
+
786
+ def get_input_embeddings(self):
787
+ return self.model.embed_tokens
788
+
789
+ def set_input_embeddings(self, value):
790
+ self.model.embed_tokens = value
791
+
792
+ def get_output_embeddings(self):
793
+ return self.lm_head
794
+
795
+ def set_output_embeddings(self, new_embeddings):
796
+ self.lm_head = new_embeddings
797
+
798
+ def set_decoder(self, decoder):
799
+ self.model = decoder
800
+
801
+ def get_decoder(self):
802
+ return self.model
803
+
804
+ def save_pretrained(self, save_directory, **kwargs):
805
+ super().save_pretrained(save_directory, **kwargs)
806
+ shutil.copyfile(
807
+ os.path.abspath(__file__),
808
+ os.path.join(save_directory, "modeling_eeqwen3.py")
809
+ )
810
+
811
+ @can_return_tuple
812
+ @deprecate_kwarg("num_logits_to_keep", version="4.50", new_name="logits_to_keep")
813
+ @add_start_docstrings_to_model_forward(EEQWEN3_INPUTS_DOCSTRING)
814
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
815
+ def forward(
816
+ self,
817
+ input_ids: Optional[torch.LongTensor] = None,
818
+ attention_mask: Optional[torch.Tensor] = None,
819
+ position_ids: Optional[torch.LongTensor] = None,
820
+ past_key_values: Optional[Cache] = None,
821
+ inputs_embeds: Optional[torch.FloatTensor] = None,
822
+ labels: Optional[torch.LongTensor] = None,
823
+ use_cache: Optional[bool] = None,
824
+ output_attentions: Optional[bool] = None,
825
+ output_hidden_states: Optional[bool] = None,
826
+ cache_position: Optional[torch.LongTensor] = None,
827
+ logits_to_keep: Union[int, torch.Tensor] = 0,
828
+ **kwargs: Unpack[KwargsForCausalLM],
829
+ ) -> CausalLMOutputWithPast:
830
+ r"""
831
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
832
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
833
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
834
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
835
+
836
+ logits_to_keep (`int` or `torch.Tensor`, *optional*):
837
+ If an `int`, compute logits for the last `logits_to_keep` tokens. If `0`, calculate logits for all
838
+ `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
839
+ token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
840
+ If a `torch.Tensor`, must be 1D corresponding to the indices to keep in the sequence length dimension.
841
+ This is useful when using packed tensor format (single dimension for batch and sequence length).
842
+
843
+ Returns:
844
+
845
+ Example:
846
+
847
+ ```python
848
+ >>> from transformers import AutoTokenizer, Qwen3ForCausalLM
849
+
850
+ >>> model = Qwen3ForCausalLM.from_pretrained("Qwen/Qwen3-8B")
851
+ >>> tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
852
+
853
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
854
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
855
+
856
+ >>> # Generate
857
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
858
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
859
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
860
+ ```"""
861
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
862
+ output_hidden_states = (
863
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
864
+ )
865
+
866
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
867
+ outputs: BaseModelOutputWithPast = self.model(
868
+ input_ids=input_ids,
869
+ attention_mask=attention_mask,
870
+ position_ids=position_ids,
871
+ past_key_values=past_key_values,
872
+ inputs_embeds=inputs_embeds,
873
+ use_cache=use_cache,
874
+ output_attentions=output_attentions,
875
+ output_hidden_states=output_hidden_states,
876
+ cache_position=cache_position,
877
+ **kwargs,
878
+ )
879
+
880
+ hidden_states = outputs.last_hidden_state
881
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
882
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
883
+ if self.shared_heads:
884
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
885
+ else:
886
+ early_exit_point = get_global_val("early_exit_point", self.config.early_exit_points[-1])
887
+ logits = self.lm_head[self.config.early_exit_points.index(early_exit_point)](hidden_states[:, slice_indices, :])
888
+
889
+ loss = None
890
+ if labels is not None:
891
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
892
+
893
+ return CausalLMOutputWithPast(
894
+ loss=loss,
895
+ logits=logits,
896
+ past_key_values=outputs.past_key_values,
897
+ hidden_states=outputs.hidden_states,
898
+ attentions=outputs.attentions,
899
+ )
900
+
901
+
902
+ __all__ = [
903
+ "EEQwen3ForCausalLM",
904
+ "EEQwen3Model",
905
+ "EEQwen3PreTrainedModel",
906
+ ]