1- from dataclasses import dataclass
1+ from transformers import PretrainedConfig
22
33
4- @dataclass
5- class ModelConfig :
6- """Hyperparameters for the BetterGPT model architecture.
4+ class BetterGPTConfig (PretrainedConfig ):
5+ model_type = "better_gpt"
76
8- Validated at construction time: emb_dim must be divisible by head_count,
9- and the resulting head_dim must be even (required by RoPE).
10- """
11- vocab_size : int = 8192
12- emb_dim : int = 512
13- num_blocks : int = 8
14- head_count : int = 8
15- seq_length : int = 512
16- ffn_multiple : int = 128
7+ def __init__ (
8+ self ,
9+ vocab_size = 8192 ,
10+ emb_dim = 512 ,
11+ num_blocks = 8 ,
12+ head_count = 8 ,
13+ seq_length = 512 ,
14+ ffn_multiple = 128 ,
15+ tie_word_embeddings = True ,
16+ rmsnorm_eps = 1e-6 ,
17+ ** kwargs
18+ ):
19+ assert emb_dim % head_count == 0 , "emb_dim must be divisible by head_count"
20+ self .vocab_size = vocab_size
21+ self .emb_dim = emb_dim
22+ self .num_blocks = num_blocks
23+ self .head_count = head_count
24+ self .seq_length = seq_length
25+ self .ffn_multiple = ffn_multiple
1726
18- def __post_init__ (self ):
19- if self .vocab_size <= 0 :
20- raise ValueError (f"vocab_size must be > 0, got { self .vocab_size } " )
21- if self .emb_dim <= 0 :
22- raise ValueError (f"emb_dim must be > 0, got { self .emb_dim } " )
23- if self .head_count <= 0 :
24- raise ValueError (f"head_count must be > 0, got { self .head_count } " )
25- if self .emb_dim % self .head_count != 0 :
26- raise ValueError (
27- f"emb_dim ({ self .emb_dim } ) must be divisible by head_count ({ self .head_count } )"
28- )
29- head_dim = self .emb_dim // self .head_count
30- if head_dim % 2 != 0 :
31- raise ValueError (
32- f"head_dim ({ head_dim } ) must be even for RoPE; adjust emb_dim or head_count"
33- )
34- if self .num_blocks <= 0 :
35- raise ValueError (f"num_blocks must be > 0, got { self .num_blocks } " )
36- if self .seq_length <= 0 :
37- raise ValueError (f"seq_length must be > 0, got { self .seq_length } " )
38- if self .ffn_multiple <= 0 :
39- raise ValueError (f"ffn_multiple must be > 0, got { self .ffn_multiple } " )
27+ # Initialize the Hugging Face base config
28+ super ().__init__ (tie_word_embeddings = tie_word_embeddings , ** kwargs )
0 commit comments