chenzongchao commited on
Commit
5953bfe
·
verified ·
1 Parent(s): d5ddbf2

Upload 9 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
added_tokens.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</think>": 166104,
3
+ "</tool_call>": 166106,
4
+ "<think>": 166103,
5
+ "<tool_call>": 166105,
6
+ "<|endoftext|>": 166102,
7
+ "<|im_end|>": 166101,
8
+ "<|im_start|>": 166100
9
+ }
config.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "NanbeigeForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_nanbeige.NanbeigeConfig",
9
+ "AutoModel": "modeling_nanbeige.NanbeigeModel",
10
+ "AutoModelForCausalLM": "modeling_nanbeige.NanbeigeForCausalLM"
11
+ },
12
+ "bos_token_id": 166100,
13
+ "eos_token_id": 166101,
14
+ "head_dim": 128,
15
+ "hidden_act": "silu",
16
+ "hidden_size": 3072,
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 10752,
19
+ "kv_channels": 128,
20
+ "loop_loss_weights": [],
21
+ "max_length": null,
22
+ "max_position_embeddings": 262144,
23
+ "model_type": "nanbeige",
24
+ "num_attention_heads": 48,
25
+ "num_hidden_layers": 22,
26
+ "num_key_value_heads": 8,
27
+ "num_loops": 2,
28
+ "pad_token_id": 0,
29
+ "pretraining_tp": 1,
30
+ "rms_norm_eps": 1e-05,
31
+ "rope_scaling": null,
32
+ "rope_theta": 70000000,
33
+ "skip_loop_final_norm": false,
34
+ "tie_word_embeddings": false,
35
+ "torch_dtype": "bfloat16",
36
+ "transformers_version": "4.42.4",
37
+ "use_cache": false,
38
+ "vocab_size": 166144
39
+ }
configuration_nanbeige.py ADDED
@@ -0,0 +1,364 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Licensed under the Apache License, Version 2.0 (the "License");
3
+ # you may not use this file except in compliance with the License.
4
+ # You may obtain a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS,
10
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ # See the License for the specific language governing permissions and
12
+ # limitations under the License.
13
+ """Nanbeige model configuration."""
14
+
15
+ from transformers.configuration_utils import PretrainedConfig
16
+ from transformers.utils import logging
17
+
18
+
19
+ logger = logging.get_logger(__name__)
20
+
21
+
22
+ class NanbeigeConfig(PretrainedConfig):
23
+ r"""
24
+ This is the configuration class to store the configuration of a [`NanbeigeModel`]. It is used to instantiate an LLaMA
25
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
26
+ defaults will yield a similar configuration to that of the LLaMA-7B.
27
+
28
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
29
+ documentation from [`PretrainedConfig`] for more information.
30
+
31
+
32
+ Args:
33
+ vocab_size (`int`, *optional*, defaults to 32000):
34
+ Vocabulary size of the LLaMA model. Defines the number of different tokens that can be represented by the
35
+ `inputs_ids` passed when calling [`NanbeigeModel`]
36
+ hidden_size (`int`, *optional*, defaults to 4096):
37
+ Dimension of the hidden representations.
38
+ intermediate_size (`int`, *optional*, defaults to 11008):
39
+ Dimension of the MLP representations.
40
+ num_hidden_layers (`int`, *optional*, defaults to 32):
41
+ Number of hidden layers in the Transformer decoder.
42
+ num_attention_heads (`int`, *optional*, defaults to 32):
43
+ Number of attention heads for each attention layer in the Transformer decoder.
44
+ head_dim (`int`, *optional*):
45
+ Dimension of each attention head. If unset, defaults to `hidden_size // num_attention_heads`.
46
+ num_key_value_heads (`int`, *optional*):
47
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
48
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
49
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
50
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
51
+ by meanpooling all the original heads within that group. For more details checkout [this
52
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
53
+ `num_attention_heads`.
54
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
55
+ The non-linear activation function (function or string) in the decoder.
56
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
57
+ The maximum sequence length that this model might ever be used with. Nanbeige 1 supports up to 2048 tokens,
58
+ Nanbeige 2 up to 4096, CodeNanbeige up to 16384.
59
+ initializer_range (`float`, *optional*, defaults to 0.02):
60
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
61
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
62
+ The epsilon used by the rms normalization layers.
63
+ use_cache (`bool`, *optional*, defaults to `True`):
64
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
65
+ relevant if `config.is_decoder=True`.
66
+ pad_token_id (`int`, *optional*):
67
+ Padding token id.
68
+ bos_token_id (`int`, *optional*, defaults to 1):
69
+ Beginning of stream token id.
70
+ eos_token_id (`int`, *optional*, defaults to 2):
71
+ End of stream token id.
72
+ pretraining_tp (`int`, *optional*, defaults to 1):
73
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
74
+ document](https://huggingface.co/docs/transformers/main/perf_train_gpu_many#tensor-parallelism) to understand more about it. This value is
75
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
76
+ issue](https://github.com/pytorch/pytorch/issues/76232).
77
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
78
+ Whether to tie weight embeddings
79
+ rope_theta (`float`, *optional*, defaults to 10000.0):
80
+ The base period of the RoPE embeddings.
81
+ rope_scaling (`Dict`, *optional*):
82
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
83
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
84
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
85
+ `max_position_embeddings` to the expected new maximum. See the following thread for more information on how
86
+ these scaling strategies behave:
87
+ https://www.reddit.com/r/LocalLLaMA/comments/14mrgpr/dynamically_scaled_rope_further_increases/. This is an
88
+ experimental feature, subject to breaking API changes in future versions.
89
+ attention_bias (`bool`, *optional*, defaults to `False`):
90
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
91
+ attention_dropout (`float`, *optional*, defaults to 0.0):
92
+ The dropout ratio for the attention probabilities.
93
+ mlp_bias (`bool`, *optional*, defaults to `False`):
94
+ Whether to use a bias in up_proj, down_proj and gate_proj layers in the MLP layers.
95
+ qk_layernorm (`bool`, *optional*, defaults to `False`):
96
+ Whether to use LayerNorm on query and key states before applying attention.
97
+ emb_neighbor_num (`int`, *optional*):
98
+ Maximum N-gram length for N-gram embeddings. This parameter determines the context window size for N-gram computation. Higher values capture
99
+ longer-range lexical patterns but increase memory usage. If None, N-gram embeddings are disabled.
100
+ emb_split_num (`int`, *optional*):
101
+ Number of hash functions (or splits) to use for N-gram embeddings. Multiple hash functions help improve the quality of N-gram representations.
102
+ Required if emb_neighbor_num is set.
103
+ ngram_vocab_size_ratio (`float`, *optional*):
104
+ Ratio multiplier for N-gram vocabulary size relative to the base vocabulary size. The N-gram vocabulary
105
+ size is calculated as `vocab_size * ngram_vocab_size_ratio`. Required if emb_neighbor_num is set.
106
+ ngram_mod_force_prime (`bool`, *optional*, defaults to `False`):
107
+ Whether to use consecutive prime numbers greater than the N-gram base vocabulary size as hash modulo
108
+ dimensions for N-gram subtables, and the first prime greater than vocab_size as the N-gram hash base.
109
+ ngram_embedding_hidden_size (`int`, *optional*):
110
+ Total hidden size used to split N-gram embedding table dimensions. If None, uses `hidden_size`.
111
+ ngram_fused_mode (`str`, *optional*, defaults to `"average"`):
112
+ How N-gram embeddings are fused into token embeddings. `"average"` preserves the existing per-table
113
+ projector and averaging behavior. `"concat"` concatenates raw N-gram table embeddings, projects once to
114
+ `hidden_size`, and adds the projected N-gram embedding to the token embedding.
115
+ emb_tp_num (`int`, *optional*):
116
+ Tensor parallel padding multiplier for N-gram embeddings. The N-gram embedding vocabulary size is padded
117
+ to the nearest multiple of emb_tp_num. This ensures compatibility with tensor parallel training in Megatron.
118
+ Required if emb_neighbor_num is set.
119
+ ngram_compressed_tokenizer (`bool`, *optional*, defaults to `False`):
120
+ Whether to use compressed tokenizer for N-gram computation. When enabled, the model's tokenizer is used to
121
+ construct a compressed tokenizer similar to the one in engram_demo_v1.py, which normalizes and deduplicates
122
+ tokens before computing N-gram hashes.
123
+ skip_ngram_for_input (`bool`, *optional*, defaults to `False`):
124
+ Whether to skip adding N-gram embeddings to the input embedding.
125
+ insert_ngram_layer_idx (`List[int]`, *optional*):
126
+ 0-based decoder layer indices where averaged N-gram embeddings are fused before attention.
127
+ ngram_insert_all_layers (`bool`, *optional*, defaults to `False`):
128
+ Whether to fuse averaged N-gram embeddings before attention in every decoder layer.
129
+ ngram_layer_downproject_size (`int`, *optional*):
130
+ Optional hidden size for N-gram layer fusion projections. If None, fusion uses `hidden_size`.
131
+
132
+ ```python
133
+ >>> from transformers import NanbeigeModel, NanbeigeConfig
134
+
135
+ >>> # Initializing a LLaMA llama-7b style configuration
136
+ >>> configuration = NanbeigeConfig()
137
+
138
+ >>> # Initializing a model from the llama-7b style configuration
139
+ >>> model = NanbeigeModel(configuration)
140
+
141
+ >>> # Accessing the model configuration
142
+ >>> configuration = model.config
143
+ ```"""
144
+
145
+ model_type = "nanbeige"
146
+ keys_to_ignore_at_inference = ["past_key_values"]
147
+
148
+ def __init__(
149
+ self,
150
+ vocab_size=32000,
151
+ hidden_size=4096,
152
+ intermediate_size=11008,
153
+ num_hidden_layers=32,
154
+ num_attention_heads=32,
155
+ num_key_value_heads=None,
156
+ head_dim=None,
157
+ hidden_act="silu",
158
+ max_position_embeddings=2048,
159
+ initializer_range=0.02,
160
+ rms_norm_eps=1e-6,
161
+ use_cache=True,
162
+ pad_token_id=None,
163
+ bos_token_id=1,
164
+ eos_token_id=2,
165
+ pretraining_tp=1,
166
+ tie_word_embeddings=False,
167
+ rope_theta=10000.0,
168
+ rope_scaling=None,
169
+ attention_bias=False,
170
+ attention_dropout=0.0,
171
+ mlp_bias=False,
172
+ qk_layernorm=False,
173
+ emb_neighbor_num=None,
174
+ emb_split_num=None,
175
+ ngram_vocab_size_ratio=None,
176
+ ngram_mod_force_prime=False,
177
+ ngram_embedding_hidden_size=None,
178
+ ngram_fused_mode="average",
179
+ emb_tp_num=None,
180
+ ngram_compressed_tokenizer=False,
181
+ skip_ngram_for_input=False,
182
+ insert_ngram_layer_idx=None,
183
+ ngram_insert_all_layers=False,
184
+ ngram_layer_downproject_size=None,
185
+ num_loops=1,
186
+ loop_loss_weights=None,
187
+ skip_loop_final_norm=False,
188
+ enable_double_loop_split=False,
189
+ loop_middle_layers=None,
190
+ loop_share_kv=False,
191
+ mhc_diff_for_loop=False,
192
+ mhc_double_stream_position_for_loop=None,
193
+ enable_hyper_connection=False,
194
+ enable_mhc=False,
195
+ enable_h_res_identity=False,
196
+ mhc_identity_nohresparam=False,
197
+ num_residual_streams=4,
198
+ mhc_sinkhorn_iterations=20,
199
+ mhc_init_gating_factor=0.01,
200
+ enable_depth_attention=False,
201
+ depth_attention_stride=None,
202
+ depth_attention_recent_window=0,
203
+ depth_attention_static_anchor_once=True,
204
+ **kwargs,
205
+ ):
206
+ self.vocab_size = vocab_size
207
+ self.max_position_embeddings = max_position_embeddings
208
+ self.hidden_size = hidden_size
209
+ self.intermediate_size = intermediate_size
210
+ self.num_hidden_layers = num_hidden_layers
211
+ self.num_attention_heads = num_attention_heads
212
+ self.head_dim = head_dim if head_dim is not None else hidden_size // num_attention_heads
213
+
214
+ # for backward compatibility
215
+ if num_key_value_heads is None:
216
+ num_key_value_heads = num_attention_heads
217
+
218
+ self.num_key_value_heads = num_key_value_heads
219
+ self.hidden_act = hidden_act
220
+ self.initializer_range = initializer_range
221
+ self.rms_norm_eps = rms_norm_eps
222
+ self.pretraining_tp = pretraining_tp
223
+ self.use_cache = use_cache
224
+ self.rope_theta = rope_theta
225
+ self.rope_scaling = rope_scaling
226
+ self._rope_scaling_validation()
227
+ self.attention_bias = attention_bias
228
+ self.attention_dropout = attention_dropout
229
+ self.mlp_bias = mlp_bias
230
+ self.qk_layernorm = qk_layernorm
231
+ self.emb_neighbor_num = emb_neighbor_num
232
+ self.emb_split_num = emb_split_num
233
+ self.ngram_vocab_size_ratio = ngram_vocab_size_ratio
234
+ self.ngram_mod_force_prime = ngram_mod_force_prime
235
+ self.ngram_embedding_hidden_size = ngram_embedding_hidden_size
236
+ self.ngram_fused_mode = ngram_fused_mode
237
+ self.emb_tp_num = emb_tp_num
238
+ self.ngram_compressed_tokenizer = ngram_compressed_tokenizer
239
+ self.skip_ngram_for_input = skip_ngram_for_input
240
+ self.insert_ngram_layer_idx = insert_ngram_layer_idx if insert_ngram_layer_idx is not None else []
241
+ self.ngram_insert_all_layers = ngram_insert_all_layers
242
+ self.ngram_layer_downproject_size = ngram_layer_downproject_size
243
+ self.num_loops = num_loops
244
+ self.loop_loss_weights = loop_loss_weights if loop_loss_weights is not None else []
245
+ self.skip_loop_final_norm = skip_loop_final_norm
246
+ self.enable_double_loop_split = enable_double_loop_split
247
+ self.loop_middle_layers = loop_middle_layers
248
+ self.loop_share_kv = loop_share_kv
249
+ self.mhc_diff_for_loop = mhc_diff_for_loop
250
+ self.mhc_double_stream_position_for_loop = mhc_double_stream_position_for_loop
251
+ self.enable_hyper_connection = enable_hyper_connection
252
+ self.enable_mhc = enable_mhc
253
+ self.enable_h_res_identity = enable_h_res_identity
254
+ self.mhc_identity_nohresparam = mhc_identity_nohresparam
255
+ self.num_residual_streams = num_residual_streams
256
+ self.mhc_sinkhorn_iterations = mhc_sinkhorn_iterations
257
+ self.mhc_init_gating_factor = mhc_init_gating_factor
258
+ self.enable_depth_attention = enable_depth_attention
259
+ self.depth_attention_stride = depth_attention_stride
260
+ self.depth_attention_recent_window = depth_attention_recent_window
261
+ self.depth_attention_static_anchor_once = depth_attention_static_anchor_once
262
+ self._hyper_connection_validation()
263
+
264
+ super().__init__(
265
+ pad_token_id=pad_token_id,
266
+ bos_token_id=bos_token_id,
267
+ eos_token_id=eos_token_id,
268
+ tie_word_embeddings=tie_word_embeddings,
269
+ **kwargs,
270
+ )
271
+
272
+ def _rope_scaling_validation(self):
273
+ """
274
+ Validate the `rope_scaling` configuration.
275
+ """
276
+ if self.rope_scaling is None:
277
+ return
278
+
279
+ if not isinstance(self.rope_scaling, dict) or len(self.rope_scaling) != 2:
280
+ raise ValueError(
281
+ "`rope_scaling` must be a dictionary with two fields, `type` and `factor`, " f"got {self.rope_scaling}"
282
+ )
283
+ rope_scaling_type = self.rope_scaling.get("type", None)
284
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
285
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic"]:
286
+ raise ValueError(
287
+ f"`rope_scaling`'s type field must be one of ['linear', 'dynamic'], got {rope_scaling_type}"
288
+ )
289
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
290
+ raise ValueError(f"`rope_scaling`'s factor field must be a float > 1, got {rope_scaling_factor}")
291
+
292
+ def _hyper_connection_validation(self):
293
+ if self.mhc_diff_for_loop and not self.enable_double_loop_split:
294
+ raise ValueError("mhc_diff_for_loop requires enable_double_loop_split=True.")
295
+ if self.mhc_diff_for_loop and not self.enable_mhc:
296
+ raise ValueError("mhc_diff_for_loop requires enable_mhc=True.")
297
+ if self.loop_share_kv and not self.enable_double_loop_split:
298
+ raise ValueError("loop_share_kv requires enable_double_loop_split=True.")
299
+ if self.enable_depth_attention:
300
+ if self.num_hidden_layers <= 0:
301
+ raise ValueError("enable_depth_attention requires num_hidden_layers to be greater than 0.")
302
+ if self.depth_attention_stride is None:
303
+ self.depth_attention_stride = self.num_hidden_layers // 2
304
+ if self.depth_attention_stride <= 0:
305
+ raise ValueError("depth_attention_stride must be greater than 0.")
306
+ if self.depth_attention_recent_window < 0:
307
+ raise ValueError("depth_attention_recent_window must be >= 0.")
308
+ if self.depth_attention_recent_window != 0:
309
+ raise ValueError("anchor-only Depth-Attention requires depth_attention_recent_window == 0.")
310
+ if self.enable_double_loop_split and not self.depth_attention_static_anchor_once:
311
+ raise ValueError(
312
+ "enable_depth_attention with double-loop split requires "
313
+ "depth_attention_static_anchor_once=True."
314
+ )
315
+ if self.mhc_double_stream_position_for_loop is not None:
316
+ if self.mhc_double_stream_position_for_loop not in ("mid", "edge"):
317
+ raise ValueError("mhc_double_stream_position_for_loop must be one of: mid, edge.")
318
+ if not self.enable_double_loop_split:
319
+ raise ValueError(
320
+ "mhc_double_stream_position_for_loop requires enable_double_loop_split=True."
321
+ )
322
+ if (self.enable_mhc or self.enable_h_res_identity) and not self.enable_hyper_connection:
323
+ raise ValueError(
324
+ "enable_mhc/enable_h_res_identity require enable_hyper_connection=True."
325
+ )
326
+ if self.mhc_identity_nohresparam:
327
+ if not self.enable_h_res_identity:
328
+ raise ValueError("mhc_identity_nohresparam requires enable_h_res_identity=True.")
329
+ if not self.enable_mhc:
330
+ raise ValueError("mhc_identity_nohresparam requires enable_mhc=True.")
331
+ if self.enable_hyper_connection and self.num_residual_streams < 2:
332
+ raise ValueError("num_residual_streams must be >= 2 when enable_hyper_connection=True.")
333
+ if self.enable_mhc and self.mhc_sinkhorn_iterations < 1:
334
+ raise ValueError("mhc_sinkhorn_iterations must be >= 1 when enable_mhc=True.")
335
+ if self.ngram_insert_all_layers and self.insert_ngram_layer_idx:
336
+ raise ValueError("ngram_insert_all_layers cannot be used with insert_ngram_layer_idx.")
337
+ if self.ngram_layer_downproject_size is not None and self.ngram_layer_downproject_size <= 0:
338
+ raise ValueError("ngram_layer_downproject_size must be greater than 0 when set.")
339
+ if self.ngram_embedding_hidden_size is not None and self.ngram_embedding_hidden_size <= 0:
340
+ raise ValueError("ngram_embedding_hidden_size must be greater than 0 when set.")
341
+ if self.ngram_fused_mode not in ("average", "concat"):
342
+ raise ValueError("ngram_fused_mode must be one of: average, concat.")
343
+ if (
344
+ not self.enable_double_loop_split
345
+ and self.loop_loss_weights is not None
346
+ and sum(self.loop_loss_weights) > 1.0
347
+ ):
348
+ raise ValueError("sum(loop_loss_weights) must be <= 1.0.")
349
+ if self.enable_double_loop_split and self.loop_middle_layers is None:
350
+ if self.num_hidden_layers <= 0:
351
+ raise ValueError("enable_double_loop_split requires num_hidden_layers to be greater than 0.")
352
+ if self.num_hidden_layers % 2 != 0:
353
+ raise ValueError(
354
+ "enable_double_loop_split requires num_hidden_layers to be divisible by 2 "
355
+ "when loop_middle_layers is not set."
356
+ )
357
+ self.loop_middle_layers = self.num_hidden_layers // 2
358
+ if self.loop_middle_layers is not None:
359
+ if self.num_hidden_layers <= 0:
360
+ raise ValueError("loop_middle_layers requires num_hidden_layers to be greater than 0.")
361
+ if self.loop_middle_layers <= 0:
362
+ raise ValueError("loop_middle_layers must be greater than 0.")
363
+ if self.num_hidden_layers % self.loop_middle_layers != 0:
364
+ raise ValueError("loop_middle_layers must be a factor of num_hidden_layers.")
generation_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 166100,
3
+ "do_sample": true,
4
+ "eos_token_id": 166101,
5
+ "pad_token_id": 0,
6
+ "temperature": 0.6,
7
+ "top_k": 20,
8
+ "top_p": 0.95,
9
+ "transformers_version": "4.51.0"
10
+ }
modeling_nanbeige.py ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|endoftext|>"
4
+ ],
5
+ "bos_token": {
6
+ "content": "<|im_start|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "eos_token": {
13
+ "content": "<|im_end|>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false
18
+ },
19
+ "pad_token": {
20
+ "content": "<unk>",
21
+ "lstrip": false,
22
+ "normalized": true,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": true,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d858a0fc007f22af6ae18bfa1ae52d30e398aa9cd1ea06e7777176869346a3f
3
+ size 18450979
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fb41d04798b714520a9b075727b0226538b7330254299062742c50ec8374bc36
3
+ size 2782298
tokenizer_config.json ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": true,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": true,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": true,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": true,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "166100": {
31
+ "content": "<|im_start|>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "166101": {
39
+ "content": "<|im_end|>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": false,
43
+ "single_word": false,
44
+ "special": true
45
+ },
46
+ "166102": {
47
+ "content": "<|endoftext|>",
48
+ "lstrip": false,
49
+ "normalized": false,
50
+ "rstrip": false,
51
+ "single_word": false,
52
+ "special": true
53
+ },
54
+ "166103": {
55
+ "content": "<think>",
56
+ "lstrip": false,
57
+ "normalized": true,
58
+ "rstrip": false,
59
+ "single_word": false,
60
+ "special": false
61
+ },
62
+ "166104": {
63
+ "content": "</think>",
64
+ "lstrip": false,
65
+ "normalized": true,
66
+ "rstrip": false,
67
+ "single_word": false,
68
+ "special": false
69
+ },
70
+ "166105": {
71
+ "content": "<tool_call>",
72
+ "lstrip": false,
73
+ "normalized": true,
74
+ "rstrip": false,
75
+ "single_word": false,
76
+ "special": false
77
+ },
78
+ "166106": {
79
+ "content": "</tool_call>",
80
+ "lstrip": false,
81
+ "normalized": true,
82
+ "rstrip": false,
83
+ "single_word": false,
84
+ "special": false
85
+ }
86
+ },
87
+ "additional_special_tokens": [
88
+ "<|endoftext|>"
89
+ ],
90
+ "bos_token": "<|im_start|>",
91
+ "chat_template": "\n\n{%- macro visible_text(content) -%}\n {%- if content is string -%}\n {{- content }}\n {%- elif content is iterable and content is not mapping -%}\n {%- for item in content -%}\n {%- if item is mapping and item.type == 'text' -%}\n {{- item.text }}\n {%- elif item is string -%}\n {{- item }}\n {%- elif item is mapping and item.type in ['image', 'image_url', 'video', 'video_url', 'audio', 'audio_url', 'input_audio'] -%}\n {%- set media_type = item.type | replace('_url', '') | replace('input_', '') -%}\n {{- \"<reminder>You are unable to process this \" ~ media_type ~ \" because you don't have multi-modal input ability. Try different methods.</reminder>\" }}\n {%- endif -%}\n {%- endfor -%}\n {%- else -%}\n {{- content }}\n {%- endif -%}\n{%- endmacro -%}\n\n\n{%- set tool_call_format = tool_call_format if tool_call_format is defined else 'xml' %}\n{%- if tools %}\n {{- '<|im_start|>system\\n' }} \n {%- if messages|length > 0 and messages[0].get('role', '') == 'system' %}\n {{- visible_text(messages[0].content) + '\\n\\n' }}\n {%- else %} \n {{- '你是一位工具函数调用专家,你会得到一个问题和一组可能的工具函数。根据问题,你需要进行一个或多个函数/工具调用以实现目的,请尽量尝试探索通过工具解决问题。\\n如果没有一个函数可以使用,请直接使用自然语言回复用户。\\n如果给定的问题缺少函数所需的参数,请使用自然语言进行提问,向用户询问必要信息。\\n如果调用结果已经足够回答用户问题,请对历史结果进行总结,使用自然语言回复用户。' }} \n {%- endif %}\n\n {{- \"# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n \n {%- if tool_call_format == 'json' %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n\" }}\n {{- '<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n' }}\n {%- else %}\n {{- \"\\n</tools>\\n\\nFor each function call, output the function name and arguments within the following XML format:\\n\" }}\n {{- '<tool_call>\n<function=example_function_name>\n<parameter=example_parameter_1>\nvalue_1\n</parameter>\n<parameter=example_parameter_2>\nThis is the value for the second parameter\nthat can span\nmultiple lines\n</parameter>\n</function>\n</tool_call><|im_end|>\\n' }}\n {%- endif %}\n \n{%- else %}\n {%- if messages|length > 0 and messages[0].get('role', '') == 'system' %}\n {{- '<|im_start|>system\\n' + visible_text(messages[0].content) + '<|im_end|>\\n' }}\n {%- else %} \n {{- '<|im_start|>system\\n你是南北阁,一款由BOSS直聘自主研发并训练的专业大语言模型。<|im_end|>\\n' }} \n {%- endif %}\n{%- endif %}\n\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.get('role', '') == \"user\" and visible_text(message.content) is string and not(visible_text(message.content).startswith('<tool_response>') and visible_text(message.content).endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n\n{%- for message in messages %}\n {%- if visible_text(message.content) is string %}\n {%- set content = visible_text(message.content) %}\n {%- else %}\n {%- set content = '' %}\n {%- endif %}\n \n {%- if message.get('role', '') == \"system\" %}\n {%- if not loop.first %}\n {{- raise_exception('System message must be at the beginning.') }}\n {%- endif %}\n \n {%- elif message.get('role', '') == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- set reasoning_content = reasoning_content|trim %}\n \n {%- if (preserve_thinking is defined and preserve_thinking is false) and (loop.index0 < ns.last_query_index) %}\n {{- '<|im_start|>' + message.get('role', '') + '\\n<think>\\n\\n</think>\\n\\n' + content }}\n {%- else %}\n {{- '<|im_start|>' + message.get('role', '') + '\\n<think>\\n' + reasoning_content + '\\n</think>\\n\\n' + content }}\n {%- endif %}\n \n {%- if message.tool_calls and message.tool_calls is iterable and message.tool_calls is not mapping %}\n {%- if tool_call_format == 'json' %}\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 tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- else %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n \n {%- if loop.first %}\n {%- if content|trim %}\n {{- '\n\n<tool_call>\n<function=' + tool_call.name + '>\n' }}\n {%- else %}\n {{- '<tool_call>\n<function=' + tool_call.name + '>\n' }}\n {%- endif %}\n {%- else %}\n {{- '\n<tool_call>\n<function=' + tool_call.name + '>\n' }}\n {%- endif %}\n \n {%- if tool_call.arguments is defined %}\n {%- for args_name, args_value in tool_call.arguments|items %}\n {{- '<parameter=' + args_name + '>\n' }}\n {%- set args_value = args_value | string if args_value is string else args_value | tojson | safe %}\n {{- args_value }}\n {{- '\n</parameter>\n' }}\n {%- endfor %}\n {%- endif %}\n {{- '</function>\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n \n {%- elif message.get('role', '') == \"tool\" %}\n {%- if loop.previtem and loop.previtem.get('role', '') != \"tool\" %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or loop.nextitem.get('role', '') != \"tool\" %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- elif message.get('role', '') != '' %}\n {{- '<|im_start|>' + message.get('role', '') + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- endif %}\n{%- endfor %}\n\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n \n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\n\n</think>\n\n' }}\n {%- else %}\n {{- '<think>\n' }}\n {%- endif %}\n \n{%- endif %}\n",
92
+ "clean_up_tokenization_spaces": false,
93
+ "eos_token": "<|im_end|>",
94
+ "extra_special_tokens": {},
95
+ "legacy": false,
96
+ "model_max_length": 1000000000000000019884624838656,
97
+ "pad_token": "<unk>",
98
+ "sp_model_kwargs": {},
99
+ "spaces_between_special_tokens": false,
100
+ "tokenizer_class": "LlamaTokenizer",
101
+ "unk_token": "<unk>",
102
+ "use_default_system_prompt": false
103
+ }