GPT-2 from scratch on Reuters

A small GPT-2 trained from random weights to predict the next token. Training data: title + new line + body of each article in ingeniumacademy/reuters_articles. Tokenizer: ingeniumacademy/gpt2-reuters-tokenizer.

Main model (this folder)

setting value
layers / heads / embedding size 6 / 6 / 384
context length 256
parameters 30,713,856
epochs 5
training time 402.8 s on NVIDIA GeForce RTX 4070 Ti SUPER
validation loss / perplexity 4.1704 / 64.74
test loss / perplexity 3.9734 / 53.16

All runs

run epochs n_layer total_params train_runtime_s final_train_loss val_loss val_ppl test_loss test_ppl best_val_epoch
baseline_6L_5ep 5 6 30713856 402.8 3.6596 4.1704 64.74 3.9734 53.16 5
exp1_6L_2ep 2 6 30713856 166.2 4.5579 4.7752 118.53 4.5487 94.51 1.98
exp2_2L_5ep 5 2 23616000 293.6 3.8018 4.3069 74.21 4.1058 60.69 5

The other models are in runs/<name>/. Loss histories, plots and generated text are in results/.

from transformers import AutoTokenizer, GPT2LMHeadModel
tok = AutoTokenizer.from_pretrained("ovindu-a/gpt2-from-scratch")
model = GPT2LMHeadModel.from_pretrained("ovindu-a/gpt2-from-scratch")                       # main model
model_2ep = GPT2LMHeadModel.from_pretrained("ovindu-a/gpt2-from-scratch", subfolder="runs/exp1_6L_2ep")

Extra runs: more heads and wider models

Part A (exp3, exp4): more heads, 64 dimensions per head (same as the main model), so width = heads x 64. Part B (exp5, exp6): 128 dimensions per head, so width = heads x 128. Everything else is the same as the main model.

run n_head dims_per_head n_embd n_layer total_params non_embedding_params embedding_share size_fp32_MB
baseline_6L_5ep 6 64 384 6 30,713,856 10,647,552 65% 122.9
exp3_8H_512d 8 64 512 6 45,670,400 18,915,328 59% 182.7
exp4_12H_768d 12 64 768 6 82,661,376 42,528,768 49% 330.6
exp5_8H_1024d 8 128 1024 6 129,089,536 75,579,392 41% 516.4
exp6_12H_1536d 12 128 1536 6 250,257,408 169,992,192 32% 1001
run n_head n_embd n_layer epochs total_params train_runtime_s final_train_loss val_loss val_ppl test_loss test_ppl best_val_loss best_val_epoch
baseline_6L_5ep 6 384 6 5 30713856 402.8 3.6596 4.1704 64.74 3.9734 53.16 4.1704 5
exp1_6L_2ep 6 384 6 2 30713856 166.2 4.5579 4.7752 118.53 4.5487 94.51 4.7752 1.98
exp2_2L_5ep 6 384 2 5 23616000 293.6 3.8018 4.3069 74.21 4.1058 60.69 4.3069 5
exp3_8H_512d 8 512 6 5 45670400 494.3 3.4076 4.05 57.4 3.8627 47.59 4.05 5
exp4_12H_768d 12 768 6 5 82661376 728.5 3.0562 3.9518 52.03 3.7819 43.9 3.9518 5
exp5_8H_1024d 8 1024 6 5 129089536 989.6 2.9106 3.9738 53.19 3.8086 45.09 3.9718 3.97
exp6_12H_1536d 12 1536 6 5 250257408 1745.7 3.1291 4.1545 63.72 3.9726 53.12 4.1545 4.96

Models: runs/exp3_8H_512d/, runs/exp4_12H_768d/, runs/exp5_8H_1024d/ and runs/exp6_12H_1536d/.

Downloads last month
137
Safetensors
Model size
30.7M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Dataset used to train ovindu-a/gpt2-from-scratch