dataclass config
Browse files- myolmoe/modeling_myolmoe.py +64 -93
myolmoe/modeling_myolmoe.py
CHANGED
|
@@ -18,102 +18,73 @@ from transformers.utils import logging
|
|
| 18 |
from transformers.configuration_utils import PretrainedConfig
|
| 19 |
from transformers.modeling_rope_utils import rope_config_validation
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
class MyOlmoeConfig(PretrainedConfig):
|
| 22 |
-
r"""
|
| 23 |
-
This is the configuration class to store the configuration of a [`OlmoeModel`].
|
| 24 |
-
[Previous docstring remains the same...]
|
| 25 |
-
|
| 26 |
-
Args:
|
| 27 |
-
[Previous args remain the same...]
|
| 28 |
-
small_expert_intermediate_ratio (`float`, *optional*, defaults to 0.5):
|
| 29 |
-
Ratio of intermediate size for small experts compared to regular experts.
|
| 30 |
-
small_expert_count (`int`, *optional*, defaults to 64):
|
| 31 |
-
Frequency of small experts - every Nth expert will be small.
|
| 32 |
-
small_expert_sparsity_coef (`float`, *optional*, defaults to 0.1):
|
| 33 |
-
Coefficient for small expert load balancing loss.
|
| 34 |
"""
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
self.attention_dropout = attention_dropout
|
| 92 |
-
self.clip_qkv = clip_qkv
|
| 93 |
-
self.num_experts_per_tok = num_experts_per_tok
|
| 94 |
-
self.num_experts = num_experts
|
| 95 |
-
self.output_router_logits = output_router_logits
|
| 96 |
-
self.router_aux_loss_coef = router_aux_loss_coef
|
| 97 |
-
self.norm_topk_prob = norm_topk_prob
|
| 98 |
-
|
| 99 |
-
# Small expert parameters
|
| 100 |
-
self.small_expert_intermediate_ratio = small_expert_intermediate_ratio
|
| 101 |
-
self.small_expert_count = small_expert_count
|
| 102 |
-
self.small_expert_sparsity_coef = small_expert_sparsity_coef
|
| 103 |
-
self.small_expert_strategy = small_expert_strategy
|
| 104 |
-
self.max_small_expert_count = max_small_expert_count
|
| 105 |
-
|
| 106 |
-
# Validate the correctness of rotary position embeddings parameters
|
| 107 |
-
if self.rope_scaling is not None and "type" in self.rope_scaling:
|
| 108 |
-
self.rope_scaling["rope_type"] = self.rope_scaling["type"]
|
| 109 |
-
rope_config_validation(self)
|
| 110 |
-
|
| 111 |
super().__init__(
|
| 112 |
-
pad_token_id=pad_token_id,
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
tie_word_embeddings=tie_word_embeddings,
|
| 116 |
-
**kwargs,
|
| 117 |
)
|
| 118 |
|
| 119 |
logger = logging.get_logger(__name__)
|
|
|
|
| 18 |
from transformers.configuration_utils import PretrainedConfig
|
| 19 |
from transformers.modeling_rope_utils import rope_config_validation
|
| 20 |
|
| 21 |
+
from dataclasses import dataclass, field
|
| 22 |
+
from typing import Optional, List, Any
|
| 23 |
+
from transformers import PretrainedConfig
|
| 24 |
+
|
| 25 |
+
@dataclass
|
| 26 |
class MyOlmoeConfig(PretrainedConfig):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
"""
|
| 28 |
+
Configuration class for MyOlmoe model.
|
| 29 |
+
"""
|
| 30 |
+
model_type: str = "myolmoe"
|
| 31 |
+
|
| 32 |
+
# Core model parameters
|
| 33 |
+
vocab_size: int = 50304
|
| 34 |
+
hidden_size: int = 2048
|
| 35 |
+
intermediate_size: int = 1024
|
| 36 |
+
num_hidden_layers: int = 16
|
| 37 |
+
num_attention_heads: int = 16
|
| 38 |
+
num_key_value_heads: int = 16
|
| 39 |
+
max_position_embeddings: int = 4096
|
| 40 |
+
|
| 41 |
+
# Expert parameters
|
| 42 |
+
num_experts: int = 64
|
| 43 |
+
num_experts_per_tok: int = 2
|
| 44 |
+
num_small_experts: int = 0
|
| 45 |
+
small_expert_count: int = 64
|
| 46 |
+
small_expert_intermediate_ratio: int = 16
|
| 47 |
+
small_expert_intermediate_size: int = 0
|
| 48 |
+
small_expert_sparsity_coef: float = 0.1
|
| 49 |
+
small_expert_strategy: str = "constant"
|
| 50 |
+
max_small_expert_count: int = 64
|
| 51 |
+
|
| 52 |
+
# Attention parameters
|
| 53 |
+
attention_bias: bool = False
|
| 54 |
+
attention_dropout: float = 0.0
|
| 55 |
+
clip_qkv: Optional[float] = None
|
| 56 |
+
|
| 57 |
+
# Normalization and activation
|
| 58 |
+
hidden_act: str = "silu"
|
| 59 |
+
rms_norm_eps: float = 1e-05
|
| 60 |
+
norm_topk_prob: bool = False
|
| 61 |
+
|
| 62 |
+
# Router parameters
|
| 63 |
+
router_aux_loss_coef: float = 0.01
|
| 64 |
+
output_router_logits: bool = False
|
| 65 |
+
|
| 66 |
+
# Training parameters
|
| 67 |
+
initializer_range: float = 0.02
|
| 68 |
+
tie_word_embeddings: bool = False
|
| 69 |
+
use_cache: bool = True
|
| 70 |
+
|
| 71 |
+
# RoPE parameters
|
| 72 |
+
rope_theta: float = 10000.0
|
| 73 |
+
rope_scaling: Optional[dict] = None
|
| 74 |
+
|
| 75 |
+
# Token IDs
|
| 76 |
+
pad_token_id: int = 1
|
| 77 |
+
eos_token_id: int = 50279
|
| 78 |
+
|
| 79 |
+
# Model architecture
|
| 80 |
+
architectures: List[str] = field(default_factory=lambda: ["MyOlmoeForCausalLM"])
|
| 81 |
+
|
| 82 |
+
def __post_init__(self):
|
| 83 |
+
"""Post-initialization to ensure compatibility with PretrainedConfig."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
super().__init__(
|
| 85 |
+
pad_token_id=self.pad_token_id,
|
| 86 |
+
eos_token_id=self.eos_token_id,
|
| 87 |
+
**{k: v for k, v in self.__dict__.items() if not k.startswith('_')}
|
|
|
|
|
|
|
| 88 |
)
|
| 89 |
|
| 90 |
logger = logging.get_logger(__name__)
|