zwpride commited on
Commit
e5c2f8a
·
verified ·
1 Parent(s): 391974f

Upload folder using huggingface_hub

Browse files
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "IQuestCoderForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": [2, 75864, 75869],
9
+ "head_dim": 128,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 5120,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 27648,
14
+ "max_position_embeddings": 131072,
15
+ "mlp_bias": false,
16
+ "model_type": "iquestcoder",
17
+ "num_attention_heads": 40,
18
+ "num_hidden_layers": 64,
19
+ "num_key_value_heads": 8,
20
+ "pretraining_tp": 1,
21
+ "rms_norm_eps": 1e-05,
22
+ "rope_scaling": null,
23
+ "rope_theta": 500000.0,
24
+ "tie_word_embeddings": false,
25
+ "torch_dtype": "bfloat16",
26
+ "transformers_version": "4.55.4",
27
+ "use_cache": true,
28
+ "vocab_size": 76800,
29
+ "clip_qkv": null,
30
+ "use_sliding_window": false,
31
+ "sliding_window": null,
32
+ "max_window_layers": 0,
33
+ "auto_map": {
34
+ "AutoConfig": "configuration_iquestcoder.IQuestCoderConfig",
35
+ "AutoModel": "modeling_iquestcoder.IQuestCoderModel",
36
+ "AutoModelForCausalLM": "modeling_iquestcoder.IQuestCoderForCausalLM",
37
+ "AutoModelForSequenceClassification": "modeling_iquestcoder.IQuestCoderForSequenceClassification",
38
+ "AutoModelForTokenClassification": "modeling_iquestcoder.IQuestCoderForTokenClassification",
39
+ "AutoModelForQuestionAnswering": "modeling_iquestcoder.IQuestCoderForQuestionAnswering"
40
+ }
41
+ }
configuration_iquestcoder.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """IQuestCoder model configuration."""
2
+
3
+ from transformers.configuration_utils import PretrainedConfig
4
+ from transformers.utils import logging
5
+
6
+
7
+ logger = logging.get_logger(__name__)
8
+
9
+
10
+ class IQuestCoderConfig(PretrainedConfig):
11
+ r"""
12
+ This is the configuration class to store the configuration of a [`IQuestCoderModel`]. It is used to instantiate
13
+ an IQuestCoder model according to the specified arguments, defining the model architecture.
14
+
15
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
16
+ documentation from [`PretrainedConfig`] for more information.
17
+
18
+ Args:
19
+ vocab_size (`int`, *optional*, defaults to 76800):
20
+ Vocabulary size of the IQuestCoder model. Defines the number of different tokens that can be represented
21
+ by the `inputs_ids` passed when calling [`IQuestCoderModel`].
22
+ hidden_size (`int`, *optional*, defaults to 5120):
23
+ Dimension of the hidden representations.
24
+ intermediate_size (`int`, *optional*, defaults to 27648):
25
+ Dimension of the MLP representations.
26
+ num_hidden_layers (`int`, *optional*, defaults to 80):
27
+ Number of hidden layers in the Transformer decoder.
28
+ num_attention_heads (`int`, *optional*, defaults to 40):
29
+ Number of attention heads for each attention layer in the Transformer decoder.
30
+ num_key_value_heads (`int`, *optional*, defaults to 8):
31
+ This is the number of key_value heads that should be used to implement Grouped Query Attention (GQA).
32
+ If `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA).
33
+ If `num_key_value_heads=1`, the model will use Multi Query Attention (MQA).
34
+ head_dim (`int`, *optional*, defaults to 128):
35
+ The dimension of each attention head. If not specified, defaults to `hidden_size // num_attention_heads`.
36
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
37
+ The non-linear activation function (function or string) in the decoder.
38
+ max_position_embeddings (`int`, *optional*, defaults to 16384):
39
+ The maximum sequence length that this model might ever be used with.
40
+ initializer_range (`float`, *optional*, defaults to 0.02):
41
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
42
+ rms_norm_eps (`float`, *optional*, defaults to 1e-05):
43
+ The epsilon used by the rms normalization layers.
44
+ use_cache (`bool`, *optional*, defaults to `True`):
45
+ Whether or not the model should return the last key/values attentions (not used by all models).
46
+ pad_token_id (`int`, *optional*):
47
+ Padding token id.
48
+ bos_token_id (`int`, *optional*, defaults to 1):
49
+ Beginning of stream token id.
50
+ eos_token_id (`int`, *optional*, defaults to 2):
51
+ End of stream token id.
52
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
53
+ Whether to tie weight embeddings.
54
+ rope_theta (`float`, *optional*, defaults to 500000.0):
55
+ The base period of the RoPE embeddings.
56
+ rope_scaling (`Dict`, *optional*):
57
+ Dictionary containing the scaling configuration for the RoPE embeddings. Supports various RoPE scaling
58
+ types including "linear", "dynamic", "yarn", "longrope", etc.
59
+ attention_bias (`bool`, *optional*, defaults to `False`):
60
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
61
+ attention_dropout (`float`, *optional*, defaults to 0.0):
62
+ The dropout ratio for the attention probabilities.
63
+ mlp_bias (`bool`, *optional*, defaults to `False`):
64
+ Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.
65
+ clip_qkv (`float`, *optional*):
66
+ If set, clip the query, key, and value tensors to this value. Borrowed from OLMo for training stability.
67
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
68
+ Whether to use sliding window attention. Borrowed from Qwen2.
69
+ sliding_window (`int`, *optional*):
70
+ The sliding window size. Only effective when `use_sliding_window=True`.
71
+ max_window_layers (`int`, *optional*, defaults to 0):
72
+ The number of layers that don't use sliding window attention. Borrowed from Qwen2.
73
+
74
+ Example:
75
+ ```python
76
+ >>> from configuration_iquestcoder import IQuestCoderConfig
77
+ >>> from modeling_iquestcoder import IQuestCoderModel
78
+
79
+ >>> # Initializing a IQuestCoder configuration
80
+ >>> configuration = IQuestCoderConfig()
81
+
82
+ >>> # Initializing a model from the configuration
83
+ >>> model = IQuestCoderModel(configuration)
84
+
85
+ >>> # Accessing the model configuration
86
+ >>> configuration = model.config
87
+ ```
88
+ """
89
+
90
+ model_type = "iquestcoder"
91
+ keys_to_ignore_at_inference = ["past_key_values"]
92
+
93
+ def __init__(
94
+ self,
95
+ vocab_size=76800,
96
+ hidden_size=5120,
97
+ intermediate_size=27648,
98
+ num_hidden_layers=80,
99
+ num_attention_heads=40,
100
+ num_key_value_heads=8,
101
+ head_dim=128,
102
+ hidden_act="silu",
103
+ max_position_embeddings=16384,
104
+ initializer_range=0.02,
105
+ rms_norm_eps=1e-5,
106
+ use_cache=True,
107
+ pad_token_id=None,
108
+ bos_token_id=1,
109
+ eos_token_id=2,
110
+ tie_word_embeddings=False,
111
+ rope_theta=500000.0,
112
+ rope_scaling=None,
113
+ attention_bias=False,
114
+ attention_dropout=0.0,
115
+ mlp_bias=False,
116
+ # IQuestCoder specific (borrowed from OLMo)
117
+ clip_qkv=None,
118
+ # IQuestCoder specific (borrowed from Qwen2)
119
+ use_sliding_window=False,
120
+ sliding_window=None,
121
+ max_window_layers=0,
122
+ **kwargs,
123
+ ):
124
+ self.vocab_size = vocab_size
125
+ self.max_position_embeddings = max_position_embeddings
126
+ self.hidden_size = hidden_size
127
+ self.intermediate_size = intermediate_size
128
+ self.num_hidden_layers = num_hidden_layers
129
+ self.num_attention_heads = num_attention_heads
130
+ self.num_key_value_heads = num_key_value_heads
131
+ self.head_dim = head_dim
132
+ self.hidden_act = hidden_act
133
+ self.initializer_range = initializer_range
134
+ self.rms_norm_eps = rms_norm_eps
135
+ self.use_cache = use_cache
136
+ self.rope_theta = rope_theta
137
+ self.rope_scaling = rope_scaling
138
+ self.attention_bias = attention_bias
139
+ self.attention_dropout = attention_dropout
140
+ self.mlp_bias = mlp_bias
141
+ # IQuestCoder specific
142
+ self.clip_qkv = clip_qkv
143
+ self.use_sliding_window = use_sliding_window
144
+ self.sliding_window = sliding_window
145
+ self.max_window_layers = max_window_layers
146
+
147
+ # Validate rope_scaling configuration
148
+ self._rope_scaling_validation()
149
+
150
+ super().__init__(
151
+ pad_token_id=pad_token_id,
152
+ bos_token_id=bos_token_id,
153
+ eos_token_id=eos_token_id,
154
+ tie_word_embeddings=tie_word_embeddings,
155
+ **kwargs,
156
+ )
157
+
158
+ def _rope_scaling_validation(self):
159
+ """Validate the `rope_scaling` configuration."""
160
+ if self.rope_scaling is None:
161
+ return
162
+
163
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) < 1:
164
+ raise ValueError(
165
+ "`rope_scaling` must be a dictionary with a minimum of one field, `type` or `rope_type`."
166
+ )
167
+
168
+ rope_scaling_type = self.rope_scaling.get("type", None) or self.rope_scaling.get("rope_type", None)
169
+ if rope_scaling_type is None:
170
+ raise ValueError(
171
+ "`rope_scaling` must have a `type` or `rope_type` field."
172
+ )
173
+
174
+ valid_rope_types = ["linear", "dynamic", "yarn", "longrope", "llama3"]
175
+ if rope_scaling_type not in valid_rope_types:
176
+ raise ValueError(
177
+ f"`rope_scaling`'s type field must be one of {valid_rope_types}, got {rope_scaling_type}"
178
+ )
179
+
180
+
181
+ __all__ = ["IQuestCoderConfig"]
182
+
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": [2, 75864, 75869],
5
+ "transformers_version": "4.55.4"
6
+ }
model-00001-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:60428b96f636f000ab1b2585e10b2fb6dd0a37c2502f6098068fdb91a444c971
3
+ size 4813050528
model-00002-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7444fa1ee4259e1d9930e2998bdffdeec9421f24181ec590f50bed2ed92a67e9
3
+ size 4875986024
model-00003-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e2d489c6ddbc1e5f5b585320596de96c4cb8b61b6b270199e04bd01a93d6c8f
3
+ size 4875986056
model-00004-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:38ee81cf31d70a84a6fb2bdd49418c4e195c147cc9b37eb91d0f0ef5e722a51d
3
+ size 4875986072
model-00005-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bed7b424ba873b240c3a9a4f74686f385c5610278713e7fcbfb7d23de28161c8
3
+ size 4875986072
model-00006-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8252f3d38cc3d0b3c66aa1d25e01c0f55ecd1b15f85108cd7cfa582eea00bcfd
3
+ size 4875986072
model-00007-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d7cd212cc3f7cab2a1a0809bd6e25e6c57f64304ffeeec5db0356a71b86c28c5
3
+ size 4875986072
model-00008-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0a274a90535a9335216a704f8d1bdc2619f2f5fca6fd5352b677fd258ecc4299
3
+ size 4875986072
model-00009-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18b658493742de29c74bbfe3859ccb0228e1180598cf009246d084bd1dcaa275
3
+ size 4875986072
model-00010-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebad1c2d9674eb07d93a0324f30f16c0315b6301aed1d11318c403a7df6c8040
3
+ size 4875986072
model-00011-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5121d45c228a743681239a41be69ad7f7ec5dc4635874bf33bc9412f3d05f092
3
+ size 4875986072
model-00012-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18ac94be220ca8c97181ee170366cf709a0c5a60ae99b94fdd216137af9f54b4
3
+ size 4875986072
model-00013-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f8c618c2fd287f5b067aee08702d973cf5ab009a3fed6bc83b0b9d791340c1d
3
+ size 4750166808
model-00014-of-00014.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d93ee5af4f357abd8d5b06c705f2af19b19e8c1e9b5daaf811ea6624bb38121b
3
+ size 786432128
model.safetensors.index.json ADDED
@@ -0,0 +1,587 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 31992714240,
4
+ "total_size": 63985428480
5
+ },
6
+ "weight_map": {
7
+ "lm_head.weight": "model-00014-of-00014.safetensors",
8
+ "model.embed_tokens.weight": "model-00001-of-00014.safetensors",
9
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00014.safetensors",
10
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00014.safetensors",
11
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00014.safetensors",
12
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00014.safetensors",
13
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00014.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00014.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00014.safetensors",
16
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00014.safetensors",
17
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00014.safetensors",
18
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00014.safetensors",
19
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00014.safetensors",
20
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00014.safetensors",
21
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00014.safetensors",
22
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00014.safetensors",
23
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00014.safetensors",
24
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00014.safetensors",
25
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00014.safetensors",
26
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00014.safetensors",
27
+ "model.layers.10.input_layernorm.weight": "model-00003-of-00014.safetensors",
28
+ "model.layers.10.mlp.down_proj.weight": "model-00003-of-00014.safetensors",
29
+ "model.layers.10.mlp.gate_proj.weight": "model-00003-of-00014.safetensors",
30
+ "model.layers.10.mlp.up_proj.weight": "model-00003-of-00014.safetensors",
31
+ "model.layers.10.post_attention_layernorm.weight": "model-00003-of-00014.safetensors",
32
+ "model.layers.10.self_attn.k_proj.weight": "model-00003-of-00014.safetensors",
33
+ "model.layers.10.self_attn.o_proj.weight": "model-00003-of-00014.safetensors",
34
+ "model.layers.10.self_attn.q_proj.weight": "model-00003-of-00014.safetensors",
35
+ "model.layers.10.self_attn.v_proj.weight": "model-00003-of-00014.safetensors",
36
+ "model.layers.11.input_layernorm.weight": "model-00003-of-00014.safetensors",
37
+ "model.layers.11.mlp.down_proj.weight": "model-00003-of-00014.safetensors",
38
+ "model.layers.11.mlp.gate_proj.weight": "model-00003-of-00014.safetensors",
39
+ "model.layers.11.mlp.up_proj.weight": "model-00003-of-00014.safetensors",
40
+ "model.layers.11.post_attention_layernorm.weight": "model-00003-of-00014.safetensors",
41
+ "model.layers.11.self_attn.k_proj.weight": "model-00003-of-00014.safetensors",
42
+ "model.layers.11.self_attn.o_proj.weight": "model-00003-of-00014.safetensors",
43
+ "model.layers.11.self_attn.q_proj.weight": "model-00003-of-00014.safetensors",
44
+ "model.layers.11.self_attn.v_proj.weight": "model-00003-of-00014.safetensors",
45
+ "model.layers.12.input_layernorm.weight": "model-00003-of-00014.safetensors",
46
+ "model.layers.12.mlp.down_proj.weight": "model-00003-of-00014.safetensors",
47
+ "model.layers.12.mlp.gate_proj.weight": "model-00003-of-00014.safetensors",
48
+ "model.layers.12.mlp.up_proj.weight": "model-00003-of-00014.safetensors",
49
+ "model.layers.12.post_attention_layernorm.weight": "model-00003-of-00014.safetensors",
50
+ "model.layers.12.self_attn.k_proj.weight": "model-00003-of-00014.safetensors",
51
+ "model.layers.12.self_attn.o_proj.weight": "model-00003-of-00014.safetensors",
52
+ "model.layers.12.self_attn.q_proj.weight": "model-00003-of-00014.safetensors",
53
+ "model.layers.12.self_attn.v_proj.weight": "model-00003-of-00014.safetensors",
54
+ "model.layers.13.input_layernorm.weight": "model-00003-of-00014.safetensors",
55
+ "model.layers.13.mlp.down_proj.weight": "model-00003-of-00014.safetensors",
56
+ "model.layers.13.mlp.gate_proj.weight": "model-00003-of-00014.safetensors",
57
+ "model.layers.13.mlp.up_proj.weight": "model-00003-of-00014.safetensors",
58
+ "model.layers.13.post_attention_layernorm.weight": "model-00003-of-00014.safetensors",
59
+ "model.layers.13.self_attn.k_proj.weight": "model-00003-of-00014.safetensors",
60
+ "model.layers.13.self_attn.o_proj.weight": "model-00003-of-00014.safetensors",
61
+ "model.layers.13.self_attn.q_proj.weight": "model-00003-of-00014.safetensors",
62
+ "model.layers.13.self_attn.v_proj.weight": "model-00003-of-00014.safetensors",
63
+ "model.layers.14.input_layernorm.weight": "model-00004-of-00014.safetensors",
64
+ "model.layers.14.mlp.down_proj.weight": "model-00004-of-00014.safetensors",
65
+ "model.layers.14.mlp.gate_proj.weight": "model-00004-of-00014.safetensors",
66
+ "model.layers.14.mlp.up_proj.weight": "model-00004-of-00014.safetensors",
67
+ "model.layers.14.post_attention_layernorm.weight": "model-00004-of-00014.safetensors",
68
+ "model.layers.14.self_attn.k_proj.weight": "model-00003-of-00014.safetensors",
69
+ "model.layers.14.self_attn.o_proj.weight": "model-00003-of-00014.safetensors",
70
+ "model.layers.14.self_attn.q_proj.weight": "model-00003-of-00014.safetensors",
71
+ "model.layers.14.self_attn.v_proj.weight": "model-00003-of-00014.safetensors",
72
+ "model.layers.15.input_layernorm.weight": "model-00004-of-00014.safetensors",
73
+ "model.layers.15.mlp.down_proj.weight": "model-00004-of-00014.safetensors",
74
+ "model.layers.15.mlp.gate_proj.weight": "model-00004-of-00014.safetensors",
75
+ "model.layers.15.mlp.up_proj.weight": "model-00004-of-00014.safetensors",
76
+ "model.layers.15.post_attention_layernorm.weight": "model-00004-of-00014.safetensors",
77
+ "model.layers.15.self_attn.k_proj.weight": "model-00004-of-00014.safetensors",
78
+ "model.layers.15.self_attn.o_proj.weight": "model-00004-of-00014.safetensors",
79
+ "model.layers.15.self_attn.q_proj.weight": "model-00004-of-00014.safetensors",
80
+ "model.layers.15.self_attn.v_proj.weight": "model-00004-of-00014.safetensors",
81
+ "model.layers.16.input_layernorm.weight": "model-00004-of-00014.safetensors",
82
+ "model.layers.16.mlp.down_proj.weight": "model-00004-of-00014.safetensors",
83
+ "model.layers.16.mlp.gate_proj.weight": "model-00004-of-00014.safetensors",
84
+ "model.layers.16.mlp.up_proj.weight": "model-00004-of-00014.safetensors",
85
+ "model.layers.16.post_attention_layernorm.weight": "model-00004-of-00014.safetensors",
86
+ "model.layers.16.self_attn.k_proj.weight": "model-00004-of-00014.safetensors",
87
+ "model.layers.16.self_attn.o_proj.weight": "model-00004-of-00014.safetensors",
88
+ "model.layers.16.self_attn.q_proj.weight": "model-00004-of-00014.safetensors",
89
+ "model.layers.16.self_attn.v_proj.weight": "model-00004-of-00014.safetensors",
90
+ "model.layers.17.input_layernorm.weight": "model-00004-of-00014.safetensors",
91
+ "model.layers.17.mlp.down_proj.weight": "model-00004-of-00014.safetensors",
92
+ "model.layers.17.mlp.gate_proj.weight": "model-00004-of-00014.safetensors",
93
+ "model.layers.17.mlp.up_proj.weight": "model-00004-of-00014.safetensors",
94
+ "model.layers.17.post_attention_layernorm.weight": "model-00004-of-00014.safetensors",
95
+ "model.layers.17.self_attn.k_proj.weight": "model-00004-of-00014.safetensors",
96
+ "model.layers.17.self_attn.o_proj.weight": "model-00004-of-00014.safetensors",
97
+ "model.layers.17.self_attn.q_proj.weight": "model-00004-of-00014.safetensors",
98
+ "model.layers.17.self_attn.v_proj.weight": "model-00004-of-00014.safetensors",
99
+ "model.layers.18.input_layernorm.weight": "model-00004-of-00014.safetensors",
100
+ "model.layers.18.mlp.down_proj.weight": "model-00004-of-00014.safetensors",
101
+ "model.layers.18.mlp.gate_proj.weight": "model-00004-of-00014.safetensors",
102
+ "model.layers.18.mlp.up_proj.weight": "model-00004-of-00014.safetensors",
103
+ "model.layers.18.post_attention_layernorm.weight": "model-00004-of-00014.safetensors",
104
+ "model.layers.18.self_attn.k_proj.weight": "model-00004-of-00014.safetensors",
105
+ "model.layers.18.self_attn.o_proj.weight": "model-00004-of-00014.safetensors",
106
+ "model.layers.18.self_attn.q_proj.weight": "model-00004-of-00014.safetensors",
107
+ "model.layers.18.self_attn.v_proj.weight": "model-00004-of-00014.safetensors",
108
+ "model.layers.19.input_layernorm.weight": "model-00005-of-00014.safetensors",
109
+ "model.layers.19.mlp.down_proj.weight": "model-00005-of-00014.safetensors",
110
+ "model.layers.19.mlp.gate_proj.weight": "model-00005-of-00014.safetensors",
111
+ "model.layers.19.mlp.up_proj.weight": "model-00005-of-00014.safetensors",
112
+ "model.layers.19.post_attention_layernorm.weight": "model-00005-of-00014.safetensors",
113
+ "model.layers.19.self_attn.k_proj.weight": "model-00004-of-00014.safetensors",
114
+ "model.layers.19.self_attn.o_proj.weight": "model-00004-of-00014.safetensors",
115
+ "model.layers.19.self_attn.q_proj.weight": "model-00004-of-00014.safetensors",
116
+ "model.layers.19.self_attn.v_proj.weight": "model-00004-of-00014.safetensors",
117
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00014.safetensors",
118
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00014.safetensors",
119
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00014.safetensors",
120
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00014.safetensors",
121
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00014.safetensors",
122
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00014.safetensors",
123
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00014.safetensors",
124
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00014.safetensors",
125
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00014.safetensors",
126
+ "model.layers.20.input_layernorm.weight": "model-00005-of-00014.safetensors",
127
+ "model.layers.20.mlp.down_proj.weight": "model-00005-of-00014.safetensors",
128
+ "model.layers.20.mlp.gate_proj.weight": "model-00005-of-00014.safetensors",
129
+ "model.layers.20.mlp.up_proj.weight": "model-00005-of-00014.safetensors",
130
+ "model.layers.20.post_attention_layernorm.weight": "model-00005-of-00014.safetensors",
131
+ "model.layers.20.self_attn.k_proj.weight": "model-00005-of-00014.safetensors",
132
+ "model.layers.20.self_attn.o_proj.weight": "model-00005-of-00014.safetensors",
133
+ "model.layers.20.self_attn.q_proj.weight": "model-00005-of-00014.safetensors",
134
+ "model.layers.20.self_attn.v_proj.weight": "model-00005-of-00014.safetensors",
135
+ "model.layers.21.input_layernorm.weight": "model-00005-of-00014.safetensors",
136
+ "model.layers.21.mlp.down_proj.weight": "model-00005-of-00014.safetensors",
137
+ "model.layers.21.mlp.gate_proj.weight": "model-00005-of-00014.safetensors",
138
+ "model.layers.21.mlp.up_proj.weight": "model-00005-of-00014.safetensors",
139
+ "model.layers.21.post_attention_layernorm.weight": "model-00005-of-00014.safetensors",
140
+ "model.layers.21.self_attn.k_proj.weight": "model-00005-of-00014.safetensors",
141
+ "model.layers.21.self_attn.o_proj.weight": "model-00005-of-00014.safetensors",
142
+ "model.layers.21.self_attn.q_proj.weight": "model-00005-of-00014.safetensors",
143
+ "model.layers.21.self_attn.v_proj.weight": "model-00005-of-00014.safetensors",
144
+ "model.layers.22.input_layernorm.weight": "model-00005-of-00014.safetensors",
145
+ "model.layers.22.mlp.down_proj.weight": "model-00005-of-00014.safetensors",
146
+ "model.layers.22.mlp.gate_proj.weight": "model-00005-of-00014.safetensors",
147
+ "model.layers.22.mlp.up_proj.weight": "model-00005-of-00014.safetensors",
148
+ "model.layers.22.post_attention_layernorm.weight": "model-00005-of-00014.safetensors",
149
+ "model.layers.22.self_attn.k_proj.weight": "model-00005-of-00014.safetensors",
150
+ "model.layers.22.self_attn.o_proj.weight": "model-00005-of-00014.safetensors",
151
+ "model.layers.22.self_attn.q_proj.weight": "model-00005-of-00014.safetensors",
152
+ "model.layers.22.self_attn.v_proj.weight": "model-00005-of-00014.safetensors",
153
+ "model.layers.23.input_layernorm.weight": "model-00005-of-00014.safetensors",
154
+ "model.layers.23.mlp.down_proj.weight": "model-00005-of-00014.safetensors",
155
+ "model.layers.23.mlp.gate_proj.weight": "model-00005-of-00014.safetensors",
156
+ "model.layers.23.mlp.up_proj.weight": "model-00005-of-00014.safetensors",
157
+ "model.layers.23.post_attention_layernorm.weight": "model-00005-of-00014.safetensors",
158
+ "model.layers.23.self_attn.k_proj.weight": "model-00005-of-00014.safetensors",
159
+ "model.layers.23.self_attn.o_proj.weight": "model-00005-of-00014.safetensors",
160
+ "model.layers.23.self_attn.q_proj.weight": "model-00005-of-00014.safetensors",
161
+ "model.layers.23.self_attn.v_proj.weight": "model-00005-of-00014.safetensors",
162
+ "model.layers.24.input_layernorm.weight": "model-00006-of-00014.safetensors",
163
+ "model.layers.24.mlp.down_proj.weight": "model-00006-of-00014.safetensors",
164
+ "model.layers.24.mlp.gate_proj.weight": "model-00006-of-00014.safetensors",
165
+ "model.layers.24.mlp.up_proj.weight": "model-00006-of-00014.safetensors",
166
+ "model.layers.24.post_attention_layernorm.weight": "model-00006-of-00014.safetensors",
167
+ "model.layers.24.self_attn.k_proj.weight": "model-00005-of-00014.safetensors",
168
+ "model.layers.24.self_attn.o_proj.weight": "model-00005-of-00014.safetensors",
169
+ "model.layers.24.self_attn.q_proj.weight": "model-00005-of-00014.safetensors",
170
+ "model.layers.24.self_attn.v_proj.weight": "model-00005-of-00014.safetensors",
171
+ "model.layers.25.input_layernorm.weight": "model-00006-of-00014.safetensors",
172
+ "model.layers.25.mlp.down_proj.weight": "model-00006-of-00014.safetensors",
173
+ "model.layers.25.mlp.gate_proj.weight": "model-00006-of-00014.safetensors",
174
+ "model.layers.25.mlp.up_proj.weight": "model-00006-of-00014.safetensors",
175
+ "model.layers.25.post_attention_layernorm.weight": "model-00006-of-00014.safetensors",
176
+ "model.layers.25.self_attn.k_proj.weight": "model-00006-of-00014.safetensors",
177
+ "model.layers.25.self_attn.o_proj.weight": "model-00006-of-00014.safetensors",
178
+ "model.layers.25.self_attn.q_proj.weight": "model-00006-of-00014.safetensors",
179
+ "model.layers.25.self_attn.v_proj.weight": "model-00006-of-00014.safetensors",
180
+ "model.layers.26.input_layernorm.weight": "model-00006-of-00014.safetensors",
181
+ "model.layers.26.mlp.down_proj.weight": "model-00006-of-00014.safetensors",
182
+ "model.layers.26.mlp.gate_proj.weight": "model-00006-of-00014.safetensors",
183
+ "model.layers.26.mlp.up_proj.weight": "model-00006-of-00014.safetensors",
184
+ "model.layers.26.post_attention_layernorm.weight": "model-00006-of-00014.safetensors",
185
+ "model.layers.26.self_attn.k_proj.weight": "model-00006-of-00014.safetensors",
186
+ "model.layers.26.self_attn.o_proj.weight": "model-00006-of-00014.safetensors",
187
+ "model.layers.26.self_attn.q_proj.weight": "model-00006-of-00014.safetensors",
188
+ "model.layers.26.self_attn.v_proj.weight": "model-00006-of-00014.safetensors",
189
+ "model.layers.27.input_layernorm.weight": "model-00006-of-00014.safetensors",
190
+ "model.layers.27.mlp.down_proj.weight": "model-00006-of-00014.safetensors",
191
+ "model.layers.27.mlp.gate_proj.weight": "model-00006-of-00014.safetensors",
192
+ "model.layers.27.mlp.up_proj.weight": "model-00006-of-00014.safetensors",
193
+ "model.layers.27.post_attention_layernorm.weight": "model-00006-of-00014.safetensors",
194
+ "model.layers.27.self_attn.k_proj.weight": "model-00006-of-00014.safetensors",
195
+ "model.layers.27.self_attn.o_proj.weight": "model-00006-of-00014.safetensors",
196
+ "model.layers.27.self_attn.q_proj.weight": "model-00006-of-00014.safetensors",
197
+ "model.layers.27.self_attn.v_proj.weight": "model-00006-of-00014.safetensors",
198
+ "model.layers.28.input_layernorm.weight": "model-00006-of-00014.safetensors",
199
+ "model.layers.28.mlp.down_proj.weight": "model-00006-of-00014.safetensors",
200
+ "model.layers.28.mlp.gate_proj.weight": "model-00006-of-00014.safetensors",
201
+ "model.layers.28.mlp.up_proj.weight": "model-00006-of-00014.safetensors",
202
+ "model.layers.28.post_attention_layernorm.weight": "model-00006-of-00014.safetensors",
203
+ "model.layers.28.self_attn.k_proj.weight": "model-00006-of-00014.safetensors",
204
+ "model.layers.28.self_attn.o_proj.weight": "model-00006-of-00014.safetensors",
205
+ "model.layers.28.self_attn.q_proj.weight": "model-00006-of-00014.safetensors",
206
+ "model.layers.28.self_attn.v_proj.weight": "model-00006-of-00014.safetensors",
207
+ "model.layers.29.input_layernorm.weight": "model-00007-of-00014.safetensors",
208
+ "model.layers.29.mlp.down_proj.weight": "model-00007-of-00014.safetensors",
209
+ "model.layers.29.mlp.gate_proj.weight": "model-00007-of-00014.safetensors",
210
+ "model.layers.29.mlp.up_proj.weight": "model-00007-of-00014.safetensors",
211
+ "model.layers.29.post_attention_layernorm.weight": "model-00007-of-00014.safetensors",
212
+ "model.layers.29.self_attn.k_proj.weight": "model-00006-of-00014.safetensors",
213
+ "model.layers.29.self_attn.o_proj.weight": "model-00006-of-00014.safetensors",
214
+ "model.layers.29.self_attn.q_proj.weight": "model-00006-of-00014.safetensors",
215
+ "model.layers.29.self_attn.v_proj.weight": "model-00006-of-00014.safetensors",
216
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00014.safetensors",
217
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00014.safetensors",
218
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00014.safetensors",
219
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00014.safetensors",
220
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00014.safetensors",
221
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00014.safetensors",
222
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00014.safetensors",
223
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00014.safetensors",
224
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00014.safetensors",
225
+ "model.layers.30.input_layernorm.weight": "model-00007-of-00014.safetensors",
226
+ "model.layers.30.mlp.down_proj.weight": "model-00007-of-00014.safetensors",
227
+ "model.layers.30.mlp.gate_proj.weight": "model-00007-of-00014.safetensors",
228
+ "model.layers.30.mlp.up_proj.weight": "model-00007-of-00014.safetensors",
229
+ "model.layers.30.post_attention_layernorm.weight": "model-00007-of-00014.safetensors",
230
+ "model.layers.30.self_attn.k_proj.weight": "model-00007-of-00014.safetensors",
231
+ "model.layers.30.self_attn.o_proj.weight": "model-00007-of-00014.safetensors",
232
+ "model.layers.30.self_attn.q_proj.weight": "model-00007-of-00014.safetensors",
233
+ "model.layers.30.self_attn.v_proj.weight": "model-00007-of-00014.safetensors",
234
+ "model.layers.31.input_layernorm.weight": "model-00007-of-00014.safetensors",
235
+ "model.layers.31.mlp.down_proj.weight": "model-00007-of-00014.safetensors",
236
+ "model.layers.31.mlp.gate_proj.weight": "model-00007-of-00014.safetensors",
237
+ "model.layers.31.mlp.up_proj.weight": "model-00007-of-00014.safetensors",
238
+ "model.layers.31.post_attention_layernorm.weight": "model-00007-of-00014.safetensors",
239
+ "model.layers.31.self_attn.k_proj.weight": "model-00007-of-00014.safetensors",
240
+ "model.layers.31.self_attn.o_proj.weight": "model-00007-of-00014.safetensors",
241
+ "model.layers.31.self_attn.q_proj.weight": "model-00007-of-00014.safetensors",
242
+ "model.layers.31.self_attn.v_proj.weight": "model-00007-of-00014.safetensors",
243
+ "model.layers.32.input_layernorm.weight": "model-00007-of-00014.safetensors",
244
+ "model.layers.32.mlp.down_proj.weight": "model-00007-of-00014.safetensors",
245
+ "model.layers.32.mlp.gate_proj.weight": "model-00007-of-00014.safetensors",
246
+ "model.layers.32.mlp.up_proj.weight": "model-00007-of-00014.safetensors",
247
+ "model.layers.32.post_attention_layernorm.weight": "model-00007-of-00014.safetensors",
248
+ "model.layers.32.self_attn.k_proj.weight": "model-00007-of-00014.safetensors",
249
+ "model.layers.32.self_attn.o_proj.weight": "model-00007-of-00014.safetensors",
250
+ "model.layers.32.self_attn.q_proj.weight": "model-00007-of-00014.safetensors",
251
+ "model.layers.32.self_attn.v_proj.weight": "model-00007-of-00014.safetensors",
252
+ "model.layers.33.input_layernorm.weight": "model-00007-of-00014.safetensors",
253
+ "model.layers.33.mlp.down_proj.weight": "model-00007-of-00014.safetensors",
254
+ "model.layers.33.mlp.gate_proj.weight": "model-00007-of-00014.safetensors",
255
+ "model.layers.33.mlp.up_proj.weight": "model-00007-of-00014.safetensors",
256
+ "model.layers.33.post_attention_layernorm.weight": "model-00007-of-00014.safetensors",
257
+ "model.layers.33.self_attn.k_proj.weight": "model-00007-of-00014.safetensors",
258
+ "model.layers.33.self_attn.o_proj.weight": "model-00007-of-00014.safetensors",
259
+ "model.layers.33.self_attn.q_proj.weight": "model-00007-of-00014.safetensors",
260
+ "model.layers.33.self_attn.v_proj.weight": "model-00007-of-00014.safetensors",
261
+ "model.layers.34.input_layernorm.weight": "model-00008-of-00014.safetensors",
262
+ "model.layers.34.mlp.down_proj.weight": "model-00008-of-00014.safetensors",
263
+ "model.layers.34.mlp.gate_proj.weight": "model-00008-of-00014.safetensors",
264
+ "model.layers.34.mlp.up_proj.weight": "model-00008-of-00014.safetensors",
265
+ "model.layers.34.post_attention_layernorm.weight": "model-00008-of-00014.safetensors",
266
+ "model.layers.34.self_attn.k_proj.weight": "model-00007-of-00014.safetensors",
267
+ "model.layers.34.self_attn.o_proj.weight": "model-00007-of-00014.safetensors",
268
+ "model.layers.34.self_attn.q_proj.weight": "model-00007-of-00014.safetensors",
269
+ "model.layers.34.self_attn.v_proj.weight": "model-00007-of-00014.safetensors",
270
+ "model.layers.35.input_layernorm.weight": "model-00008-of-00014.safetensors",
271
+ "model.layers.35.mlp.down_proj.weight": "model-00008-of-00014.safetensors",
272
+ "model.layers.35.mlp.gate_proj.weight": "model-00008-of-00014.safetensors",
273
+ "model.layers.35.mlp.up_proj.weight": "model-00008-of-00014.safetensors",
274
+ "model.layers.35.post_attention_layernorm.weight": "model-00008-of-00014.safetensors",
275
+ "model.layers.35.self_attn.k_proj.weight": "model-00008-of-00014.safetensors",
276
+ "model.layers.35.self_attn.o_proj.weight": "model-00008-of-00014.safetensors",
277
+ "model.layers.35.self_attn.q_proj.weight": "model-00008-of-00014.safetensors",
278
+ "model.layers.35.self_attn.v_proj.weight": "model-00008-of-00014.safetensors",
279
+ "model.layers.36.input_layernorm.weight": "model-00008-of-00014.safetensors",
280
+ "model.layers.36.mlp.down_proj.weight": "model-00008-of-00014.safetensors",
281
+ "model.layers.36.mlp.gate_proj.weight": "model-00008-of-00014.safetensors",
282
+ "model.layers.36.mlp.up_proj.weight": "model-00008-of-00014.safetensors",
283
+ "model.layers.36.post_attention_layernorm.weight": "model-00008-of-00014.safetensors",
284
+ "model.layers.36.self_attn.k_proj.weight": "model-00008-of-00014.safetensors",
285
+ "model.layers.36.self_attn.o_proj.weight": "model-00008-of-00014.safetensors",
286
+ "model.layers.36.self_attn.q_proj.weight": "model-00008-of-00014.safetensors",
287
+ "model.layers.36.self_attn.v_proj.weight": "model-00008-of-00014.safetensors",
288
+ "model.layers.37.input_layernorm.weight": "model-00008-of-00014.safetensors",
289
+ "model.layers.37.mlp.down_proj.weight": "model-00008-of-00014.safetensors",
290
+ "model.layers.37.mlp.gate_proj.weight": "model-00008-of-00014.safetensors",
291
+ "model.layers.37.mlp.up_proj.weight": "model-00008-of-00014.safetensors",
292
+ "model.layers.37.post_attention_layernorm.weight": "model-00008-of-00014.safetensors",
293
+ "model.layers.37.self_attn.k_proj.weight": "model-00008-of-00014.safetensors",
294
+ "model.layers.37.self_attn.o_proj.weight": "model-00008-of-00014.safetensors",
295
+ "model.layers.37.self_attn.q_proj.weight": "model-00008-of-00014.safetensors",
296
+ "model.layers.37.self_attn.v_proj.weight": "model-00008-of-00014.safetensors",
297
+ "model.layers.38.input_layernorm.weight": "model-00008-of-00014.safetensors",
298
+ "model.layers.38.mlp.down_proj.weight": "model-00008-of-00014.safetensors",
299
+ "model.layers.38.mlp.gate_proj.weight": "model-00008-of-00014.safetensors",
300
+ "model.layers.38.mlp.up_proj.weight": "model-00008-of-00014.safetensors",
301
+ "model.layers.38.post_attention_layernorm.weight": "model-00008-of-00014.safetensors",
302
+ "model.layers.38.self_attn.k_proj.weight": "model-00008-of-00014.safetensors",
303
+ "model.layers.38.self_attn.o_proj.weight": "model-00008-of-00014.safetensors",
304
+ "model.layers.38.self_attn.q_proj.weight": "model-00008-of-00014.safetensors",
305
+ "model.layers.38.self_attn.v_proj.weight": "model-00008-of-00014.safetensors",
306
+ "model.layers.39.input_layernorm.weight": "model-00009-of-00014.safetensors",
307
+ "model.layers.39.mlp.down_proj.weight": "model-00009-of-00014.safetensors",
308
+ "model.layers.39.mlp.gate_proj.weight": "model-00009-of-00014.safetensors",
309
+ "model.layers.39.mlp.up_proj.weight": "model-00009-of-00014.safetensors",
310
+ "model.layers.39.post_attention_layernorm.weight": "model-00009-of-00014.safetensors",
311
+ "model.layers.39.self_attn.k_proj.weight": "model-00008-of-00014.safetensors",
312
+ "model.layers.39.self_attn.o_proj.weight": "model-00008-of-00014.safetensors",
313
+ "model.layers.39.self_attn.q_proj.weight": "model-00008-of-00014.safetensors",
314
+ "model.layers.39.self_attn.v_proj.weight": "model-00008-of-00014.safetensors",
315
+ "model.layers.4.input_layernorm.weight": "model-00002-of-00014.safetensors",
316
+ "model.layers.4.mlp.down_proj.weight": "model-00002-of-00014.safetensors",
317
+ "model.layers.4.mlp.gate_proj.weight": "model-00002-of-00014.safetensors",
318
+ "model.layers.4.mlp.up_proj.weight": "model-00002-of-00014.safetensors",
319
+ "model.layers.4.post_attention_layernorm.weight": "model-00002-of-00014.safetensors",
320
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00014.safetensors",
321
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00014.safetensors",
322
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00014.safetensors",
323
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00014.safetensors",
324
+ "model.layers.40.input_layernorm.weight": "model-00009-of-00014.safetensors",
325
+ "model.layers.40.mlp.down_proj.weight": "model-00009-of-00014.safetensors",
326
+ "model.layers.40.mlp.gate_proj.weight": "model-00009-of-00014.safetensors",
327
+ "model.layers.40.mlp.up_proj.weight": "model-00009-of-00014.safetensors",
328
+ "model.layers.40.post_attention_layernorm.weight": "model-00009-of-00014.safetensors",
329
+ "model.layers.40.self_attn.k_proj.weight": "model-00009-of-00014.safetensors",
330
+ "model.layers.40.self_attn.o_proj.weight": "model-00009-of-00014.safetensors",
331
+ "model.layers.40.self_attn.q_proj.weight": "model-00009-of-00014.safetensors",
332
+ "model.layers.40.self_attn.v_proj.weight": "model-00009-of-00014.safetensors",
333
+ "model.layers.41.input_layernorm.weight": "model-00009-of-00014.safetensors",
334
+ "model.layers.41.mlp.down_proj.weight": "model-00009-of-00014.safetensors",
335
+ "model.layers.41.mlp.gate_proj.weight": "model-00009-of-00014.safetensors",
336
+ "model.layers.41.mlp.up_proj.weight": "model-00009-of-00014.safetensors",
337
+ "model.layers.41.post_attention_layernorm.weight": "model-00009-of-00014.safetensors",
338
+ "model.layers.41.self_attn.k_proj.weight": "model-00009-of-00014.safetensors",
339
+ "model.layers.41.self_attn.o_proj.weight": "model-00009-of-00014.safetensors",
340
+ "model.layers.41.self_attn.q_proj.weight": "model-00009-of-00014.safetensors",
341
+ "model.layers.41.self_attn.v_proj.weight": "model-00009-of-00014.safetensors",
342
+ "model.layers.42.input_layernorm.weight": "model-00009-of-00014.safetensors",
343
+ "model.layers.42.mlp.down_proj.weight": "model-00009-of-00014.safetensors",
344
+ "model.layers.42.mlp.gate_proj.weight": "model-00009-of-00014.safetensors",
345
+ "model.layers.42.mlp.up_proj.weight": "model-00009-of-00014.safetensors",
346
+ "model.layers.42.post_attention_layernorm.weight": "model-00009-of-00014.safetensors",
347
+ "model.layers.42.self_attn.k_proj.weight": "model-00009-of-00014.safetensors",
348
+ "model.layers.42.self_attn.o_proj.weight": "model-00009-of-00014.safetensors",
349
+ "model.layers.42.self_attn.q_proj.weight": "model-00009-of-00014.safetensors",
350
+ "model.layers.42.self_attn.v_proj.weight": "model-00009-of-00014.safetensors",
351
+ "model.layers.43.input_layernorm.weight": "model-00009-of-00014.safetensors",
352
+ "model.layers.43.mlp.down_proj.weight": "model-00009-of-00014.safetensors",
353
+ "model.layers.43.mlp.gate_proj.weight": "model-00009-of-00014.safetensors",
354
+ "model.layers.43.mlp.up_proj.weight": "model-00009-of-00014.safetensors",
355
+ "model.layers.43.post_attention_layernorm.weight": "model-00009-of-00014.safetensors",
356
+ "model.layers.43.self_attn.k_proj.weight": "model-00009-of-00014.safetensors",
357
+ "model.layers.43.self_attn.o_proj.weight": "model-00009-of-00014.safetensors",
358
+ "model.layers.43.self_attn.q_proj.weight": "model-00009-of-00014.safetensors",
359
+ "model.layers.43.self_attn.v_proj.weight": "model-00009-of-00014.safetensors",
360
+ "model.layers.44.input_layernorm.weight": "model-00010-of-00014.safetensors",
361
+ "model.layers.44.mlp.down_proj.weight": "model-00010-of-00014.safetensors",
362
+ "model.layers.44.mlp.gate_proj.weight": "model-00010-of-00014.safetensors",
363
+ "model.layers.44.mlp.up_proj.weight": "model-00010-of-00014.safetensors",
364
+ "model.layers.44.post_attention_layernorm.weight": "model-00010-of-00014.safetensors",
365
+ "model.layers.44.self_attn.k_proj.weight": "model-00009-of-00014.safetensors",
366
+ "model.layers.44.self_attn.o_proj.weight": "model-00009-of-00014.safetensors",
367
+ "model.layers.44.self_attn.q_proj.weight": "model-00009-of-00014.safetensors",
368
+ "model.layers.44.self_attn.v_proj.weight": "model-00009-of-00014.safetensors",
369
+ "model.layers.45.input_layernorm.weight": "model-00010-of-00014.safetensors",
370
+ "model.layers.45.mlp.down_proj.weight": "model-00010-of-00014.safetensors",
371
+ "model.layers.45.mlp.gate_proj.weight": "model-00010-of-00014.safetensors",
372
+ "model.layers.45.mlp.up_proj.weight": "model-00010-of-00014.safetensors",
373
+ "model.layers.45.post_attention_layernorm.weight": "model-00010-of-00014.safetensors",
374
+ "model.layers.45.self_attn.k_proj.weight": "model-00010-of-00014.safetensors",
375
+ "model.layers.45.self_attn.o_proj.weight": "model-00010-of-00014.safetensors",
376
+ "model.layers.45.self_attn.q_proj.weight": "model-00010-of-00014.safetensors",
377
+ "model.layers.45.self_attn.v_proj.weight": "model-00010-of-00014.safetensors",
378
+ "model.layers.46.input_layernorm.weight": "model-00010-of-00014.safetensors",
379
+ "model.layers.46.mlp.down_proj.weight": "model-00010-of-00014.safetensors",
380
+ "model.layers.46.mlp.gate_proj.weight": "model-00010-of-00014.safetensors",
381
+ "model.layers.46.mlp.up_proj.weight": "model-00010-of-00014.safetensors",
382
+ "model.layers.46.post_attention_layernorm.weight": "model-00010-of-00014.safetensors",
383
+ "model.layers.46.self_attn.k_proj.weight": "model-00010-of-00014.safetensors",
384
+ "model.layers.46.self_attn.o_proj.weight": "model-00010-of-00014.safetensors",
385
+ "model.layers.46.self_attn.q_proj.weight": "model-00010-of-00014.safetensors",
386
+ "model.layers.46.self_attn.v_proj.weight": "model-00010-of-00014.safetensors",
387
+ "model.layers.47.input_layernorm.weight": "model-00010-of-00014.safetensors",
388
+ "model.layers.47.mlp.down_proj.weight": "model-00010-of-00014.safetensors",
389
+ "model.layers.47.mlp.gate_proj.weight": "model-00010-of-00014.safetensors",
390
+ "model.layers.47.mlp.up_proj.weight": "model-00010-of-00014.safetensors",
391
+ "model.layers.47.post_attention_layernorm.weight": "model-00010-of-00014.safetensors",
392
+ "model.layers.47.self_attn.k_proj.weight": "model-00010-of-00014.safetensors",
393
+ "model.layers.47.self_attn.o_proj.weight": "model-00010-of-00014.safetensors",
394
+ "model.layers.47.self_attn.q_proj.weight": "model-00010-of-00014.safetensors",
395
+ "model.layers.47.self_attn.v_proj.weight": "model-00010-of-00014.safetensors",
396
+ "model.layers.48.input_layernorm.weight": "model-00010-of-00014.safetensors",
397
+ "model.layers.48.mlp.down_proj.weight": "model-00010-of-00014.safetensors",
398
+ "model.layers.48.mlp.gate_proj.weight": "model-00010-of-00014.safetensors",
399
+ "model.layers.48.mlp.up_proj.weight": "model-00010-of-00014.safetensors",
400
+ "model.layers.48.post_attention_layernorm.weight": "model-00010-of-00014.safetensors",
401
+ "model.layers.48.self_attn.k_proj.weight": "model-00010-of-00014.safetensors",
402
+ "model.layers.48.self_attn.o_proj.weight": "model-00010-of-00014.safetensors",
403
+ "model.layers.48.self_attn.q_proj.weight": "model-00010-of-00014.safetensors",
404
+ "model.layers.48.self_attn.v_proj.weight": "model-00010-of-00014.safetensors",
405
+ "model.layers.49.input_layernorm.weight": "model-00011-of-00014.safetensors",
406
+ "model.layers.49.mlp.down_proj.weight": "model-00011-of-00014.safetensors",
407
+ "model.layers.49.mlp.gate_proj.weight": "model-00011-of-00014.safetensors",
408
+ "model.layers.49.mlp.up_proj.weight": "model-00011-of-00014.safetensors",
409
+ "model.layers.49.post_attention_layernorm.weight": "model-00011-of-00014.safetensors",
410
+ "model.layers.49.self_attn.k_proj.weight": "model-00010-of-00014.safetensors",
411
+ "model.layers.49.self_attn.o_proj.weight": "model-00010-of-00014.safetensors",
412
+ "model.layers.49.self_attn.q_proj.weight": "model-00010-of-00014.safetensors",
413
+ "model.layers.49.self_attn.v_proj.weight": "model-00010-of-00014.safetensors",
414
+ "model.layers.5.input_layernorm.weight": "model-00002-of-00014.safetensors",
415
+ "model.layers.5.mlp.down_proj.weight": "model-00002-of-00014.safetensors",
416
+ "model.layers.5.mlp.gate_proj.weight": "model-00002-of-00014.safetensors",
417
+ "model.layers.5.mlp.up_proj.weight": "model-00002-of-00014.safetensors",
418
+ "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00014.safetensors",
419
+ "model.layers.5.self_attn.k_proj.weight": "model-00002-of-00014.safetensors",
420
+ "model.layers.5.self_attn.o_proj.weight": "model-00002-of-00014.safetensors",
421
+ "model.layers.5.self_attn.q_proj.weight": "model-00002-of-00014.safetensors",
422
+ "model.layers.5.self_attn.v_proj.weight": "model-00002-of-00014.safetensors",
423
+ "model.layers.50.input_layernorm.weight": "model-00011-of-00014.safetensors",
424
+ "model.layers.50.mlp.down_proj.weight": "model-00011-of-00014.safetensors",
425
+ "model.layers.50.mlp.gate_proj.weight": "model-00011-of-00014.safetensors",
426
+ "model.layers.50.mlp.up_proj.weight": "model-00011-of-00014.safetensors",
427
+ "model.layers.50.post_attention_layernorm.weight": "model-00011-of-00014.safetensors",
428
+ "model.layers.50.self_attn.k_proj.weight": "model-00011-of-00014.safetensors",
429
+ "model.layers.50.self_attn.o_proj.weight": "model-00011-of-00014.safetensors",
430
+ "model.layers.50.self_attn.q_proj.weight": "model-00011-of-00014.safetensors",
431
+ "model.layers.50.self_attn.v_proj.weight": "model-00011-of-00014.safetensors",
432
+ "model.layers.51.input_layernorm.weight": "model-00011-of-00014.safetensors",
433
+ "model.layers.51.mlp.down_proj.weight": "model-00011-of-00014.safetensors",
434
+ "model.layers.51.mlp.gate_proj.weight": "model-00011-of-00014.safetensors",
435
+ "model.layers.51.mlp.up_proj.weight": "model-00011-of-00014.safetensors",
436
+ "model.layers.51.post_attention_layernorm.weight": "model-00011-of-00014.safetensors",
437
+ "model.layers.51.self_attn.k_proj.weight": "model-00011-of-00014.safetensors",
438
+ "model.layers.51.self_attn.o_proj.weight": "model-00011-of-00014.safetensors",
439
+ "model.layers.51.self_attn.q_proj.weight": "model-00011-of-00014.safetensors",
440
+ "model.layers.51.self_attn.v_proj.weight": "model-00011-of-00014.safetensors",
441
+ "model.layers.52.input_layernorm.weight": "model-00011-of-00014.safetensors",
442
+ "model.layers.52.mlp.down_proj.weight": "model-00011-of-00014.safetensors",
443
+ "model.layers.52.mlp.gate_proj.weight": "model-00011-of-00014.safetensors",
444
+ "model.layers.52.mlp.up_proj.weight": "model-00011-of-00014.safetensors",
445
+ "model.layers.52.post_attention_layernorm.weight": "model-00011-of-00014.safetensors",
446
+ "model.layers.52.self_attn.k_proj.weight": "model-00011-of-00014.safetensors",
447
+ "model.layers.52.self_attn.o_proj.weight": "model-00011-of-00014.safetensors",
448
+ "model.layers.52.self_attn.q_proj.weight": "model-00011-of-00014.safetensors",
449
+ "model.layers.52.self_attn.v_proj.weight": "model-00011-of-00014.safetensors",
450
+ "model.layers.53.input_layernorm.weight": "model-00011-of-00014.safetensors",
451
+ "model.layers.53.mlp.down_proj.weight": "model-00011-of-00014.safetensors",
452
+ "model.layers.53.mlp.gate_proj.weight": "model-00011-of-00014.safetensors",
453
+ "model.layers.53.mlp.up_proj.weight": "model-00011-of-00014.safetensors",
454
+ "model.layers.53.post_attention_layernorm.weight": "model-00011-of-00014.safetensors",
455
+ "model.layers.53.self_attn.k_proj.weight": "model-00011-of-00014.safetensors",
456
+ "model.layers.53.self_attn.o_proj.weight": "model-00011-of-00014.safetensors",
457
+ "model.layers.53.self_attn.q_proj.weight": "model-00011-of-00014.safetensors",
458
+ "model.layers.53.self_attn.v_proj.weight": "model-00011-of-00014.safetensors",
459
+ "model.layers.54.input_layernorm.weight": "model-00012-of-00014.safetensors",
460
+ "model.layers.54.mlp.down_proj.weight": "model-00012-of-00014.safetensors",
461
+ "model.layers.54.mlp.gate_proj.weight": "model-00012-of-00014.safetensors",
462
+ "model.layers.54.mlp.up_proj.weight": "model-00012-of-00014.safetensors",
463
+ "model.layers.54.post_attention_layernorm.weight": "model-00012-of-00014.safetensors",
464
+ "model.layers.54.self_attn.k_proj.weight": "model-00011-of-00014.safetensors",
465
+ "model.layers.54.self_attn.o_proj.weight": "model-00011-of-00014.safetensors",
466
+ "model.layers.54.self_attn.q_proj.weight": "model-00011-of-00014.safetensors",
467
+ "model.layers.54.self_attn.v_proj.weight": "model-00011-of-00014.safetensors",
468
+ "model.layers.55.input_layernorm.weight": "model-00012-of-00014.safetensors",
469
+ "model.layers.55.mlp.down_proj.weight": "model-00012-of-00014.safetensors",
470
+ "model.layers.55.mlp.gate_proj.weight": "model-00012-of-00014.safetensors",
471
+ "model.layers.55.mlp.up_proj.weight": "model-00012-of-00014.safetensors",
472
+ "model.layers.55.post_attention_layernorm.weight": "model-00012-of-00014.safetensors",
473
+ "model.layers.55.self_attn.k_proj.weight": "model-00012-of-00014.safetensors",
474
+ "model.layers.55.self_attn.o_proj.weight": "model-00012-of-00014.safetensors",
475
+ "model.layers.55.self_attn.q_proj.weight": "model-00012-of-00014.safetensors",
476
+ "model.layers.55.self_attn.v_proj.weight": "model-00012-of-00014.safetensors",
477
+ "model.layers.56.input_layernorm.weight": "model-00012-of-00014.safetensors",
478
+ "model.layers.56.mlp.down_proj.weight": "model-00012-of-00014.safetensors",
479
+ "model.layers.56.mlp.gate_proj.weight": "model-00012-of-00014.safetensors",
480
+ "model.layers.56.mlp.up_proj.weight": "model-00012-of-00014.safetensors",
481
+ "model.layers.56.post_attention_layernorm.weight": "model-00012-of-00014.safetensors",
482
+ "model.layers.56.self_attn.k_proj.weight": "model-00012-of-00014.safetensors",
483
+ "model.layers.56.self_attn.o_proj.weight": "model-00012-of-00014.safetensors",
484
+ "model.layers.56.self_attn.q_proj.weight": "model-00012-of-00014.safetensors",
485
+ "model.layers.56.self_attn.v_proj.weight": "model-00012-of-00014.safetensors",
486
+ "model.layers.57.input_layernorm.weight": "model-00012-of-00014.safetensors",
487
+ "model.layers.57.mlp.down_proj.weight": "model-00012-of-00014.safetensors",
488
+ "model.layers.57.mlp.gate_proj.weight": "model-00012-of-00014.safetensors",
489
+ "model.layers.57.mlp.up_proj.weight": "model-00012-of-00014.safetensors",
490
+ "model.layers.57.post_attention_layernorm.weight": "model-00012-of-00014.safetensors",
491
+ "model.layers.57.self_attn.k_proj.weight": "model-00012-of-00014.safetensors",
492
+ "model.layers.57.self_attn.o_proj.weight": "model-00012-of-00014.safetensors",
493
+ "model.layers.57.self_attn.q_proj.weight": "model-00012-of-00014.safetensors",
494
+ "model.layers.57.self_attn.v_proj.weight": "model-00012-of-00014.safetensors",
495
+ "model.layers.58.input_layernorm.weight": "model-00012-of-00014.safetensors",
496
+ "model.layers.58.mlp.down_proj.weight": "model-00012-of-00014.safetensors",
497
+ "model.layers.58.mlp.gate_proj.weight": "model-00012-of-00014.safetensors",
498
+ "model.layers.58.mlp.up_proj.weight": "model-00012-of-00014.safetensors",
499
+ "model.layers.58.post_attention_layernorm.weight": "model-00012-of-00014.safetensors",
500
+ "model.layers.58.self_attn.k_proj.weight": "model-00012-of-00014.safetensors",
501
+ "model.layers.58.self_attn.o_proj.weight": "model-00012-of-00014.safetensors",
502
+ "model.layers.58.self_attn.q_proj.weight": "model-00012-of-00014.safetensors",
503
+ "model.layers.58.self_attn.v_proj.weight": "model-00012-of-00014.safetensors",
504
+ "model.layers.59.input_layernorm.weight": "model-00013-of-00014.safetensors",
505
+ "model.layers.59.mlp.down_proj.weight": "model-00013-of-00014.safetensors",
506
+ "model.layers.59.mlp.gate_proj.weight": "model-00013-of-00014.safetensors",
507
+ "model.layers.59.mlp.up_proj.weight": "model-00013-of-00014.safetensors",
508
+ "model.layers.59.post_attention_layernorm.weight": "model-00013-of-00014.safetensors",
509
+ "model.layers.59.self_attn.k_proj.weight": "model-00012-of-00014.safetensors",
510
+ "model.layers.59.self_attn.o_proj.weight": "model-00012-of-00014.safetensors",
511
+ "model.layers.59.self_attn.q_proj.weight": "model-00012-of-00014.safetensors",
512
+ "model.layers.59.self_attn.v_proj.weight": "model-00012-of-00014.safetensors",
513
+ "model.layers.6.input_layernorm.weight": "model-00002-of-00014.safetensors",
514
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00014.safetensors",
515
+ "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00014.safetensors",
516
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00014.safetensors",
517
+ "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00014.safetensors",
518
+ "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00014.safetensors",
519
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00014.safetensors",
520
+ "model.layers.6.self_attn.q_proj.weight": "model-00002-of-00014.safetensors",
521
+ "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00014.safetensors",
522
+ "model.layers.60.input_layernorm.weight": "model-00013-of-00014.safetensors",
523
+ "model.layers.60.mlp.down_proj.weight": "model-00013-of-00014.safetensors",
524
+ "model.layers.60.mlp.gate_proj.weight": "model-00013-of-00014.safetensors",
525
+ "model.layers.60.mlp.up_proj.weight": "model-00013-of-00014.safetensors",
526
+ "model.layers.60.post_attention_layernorm.weight": "model-00013-of-00014.safetensors",
527
+ "model.layers.60.self_attn.k_proj.weight": "model-00013-of-00014.safetensors",
528
+ "model.layers.60.self_attn.o_proj.weight": "model-00013-of-00014.safetensors",
529
+ "model.layers.60.self_attn.q_proj.weight": "model-00013-of-00014.safetensors",
530
+ "model.layers.60.self_attn.v_proj.weight": "model-00013-of-00014.safetensors",
531
+ "model.layers.61.input_layernorm.weight": "model-00013-of-00014.safetensors",
532
+ "model.layers.61.mlp.down_proj.weight": "model-00013-of-00014.safetensors",
533
+ "model.layers.61.mlp.gate_proj.weight": "model-00013-of-00014.safetensors",
534
+ "model.layers.61.mlp.up_proj.weight": "model-00013-of-00014.safetensors",
535
+ "model.layers.61.post_attention_layernorm.weight": "model-00013-of-00014.safetensors",
536
+ "model.layers.61.self_attn.k_proj.weight": "model-00013-of-00014.safetensors",
537
+ "model.layers.61.self_attn.o_proj.weight": "model-00013-of-00014.safetensors",
538
+ "model.layers.61.self_attn.q_proj.weight": "model-00013-of-00014.safetensors",
539
+ "model.layers.61.self_attn.v_proj.weight": "model-00013-of-00014.safetensors",
540
+ "model.layers.62.input_layernorm.weight": "model-00013-of-00014.safetensors",
541
+ "model.layers.62.mlp.down_proj.weight": "model-00013-of-00014.safetensors",
542
+ "model.layers.62.mlp.gate_proj.weight": "model-00013-of-00014.safetensors",
543
+ "model.layers.62.mlp.up_proj.weight": "model-00013-of-00014.safetensors",
544
+ "model.layers.62.post_attention_layernorm.weight": "model-00013-of-00014.safetensors",
545
+ "model.layers.62.self_attn.k_proj.weight": "model-00013-of-00014.safetensors",
546
+ "model.layers.62.self_attn.o_proj.weight": "model-00013-of-00014.safetensors",
547
+ "model.layers.62.self_attn.q_proj.weight": "model-00013-of-00014.safetensors",
548
+ "model.layers.62.self_attn.v_proj.weight": "model-00013-of-00014.safetensors",
549
+ "model.layers.63.input_layernorm.weight": "model-00013-of-00014.safetensors",
550
+ "model.layers.63.mlp.down_proj.weight": "model-00013-of-00014.safetensors",
551
+ "model.layers.63.mlp.gate_proj.weight": "model-00013-of-00014.safetensors",
552
+ "model.layers.63.mlp.up_proj.weight": "model-00013-of-00014.safetensors",
553
+ "model.layers.63.post_attention_layernorm.weight": "model-00013-of-00014.safetensors",
554
+ "model.layers.63.self_attn.k_proj.weight": "model-00013-of-00014.safetensors",
555
+ "model.layers.63.self_attn.o_proj.weight": "model-00013-of-00014.safetensors",
556
+ "model.layers.63.self_attn.q_proj.weight": "model-00013-of-00014.safetensors",
557
+ "model.layers.63.self_attn.v_proj.weight": "model-00013-of-00014.safetensors",
558
+ "model.layers.7.input_layernorm.weight": "model-00002-of-00014.safetensors",
559
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00014.safetensors",
560
+ "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00014.safetensors",
561
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00014.safetensors",
562
+ "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00014.safetensors",
563
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00014.safetensors",
564
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00014.safetensors",
565
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00014.safetensors",
566
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00014.safetensors",
567
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00014.safetensors",
568
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00014.safetensors",
569
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00014.safetensors",
570
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00014.safetensors",
571
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00014.safetensors",
572
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00014.safetensors",
573
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00014.safetensors",
574
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00014.safetensors",
575
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00014.safetensors",
576
+ "model.layers.9.input_layernorm.weight": "model-00003-of-00014.safetensors",
577
+ "model.layers.9.mlp.down_proj.weight": "model-00003-of-00014.safetensors",
578
+ "model.layers.9.mlp.gate_proj.weight": "model-00003-of-00014.safetensors",
579
+ "model.layers.9.mlp.up_proj.weight": "model-00003-of-00014.safetensors",
580
+ "model.layers.9.post_attention_layernorm.weight": "model-00003-of-00014.safetensors",
581
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00014.safetensors",
582
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00014.safetensors",
583
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00014.safetensors",
584
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00014.safetensors",
585
+ "model.norm.weight": "model-00013-of-00014.safetensors"
586
+ }
587
+ }
modeling_iquestcoder.py ADDED
@@ -0,0 +1,1063 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Modified MIT License
3
+
4
+ Software Copyright© 2025 IQuest Research
5
+
6
+ Our only modification is that, if the Software (or any derivative works
7
+ thereof) is used for any of your commercial products or services, you shall
8
+ prominently display "IQuest Coder" on the user interface of such product or
9
+ service.
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+ """
27
+
28
+ from typing import Callable, List, Optional, Tuple, Union
29
+
30
+ import torch
31
+ import torch.nn as nn
32
+ import torch.nn.functional as F
33
+
34
+ from transformers.activations import ACT2FN
35
+ from transformers.cache_utils import Cache, DynamicCache, SlidingWindowCache, StaticCache
36
+ from transformers.generation import GenerationMixin
37
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
38
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
39
+ from transformers.modeling_layers import GradientCheckpointingLayer
40
+ from transformers.modeling_outputs import (
41
+ BaseModelOutputWithPast,
42
+ CausalLMOutputWithPast,
43
+ QuestionAnsweringModelOutput,
44
+ SequenceClassifierOutputWithPast,
45
+ TokenClassifierOutput,
46
+ )
47
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
48
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
49
+ from transformers.processing_utils import Unpack
50
+ from transformers.utils import (
51
+ auto_docstring,
52
+ can_return_tuple,
53
+ is_torch_flex_attn_available,
54
+ logging,
55
+ )
56
+
57
+ from .configuration_iquestcoder import IQuestCoderConfig
58
+
59
+
60
+ if is_torch_flex_attn_available():
61
+ from torch.nn.attention.flex_attention import BlockMask
62
+ from transformers.integrations.flex_attention import make_flex_block_causal_mask
63
+
64
+
65
+ logger = logging.get_logger(__name__)
66
+
67
+
68
+ # =============================================================================
69
+ # Helper Functions
70
+ # =============================================================================
71
+
72
+ def rotate_half(x: torch.Tensor) -> torch.Tensor:
73
+ """Rotates half the hidden dims of the input."""
74
+ x1 = x[..., : x.shape[-1] // 2]
75
+ x2 = x[..., x.shape[-1] // 2 :]
76
+ return torch.cat((-x2, x1), dim=-1)
77
+
78
+
79
+ def apply_rotary_pos_emb(
80
+ q: torch.Tensor,
81
+ k: torch.Tensor,
82
+ cos: torch.Tensor,
83
+ sin: torch.Tensor,
84
+ position_ids: Optional[torch.Tensor] = None,
85
+ unsqueeze_dim: int = 1,
86
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
87
+ """Applies Rotary Position Embedding to the query and key tensors.
88
+
89
+ Args:
90
+ q: The query tensor.
91
+ k: The key tensor.
92
+ cos: The cosine part of the rotary embedding.
93
+ sin: The sine part of the rotary embedding.
94
+ position_ids: Deprecated and unused.
95
+ unsqueeze_dim: The dimension along which to unsqueeze cos and sin.
96
+
97
+ Returns:
98
+ Tuple of query and key tensors rotated using the Rotary Position Embedding.
99
+ """
100
+ # Borrowed from OLMo: preserve original dtypes for numerical stability
101
+ q_dtype, k_dtype = q.dtype, k.dtype
102
+ cos = cos.unsqueeze(unsqueeze_dim)
103
+ sin = sin.unsqueeze(unsqueeze_dim)
104
+ q_embed = (q * cos) + (rotate_half(q) * sin)
105
+ k_embed = (k * cos) + (rotate_half(k) * sin)
106
+ return q_embed.to(q_dtype), k_embed.to(k_dtype)
107
+
108
+
109
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
110
+ """
111
+ Expands key/value heads for Grouped Query Attention.
112
+
113
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep).
114
+ The hidden states go from (batch, num_key_value_heads, seqlen, head_dim) to
115
+ (batch, num_attention_heads, seqlen, head_dim).
116
+ """
117
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
118
+ if n_rep == 1:
119
+ return hidden_states
120
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
121
+ return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
122
+
123
+
124
+ def eager_attention_forward(
125
+ module: nn.Module,
126
+ query: torch.Tensor,
127
+ key: torch.Tensor,
128
+ value: torch.Tensor,
129
+ attention_mask: Optional[torch.Tensor],
130
+ scaling: float,
131
+ dropout: float = 0.0,
132
+ **kwargs,
133
+ ) -> Tuple[torch.Tensor, torch.Tensor]:
134
+ """Standard eager attention implementation."""
135
+ key_states = repeat_kv(key, module.num_key_value_groups)
136
+ value_states = repeat_kv(value, module.num_key_value_groups)
137
+
138
+ attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
139
+ if attention_mask is not None:
140
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
141
+ attn_weights = attn_weights + causal_mask
142
+
143
+ attn_weights = F.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
144
+ attn_weights = F.dropout(attn_weights, p=dropout, training=module.training)
145
+ attn_output = torch.matmul(attn_weights, value_states)
146
+ attn_output = attn_output.transpose(1, 2).contiguous()
147
+
148
+ return attn_output, attn_weights
149
+
150
+
151
+ # =============================================================================
152
+ # Model Components
153
+ # =============================================================================
154
+
155
+ class IQuestCoderRMSNorm(nn.Module):
156
+ """Root Mean Square Layer Normalization.
157
+
158
+ RMSNorm is computationally simpler than LayerNorm while achieving similar
159
+ performance. It normalizes the input by its RMS value.
160
+ """
161
+
162
+ def __init__(self, hidden_size: int, eps: float = 1e-6):
163
+ super().__init__()
164
+ self.weight = nn.Parameter(torch.ones(hidden_size))
165
+ self.variance_epsilon = eps
166
+
167
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
168
+ input_dtype = hidden_states.dtype
169
+ hidden_states = hidden_states.to(torch.float32)
170
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
171
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
172
+ return self.weight * hidden_states.to(input_dtype)
173
+
174
+ def extra_repr(self) -> str:
175
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
176
+
177
+
178
+ class IQuestCoderRotaryEmbedding(nn.Module):
179
+ """Rotary Position Embedding (RoPE).
180
+
181
+ Implements rotary positional embeddings as described in the RoFormer paper.
182
+ Supports various RoPE scaling methods for extended context lengths.
183
+ """
184
+
185
+ def __init__(self, config: IQuestCoderConfig, device=None):
186
+ super().__init__()
187
+ # BC: "rope_type" was originally "type"
188
+ if hasattr(config, "rope_scaling") and config.rope_scaling is not None:
189
+ self.rope_type = config.rope_scaling.get("rope_type", config.rope_scaling.get("type"))
190
+ else:
191
+ self.rope_type = "default"
192
+ self.max_seq_len_cached = config.max_position_embeddings
193
+ self.original_max_seq_len = config.max_position_embeddings
194
+
195
+ self.config = config
196
+ self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
197
+
198
+ inv_freq, self.attention_scaling = self.rope_init_fn(self.config, device)
199
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
200
+ self.original_inv_freq = self.inv_freq
201
+
202
+ @torch.no_grad()
203
+ @dynamic_rope_update
204
+ def forward(self, x: torch.Tensor, position_ids: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
205
+ inv_freq_expanded = self.inv_freq[None, :, None].float().expand(position_ids.shape[0], -1, 1).to(x.device)
206
+ position_ids_expanded = position_ids[:, None, :].float()
207
+
208
+ device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
209
+ with torch.autocast(device_type=device_type, enabled=False):
210
+ freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(1, 2)
211
+ emb = torch.cat((freqs, freqs), dim=-1)
212
+ cos = emb.cos() * self.attention_scaling
213
+ sin = emb.sin() * self.attention_scaling
214
+
215
+ return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
216
+
217
+
218
+ class IQuestCoderMLP(nn.Module):
219
+ """Feed-forward network with SwiGLU activation.
220
+
221
+ Uses the gated linear unit variant with SiLU activation for improved
222
+ performance compared to standard FFN.
223
+ """
224
+
225
+ def __init__(self, config: IQuestCoderConfig):
226
+ super().__init__()
227
+ self.config = config
228
+ self.hidden_size = config.hidden_size
229
+ self.intermediate_size = config.intermediate_size
230
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
231
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=config.mlp_bias)
232
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=config.mlp_bias)
233
+ self.act_fn = ACT2FN[config.hidden_act]
234
+
235
+ def forward(self, x: torch.Tensor) -> torch.Tensor:
236
+ # SwiGLU: down_proj(act_fn(gate_proj(x)) * up_proj(x))
237
+ return self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
238
+
239
+
240
+ class IQuestCoderAttention(nn.Module):
241
+ """Multi-headed attention with support for Grouped Query Attention (GQA).
242
+
243
+ Features:
244
+ - Grouped Query Attention for memory efficiency
245
+ - Optional QKV clipping for training stability (from OLMo)
246
+ - Optional sliding window attention (from Qwen2)
247
+ - Rotary Position Embeddings
248
+ """
249
+
250
+ def __init__(self, config: IQuestCoderConfig, layer_idx: int):
251
+ super().__init__()
252
+ self.config = config
253
+ self.layer_idx = layer_idx
254
+ self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
255
+ self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
256
+ self.scaling = self.head_dim ** -0.5
257
+ self.attention_dropout = config.attention_dropout
258
+ self.is_causal = True
259
+
260
+ # Projection layers
261
+ self.q_proj = nn.Linear(
262
+ config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
263
+ )
264
+ self.k_proj = nn.Linear(
265
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
266
+ )
267
+ self.v_proj = nn.Linear(
268
+ config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
269
+ )
270
+ self.o_proj = nn.Linear(
271
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
272
+ )
273
+
274
+ def forward(
275
+ self,
276
+ hidden_states: torch.Tensor,
277
+ position_embeddings: Tuple[torch.Tensor, torch.Tensor],
278
+ attention_mask: Optional[torch.Tensor],
279
+ past_key_value: Optional[Cache] = None,
280
+ cache_position: Optional[torch.LongTensor] = None,
281
+ **kwargs: Unpack[FlashAttentionKwargs],
282
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
283
+ input_shape = hidden_states.shape[:-1]
284
+ hidden_shape = (*input_shape, -1, self.head_dim)
285
+
286
+ # Compute Q, K, V projections
287
+ query_states = self.q_proj(hidden_states)
288
+ key_states = self.k_proj(hidden_states)
289
+ value_states = self.v_proj(hidden_states)
290
+
291
+ # [OLMo Feature] Optional QKV clipping for training stability
292
+ if self.config.clip_qkv is not None:
293
+ query_states = query_states.clamp(min=-self.config.clip_qkv, max=self.config.clip_qkv)
294
+ key_states = key_states.clamp(min=-self.config.clip_qkv, max=self.config.clip_qkv)
295
+ value_states = value_states.clamp(min=-self.config.clip_qkv, max=self.config.clip_qkv)
296
+
297
+ # Reshape to (batch, heads, seq_len, head_dim)
298
+ query_states = query_states.view(hidden_shape).transpose(1, 2)
299
+ key_states = key_states.view(hidden_shape).transpose(1, 2)
300
+ value_states = value_states.view(hidden_shape).transpose(1, 2)
301
+
302
+ # Apply rotary position embeddings
303
+ cos, sin = position_embeddings
304
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
305
+
306
+ # Update KV cache if provided
307
+ if past_key_value is not None:
308
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
309
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
310
+
311
+ # [Qwen2 Feature] Sliding window attention
312
+ sliding_window = None
313
+ if (
314
+ self.config.use_sliding_window
315
+ and getattr(self.config, "sliding_window", None) is not None
316
+ and self.layer_idx >= self.config.max_window_layers
317
+ ):
318
+ sliding_window = self.config.sliding_window
319
+
320
+ # Select attention implementation
321
+ attention_interface: Callable = eager_attention_forward
322
+ if self.config._attn_implementation != "eager":
323
+ if self.config._attn_implementation == "sdpa" and kwargs.get("output_attentions", False):
324
+ logger.warning_once(
325
+ "`torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. "
326
+ 'Falling back to eager attention. This warning can be removed using the argument '
327
+ '`attn_implementation="eager"` when loading the model.'
328
+ )
329
+ else:
330
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
331
+
332
+ # Compute attention
333
+ attn_output, attn_weights = attention_interface(
334
+ self,
335
+ query_states,
336
+ key_states,
337
+ value_states,
338
+ attention_mask,
339
+ dropout=0.0 if not self.training else self.attention_dropout,
340
+ scaling=self.scaling,
341
+ sliding_window=sliding_window,
342
+ **kwargs,
343
+ )
344
+
345
+ # Reshape and project output
346
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
347
+ attn_output = self.o_proj(attn_output)
348
+
349
+ return attn_output, attn_weights
350
+
351
+
352
+ class IQuestCoderDecoderLayer(GradientCheckpointingLayer):
353
+ """Transformer decoder layer with pre-normalization.
354
+
355
+ Architecture: Pre-RMSNorm -> Attention -> Residual -> Pre-RMSNorm -> MLP -> Residual
356
+ """
357
+
358
+ def __init__(self, config: IQuestCoderConfig, layer_idx: int):
359
+ super().__init__()
360
+ self.hidden_size = config.hidden_size
361
+ self.self_attn = IQuestCoderAttention(config=config, layer_idx=layer_idx)
362
+ self.mlp = IQuestCoderMLP(config)
363
+ self.input_layernorm = IQuestCoderRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
364
+ self.post_attention_layernorm = IQuestCoderRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
365
+
366
+ # Warn if sliding window is enabled but not properly supported
367
+ if config.use_sliding_window and config._attn_implementation != "flash_attention_2":
368
+ logger.warning_once(
369
+ f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
370
+ "unexpected results may be encountered."
371
+ )
372
+
373
+ def forward(
374
+ self,
375
+ hidden_states: torch.Tensor,
376
+ attention_mask: Optional[torch.Tensor] = None,
377
+ position_ids: Optional[torch.LongTensor] = None,
378
+ past_key_value: Optional[Cache] = None,
379
+ output_attentions: Optional[bool] = False,
380
+ use_cache: Optional[bool] = False,
381
+ cache_position: Optional[torch.LongTensor] = None,
382
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
383
+ **kwargs: Unpack[FlashAttentionKwargs],
384
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
385
+ # Pre-norm + Self Attention
386
+ residual = hidden_states
387
+ hidden_states = self.input_layernorm(hidden_states)
388
+
389
+ hidden_states, self_attn_weights = self.self_attn(
390
+ hidden_states=hidden_states,
391
+ attention_mask=attention_mask,
392
+ position_ids=position_ids,
393
+ past_key_value=past_key_value,
394
+ output_attentions=output_attentions,
395
+ use_cache=use_cache,
396
+ cache_position=cache_position,
397
+ position_embeddings=position_embeddings,
398
+ **kwargs,
399
+ )
400
+ hidden_states = residual + hidden_states
401
+
402
+ # Pre-norm + MLP
403
+ residual = hidden_states
404
+ hidden_states = self.post_attention_layernorm(hidden_states)
405
+ hidden_states = self.mlp(hidden_states)
406
+ hidden_states = residual + hidden_states
407
+
408
+ outputs = (hidden_states,)
409
+ if output_attentions:
410
+ outputs += (self_attn_weights,)
411
+
412
+ return outputs
413
+
414
+
415
+ # =============================================================================
416
+ # Base Model
417
+ # =============================================================================
418
+
419
+ @auto_docstring
420
+ class IQuestCoderPreTrainedModel(PreTrainedModel):
421
+ """Base class for IQuestCoder models."""
422
+
423
+ config_class = IQuestCoderConfig
424
+ base_model_prefix = "model"
425
+ supports_gradient_checkpointing = True
426
+ _no_split_modules = ["IQuestCoderDecoderLayer"]
427
+ _skip_keys_device_placement = ["past_key_values"]
428
+ _supports_flash_attn_2 = True
429
+ _supports_sdpa = True
430
+ _supports_flex_attn = True
431
+ _supports_cache_class = True
432
+ _supports_quantized_cache = True
433
+ _supports_static_cache = True
434
+ _supports_attention_backend = True
435
+
436
+ def _init_weights(self, module: nn.Module):
437
+ std = self.config.initializer_range
438
+ if isinstance(module, nn.Linear):
439
+ module.weight.data.normal_(mean=0.0, std=std)
440
+ if module.bias is not None:
441
+ module.bias.data.zero_()
442
+ elif isinstance(module, nn.Embedding):
443
+ module.weight.data.normal_(mean=0.0, std=std)
444
+ if module.padding_idx is not None:
445
+ module.weight.data[module.padding_idx].zero_()
446
+ elif isinstance(module, IQuestCoderRMSNorm):
447
+ module.weight.data.fill_(1.0)
448
+
449
+
450
+ @auto_docstring
451
+ class IQuestCoderModel(IQuestCoderPreTrainedModel):
452
+ """
453
+ IQuestCoder Model outputting raw hidden-states without any specific head on top.
454
+
455
+ This model is compatible with LLaMA weights while incorporating features from OLMo and Qwen2.
456
+ """
457
+
458
+ def __init__(self, config: IQuestCoderConfig):
459
+ super().__init__(config)
460
+ self.padding_idx = config.pad_token_id
461
+ self.vocab_size = config.vocab_size
462
+
463
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
464
+ self.layers = nn.ModuleList(
465
+ [IQuestCoderDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
466
+ )
467
+ self.norm = IQuestCoderRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
468
+ self.rotary_emb = IQuestCoderRotaryEmbedding(config=config)
469
+ self.gradient_checkpointing = False
470
+
471
+ # Initialize weights and apply final processing
472
+ self.post_init()
473
+
474
+ def get_input_embeddings(self) -> nn.Embedding:
475
+ return self.embed_tokens
476
+
477
+ def set_input_embeddings(self, value: nn.Embedding):
478
+ self.embed_tokens = value
479
+
480
+ @can_return_tuple
481
+ @auto_docstring
482
+ def forward(
483
+ self,
484
+ input_ids: Optional[torch.LongTensor] = None,
485
+ attention_mask: Optional[torch.Tensor] = None,
486
+ position_ids: Optional[torch.LongTensor] = None,
487
+ past_key_values: Optional[Cache] = None,
488
+ inputs_embeds: Optional[torch.FloatTensor] = None,
489
+ use_cache: Optional[bool] = None,
490
+ output_attentions: Optional[bool] = None,
491
+ output_hidden_states: Optional[bool] = None,
492
+ cache_position: Optional[torch.LongTensor] = None,
493
+ **flash_attn_kwargs: Unpack[FlashAttentionKwargs],
494
+ ) -> BaseModelOutputWithPast:
495
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
496
+ output_hidden_states = (
497
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
498
+ )
499
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
500
+
501
+ if (input_ids is None) ^ (inputs_embeds is not None):
502
+ raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
503
+
504
+ if self.gradient_checkpointing and self.training and use_cache:
505
+ logger.warning_once(
506
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`."
507
+ )
508
+ use_cache = False
509
+
510
+ if not isinstance(past_key_values, (type(None), Cache)):
511
+ raise ValueError("The `past_key_values` should be either a `Cache` object or `None`.")
512
+
513
+ if inputs_embeds is None:
514
+ inputs_embeds = self.embed_tokens(input_ids)
515
+
516
+ if use_cache and past_key_values is None:
517
+ past_key_values = DynamicCache()
518
+
519
+ if cache_position is None:
520
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
521
+ cache_position = torch.arange(
522
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
523
+ )
524
+
525
+ if position_ids is None:
526
+ position_ids = cache_position.unsqueeze(0)
527
+
528
+ causal_mask = self._update_causal_mask(
529
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
530
+ )
531
+
532
+ hidden_states = inputs_embeds
533
+
534
+ # Create position embeddings to be shared across the decoder layers
535
+ position_embeddings = self.rotary_emb(hidden_states, position_ids)
536
+
537
+ # Decoder layers
538
+ all_hidden_states = () if output_hidden_states else None
539
+ all_self_attns = () if output_attentions else None
540
+
541
+ for decoder_layer in self.layers[: self.config.num_hidden_layers]:
542
+ if output_hidden_states:
543
+ all_hidden_states += (hidden_states,)
544
+
545
+ layer_outputs = decoder_layer(
546
+ hidden_states,
547
+ attention_mask=causal_mask,
548
+ position_ids=position_ids,
549
+ past_key_value=past_key_values,
550
+ output_attentions=output_attentions,
551
+ use_cache=use_cache,
552
+ cache_position=cache_position,
553
+ position_embeddings=position_embeddings,
554
+ **flash_attn_kwargs,
555
+ )
556
+
557
+ hidden_states = layer_outputs[0]
558
+
559
+ if output_attentions:
560
+ all_self_attns += (layer_outputs[1],)
561
+
562
+ hidden_states = self.norm(hidden_states)
563
+
564
+ # Add hidden states from the last decoder layer
565
+ if output_hidden_states:
566
+ all_hidden_states += (hidden_states,)
567
+
568
+ return BaseModelOutputWithPast(
569
+ last_hidden_state=hidden_states,
570
+ past_key_values=past_key_values if use_cache else None,
571
+ hidden_states=all_hidden_states,
572
+ attentions=all_self_attns,
573
+ )
574
+
575
+ def _update_causal_mask(
576
+ self,
577
+ attention_mask: Union[torch.Tensor, "BlockMask"],
578
+ input_tensor: torch.Tensor,
579
+ cache_position: torch.Tensor,
580
+ past_key_values: Cache,
581
+ output_attentions: bool = False,
582
+ ):
583
+ if self.config._attn_implementation == "flash_attention_2":
584
+ if attention_mask is not None and past_key_values is not None:
585
+ is_padding_right = attention_mask[:, -1].sum().item() != input_tensor.size()[0]
586
+ if is_padding_right:
587
+ raise ValueError(
588
+ "You are attempting to perform batched generation with padding_side='right'. "
589
+ "This may lead to unexpected behaviour for Flash Attention version of IQuestCoder. "
590
+ "Make sure to call `tokenizer.padding_side = 'left'` before tokenizing the input."
591
+ )
592
+ if attention_mask is not None and 0.0 in attention_mask:
593
+ return attention_mask
594
+ return None
595
+
596
+ if self.config._attn_implementation == "flex_attention":
597
+ if isinstance(attention_mask, torch.Tensor):
598
+ attention_mask = make_flex_block_causal_mask(attention_mask)
599
+ return attention_mask
600
+
601
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
602
+ using_static_cache = isinstance(past_key_values, StaticCache)
603
+ using_sliding_window_cache = isinstance(past_key_values, SlidingWindowCache)
604
+
605
+ if (
606
+ self.config._attn_implementation == "sdpa"
607
+ and not (using_static_cache or using_sliding_window_cache)
608
+ and not output_attentions
609
+ ):
610
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
611
+ attention_mask,
612
+ inputs_embeds=input_tensor,
613
+ past_key_values_length=past_seen_tokens,
614
+ sliding_window=self.config.sliding_window if self.config.use_sliding_window else None,
615
+ is_training=self.training,
616
+ ):
617
+ return None
618
+
619
+ dtype = input_tensor.dtype
620
+ min_dtype = torch.finfo(dtype).min
621
+ sequence_length = input_tensor.shape[1]
622
+
623
+ if using_sliding_window_cache or using_static_cache:
624
+ target_length = past_key_values.get_max_cache_shape()
625
+ else:
626
+ target_length = (
627
+ attention_mask.shape[-1]
628
+ if isinstance(attention_mask, torch.Tensor)
629
+ else past_seen_tokens + sequence_length + 1
630
+ )
631
+
632
+ causal_mask = self._prepare_4d_causal_attention_mask_with_cache_position(
633
+ attention_mask,
634
+ sequence_length=sequence_length,
635
+ target_length=target_length,
636
+ dtype=dtype,
637
+ cache_position=cache_position,
638
+ batch_size=input_tensor.shape[0],
639
+ config=self.config,
640
+ past_key_values=past_key_values,
641
+ )
642
+
643
+ if (
644
+ self.config._attn_implementation == "sdpa"
645
+ and attention_mask is not None
646
+ and attention_mask.device.type in ["cuda", "xpu", "npu"]
647
+ and not output_attentions
648
+ ):
649
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
650
+
651
+ return causal_mask
652
+
653
+ @staticmethod
654
+ def _prepare_4d_causal_attention_mask_with_cache_position(
655
+ attention_mask: torch.Tensor,
656
+ sequence_length: int,
657
+ target_length: int,
658
+ dtype: torch.dtype,
659
+ cache_position: torch.Tensor,
660
+ batch_size: int,
661
+ config: IQuestCoderConfig,
662
+ past_key_values: Cache,
663
+ ):
664
+ """Creates a causal 4D mask from a 2D mask, or returns the 4D mask if already provided."""
665
+ if attention_mask is not None and attention_mask.dim() == 4:
666
+ causal_mask = attention_mask
667
+ else:
668
+ min_dtype = torch.finfo(dtype).min
669
+ causal_mask = torch.full(
670
+ (sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=cache_position.device
671
+ )
672
+ diagonal_attend_mask = torch.arange(target_length, device=cache_position.device) > cache_position.reshape(
673
+ -1, 1
674
+ )
675
+
676
+ # [Qwen2 Feature] Handle sliding window mask
677
+ if getattr(config, "use_sliding_window", False) and config.sliding_window is not None:
678
+ if not isinstance(past_key_values, SlidingWindowCache) or sequence_length > target_length:
679
+ sliding_attend_mask = torch.arange(target_length, device=cache_position.device) <= (
680
+ cache_position.reshape(-1, 1) - config.sliding_window
681
+ )
682
+ diagonal_attend_mask.bitwise_or_(sliding_attend_mask)
683
+
684
+ causal_mask *= diagonal_attend_mask
685
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
686
+
687
+ if attention_mask is not None:
688
+ causal_mask = causal_mask.clone()
689
+ if attention_mask.shape[-1] > target_length:
690
+ attention_mask = attention_mask[:, :target_length]
691
+ mask_length = attention_mask.shape[-1]
692
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :].to(
693
+ causal_mask.device
694
+ )
695
+ padding_mask = padding_mask == 0
696
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
697
+ padding_mask, min_dtype
698
+ )
699
+
700
+ return causal_mask
701
+
702
+
703
+ # =============================================================================
704
+ # Model Heads
705
+ # =============================================================================
706
+
707
+ @auto_docstring
708
+ class IQuestCoderForCausalLM(IQuestCoderPreTrainedModel, GenerationMixin):
709
+ """IQuestCoder Model with a language modeling head on top for causal LM."""
710
+
711
+ _tied_weights_keys = ["lm_head.weight"]
712
+ _tp_plan = {"lm_head": "colwise_rep"}
713
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
714
+
715
+ def __init__(self, config: IQuestCoderConfig):
716
+ super().__init__(config)
717
+ self.model = IQuestCoderModel(config)
718
+ self.vocab_size = config.vocab_size
719
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
720
+
721
+ # Initialize weights and apply final processing
722
+ self.post_init()
723
+
724
+ def get_input_embeddings(self) -> nn.Embedding:
725
+ return self.model.embed_tokens
726
+
727
+ def set_input_embeddings(self, value: nn.Embedding):
728
+ self.model.embed_tokens = value
729
+
730
+ def get_output_embeddings(self) -> nn.Linear:
731
+ return self.lm_head
732
+
733
+ def set_output_embeddings(self, new_embeddings: nn.Linear):
734
+ self.lm_head = new_embeddings
735
+
736
+ def set_decoder(self, decoder: IQuestCoderModel):
737
+ self.model = decoder
738
+
739
+ def get_decoder(self) -> IQuestCoderModel:
740
+ return self.model
741
+
742
+ @can_return_tuple
743
+ @auto_docstring
744
+ def forward(
745
+ self,
746
+ input_ids: Optional[torch.LongTensor] = None,
747
+ attention_mask: Optional[torch.Tensor] = None,
748
+ position_ids: Optional[torch.LongTensor] = None,
749
+ past_key_values: Optional[Cache] = None,
750
+ inputs_embeds: Optional[torch.FloatTensor] = None,
751
+ labels: Optional[torch.LongTensor] = None,
752
+ use_cache: Optional[bool] = None,
753
+ output_attentions: Optional[bool] = None,
754
+ output_hidden_states: Optional[bool] = None,
755
+ cache_position: Optional[torch.LongTensor] = None,
756
+ logits_to_keep: Union[int, torch.Tensor] = 0,
757
+ **kwargs
758
+ ) -> CausalLMOutputWithPast:
759
+ r"""
760
+ Args:
761
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
762
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
763
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
764
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
765
+
766
+ Example:
767
+ ```python
768
+ >>> from transformers import AutoTokenizer
769
+ >>> from modeling_iquestcoder import IQuestCoderForCausalLM
770
+
771
+ >>> model = IQuestCoderForCausalLM.from_pretrained("path/to/IQuestCoder")
772
+ >>> tokenizer = AutoTokenizer.from_pretrained("path/to/IQuestCoder")
773
+
774
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
775
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
776
+
777
+ >>> # Generate
778
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
779
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
780
+ "Hey, are you conscious? Can you talk to me?\\nI'm not conscious, but I can talk to you."
781
+ ```
782
+ """
783
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
784
+ output_hidden_states = (
785
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
786
+ )
787
+
788
+ # Decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
789
+ outputs: BaseModelOutputWithPast = self.model(
790
+ input_ids=input_ids,
791
+ attention_mask=attention_mask,
792
+ position_ids=position_ids,
793
+ past_key_values=past_key_values,
794
+ inputs_embeds=inputs_embeds,
795
+ use_cache=use_cache,
796
+ output_attentions=output_attentions,
797
+ output_hidden_states=output_hidden_states,
798
+ cache_position=cache_position,
799
+ **kwargs,
800
+ )
801
+
802
+ hidden_states = outputs.last_hidden_state
803
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
804
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
805
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
806
+
807
+ loss = None
808
+ if labels is not None:
809
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
810
+
811
+ return CausalLMOutputWithPast(
812
+ loss=loss,
813
+ logits=logits,
814
+ past_key_values=outputs.past_key_values,
815
+ hidden_states=outputs.hidden_states,
816
+ attentions=outputs.attentions,
817
+ )
818
+
819
+
820
+ @auto_docstring(
821
+ custom_intro="""
822
+ The IQuestCoder Model transformer with a sequence classification head on top (linear layer).
823
+
824
+ [`IQuestCoderForSequenceClassification`] uses the last token in order to do the classification, as other causal
825
+ models (e.g. GPT-2) do.
826
+
827
+ Since it does classification on the last token, it requires to know the position of the last token. If a
828
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row.
829
+ If no `pad_token_id` is defined, it simply takes the last value in each row of the batch.
830
+ """
831
+ )
832
+ class IQuestCoderForSequenceClassification(IQuestCoderPreTrainedModel):
833
+ """IQuestCoder Model with a sequence classification head."""
834
+
835
+ def __init__(self, config: IQuestCoderConfig):
836
+ super().__init__(config)
837
+ self.num_labels = config.num_labels
838
+ self.model = IQuestCoderModel(config)
839
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
840
+
841
+ # Initialize weights and apply final processing
842
+ self.post_init()
843
+
844
+ def get_input_embeddings(self) -> nn.Embedding:
845
+ return self.model.embed_tokens
846
+
847
+ def set_input_embeddings(self, value: nn.Embedding):
848
+ self.model.embed_tokens = value
849
+
850
+ @can_return_tuple
851
+ @auto_docstring
852
+ def forward(
853
+ self,
854
+ input_ids: Optional[torch.LongTensor] = None,
855
+ attention_mask: Optional[torch.Tensor] = None,
856
+ position_ids: Optional[torch.LongTensor] = None,
857
+ past_key_values: Optional[Cache] = None,
858
+ inputs_embeds: Optional[torch.FloatTensor] = None,
859
+ labels: Optional[torch.LongTensor] = None,
860
+ use_cache: Optional[bool] = None,
861
+ output_attentions: Optional[bool] = None,
862
+ output_hidden_states: Optional[bool] = None,
863
+ ) -> SequenceClassifierOutputWithPast:
864
+ r"""
865
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
866
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
867
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss),
868
+ If `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
869
+ """
870
+ transformer_outputs: BaseModelOutputWithPast = self.model(
871
+ input_ids,
872
+ attention_mask=attention_mask,
873
+ position_ids=position_ids,
874
+ past_key_values=past_key_values,
875
+ inputs_embeds=inputs_embeds,
876
+ use_cache=use_cache,
877
+ output_attentions=output_attentions,
878
+ output_hidden_states=output_hidden_states,
879
+ )
880
+ hidden_states = transformer_outputs.last_hidden_state
881
+ logits = self.score(hidden_states)
882
+
883
+ if input_ids is not None:
884
+ batch_size = input_ids.shape[0]
885
+ else:
886
+ batch_size = inputs_embeds.shape[0]
887
+
888
+ if self.config.pad_token_id is None and batch_size != 1:
889
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
890
+ if self.config.pad_token_id is None:
891
+ last_non_pad_token = -1
892
+ elif input_ids is not None:
893
+ non_pad_mask = (input_ids != self.config.pad_token_id).to(logits.device, torch.int32)
894
+ token_indices = torch.arange(input_ids.shape[-1], device=logits.device, dtype=torch.int32)
895
+ last_non_pad_token = (token_indices * non_pad_mask).argmax(-1)
896
+ else:
897
+ last_non_pad_token = -1
898
+ logger.warning_once(
899
+ f"{self.__class__.__name__} will not detect padding tokens in `inputs_embeds`. Results may be "
900
+ "unexpected if using padding tokens in conjunction with `inputs_embeds.`"
901
+ )
902
+
903
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), last_non_pad_token]
904
+
905
+ loss = None
906
+ if labels is not None:
907
+ loss = self.loss_function(logits=logits, labels=labels, pooled_logits=pooled_logits, config=self.config)
908
+
909
+ return SequenceClassifierOutputWithPast(
910
+ loss=loss,
911
+ logits=pooled_logits,
912
+ past_key_values=transformer_outputs.past_key_values,
913
+ hidden_states=transformer_outputs.hidden_states,
914
+ attentions=transformer_outputs.attentions,
915
+ )
916
+
917
+
918
+ @auto_docstring
919
+ class IQuestCoderForTokenClassification(IQuestCoderPreTrainedModel):
920
+ """IQuestCoder Model with a token classification head."""
921
+
922
+ def __init__(self, config: IQuestCoderConfig):
923
+ super().__init__(config)
924
+ self.num_labels = config.num_labels
925
+ self.model = IQuestCoderModel(config)
926
+ if getattr(config, "classifier_dropout", None) is not None:
927
+ classifier_dropout = config.classifier_dropout
928
+ elif getattr(config, "hidden_dropout", None) is not None:
929
+ classifier_dropout = config.hidden_dropout
930
+ else:
931
+ classifier_dropout = 0.1
932
+ self.dropout = nn.Dropout(classifier_dropout)
933
+ self.score = nn.Linear(config.hidden_size, config.num_labels)
934
+
935
+ # Initialize weights and apply final processing
936
+ self.post_init()
937
+
938
+ def get_input_embeddings(self) -> nn.Embedding:
939
+ return self.model.embed_tokens
940
+
941
+ def set_input_embeddings(self, value: nn.Embedding):
942
+ self.model.embed_tokens = value
943
+
944
+ @can_return_tuple
945
+ @auto_docstring
946
+ def forward(
947
+ self,
948
+ input_ids: Optional[torch.LongTensor] = None,
949
+ attention_mask: Optional[torch.Tensor] = None,
950
+ position_ids: Optional[torch.LongTensor] = None,
951
+ past_key_values: Optional[Cache] = None,
952
+ inputs_embeds: Optional[torch.FloatTensor] = None,
953
+ labels: Optional[torch.LongTensor] = None,
954
+ use_cache: Optional[bool] = None,
955
+ output_attentions: Optional[bool] = None,
956
+ output_hidden_states: Optional[bool] = None,
957
+ ) -> TokenClassifierOutput:
958
+ r"""
959
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
960
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
961
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss),
962
+ If `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
963
+ """
964
+ outputs: BaseModelOutputWithPast = self.model(
965
+ input_ids,
966
+ attention_mask=attention_mask,
967
+ position_ids=position_ids,
968
+ past_key_values=past_key_values,
969
+ inputs_embeds=inputs_embeds,
970
+ use_cache=use_cache,
971
+ output_attentions=output_attentions,
972
+ output_hidden_states=output_hidden_states,
973
+ )
974
+ sequence_output = outputs.last_hidden_state
975
+ sequence_output = self.dropout(sequence_output)
976
+ logits = self.score(sequence_output)
977
+
978
+ loss = None
979
+ if labels is not None:
980
+ loss = self.loss_function(logits, labels, self.config)
981
+
982
+ return TokenClassifierOutput(
983
+ loss=loss,
984
+ logits=logits,
985
+ hidden_states=outputs.hidden_states,
986
+ attentions=outputs.attentions,
987
+ )
988
+
989
+
990
+ @auto_docstring
991
+ class IQuestCoderForQuestionAnswering(IQuestCoderPreTrainedModel):
992
+ """IQuestCoder Model with a span classification head for extractive question-answering."""
993
+
994
+ base_model_prefix = "transformer"
995
+
996
+ def __init__(self, config: IQuestCoderConfig):
997
+ super().__init__(config)
998
+ self.transformer = IQuestCoderModel(config)
999
+ self.qa_outputs = nn.Linear(config.hidden_size, 2)
1000
+
1001
+ # Initialize weights and apply final processing
1002
+ self.post_init()
1003
+
1004
+ def get_input_embeddings(self) -> nn.Embedding:
1005
+ return self.transformer.embed_tokens
1006
+
1007
+ def set_input_embeddings(self, value: nn.Embedding):
1008
+ self.transformer.embed_tokens = value
1009
+
1010
+ @can_return_tuple
1011
+ @auto_docstring
1012
+ def forward(
1013
+ self,
1014
+ input_ids: Optional[torch.LongTensor] = None,
1015
+ attention_mask: Optional[torch.Tensor] = None,
1016
+ position_ids: Optional[torch.LongTensor] = None,
1017
+ past_key_values: Optional[Cache] = None,
1018
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1019
+ start_positions: Optional[torch.LongTensor] = None,
1020
+ end_positions: Optional[torch.LongTensor] = None,
1021
+ output_attentions: Optional[bool] = None,
1022
+ output_hidden_states: Optional[bool] = None,
1023
+ **kwargs,
1024
+ ) -> QuestionAnsweringModelOutput:
1025
+ outputs: BaseModelOutputWithPast = self.transformer(
1026
+ input_ids,
1027
+ attention_mask=attention_mask,
1028
+ position_ids=position_ids,
1029
+ past_key_values=past_key_values,
1030
+ inputs_embeds=inputs_embeds,
1031
+ output_attentions=output_attentions,
1032
+ output_hidden_states=output_hidden_states,
1033
+ )
1034
+
1035
+ sequence_output = outputs.last_hidden_state
1036
+
1037
+ logits = self.qa_outputs(sequence_output)
1038
+ start_logits, end_logits = logits.split(1, dim=-1)
1039
+ start_logits = start_logits.squeeze(-1).contiguous()
1040
+ end_logits = end_logits.squeeze(-1).contiguous()
1041
+
1042
+ loss = None
1043
+ if start_positions is not None and end_positions is not None:
1044
+ loss = self.loss_function(start_logits, end_logits, start_positions, end_positions, **kwargs)
1045
+
1046
+ return QuestionAnsweringModelOutput(
1047
+ loss=loss,
1048
+ start_logits=start_logits,
1049
+ end_logits=end_logits,
1050
+ hidden_states=outputs.hidden_states,
1051
+ attentions=outputs.attentions,
1052
+ )
1053
+
1054
+
1055
+ __all__ = [
1056
+ "IQuestCoderPreTrainedModel",
1057
+ "IQuestCoderModel",
1058
+ "IQuestCoderForCausalLM",
1059
+ "IQuestCoderForSequenceClassification",
1060
+ "IQuestCoderForTokenClassification",
1061
+ "IQuestCoderForQuestionAnswering",
1062
+ ]
1063
+
tokenization_iquestcoder.py ADDED
@@ -0,0 +1,552 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tokenization classes for IQuestCoder."""
2
+
3
+ import os
4
+ from shutil import copyfile
5
+ from typing import Any, Dict, List, Optional, Tuple, Union
6
+
7
+ import sentencepiece as spm
8
+
9
+ from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
10
+ from transformers.utils import logging
11
+
12
+
13
+ logger = logging.get_logger(__name__)
14
+
15
+ VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
16
+
17
+ PRETRAINED_VOCAB_FILES_MAP = {
18
+ "vocab_file": {},
19
+ "tokenizer_file": {},
20
+ }
21
+ PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {}
22
+
23
+
24
+
25
+ class IQuestCoderTokenizer(PreTrainedTokenizer):
26
+
27
+ vocab_files_names = VOCAB_FILES_NAMES
28
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
29
+ max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
30
+ model_input_names = ["input_ids", "attention_mask"]
31
+
32
+ def __init__(
33
+ self,
34
+ vocab_file,
35
+ unk_token="<unk>",
36
+ bos_token="<s>",
37
+ eos_token="</s>",
38
+ pad_token=None,
39
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
40
+ add_bos_token=True,
41
+ add_eos_token=False,
42
+ clean_up_tokenization_spaces=False,
43
+ add_prefix_space=False,
44
+ legacy=None,
45
+ use_default_system_prompt=False,
46
+ chat_template=None,
47
+ **kwargs,
48
+ ):
49
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
50
+ bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token
51
+ eos_token = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token
52
+ unk_token = AddedToken(unk_token, lstrip=False, rstrip=False) if isinstance(unk_token, str) else unk_token
53
+ pad_token = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token
54
+
55
+ # Legacy behavior handling
56
+ if legacy is None:
57
+ logger.warning_once(
58
+ f"You are using the default legacy behaviour of the {self.__class__.__name__}. This is"
59
+ " expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you."
60
+ " If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it"
61
+ " means, and thoroughly read the reason why this was added as explained in"
62
+ " https://github.com/huggingface/transformers/pull/24565"
63
+ )
64
+ legacy = True
65
+
66
+ self.legacy = legacy
67
+ self.vocab_file = vocab_file
68
+ self.add_bos_token = add_bos_token
69
+ self.add_eos_token = add_eos_token
70
+ self.add_prefix_space = add_prefix_space
71
+ self.use_default_system_prompt = use_default_system_prompt
72
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
73
+ self.sp_model.Load(vocab_file)
74
+
75
+
76
+
77
+ super().__init__(
78
+ bos_token=bos_token,
79
+ eos_token=eos_token,
80
+ unk_token=unk_token,
81
+ pad_token=pad_token,
82
+ add_bos_token=add_bos_token,
83
+ add_eos_token=add_eos_token,
84
+ sp_model_kwargs=self.sp_model_kwargs,
85
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
86
+ add_prefix_space=add_prefix_space,
87
+ legacy=legacy,
88
+ use_default_system_prompt=use_default_system_prompt,
89
+ chat_template=chat_template,
90
+ **kwargs,
91
+ )
92
+
93
+ def __getstate__(self):
94
+ state = self.__dict__.copy()
95
+ state["sp_model"] = None
96
+ return state
97
+
98
+ def __setstate__(self, d):
99
+ self.__dict__ = d
100
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
101
+ self.sp_model.Load(self.vocab_file)
102
+
103
+ @property
104
+ def vocab_size(self) -> int:
105
+ """Returns the vocabulary size."""
106
+ return self.sp_model.get_piece_size()
107
+
108
+ def get_vocab(self) -> Dict[str, int]:
109
+ """Returns the vocabulary as a dictionary of token to index."""
110
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
111
+ vocab.update(self.added_tokens_encoder)
112
+ return vocab
113
+
114
+ def _tokenize(self, text: str) -> List[str]:
115
+ """
116
+ Tokenize a string.
117
+
118
+ Args:
119
+ text (`str`): The text to tokenize.
120
+
121
+ Returns:
122
+ `List[str]`: The list of tokens.
123
+ """
124
+ if self.add_prefix_space:
125
+ text = " " + text
126
+
127
+ if self.legacy:
128
+ return self.sp_model.encode(text, out_type=str)
129
+
130
+ # Non-legacy behavior: handle special tokens properly
131
+ return self.sp_model.encode(text, out_type=str)
132
+
133
+ def _convert_token_to_id(self, token: str) -> int:
134
+ """Converts a token (str) to an id using the vocab."""
135
+ return self.sp_model.piece_to_id(token)
136
+
137
+ def _convert_id_to_token(self, index: int) -> str:
138
+ """Converts an index (integer) to a token (str) using the vocab."""
139
+ token = self.sp_model.IdToPiece(index)
140
+ return token
141
+
142
+ def convert_tokens_to_string(self, tokens: List[str]) -> str:
143
+ """
144
+ Converts a sequence of tokens (strings) to a single string.
145
+
146
+ This method handles special tokens separately to ensure they are not
147
+ decoded using the SentencePiece model.
148
+
149
+ Args:
150
+ tokens (`List[str]`): The list of tokens to convert.
151
+
152
+ Returns:
153
+ `str`: The decoded string.
154
+ """
155
+ current_sub_tokens = []
156
+ out_string = ""
157
+ prev_is_special = False
158
+ for i, token in enumerate(tokens):
159
+ # make sure that special tokens are not decoded using sentencepiece model
160
+ if token in self.all_special_tokens:
161
+ if not prev_is_special and i != 0:
162
+ out_string += " "
163
+ out_string += self.sp_model.decode(current_sub_tokens) + token
164
+ prev_is_special = True
165
+ current_sub_tokens = []
166
+ else:
167
+ current_sub_tokens.append(token)
168
+ prev_is_special = False
169
+ out_string += self.sp_model.decode(current_sub_tokens)
170
+ return out_string
171
+
172
+ def save_vocabulary(self, save_directory: str, filename_prefix: Optional[str] = None) -> Tuple[str]:
173
+ """
174
+ Save the vocabulary and special tokens file to a directory.
175
+
176
+ Args:
177
+ save_directory (`str`):
178
+ The directory in which to save the vocabulary.
179
+ filename_prefix (`str`, *optional*):
180
+ An optional prefix to add to the named of the saved files.
181
+
182
+ Returns:
183
+ `Tuple(str)`: Paths to the files saved.
184
+ """
185
+ if not os.path.isdir(save_directory):
186
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
187
+ return
188
+ out_vocab_file = os.path.join(
189
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
190
+ )
191
+
192
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
193
+ copyfile(self.vocab_file, out_vocab_file)
194
+ elif not os.path.isfile(self.vocab_file):
195
+ with open(out_vocab_file, "wb") as fi:
196
+ content_spiece_model = self.sp_model.serialized_model_proto()
197
+ fi.write(content_spiece_model)
198
+
199
+ return (out_vocab_file,)
200
+
201
+ def build_inputs_with_special_tokens(
202
+ self,
203
+ token_ids_0: List[int],
204
+ token_ids_1: Optional[List[int]] = None
205
+ ) -> List[int]:
206
+ """
207
+ Build model inputs from a sequence or a pair of sequences for sequence classification tasks by concatenating
208
+ and adding special tokens.
209
+
210
+ An IQuestCoder sequence has the following format:
211
+
212
+ - single sequence: `<s> X </s>` (if add_eos_token is True) or `<s> X` (default)
213
+ - pair of sequences: `<s> A </s> <s> B </s>` (if add_eos_token is True) or `<s> A <s> B` (default)
214
+
215
+ Args:
216
+ token_ids_0 (`List[int]`):
217
+ List of IDs to which the special tokens will be added.
218
+ token_ids_1 (`List[int]`, *optional*):
219
+ Optional second list of IDs for sequence pairs.
220
+
221
+ Returns:
222
+ `List[int]`: List of input IDs with the appropriate special tokens.
223
+ """
224
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
225
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
226
+
227
+ output = bos_token_id + token_ids_0 + eos_token_id
228
+
229
+ if token_ids_1 is not None:
230
+ output = output + bos_token_id + token_ids_1 + eos_token_id
231
+
232
+ return output
233
+
234
+ def get_special_tokens_mask(
235
+ self,
236
+ token_ids_0: List[int],
237
+ token_ids_1: Optional[List[int]] = None,
238
+ already_has_special_tokens: bool = False
239
+ ) -> List[int]:
240
+ """
241
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
242
+ special tokens using the tokenizer `prepare_for_model` method.
243
+
244
+ Args:
245
+ token_ids_0 (`List[int]`):
246
+ List of IDs.
247
+ token_ids_1 (`List[int]`, *optional*):
248
+ Optional second list of IDs for sequence pairs.
249
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
250
+ Whether or not the token list is already formatted with special tokens for the model.
251
+
252
+ Returns:
253
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
254
+ """
255
+ if already_has_special_tokens:
256
+ return super().get_special_tokens_mask(
257
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
258
+ )
259
+
260
+ bos_token_id = [1] if self.add_bos_token else []
261
+ eos_token_id = [1] if self.add_eos_token else []
262
+
263
+ if token_ids_1 is None:
264
+ return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id
265
+ return (
266
+ bos_token_id
267
+ + ([0] * len(token_ids_0))
268
+ + eos_token_id
269
+ + bos_token_id
270
+ + ([0] * len(token_ids_1))
271
+ + eos_token_id
272
+ )
273
+
274
+ def create_token_type_ids_from_sequences(
275
+ self,
276
+ token_ids_0: List[int],
277
+ token_ids_1: Optional[List[int]] = None
278
+ ) -> List[int]:
279
+ """
280
+ Create a mask from the two sequences passed to be used in a sequence-pair classification task.
281
+
282
+ An IQuestCoder sequence pair mask has the following format:
283
+
284
+ ```
285
+ 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
286
+ | first sequence | second sequence |
287
+ ```
288
+
289
+ If `token_ids_1` is `None`, this method only returns the first portion of the mask (0s).
290
+
291
+ Args:
292
+ token_ids_0 (`List[int]`):
293
+ List of IDs.
294
+ token_ids_1 (`List[int]`, *optional*):
295
+ Optional second list of IDs for sequence pairs.
296
+
297
+ Returns:
298
+ `List[int]`: List of token type IDs according to the given sequence(s).
299
+ """
300
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
301
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
302
+
303
+ output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
304
+
305
+ if token_ids_1 is not None:
306
+ output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
307
+
308
+ return output
309
+
310
+ @property
311
+ def default_chat_template(self) -> str:
312
+ """
313
+ Returns the default chat template for IQuestCoder.
314
+
315
+ This template formats conversations with system, user, and assistant roles.
316
+ """
317
+ return DEFAULT_CHAT_TEMPLATE
318
+
319
+ def apply_chat_template(
320
+ self,
321
+ conversation: Union[List[Dict[str, str]], "Conversation"],
322
+ chat_template: Optional[str] = None,
323
+ add_generation_prompt: bool = False,
324
+ tokenize: bool = True,
325
+ padding: bool = False,
326
+ truncation: bool = False,
327
+ max_length: Optional[int] = None,
328
+ return_tensors: Optional[str] = None,
329
+ return_dict: bool = False,
330
+ **tokenizer_kwargs,
331
+ ):
332
+ """
333
+ Apply a chat template to format a conversation.
334
+
335
+ Args:
336
+ conversation (`List[Dict[str, str]]` or `Conversation`):
337
+ A list of dicts with "role" and "content" keys, representing the conversation history.
338
+ chat_template (`str`, *optional*):
339
+ A Jinja template to use for formatting. If not provided, the tokenizer's default will be used.
340
+ add_generation_prompt (`bool`, *optional*, defaults to `False`):
341
+ Whether to add a generation prompt at the end for the assistant to continue.
342
+ tokenize (`bool`, *optional*, defaults to `True`):
343
+ Whether to tokenize the output. If `False`, returns a string.
344
+ padding (`bool`, *optional*, defaults to `False`):
345
+ Whether to pad sequences.
346
+ truncation (`bool`, *optional*, defaults to `False`):
347
+ Whether to truncate sequences.
348
+ max_length (`int`, *optional*):
349
+ Maximum length of the output.
350
+ return_tensors (`str`, *optional*):
351
+ The type of tensors to return ("pt", "tf", "np", or None).
352
+ return_dict (`bool`, *optional*, defaults to `False`):
353
+ Whether to return a dictionary with additional information.
354
+ **tokenizer_kwargs:
355
+ Additional keyword arguments passed to the tokenizer.
356
+
357
+ Returns:
358
+ `Union[str, List[int], BatchEncoding]`: The formatted (and optionally tokenized) conversation.
359
+
360
+ Example:
361
+ ```python
362
+ >>> tokenizer = IQuestCoderTokenizer.from_pretrained("path/to/model")
363
+ >>> conversation = [
364
+ ... {"role": "system", "content": "You are a helpful assistant."},
365
+ ... {"role": "user", "content": "Hello!"},
366
+ ... {"role": "assistant", "content": "Hi there! How can I help you today?"},
367
+ ... {"role": "user", "content": "What's the weather like?"},
368
+ ... ]
369
+ >>> tokenizer.apply_chat_template(conversation, add_generation_prompt=True, tokenize=False)
370
+ '<|system|>\\nYou are a helpful assistant.\\n</|system|><|user|>\\nHello!\\n</|user|>...'
371
+ ```
372
+ """
373
+ # Use parent class implementation with our template
374
+ return super().apply_chat_template(
375
+ conversation,
376
+ chat_template=chat_template,
377
+ add_generation_prompt=add_generation_prompt,
378
+ tokenize=tokenize,
379
+ padding=padding,
380
+ truncation=truncation,
381
+ max_length=max_length,
382
+ return_tensors=return_tensors,
383
+ return_dict=return_dict,
384
+ **tokenizer_kwargs,
385
+ )
386
+
387
+
388
+ # Try to import and create Fast tokenizer version
389
+ try:
390
+ from transformers import PreTrainedTokenizerFast
391
+ from tokenizers import Tokenizer, decoders, models, normalizers, pre_tokenizers, processors
392
+
393
+ class IQuestCoderTokenizerFast(PreTrainedTokenizerFast):
394
+ """
395
+ Construct a "fast" IQuestCoder tokenizer (backed by HuggingFace's *tokenizers* library).
396
+
397
+ This is a fast implementation of [`IQuestCoderTokenizer`] using the 🤗 Tokenizers library.
398
+
399
+ Args:
400
+ vocab_file (`str`, *optional*):
401
+ Path to the vocabulary file (SentencePiece model).
402
+ tokenizer_file (`str`, *optional*):
403
+ Path to a tokenizer JSON file.
404
+ unk_token (`str`, *optional*, defaults to `"<unk>"`):
405
+ The unknown token.
406
+ bos_token (`str`, *optional*, defaults to `"<s>"`):
407
+ The beginning of sequence token.
408
+ eos_token (`str`, *optional*, defaults to `"</s>"`):
409
+ The end of sequence token.
410
+ pad_token (`str`, *optional*):
411
+ The token used for padding.
412
+ add_bos_token (`bool`, *optional*, defaults to `True`):
413
+ Whether to add a BOS token at the start of sequences.
414
+ add_eos_token (`bool`, *optional*, defaults to `False`):
415
+ Whether to add an EOS token at the end of sequences.
416
+ add_prefix_space (`bool`, *optional*, defaults to `False`):
417
+ Whether to add an initial space to the input.
418
+ use_default_system_prompt (`bool`, *optional*, defaults to `False`):
419
+ Whether to use the default system prompt.
420
+ chat_template (`str`, *optional*):
421
+ A Jinja template for formatting conversations.
422
+
423
+ Example:
424
+ ```python
425
+ >>> from tokenization_iquestcoder import IQuestCoderTokenizerFast
426
+
427
+ >>> tokenizer = IQuestCoderTokenizerFast.from_pretrained("path/to/model")
428
+ >>> tokenizer.encode("Hello, world!")
429
+ [1, 15043, 29892, 3186, 29991]
430
+ ```
431
+ """
432
+
433
+ vocab_files_names = VOCAB_FILES_NAMES
434
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
435
+ max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
436
+ model_input_names = ["input_ids", "attention_mask"]
437
+ slow_tokenizer_class = IQuestCoderTokenizer
438
+
439
+ def __init__(
440
+ self,
441
+ vocab_file=None,
442
+ tokenizer_file=None,
443
+ unk_token="<unk>",
444
+ bos_token="<s>",
445
+ eos_token="</s>",
446
+ pad_token=None,
447
+ add_bos_token=True,
448
+ add_eos_token=False,
449
+ add_prefix_space=False,
450
+ use_default_system_prompt=False,
451
+ chat_template=None,
452
+ **kwargs,
453
+ ):
454
+ self.add_bos_token = add_bos_token
455
+ self.add_eos_token = add_eos_token
456
+ self.add_prefix_space = add_prefix_space
457
+ self.use_default_system_prompt = use_default_system_prompt
458
+
459
+ if chat_template is None:
460
+ chat_template = DEFAULT_CHAT_TEMPLATE
461
+
462
+ super().__init__(
463
+ vocab_file=vocab_file,
464
+ tokenizer_file=tokenizer_file,
465
+ unk_token=unk_token,
466
+ bos_token=bos_token,
467
+ eos_token=eos_token,
468
+ pad_token=pad_token,
469
+ add_bos_token=add_bos_token,
470
+ add_eos_token=add_eos_token,
471
+ add_prefix_space=add_prefix_space,
472
+ use_default_system_prompt=use_default_system_prompt,
473
+ chat_template=chat_template,
474
+ **kwargs,
475
+ )
476
+
477
+ @property
478
+ def can_save_slow_tokenizer(self) -> bool:
479
+ return os.path.isfile(self.vocab_file) if self.vocab_file else False
480
+
481
+ @property
482
+ def default_chat_template(self) -> str:
483
+ """Returns the default chat template."""
484
+ return DEFAULT_CHAT_TEMPLATE
485
+
486
+ def build_inputs_with_special_tokens(
487
+ self,
488
+ token_ids_0: List[int],
489
+ token_ids_1: Optional[List[int]] = None
490
+ ) -> List[int]:
491
+ """Build model inputs with special tokens."""
492
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
493
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
494
+
495
+ output = bos_token_id + token_ids_0 + eos_token_id
496
+
497
+ if token_ids_1 is not None:
498
+ output = output + bos_token_id + token_ids_1 + eos_token_id
499
+
500
+ return output
501
+
502
+ def get_special_tokens_mask(
503
+ self,
504
+ token_ids_0: List[int],
505
+ token_ids_1: Optional[List[int]] = None,
506
+ already_has_special_tokens: bool = False
507
+ ) -> List[int]:
508
+ """Retrieve special tokens mask."""
509
+ if already_has_special_tokens:
510
+ return super().get_special_tokens_mask(
511
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
512
+ )
513
+
514
+ bos_token_id = [1] if self.add_bos_token else []
515
+ eos_token_id = [1] if self.add_eos_token else []
516
+
517
+ if token_ids_1 is None:
518
+ return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id
519
+ return (
520
+ bos_token_id
521
+ + ([0] * len(token_ids_0))
522
+ + eos_token_id
523
+ + bos_token_id
524
+ + ([0] * len(token_ids_1))
525
+ + eos_token_id
526
+ )
527
+
528
+ def create_token_type_ids_from_sequences(
529
+ self,
530
+ token_ids_0: List[int],
531
+ token_ids_1: Optional[List[int]] = None
532
+ ) -> List[int]:
533
+ """Create token type IDs from sequences."""
534
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
535
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
536
+
537
+ output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
538
+
539
+ if token_ids_1 is not None:
540
+ output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
541
+
542
+ return output
543
+
544
+ except ImportError:
545
+ # tokenizers library not available, Fast tokenizer not supported
546
+ IQuestCoderTokenizerFast = None
547
+ logger.info(
548
+ "The `tokenizers` library is not installed. "
549
+ "IQuestCoderTokenizerFast will not be available. "
550
+ "Install it with `pip install tokenizers`."
551
+ )
552
+
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d3be68e090a927f31e0e378d7599b15c206dd47e4a73933775a746cc9c1cd91
3
+ size 1345108
tokenizer_config.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
+ "0": {
6
+ "content": "<unk>",
7
+ "lstrip": false,
8
+ "normalized": true,
9
+ "rstrip": false,
10
+ "single_word": true,
11
+ "special": true
12
+ },
13
+ "1": {
14
+ "content": "<s>",
15
+ "lstrip": false,
16
+ "normalized": true,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "2": {
22
+ "content": "</s>",
23
+ "lstrip": false,
24
+ "normalized": true,
25
+ "rstrip": false,
26
+ "single_word": true,
27
+ "special": true
28
+ },
29
+ "75858": {
30
+ "content": "<CLS>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "75859": {
38
+ "content": "<SEP>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "75860": {
46
+ "content": "<EOD>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "75861": {
54
+ "content": "<MASK>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "75862": {
62
+ "content": "<PAD>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "75863": {
70
+ "content": "<|im_start|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "75864": {
78
+ "content": "<|im_end|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "75865": {
86
+ "content": "<|fim_prefix|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "75866": {
94
+ "content": "<|fim_middle|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "75867": {
102
+ "content": "<|fim_suffix|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "75868": {
110
+ "content": "<|fim_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "75869": {
118
+ "content": "<|endoftext|>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": true
124
+ },
125
+ "75870": {
126
+ "content": "<|repo_name|>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": true
132
+ },
133
+ "75871": {
134
+ "content": "<|file_sep|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": true
140
+ },
141
+ "75872": {
142
+ "content": "<think>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "75873": {
150
+ "content": "</think>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "75874": {
158
+ "content": "<tools>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "75875": {
166
+ "content": "</tools>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "75876": {
174
+ "content": "<tool_call>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "75877": {
182
+ "content": "</tool_call>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "75878": {
190
+ "content": "<tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "75879": {
198
+ "content": "</tool_response>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ }
205
+ },
206
+ "additional_special_tokens": [
207
+ "<|CLS|>",
208
+ "<|SEP|>",
209
+ "<|EOD|>",
210
+ "<|MASK|>",
211
+ "<|PAD|>",
212
+ "<|fim_prefix|>",
213
+ "<|fim_middle|>",
214
+ "<|fim_suffix|>",
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|fim_pad|>",
218
+ "<|endoftext|>",
219
+ "<|repo_name|>",
220
+ "<|file_sep|>"
221
+ ],
222
+ "auto_map": {
223
+ "AutoTokenizer": [
224
+ "tokenization_iquestcoder.IQuestCoderTokenizer",
225
+ null
226
+ ]
227
+ },
228
+ "bos_token": "<s>",
229
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- else %}\n {{- 'You are IndustrialCoder, a helpful assistant developed by Beihang University.' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {%- if tool.type == 'function' and tool.function %}\n {%- set func = tool.function %}\n {%- else %}\n {%- set func = tool %}\n {%- endif %}\n {{- \"\\n<function>\\n<name>\" + func.name + \"</name>\" }}\n {%- if func.description %}\n {{- \"\\n<description>\" + func.description + \"</description>\" }}\n {%- endif %}\n {{- \"\\n<parameters>\" }}\n {%- if func.parameters and func.parameters.properties %}\n {%- for param_name, param_fields in func.parameters.properties.items() %}\n {{- \"\\n<parameter>\" }}\n {{- \"\\n<name>\" + param_name + \"</name>\" }}\n {%- if param_fields.type %}\n {{- \"\\n<type>\" + param_fields.type + \"</type>\" }}\n {%- endif %}\n {%- if param_fields.description %}\n {{- \"\\n<description>\" + param_fields.description + \"</description>\" }}\n {%- endif %}\n {{- \"\\n</parameter>\" }}\n {%- endfor %}\n {%- endif %}\n {{- \"\\n</parameters>\\n</function>\" }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nIf you choose to call a function ONLY reply in the following format:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n</function>\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are IndustrialCoder, a helpful assistant developed by Beihang University.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set content = message.content %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tc = tool_call.function %}\n {%- else %}\n {%- set tc = tool_call %}\n {%- endif %}\n {{- '<tool_call>\\n<function=' + tc.name + '>\\n' }}\n {%- if tc.arguments is string %}\n {%- set args = tc.arguments | fromjson %}\n {%- else %}\n {%- set args = tc.arguments %}\n {%- endif %}\n {%- for arg_name, arg_value in args.items() %}\n {{- '<parameter=' + arg_name + '>\\n' }}\n {%- if arg_value is string %}\n {{- arg_value }}\n {%- else %}\n {{- arg_value | tojson }}\n {%- endif %}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}",
230
+ "clean_up_tokenization_spaces": false,
231
+ "eos_token": "<|im_end|>",
232
+ "model_max_length": 131072,
233
+ "pad_token": "<|endoftext|>",
234
+ "padding_side": "right",
235
+ "sp_model_kwargs": {},
236
+ "split_special_tokens": false,
237
+ "tokenizer_class": "IQuestCoderTokenizer",
238
+ "unk_token": "<unk>",
239
+ "use_fast": false
240
+ }