File size: 2,655 Bytes
8f20aff | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | import argparse
import math
from pathlib import Path
import yaml
def estimate_params(hidden, layers, vocab, intermediate):
embeddings = vocab * hidden
transformer = layers * (
4 * hidden * hidden +
2 * hidden * intermediate
)
return embeddings + transformer
def round_multiple(value, multiple=64):
return int(math.ceil(value / multiple) * multiple)
def generate_config(target_params):
vocab = 32000
if target_params <= 500_000_000:
hidden = 1280
layers = 20
elif target_params <= 700_000_000:
hidden = 1536
layers = 24
elif target_params <= 1_000_000_000:
hidden = 2048
layers = 24
else:
hidden = 2560
layers = 28
intermediate = round_multiple(hidden * 4)
while estimate_params(hidden, layers, vocab, intermediate) < target_params:
hidden += 64
intermediate = round_multiple(hidden * 4)
heads = hidden // 128
config = {
"model": {
"vocab_size": vocab,
"hidden_size": hidden,
"intermediate_size": intermediate,
"num_hidden_layers": layers,
"num_attention_heads": heads,
"max_position_embeddings": 4096,
"dropout": 0.0,
"rope_theta": 10000.0,
},
"training": {
"epochs": 10,
"batch_size": 1,
"learning_rate": 1e-4,
"weight_decay": 0.01,
"block_size": 512,
"checkpoint_interval": 100,
"gradient_accumulation_steps": 32,
"warmup_steps": 1000,
},
"system": {
"device": "auto",
"torch_threads": 4,
},
}
return config, estimate_params(hidden, layers, vocab, intermediate)
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--params",
type=float,
default=1.0,
help="Objetivo en miles de millones (ej: 1.0 = 1B)",
)
parser.add_argument(
"--output",
default="configs/marslm-auto.yaml",
)
args = parser.parse_args()
target = int(args.params * 1_000_000_000)
config, estimated = generate_config(target)
output = Path(args.output)
output.parent.mkdir(parents=True, exist_ok=True)
with output.open("w", encoding="utf-8") as f:
yaml.safe_dump(config, f, sort_keys=False)
print(f"Archivo generado: {output}")
print(f"Parámetros aproximados: {estimated:,}")
if __name__ == "__main__":
main() |