decoder-transformer-0.2b-fineweb
A 0.2B-parameter decoder-only Transformer language model pretrained from scratch on FineWeb-Edu (sample-10BT) for a graduate ML course assignment (pretraining + scaling-law study). The architecture and training loop are implemented directly in PyTorch (no HuggingFace model classes / Trainer).
Model
| Parameters | 217.7M total (201.4M non-embedding, tied embeddings) |
| Architecture | 16 layers, d_model 1024, 16 heads, d_ff 4096, RoPE, RMSNorm, pre-norm, no bias |
| Context length | 1024 |
| Tokenizer | flexitok/bpe_fw_edu_16000 (16k BPE), eos = </s> (id 2) |
| Training data | FineWeb-Edu sample-10BT, 10.0B tokens (~2.3x Chinchilla) |
| Optimizer | AdamW (0.9, 0.95), wd 0.1, peak lr 4e-4, cosine to 10%, warmup 1.5% |
| Batch | 262,144 tokens/step, 38,146 steps, bf16, 2x H100 |
Results (validation)
| Metric | Value |
|---|---|
| Cross-entropy | 2.716 |
| Perplexity | 15.12 |
| Bits-per-byte | 0.908 |
The companion scaling-law study (6 model sizes x 3 data budgets, 18 runs) fits L(N) = 1.642 + 58.5 / N^0.209 on the data-rich runs; extrapolating to this model's size predicts CE 2.727 vs. 2.716 measured (0.4% error).
Usage
The checkpoint is a plain PyTorch state_dict (fp32) plus the model config.
Load it with model.py from the code repository:
https://github.com/nihao-zhangtongxue/aml-hw1-decoder-transformer
import torch
from model import GPT, GPTConfig # from the GitHub repo (code/model.py)
ck = torch.load("model_weights_only.pt", map_location="cpu")
model = GPT(GPTConfig(**ck["model_config"]))
model.load_state_dict(ck["model"])
model.eval()
from tokenizers import Tokenizer
tok = Tokenizer.from_file("tokenizer.json") # flexitok/bpe_fw_edu_16000
ids = torch.tensor([tok.encode("The history of mathematics").ids])
out = model.generate(ids, max_new_tokens=100, temperature=0.8, top_k=50, eos_id=2)
print(tok.decode(out[0].tolist()))
File model_weights_only.pt contains: model (state_dict), model_config,
step (38145), val_ce_best (2.7159).