train: fix SwiGLU width in build_config variants (was 2x)
Browse files- train/train_ounce100m.py +7 -5
train/train_ounce100m.py
CHANGED
|
@@ -33,19 +33,21 @@ BASE = dict(hidden=576, layers=22, heads=9, kv_heads=3, ffn=1536, vocab=49152,
|
|
| 33 |
|
| 34 |
|
| 35 |
def build_config(seq_len, layers=None, hidden=None):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
h = hidden or BASE["hidden"]
|
| 37 |
L = layers or BASE["layers"]
|
| 38 |
-
inter = BASE["ffn"] if hidden is None and layers is None else int(round(8
|
|
|
|
| 39 |
cfg = LlamaConfig(vocab_size=BASE["vocab"], hidden_size=h, intermediate_size=inter,
|
| 40 |
num_hidden_layers=L, num_attention_heads=BASE["heads"],
|
| 41 |
-
num_key_value_heads=
|
| 42 |
max_position_embeddings=seq_len, rope_theta=BASE["rope_theta"],
|
| 43 |
rms_norm_eps=BASE["rms_eps"], tie_word_embeddings=BASE["tie"],
|
| 44 |
attention_dropout=0.0, hidden_act="silu", mlp_bias=False,
|
| 45 |
pad_token_id=BASE["vocab"] - 1, eos_token_id=0)
|
| 46 |
-
# GQA ratio is part of the frozen shape; 9 heads with 3 kv heads, never MHA at this budget.
|
| 47 |
-
if hidden is None:
|
| 48 |
-
cfg.num_key_value_heads = BASE["kv_heads"]
|
| 49 |
return cfg
|
| 50 |
|
| 51 |
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
def build_config(seq_len, layers=None, hidden=None):
|
| 36 |
+
"""The frozen shape, and the two variants test T1 needs (20L at the same width, and a wider/shallower
|
| 37 |
+
alternative). SwiGLU width is int(2*4h/3) rounded to a 64-multiple -- 1536 at h=576, which is the
|
| 38 |
+
value the frozen 106,194,240 count was derived from. Getting this factor wrong silently changes the
|
| 39 |
+
parameter count and makes T1 compare two different models."""
|
| 40 |
h = hidden or BASE["hidden"]
|
| 41 |
L = layers or BASE["layers"]
|
| 42 |
+
inter = BASE["ffn"] if hidden is None and layers is None else (int(round(8 * h / 3)) // 64) * 64
|
| 43 |
+
kv = BASE["kv_heads"] if hidden is None else max(1, h // 64)
|
| 44 |
cfg = LlamaConfig(vocab_size=BASE["vocab"], hidden_size=h, intermediate_size=inter,
|
| 45 |
num_hidden_layers=L, num_attention_heads=BASE["heads"],
|
| 46 |
+
num_key_value_heads=kv,
|
| 47 |
max_position_embeddings=seq_len, rope_theta=BASE["rope_theta"],
|
| 48 |
rms_norm_eps=BASE["rms_eps"], tie_word_embeddings=BASE["tie"],
|
| 49 |
attention_dropout=0.0, hidden_act="silu", mlp_bias=False,
|
| 50 |
pad_token_id=BASE["vocab"] - 1, eos_token_id=0)
|
|
|
|
|
|
|
|
|
|
| 51 |
return cfg
|
| 52 |
|
| 53 |
|