Upload DogeForCausalLM
Browse files- config.json +37 -0
- configuration_doge.py +189 -0
- generation_config.json +7 -0
- model.safetensors +3 -0
config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "./results/Doge-20M-registered",
|
3 |
+
"architectures": [
|
4 |
+
"DogeForCausalLM"
|
5 |
+
],
|
6 |
+
"attention_dropout": 0.0,
|
7 |
+
"auto_map": {
|
8 |
+
"AutoConfig": "configuration_doge.DogeConfig",
|
9 |
+
"AutoModelForCausalLM": "modeling_doge.DogeForCausalLM"
|
10 |
+
},
|
11 |
+
"bos_token_id": 1,
|
12 |
+
"eos_token_id": 2,
|
13 |
+
"expert_retrieval_size": 256,
|
14 |
+
"hidden_act": "silu",
|
15 |
+
"hidden_bias": false,
|
16 |
+
"hidden_dropout": 0.0,
|
17 |
+
"hidden_size": 256,
|
18 |
+
"initializer_range": 0.02,
|
19 |
+
"intermediate_size": 1024,
|
20 |
+
"is_moe": false,
|
21 |
+
"max_position_embeddings": 2048,
|
22 |
+
"model_type": "doge",
|
23 |
+
"num_attention_heads": 2,
|
24 |
+
"num_cdmmoe_experts": 4096,
|
25 |
+
"num_cdmmoe_experts_per_head": 8,
|
26 |
+
"num_cdmmoe_heads": 4,
|
27 |
+
"num_hidden_layers": 4,
|
28 |
+
"pad_token_id": 0,
|
29 |
+
"rms_norm_eps": 1e-06,
|
30 |
+
"rope_scaling": null,
|
31 |
+
"rope_theta": 10000.0,
|
32 |
+
"tie_word_embeddings": false,
|
33 |
+
"torch_dtype": "float32",
|
34 |
+
"transformers_version": "4.46.1",
|
35 |
+
"use_cache": true,
|
36 |
+
"vocab_size": 32768
|
37 |
+
}
|
configuration_doge.py
ADDED
@@ -0,0 +1,189 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2024 Jingze Shi and the HuggingFace Inc. team. All rights reserved.
|
3 |
+
#
|
4 |
+
# This code is based on the Wonderful Matrices paper implementation.
|
5 |
+
#
|
6 |
+
# https://arxiv.org/abs/2407.16958
|
7 |
+
#
|
8 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9 |
+
# you may not use this file except in compliance with the License.
|
10 |
+
# You may obtain a copy of the License at
|
11 |
+
#
|
12 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13 |
+
#
|
14 |
+
# Unless required by applicable law or agreed to in writing, software
|
15 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17 |
+
# See the License for the specific language governing permissions and
|
18 |
+
# limitations under the License.
|
19 |
+
"""PyTorch Doge model configuration"""
|
20 |
+
|
21 |
+
from transformers.configuration_utils import PretrainedConfig
|
22 |
+
from transformers.modeling_rope_utils import rope_config_validation
|
23 |
+
|
24 |
+
|
25 |
+
class DogeConfig(PretrainedConfig):
|
26 |
+
r"""
|
27 |
+
This is the configuration class to store the configuration of a [`DogeModel`]. It is used to instantiate an Doge
|
28 |
+
model according to the specified arguments, defining the model architecture like [LoserCheems/doge-tiny-test](https://huggingface.co/LoserCheems/doge-tiny-test)
|
29 |
+
|
30 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
31 |
+
documentation from [`PretrainedConfig`] for more information.
|
32 |
+
|
33 |
+
Args:
|
34 |
+
vocab_size (`int`, *optional*, defaults to 32768):
|
35 |
+
Vocabulary size of the Doge model. Defines the number of different tokens that can be represented by the
|
36 |
+
`inputs_ids` passed when calling [`DogeModel`]
|
37 |
+
hidden_size (`int`, *optional*, defaults to 1024):
|
38 |
+
Dimension of the hidden representations.
|
39 |
+
intermediate_size (`int`, *optional*, defaults to 4096):
|
40 |
+
Dimension of the CDMoE representations.
|
41 |
+
num_hidden_layers (`int`, *optional*, defaults to 16):
|
42 |
+
Number of hidden layers in the Transformer decoder.
|
43 |
+
hidden_bias (`bool`, *optional*, defaults to `False`):
|
44 |
+
Whether to use bias in the hidden layers.
|
45 |
+
hidden_dropout (`float`, *optional*, defaults to 0.0):
|
46 |
+
Dropout probability for each sequence transformation and state transformation module.
|
47 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
48 |
+
The non-linear activation function (function or string) in the decoder.
|
49 |
+
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
50 |
+
The maximum sequence length that this model might ever be used with.
|
51 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
52 |
+
The base period of the RoPE embeddings.
|
53 |
+
rope_scaling (`Dict`, *optional*):
|
54 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. NOTE: if you apply new rope type
|
55 |
+
and you expect the model to work on longer `max_position_embeddings`, we recommend you to update this value
|
56 |
+
accordingly.
|
57 |
+
Expected contents:
|
58 |
+
`rope_type` (`str`):
|
59 |
+
The sub-variant of RoPE to use. Can be one of ['default', 'linear', 'dynamic', 'yarn', 'longrope',
|
60 |
+
'llama3'], with 'default' being the original RoPE implementation.
|
61 |
+
`factor` (`float`, *optional*):
|
62 |
+
Used with all rope types except 'default'. The scaling factor to apply to the RoPE embeddings. In
|
63 |
+
most scaling types, a `factor` of x will enable the model to handle sequences of length x *
|
64 |
+
original maximum pre-trained length.
|
65 |
+
`original_max_position_embeddings` (`int`, *optional*):
|
66 |
+
Used with 'dynamic', 'longrope' and 'llama3'. The original max position embeddings used during
|
67 |
+
pretraining.
|
68 |
+
`attention_factor` (`float`, *optional*):
|
69 |
+
Used with 'yarn' and 'longrope'. The scaling factor to be applied on the attention
|
70 |
+
computation. If unspecified, it defaults to value recommended by the implementation, using the
|
71 |
+
`factor` field to infer the suggested value.
|
72 |
+
`beta_fast` (`float`, *optional*):
|
73 |
+
Only used with 'yarn'. Parameter to set the boundary for extrapolation (only) in the linear
|
74 |
+
ramp function. If unspecified, it defaults to 32.
|
75 |
+
`beta_slow` (`float`, *optional*):
|
76 |
+
Only used with 'yarn'. Parameter to set the boundary for interpolation (only) in the linear
|
77 |
+
ramp function. If unspecified, it defaults to 1.
|
78 |
+
`short_factor` (`List[float]`, *optional*):
|
79 |
+
Only used with 'longrope'. The scaling factor to be applied to short contexts (<
|
80 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
81 |
+
size divided by the number of attention heads divided by 2
|
82 |
+
`long_factor` (`List[float]`, *optional*):
|
83 |
+
Only used with 'longrope'. The scaling factor to be applied to long contexts (<
|
84 |
+
`original_max_position_embeddings`). Must be a list of numbers with the same length as the hidden
|
85 |
+
size divided by the number of attention heads divided by 2
|
86 |
+
`low_freq_factor` (`float`, *optional*):
|
87 |
+
Only used with 'llama3'. Scaling factor applied to low frequency components of the RoPE
|
88 |
+
`high_freq_factor` (`float`, *optional*):
|
89 |
+
Only used with 'llama3'. Scaling factor applied to high frequency components of the RoPE
|
90 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
91 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
92 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
93 |
+
The epsilon used by the rms normalization layers.
|
94 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
95 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
96 |
+
relevant if `config.is_decoder=True`.
|
97 |
+
pad_token_id (`int`, *optional*, defaults to 0):
|
98 |
+
Padding token id.
|
99 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
100 |
+
Beginning of stream token id.
|
101 |
+
eos_token_id (`int`, *optional*, defaults to 2):
|
102 |
+
End of stream token id.
|
103 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
104 |
+
Whether to tie weight embeddings
|
105 |
+
num_attention_heads (`int`, *optional*, defaults to 8):
|
106 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
107 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
108 |
+
The dropout ratio for the attention probabilities.
|
109 |
+
is_moe (`bool`, *optional*, defaults to `False`):
|
110 |
+
Whether to use the Cross Domain Mixture of Experts, if `True`, the MoE will inherit the MLP to initialize
|
111 |
+
num_cdmmoe_experts (`int`, *optional*, defaults to 4096):
|
112 |
+
Number of Private Experts for the Cross Domain Mixture of Experts.
|
113 |
+
num_cdmmoe_heads (`int`, *optional*, defaults to 4):
|
114 |
+
Number of heads of Private Experts for the Cross Domain Mixture of Experts.
|
115 |
+
num_cdmmoe_experts_per_head (`int`, *optional*, defaults to 8):
|
116 |
+
Number of Private Experts per head for the Cross Domain Mixture of Experts.
|
117 |
+
expert_retrieval_size (`int`, *optional*, defaults to 256):
|
118 |
+
Dimension of the Expert retrieval states for the Cross Domain Mixture of Experts.
|
119 |
+
"""
|
120 |
+
|
121 |
+
model_type = "doge"
|
122 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
123 |
+
|
124 |
+
def __init__(
|
125 |
+
self,
|
126 |
+
vocab_size=32768,
|
127 |
+
hidden_size=1024,
|
128 |
+
intermediate_size=4096,
|
129 |
+
num_hidden_layers=16,
|
130 |
+
hidden_bias=False,
|
131 |
+
hidden_dropout=0.0,
|
132 |
+
hidden_act="silu",
|
133 |
+
max_position_embeddings=2048,
|
134 |
+
rope_theta=10000.0,
|
135 |
+
rope_scaling=None,
|
136 |
+
initializer_range=0.02,
|
137 |
+
rms_norm_eps=1e-06,
|
138 |
+
use_cache=True,
|
139 |
+
pad_token_id=0,
|
140 |
+
bos_token_id=1,
|
141 |
+
eos_token_id=2,
|
142 |
+
tie_word_embeddings=False,
|
143 |
+
num_attention_heads=8,
|
144 |
+
attention_dropout=0.0,
|
145 |
+
is_moe=False,
|
146 |
+
num_cdmmoe_experts=4096,
|
147 |
+
num_cdmmoe_heads=4,
|
148 |
+
num_cdmmoe_experts_per_head=8,
|
149 |
+
expert_retrieval_size=256,
|
150 |
+
**kwargs,
|
151 |
+
):
|
152 |
+
self.vocab_size = vocab_size
|
153 |
+
self.hidden_size = hidden_size
|
154 |
+
self.intermediate_size = intermediate_size
|
155 |
+
self.num_hidden_layers = num_hidden_layers
|
156 |
+
self.hidden_bias = hidden_bias
|
157 |
+
self.hidden_dropout = hidden_dropout
|
158 |
+
self.hidden_act = hidden_act
|
159 |
+
self.max_position_embeddings = max_position_embeddings
|
160 |
+
self.rope_theta = rope_theta
|
161 |
+
self.rope_scaling = rope_scaling
|
162 |
+
self.initializer_range = initializer_range
|
163 |
+
self.rms_norm_eps = rms_norm_eps
|
164 |
+
self.use_cache = use_cache
|
165 |
+
self.pad_token_id = pad_token_id
|
166 |
+
self.bos_token_id = bos_token_id
|
167 |
+
self.eos_token_id = eos_token_id
|
168 |
+
self.tie_word_embeddings = tie_word_embeddings
|
169 |
+
self.num_attention_heads = num_attention_heads
|
170 |
+
self.attention_dropout = attention_dropout
|
171 |
+
self.is_moe = is_moe
|
172 |
+
self.num_cdmmoe_experts = num_cdmmoe_experts
|
173 |
+
self.num_cdmmoe_heads = num_cdmmoe_heads
|
174 |
+
self.num_cdmmoe_experts_per_head = num_cdmmoe_experts_per_head
|
175 |
+
self.expert_retrieval_size = expert_retrieval_size
|
176 |
+
|
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 |
+
rope_config_validation(self)
|
182 |
+
|
183 |
+
super().__init__(
|
184 |
+
pad_token_id=pad_token_id,
|
185 |
+
bos_token_id=bos_token_id,
|
186 |
+
eos_token_id=eos_token_id,
|
187 |
+
tie_word_embeddings=tie_word_embeddings,
|
188 |
+
**kwargs,
|
189 |
+
)
|
generation_config.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 1,
|
4 |
+
"eos_token_id": 2,
|
5 |
+
"pad_token_id": 0,
|
6 |
+
"transformers_version": "4.46.1"
|
7 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dfd577ea7afde42a64798750dbdbc5756d41f15ee4e8a86568729feb0f59372b
|
3 |
+
size 83917640
|