Upload config.py with huggingface_hub
Browse files
config.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Model configuration for the tiny Gemma-style transformer.
|
| 2 |
+
|
| 3 |
+
Gemma's distinctive choices (vs Qwen):
|
| 4 |
+
* 5 local (sliding-window) attention layers for every 1 global layer.
|
| 5 |
+
* Local layers use a small RoPE base; global layers use a large one.
|
| 6 |
+
* "Sandwich" normalization: an RMSNorm BEFORE and AFTER each sub-layer.
|
| 7 |
+
* GeGLU (gelu) feed-forward instead of SwiGLU (silu).
|
| 8 |
+
* Input embeddings are scaled by sqrt(hidden_size).
|
| 9 |
+
* Per-Layer Embeddings (a small extra embedding added at every layer).
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@dataclass
|
| 16 |
+
class ModelConfig:
|
| 17 |
+
vocab_size: int = 30 # 30 Turkish chars (incl. newline)
|
| 18 |
+
hidden_size: int = 32 # model / embedding dimension
|
| 19 |
+
num_layers: int = 6 # 6 layers -> exactly one global layer (pattern below)
|
| 20 |
+
num_heads: int = 4 # number of query heads
|
| 21 |
+
num_kv_heads: int = 2 # key/value heads (GQA)
|
| 22 |
+
head_dim: int = 8 # dimension per head
|
| 23 |
+
intermediate_size: int = 64 # GeGLU hidden dimension
|
| 24 |
+
max_seq_len: int = 32 # longest sequence we ever feed in
|
| 25 |
+
rms_norm_eps: float = 1e-6 # epsilon inside RMSNorm
|
| 26 |
+
|
| 27 |
+
# Local vs global attention.
|
| 28 |
+
sliding_window: int = 8 # local layers only attend to the last `sliding_window` tokens
|
| 29 |
+
global_every: int = 6 # every 6th layer is global (so 5 local : 1 global)
|
| 30 |
+
rope_theta_local: float = 10000.0 # RoPE base for local layers
|
| 31 |
+
rope_theta_global: float = 1000000.0 # RoPE base for global layers
|
| 32 |
+
|
| 33 |
+
# Gemma scales queries by 1/sqrt(query_pre_attn_scalar) (here = head_dim).
|
| 34 |
+
query_pre_attn_scalar: int = 8
|