Adding files from hf_modeling_btm_reversed
Browse files- configuration.py +62 -0
configuration.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class MoLMConfig(PretrainedConfig):
|
| 4 |
+
model_type = "MoLM"
|
| 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 |
+
num_experts=6,
|
| 17 |
+
expert_configs=None,
|
| 18 |
+
use_router=False,
|
| 19 |
+
top_k_experts=6,
|
| 20 |
+
architectures=["MoLM"],
|
| 21 |
+
auto_map={
|
| 22 |
+
"AutoConfig": "configuration.MoLMConfig",
|
| 23 |
+
"AutoModelForCausalLM": "modeling.MoLM",
|
| 24 |
+
"AutoTokenizer": "GPT2TokenizerFast"
|
| 25 |
+
},
|
| 26 |
+
**kwargs,
|
| 27 |
+
):
|
| 28 |
+
super().__init__(**kwargs)
|
| 29 |
+
self.vocab_size = vocab_size
|
| 30 |
+
self.n_embd = n_embd
|
| 31 |
+
self.n_layer = n_layer
|
| 32 |
+
self.n_head = n_head
|
| 33 |
+
self.sequence_length = sequence_length
|
| 34 |
+
self.mlp_dim_exp_factor = mlp_dim_exp_factor
|
| 35 |
+
self.dropout = dropout
|
| 36 |
+
self.bias = bias
|
| 37 |
+
self.num_experts = num_experts
|
| 38 |
+
self.expert_configs = expert_configs
|
| 39 |
+
self.use_router = use_router
|
| 40 |
+
self.architectures = architectures
|
| 41 |
+
self.auto_map = auto_map
|
| 42 |
+
self.top_k_experts = top_k_experts
|
| 43 |
+
def to_dict(self):
|
| 44 |
+
config_dict = super().to_dict()
|
| 45 |
+
config_dict.update({
|
| 46 |
+
"vocab_size": self.vocab_size,
|
| 47 |
+
"n_embd": self.n_embd,
|
| 48 |
+
"n_layer": self.n_layer,
|
| 49 |
+
"n_head": self.n_head,
|
| 50 |
+
"sequence_length": self.sequence_length,
|
| 51 |
+
"mlp_dim_exp_factor": self.mlp_dim_exp_factor,
|
| 52 |
+
"dropout": self.dropout,
|
| 53 |
+
"bias": self.bias,
|
| 54 |
+
"num_experts": self.num_experts,
|
| 55 |
+
"expert_configs": [
|
| 56 |
+
expert_config.to_dict() if not isinstance(expert_config, dict) else expert_config
|
| 57 |
+
for expert_config in self.expert_configs
|
| 58 |
+
] if self.expert_configs else None,
|
| 59 |
+
"use_router": self.use_router,
|
| 60 |
+
"top_k_experts": self.top_k_experts,
|
| 61 |
+
})
|
| 62 |
+
return config_dict
|