Views
No views yet
| Component | Value |
|---|---|
| Parameters | 29,027,968 |
Embedding dim (n_embed) | 256 |
Attention heads (n_head) | 8 |
Transformer blocks (N_BLOCKS) | 4 |
| Context length | 256 |
| Vocab size | 50,304 (GPT-2 tokenizer, padded) |
| Positional embeddings | Learned |
transformers class). Token + learned-position
embeddings → 4 pre-norm Transformer blocks → final LayerNorm → tied-free LM head.| Setting | Value |
|---|---|
| Optimizer | AdamW |
| LR | 5e-4, decayed to 5e-5 at step 11,000 |
| Steps | 15,000 |
| Batch size | 16 |
| Train context | 256 |
| Grad clip | 1.0 (max norm) |
| Tokens seen | ~61M (≈2 tokens/param) |
| Hardware | Apple M2, MPS backend |
| Wall time | ~3.5 hours |
.pt file is a dict, not a bare state_dict:1{
2 "model_state_dict": ...,
3 "optimizer_state_dict": ...,
4 "losses": [...],
5 "train_loss": 3.918,
6 "dev_loss": 4.006,
7 "steps": 15000,
8 "device": "mps",
9 "pytorch_version": "...",
10 "cuda_version": None
11}Transformer + its Block) is not bundled here — clone it from the
training repo, or drop in modeling.py if included in this repo.1import torch
2from huggingface_hub import hf_hub_download
3# from your repo: from src.models.transformer import Transformer
4
5ckpt_path = hf_hub_download("Suyash11/pile-30m-base", "pile-30m-base.pt")
6ckpt = torch.load(ckpt_path, map_location="cpu")
7
8model = Transformer(
9 n_head=8, n_embed=256, context_length=256,
10 vocab_size=50304, N_BLOCKS=4,
11)
12model.load_state_dict(ckpt["model_state_dict"])
13model.eval()
14
15# generate (tokenize with the GPT-2 tokenizer)
16import tiktoken
17enc = tiktoken.get_encoding("gpt2")
18idx = torch.tensor([enc.encode("The meaning of life is")], dtype=torch.long)
19out = model.generate(idx, max_new_tokens=50)
20print(enc.decode(out[0].tolist()))