sandyGPT / README.md
sandysanta's picture
Model card: add base-stem branch (STEM continued pretraining)
2098714 verified
|
Raw History Blame Contribute Delete
6.9 kB
metadata
license: mit
library_name: pytorch
tags:
  - gpt2
  - nanogpt
  - text-generation
  - from-scratch
datasets:
  - HuggingFaceFW/fineweb-edu
language:
  - en

sandyGPT: a 106.8M-parameter language model trained from scratch

A small GPT-2-style decoder, pretrained from scratch on a single consumer GPU with nanoGPT. This page is the model card for the whole repo; main holds the base model (pretraining only). Other versions live on branches.

Branch What it is Training data Val loss
main Base model ~2.0B tokens FineWeb-Edu 3.41
base-cpt Base + continued pretraining + ~4.0B tokens (FineWeb-Edu, FineWeb, Wikipedia, Gutenberg) 3.28 (different val set)
base-stem base-cpt + STEM-focused continued pretraining + ~2.1B tokens (80% STEM text, 20% general replay) 2.94 (half STEM / half general)
chat main + SFT + 59.5k SmolTalk conversations 1.82 (assistant tokens)
chat-cpt base-cpt + SFT (best chat model) same SFT data 1.69 (assistant tokens)

Validation losses on different sets are not comparable with each other.

Model

  • Parameters: 106.8M (tied input/output embeddings)
  • 12 layers, 11 heads, d_model 704, context 1024
  • GPT-2 BPE tokenizer, vocab 50304 (50257 padded to a multiple of 64)
  • Architecture is nanoGPT's model.py (GPT-2 style: learned positions, LayerNorm, GELU MLP)

Training data

Stage Dataset Tokens
Pretraining (main) FineWeb-Edu, sample-10BT ~2.0B (1 epoch)
Continued pretraining (base-cpt, chat-cpt) FineWeb-Edu 2.0B
FineWeb, sample-10BT 0.8B
Wikipedia, 20231101.en 0.6B
Project Gutenberg, English 0.6B
STEM continued pretraining (base-stem) STEM-filtered Cosmopedia v2 and FineWeb-Edu, OpenWebMath, FineMath, Stack Exchange STEM sites (compiled by the author, benchmark test sets removed) ~1.65B (80%)
Replay of the general continued-pretraining mix above ~0.41B (20%)
SFT (chat, chat-cpt) SmolTalk: everyday-conversations + 60k of smol-magpie-ultra 59,521 train / 1,000 val conversations, avg ~730 tokens

The continued-pretraining mix is shuffled in 1M-token chunks (3.99B train + 8M val tokens).

Training compute

  • Hardware: 1x NVIDIA RTX 5080 (16 GB), AMD Ryzen 9 9950X3D, 31 GB RAM (28 GB given to WSL2), Windows 11 + WSL2 Ubuntu 24.04
  • Software: PyTorch 2.11 (CUDA 12.8), bf16 autocast, torch.compile
  • Pretraining (main): 3,750 iterations x 524,288 tokens (batch 16 x 32 grad-accum x 1024) = ~1.97B tokens. AdamW, lr 6e-4 cosine to 6e-5. About 4.75 s/iteration, ~110k tokens/s, ~26% MFU (A100 reference). About 5 hours. The run continued to iteration 3,900; the released weights are the iteration-3,750 checkpoint (best validation loss).
  • Continued pretraining (base-cpt): 7,600 iterations x 524,288 tokens (~4.0B tokens), fresh LR schedule (peak 3e-4, min 3e-5, 100 warmup steps), same hardware, about 10 hours (interrupted once and resumed from a checkpoint). Released weights are from step 7,500.
  • STEM continued pretraining (base-stem): resumed from base-cpt (optimizer state kept) with a fresh schedule (peak lr 2e-4 cosine to 2e-5, 100 warmup iterations), 4,000 iterations x 524,288 tokens (~2.1B tokens, about 1 epoch of the mix), same hardware, about 5.3 hours (4.75 s/iteration). Released weights are the final iteration-4,000 checkpoint.
  • SFT (chat, chat-cpt): full fine-tune, 3 epochs, lr 5e-5 cosine, loss on assistant tokens only, multi-turn conversations cut at turn boundaries to 1024 tokens, same GPU, about 35 minutes. Assistant validation loss: 2.82 (before SFT) to 1.82 on main; to 1.69 on base-cpt.

Total: roughly 15 GPU-hours for pretraining plus continued pretraining, under an hour per SFT run.

Benchmarks (zero-shot, lm-evaluation-harness)

This is a tiny model, so most scores sit close to chance. Differences under ~1 point are noise.

Task Chance main base-cpt chat chat-cpt
HellaSwag (acc_norm) 25 28.4 29.4 28.3 28.8
ARC-Easy (acc) 25 46.4 47.7 44.1 44.7
ARC-Challenge (acc_norm) 25 24.1 23.5 23.9 24.7
PIQA (acc) 50 60.2 62.1 59.8 60.5
Winogrande (acc) 50 51.9 49.7 50.7 50.2
LAMBADA ppl (lower better) 405 99.6 980 311

Continued pretraining helps (LAMBADA perplexity 405 to 99.6). SFT adds chat format but costs some knowledge, most visibly on LAMBADA.

base-stem vs base-cpt (zero-shot): SciQ 65.3 to 67.0, ARC-Easy 47.7 to 49.3, OpenBookQA 28.0 to 28.8, MMLU 23.0 to 23.3 (still chance), HellaSwag 29.4 to 29.6; small costs on general text: PIQA 62.1 to 60.8, LAMBADA perplexity 99.6 to 115.3. MMLU/SciQ/OpenBookQA for earlier branches were run on CPU in float32; base-stem in float32 on GPU. Differences under ~1 point are noise. See the base-stem card for the full table.

Limits

Base model: it continues text, it does not follow instructions or answer questions (use a chat branch for that). Output is fluent but often factually wrong, and repetitive at low temperature. Weak at math and reasoning. No safety tuning. Not suitable for anything that needs reliable facts.

Use

pip install torch tiktoken safetensors
python chat.py   # type a prompt; /t 0.9 temperature, /n 200 length, /k 50 top_k

model.py is nanoGPT's. Weights are in model.safetensors (lm_head is tied to transformer.wte). For a chat version, load the chat-cpt branch (revision="chat-cpt" or git checkout chat-cpt).

License and data

Weights and code in this repo: MIT. The training datasets carry their own licenses (see each dataset card linked above), which may impose attribution or share-alike terms, so check them before commercial use.

Acknowledgements

Built with Andrej Karpathy's nanoGPT; data from Hugging Face's FineWeb, SmolTalk and Wikimedia / Project Gutenberg sources.