Update configuration.py
Browse files- configuration.py +25 -34
configuration.py
CHANGED
|
@@ -1,25 +1,30 @@
|
|
| 1 |
from transformers import PretrainedConfig
|
| 2 |
|
| 3 |
-
class
|
| 4 |
-
model_type = "
|
| 5 |
|
| 6 |
def __init__(
|
| 7 |
self,
|
| 8 |
vocab_size=50304,
|
| 9 |
-
n_embd=768,
|
| 10 |
-
n_layer=12,
|
| 11 |
-
n_head=12,
|
| 12 |
sequence_length=1024,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
mlp_dim_exp_factor=1.0,
|
| 14 |
dropout=0.0,
|
| 15 |
bias=False,
|
| 16 |
-
|
| 17 |
-
expert_configs=None,
|
| 18 |
-
use_router=False,
|
| 19 |
-
architectures=["MoLM"],
|
| 20 |
auto_map={
|
| 21 |
-
"AutoConfig": "configuration.
|
| 22 |
-
"AutoModelForCausalLM": "modeling.
|
| 23 |
"AutoTokenizer": "GPT2TokenizerFast"
|
| 24 |
},
|
| 25 |
**kwargs,
|
|
@@ -30,31 +35,17 @@ class MoLMConfig(PretrainedConfig):
|
|
| 30 |
self.n_layer = n_layer
|
| 31 |
self.n_head = n_head
|
| 32 |
self.sequence_length = sequence_length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
self.mlp_dim_exp_factor = mlp_dim_exp_factor
|
| 34 |
self.dropout = dropout
|
| 35 |
self.bias = bias
|
| 36 |
-
self.num_experts = num_experts
|
| 37 |
-
self.expert_configs = expert_configs
|
| 38 |
-
self.use_router = use_router
|
| 39 |
self.architectures = architectures
|
| 40 |
self.auto_map = auto_map
|
| 41 |
-
|
| 42 |
-
def to_dict(self):
|
| 43 |
-
config_dict = super().to_dict()
|
| 44 |
-
config_dict.update({
|
| 45 |
-
"vocab_size": self.vocab_size,
|
| 46 |
-
"n_embd": self.n_embd,
|
| 47 |
-
"n_layer": self.n_layer,
|
| 48 |
-
"n_head": self.n_head,
|
| 49 |
-
"sequence_length": self.sequence_length,
|
| 50 |
-
"mlp_dim_exp_factor": self.mlp_dim_exp_factor,
|
| 51 |
-
"dropout": self.dropout,
|
| 52 |
-
"bias": self.bias,
|
| 53 |
-
"num_experts": self.num_experts,
|
| 54 |
-
"expert_configs": [
|
| 55 |
-
expert_config.to_dict() if not isinstance(expert_config, dict) else expert_config
|
| 56 |
-
for expert_config in self.expert_configs
|
| 57 |
-
] if self.expert_configs else None,
|
| 58 |
-
"use_router": self.use_router
|
| 59 |
-
})
|
| 60 |
-
return config_dict
|
|
|
|
| 1 |
from transformers import PretrainedConfig
|
| 2 |
|
| 3 |
+
class MoEGPTConfig(PretrainedConfig):
|
| 4 |
+
model_type = "moegpt"
|
| 5 |
|
| 6 |
def __init__(
|
| 7 |
self,
|
| 8 |
vocab_size=50304,
|
| 9 |
+
n_embd=1152, #768,
|
| 10 |
+
n_layer=24,#12,
|
| 11 |
+
n_head=16,#12,
|
| 12 |
sequence_length=1024,
|
| 13 |
+
moe=False,
|
| 14 |
+
moe_routing="standard_gating",
|
| 15 |
+
moe_num_experts=4,
|
| 16 |
+
moe_num_experts_per_tok=2,
|
| 17 |
+
moe_softmax_order="softmax_topk",
|
| 18 |
+
moe_router_loss="load_balancing_z_loss",
|
| 19 |
+
moe_aux_loss_factor=0.01,
|
| 20 |
+
moe_z_loss_factor=1.0,
|
| 21 |
mlp_dim_exp_factor=1.0,
|
| 22 |
dropout=0.0,
|
| 23 |
bias=False,
|
| 24 |
+
architectures=["MoEGPTForCausalLM"],
|
|
|
|
|
|
|
|
|
|
| 25 |
auto_map={
|
| 26 |
+
"AutoConfig": "configuration.MoEGPTConfig",
|
| 27 |
+
"AutoModelForCausalLM": "modeling.MoEGPTForCausalLM",
|
| 28 |
"AutoTokenizer": "GPT2TokenizerFast"
|
| 29 |
},
|
| 30 |
**kwargs,
|
|
|
|
| 35 |
self.n_layer = n_layer
|
| 36 |
self.n_head = n_head
|
| 37 |
self.sequence_length = sequence_length
|
| 38 |
+
self.moe = moe
|
| 39 |
+
self.moe_routing = moe_routing
|
| 40 |
+
self.moe_num_experts = moe_num_experts
|
| 41 |
+
self.moe_num_experts_per_tok = moe_num_experts_per_tok
|
| 42 |
+
self.moe_softmax_order = moe_softmax_order
|
| 43 |
+
self.moe_router_loss = moe_router_loss
|
| 44 |
+
self.moe_aux_loss_factor = moe_aux_loss_factor
|
| 45 |
+
self.moe_z_loss_factor = moe_z_loss_factor
|
| 46 |
self.mlp_dim_exp_factor = mlp_dim_exp_factor
|
| 47 |
self.dropout = dropout
|
| 48 |
self.bias = bias
|
|
|
|
|
|
|
|
|
|
| 49 |
self.architectures = architectures
|
| 50 |
self.auto_map = auto_map
|
| 51 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|