Align with transformers merging

#9
Files changed (1) hide show
  1. configuration_youtu.py +0 -198
configuration_youtu.py DELETED
@@ -1,198 +0,0 @@
1
- # coding=utf-8
2
- # Copyright 2025 Tencent Youtu Lab and the HuggingFace Inc. team. All rights reserved.
3
-
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
- #
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
- #
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- from transformers.configuration_utils import PretrainedConfig
16
- from transformers.modeling_rope_utils import rope_config_validation
17
-
18
-
19
- Youtu_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
20
-
21
-
22
- class YoutuConfig(PretrainedConfig):
23
- r"""
24
- This is the configuration class to store the configuration of a [`YoutuModel`]. It is used to instantiate an Youtu
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 Youtu-LLM-2B.
27
- e.g. [tencent/Youtu-LLM-2B](https://huggingface.co/tencent/Youtu-LLM-2B)
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 128256):
34
- Vocabulary size of the Deep model. Defines the number of different tokens that can be represented by the
35
- `inputs_ids` passed when calling [`YoutuModel`]
36
- hidden_size (`int`, *optional*, defaults to 2048):
37
- Dimension of the hidden representations.
38
- intermediate_size (`int`, *optional*, defaults to 6144):
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 16):
43
- Number of attention heads for each attention layer in the Transformer decoder.
44
- num_key_value_heads (`int`, *optional*, defaults to 16):
45
- In MLA, num_key_value_heads=num_attention_heads.
46
- kv_lora_rank (`int`, *optional*, defaults to 512):
47
- Rank of the LoRA matrices for key and value projections.
48
- q_lora_rank (`int`, *optional*, defaults to 1536):
49
- Rank of the LoRA matrices for query projections.
50
- qk_rope_head_dim (`int`, *optional*, defaults to 64):
51
- Dimension of the query/key heads that use rotary position embeddings.
52
- v_head_dim (`int`, *optional*, defaults to 128):
53
- Dimension of the value heads.
54
- qk_nope_head_dim (`int`, *optional*, defaults to 128):
55
- Dimension of the query/key heads that don't use rotary position embeddings.
56
- hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
57
- The non-linear activation function (function or string) in the decoder.
58
- max_position_embeddings (`int`, *optional*, defaults to 131072):
59
- The maximum sequence length that this model might ever be used with.
60
- initializer_range (`float`, *optional*, defaults to None):
61
- The standard deviation of the truncated_normal_initializer for initializing all weight matrices, except embedding matrices.
62
- embedding_initializer_range (`float`, *optional*, defaults to None):
63
- The standard deviation of the truncated_normal_initializer for initializing all embedding matrices.
64
- rms_norm_eps (`float`, *optional*, defaults to 1e-06):
65
- The epsilon used by the rms normalization layers.
66
- use_cache (`bool`, *optional*, defaults to `True`):
67
- Whether or not the model should return the last key/values attentions (not used by all models). Only
68
- relevant if `config.is_decoder=True`.
69
- pad_token_id (`int`, *optional*):
70
- Padding token id.
71
- bos_token_id (`int`, *optional*, defaults to 128000):
72
- Beginning of stream token id.
73
- eos_token_id (`int`, *optional*, defaults to 128001):
74
- End of stream token id.
75
- tie_word_embeddings (`bool`, *optional*, defaults to `True`):
76
- Whether to tie weight embeddings
77
- rope_theta (`float`, *optional*, defaults to 1600000):
78
- The base period of the RoPE embeddings.
79
- rope_scaling (`Dict`, *optional*, defaults to `None`):
80
- Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
81
- strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
82
- `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
83
- `max_position_embeddings` to the expected new maximum.
84
- rope_interleave (`bool`, *optional*, defaults to `True`):
85
- Whether to interleave the rotary position embeddings.
86
- attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
87
- Whether to use a bias in the query, key, value and output projection layers during self-attention.
88
- attention_dropout (`float`, *optional*, defaults to 0.0):
89
- The dropout ratio for the attention probabilities.
90
-
91
- ```python
92
- >>> from transformers import YoutuModel, YoutuConfig
93
-
94
- >>> # Initializing a Youtu-LLM-2B style configuration
95
- >>> configuration = YoutuConfig()
96
-
97
- >>> # Accessing the model configuration
98
- >>> configuration = model.config
99
- ```"""
100
-
101
- model_type = "youtu_llm"
102
- keys_to_ignore_at_inference = ["past_key_values"]
103
- base_model_tp_plan = {
104
- "layers.*.mlp.gate_proj": "local_colwise",
105
- "layers.*.mlp.up_proj": "local_colwise",
106
- "layers.*.mlp.down_proj": "local_rowwise",
107
- "layers.*.mlp": "gather", # This is the only moment where results are gathered
108
- }
109
- base_model_pp_plan = {
110
- "embed_tokens": (["input_ids"], ["inputs_embeds"]),
111
- "layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
112
- "norm": (["hidden_states"], ["hidden_states"]),
113
- }
114
-
115
- def __init__(
116
- self,
117
- vocab_size=128256,
118
- hidden_size=2048,
119
- intermediate_size=6144,
120
- num_hidden_layers=32,
121
- num_attention_heads=16,
122
- num_key_value_heads=16,
123
- kv_lora_rank=512,
124
- q_lora_rank=1536,
125
- qk_rope_head_dim=64,
126
- v_head_dim=128,
127
- qk_nope_head_dim=128,
128
- hidden_act="silu",
129
- max_position_embeddings=131072,
130
- initializer_range=None,
131
- embedding_initializer_range=None,
132
- rms_norm_eps=1e-6,
133
- use_cache=True,
134
- pad_token_id=None,
135
- bos_token_id=128000,
136
- eos_token_id=128001,
137
- tie_word_embeddings=True,
138
- rope_theta=1600000,
139
- rope_scaling=None,
140
- rope_interleave=True,
141
- attention_bias=False,
142
- attention_dropout=0.0,
143
- **kwargs,
144
- ):
145
- self.vocab_size = vocab_size
146
- self.max_position_embeddings = max_position_embeddings
147
- self.hidden_size = hidden_size
148
- self.intermediate_size = intermediate_size
149
- self.num_hidden_layers = num_hidden_layers
150
- self.num_attention_heads = num_attention_heads
151
- self.kv_lora_rank = kv_lora_rank
152
- self.q_lora_rank = q_lora_rank
153
- self.qk_rope_head_dim = qk_rope_head_dim
154
- self.v_head_dim = v_head_dim
155
- self.qk_nope_head_dim = qk_nope_head_dim
156
- self.qk_head_dim = qk_nope_head_dim + qk_rope_head_dim
157
- self.head_dim = qk_rope_head_dim
158
- self.rope_interleave = rope_interleave
159
-
160
- # for backward compatibility
161
- if num_key_value_heads is None:
162
- num_key_value_heads = num_attention_heads
163
-
164
- self.mlp_bias = False
165
- self.num_key_value_heads = num_key_value_heads
166
- self.hidden_act = hidden_act
167
- # if initializer_range is None, set it to 2.0 / (5.0 * self.hidden_size) ** 0.5
168
- self.initializer_range = (2.0 / (5.0 * self.hidden_size)) ** 0.5 if initializer_range is None else initializer_range
169
- # if embedding_initializer_range is None, set it to 2.0 * self.initializer_range
170
- self.embedding_initializer_range = self.initializer_range * 2.0 if embedding_initializer_range is None else embedding_initializer_range
171
- self.rms_norm_eps = rms_norm_eps
172
- self.use_cache = use_cache
173
- self.rope_theta = rope_theta
174
- self.rope_scaling = rope_scaling
175
- self.attention_bias = attention_bias
176
- self.attention_dropout = attention_dropout
177
- # Validate the correctness of rotary position embeddings parameters
178
- # BC: if there is a 'type' field, copy it it to 'rope_type'.
179
- if self.rope_scaling is not None and "type" in self.rope_scaling:
180
- self.rope_scaling["rope_type"] = self.rope_scaling["type"]
181
-
182
- if self.rope_scaling is not None:
183
- for key in ["beta_fast", "beta_slow", "factor"]:
184
- if key in self.rope_scaling:
185
- self.rope_scaling[key] = float(self.rope_scaling[key])
186
-
187
- rope_config_validation(self)
188
-
189
- super().__init__(
190
- pad_token_id=pad_token_id,
191
- bos_token_id=bos_token_id,
192
- eos_token_id=eos_token_id,
193
- tie_word_embeddings=tie_word_embeddings,
194
- **kwargs,
195
- )
196
-
197
-
198
- __all__ = ["YoutuConfig"]