dwzhu commited on
Commit
dc760c9
1 Parent(s): 3f4e87a

Upload pose_configuration_baichuan.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. pose_configuration_baichuan.py +96 -0
pose_configuration_baichuan.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Modification Copyright 2023 Dawei Zhu
2
+ # Copyright 2023 Baichuan Inc. All Rights Reserved.
3
+
4
+ # Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.
5
+ #
6
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
7
+ # and OPT implementations in this library. It has been modified from its
8
+ # original forms to accommodate minor architectural differences compared
9
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
10
+ #
11
+ # Licensed under the Apache License, Version 2.0 (the "License");
12
+ # you may not use this file except in compliance with the License.
13
+ # You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+
23
+ from transformers.configuration_utils import PretrainedConfig
24
+ from transformers.utils import logging
25
+
26
+
27
+ logger = logging.get_logger(__name__)
28
+
29
+
30
+ class BaichuanConfig(PretrainedConfig):
31
+ model_type = "baichuan"
32
+ keys_to_ignore_at_inference = ["past_key_values"]
33
+
34
+ def __init__(
35
+ self,
36
+ vocab_size=125696,
37
+ hidden_size=4096,
38
+ intermediate_size=11008,
39
+ num_hidden_layers=32,
40
+ num_attention_heads=32,
41
+ hidden_act="silu",
42
+ max_position_embeddings=4096,
43
+ initializer_range=0.02,
44
+ rms_norm_eps=1e-6,
45
+ use_cache=True,
46
+ pad_token_id=0,
47
+ bos_token_id=1,
48
+ eos_token_id=2,
49
+ tie_word_embeddings=False,
50
+ z_loss_weight=0,
51
+ rope_scaling=None,
52
+ **kwargs,
53
+ ):
54
+ self.vocab_size = vocab_size
55
+ self.max_position_embeddings = max_position_embeddings
56
+ self.hidden_size = hidden_size
57
+ self.intermediate_size = intermediate_size
58
+ self.num_hidden_layers = num_hidden_layers
59
+ self.num_attention_heads = num_attention_heads
60
+ self.hidden_act = hidden_act
61
+ self.initializer_range = initializer_range
62
+ self.rms_norm_eps = rms_norm_eps
63
+ self.use_cache = use_cache
64
+
65
+ self.rope_scaling = rope_scaling
66
+ self._rope_scaling_validation()
67
+
68
+ self.z_loss_weight = z_loss_weight
69
+ super().__init__(
70
+ pad_token_id=pad_token_id,
71
+ bos_token_id=bos_token_id,
72
+ eos_token_id=eos_token_id,
73
+ tie_word_embeddings=tie_word_embeddings,
74
+ **kwargs,
75
+ )
76
+
77
+ def _rope_scaling_validation(self):
78
+ """
79
+ Validate the `rope_scaling` configuration.
80
+ """
81
+ if self.rope_scaling is None:
82
+ return
83
+
84
+ if not isinstance(self.rope_scaling, dict):
85
+ raise ValueError(
86
+ "`rope_scaling` must be a dictionary with with two fields, `name` and `factor`, "
87
+ f"got {self.rope_scaling}"
88
+ )
89
+ rope_scaling_type = self.rope_scaling.get("type", None)
90
+ rope_scaling_factor = self.rope_scaling.get("factor", None)
91
+ if rope_scaling_type is None or rope_scaling_type not in ["linear", "dynamic", "vanilla_ntk", "yarn"]:
92
+ raise ValueError(
93
+ f"`rope_scaling`'s name field must be one of ['linear', 'smart_linear', 'dynamic', 'vanilla_ntk', 'yarn'], got {rope_scaling_type}"
94
+ )
95
+ if rope_scaling_factor is None or not isinstance(rope_scaling_factor, float) or rope_scaling_factor <= 1.0:
96
+ raise ValueError(f"`rope_scaling`'s factor field must be an float > 1, got {rope_scaling_factor}")