--- language: en library_name: transformers pipeline_tag: text-generation datasets: - roneneldan/TinyStories tags: - llama - causal-lm - tinystories - from-scratch --- ### **This work was done by Mohammad Almalke & Abdullrahman Almuharib** # GenerativeAICourse-llama-75m A 75M-parameter Llama-style language model trained from scratch on [TinyStories](https://huggingface.co/datasets/roneneldan/TinyStories) for a Generative AI course lab on scaling laws. It writes short, simple children's stories in English. ## Quick start ```python from transformers import AutoModelForCausalLM, AutoTokenizer repo = "superMohammad/GenerativeAICourse-llama-75m" tokenizer = AutoTokenizer.from_pretrained(repo) model = AutoModelForCausalLM.from_pretrained(repo) prompt = "Once upon a time, a little robot found a book." inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False) output = model.generate(**inputs, max_new_tokens=80, do_sample=False) print(tokenizer.decode(output[0], skip_special_tokens=True)) ``` ## Model | | | |---|---| | Architecture | `LlamaForCausalLM` | | Parameters | 74,998,272 | | Layers | 24 | | Hidden size | 512 | | MLP size | 1408 (SiLU) | | Attention heads | 8 query / 4 key-value (GQA), head dim 64 | | Context length | 512 tokens | | Vocabulary | 8,192 (byte-level BPE trained on the training split) | | Embeddings | tied input/output | ## Training | | | |---|---| | Data | 300,000 TinyStories documents, split 270k / 15k / 15k (train / val / test) | | Tokens seen | 524,288,000 (1,000 updates × 32 sequences × 32 accumulation × 512 tokens) | | Optimizer | AdamW, β = (0.9, 0.95), weight decay 0.1, grad clip 1.0 | | Learning rate | 3e-4, 100 warmup steps, cosine decay to 0 | | Precision | mixed precision (FP16 autocast) on a single GPU | | Seed | 42 | The run used about 35% of the Chinchilla-style budget of 20 tokens per parameter (≈1.5B tokens). ## Results | Split | Loss | Perplexity | |---|---|---| | Validation (before training) | 9.033 | 8374 | | Validation | 1.901 | 6.69 | | Test | 1.899 | 6.68 | The repository also contains `experiment.json` (the full run record) and `loss_curve.png`. **Prompt:** *Once upon a time, a little robot found a book.* - **Before training:** `bo bo bo bo bo bo ...` - **After training:** *The robot was very happy and wanted to read it. So, the robot went to the library to find the book. But when he got there, he saw that the book was not there. The robot was sad and scared...* ## Limitations - Trained only on synthetic children's stories, so it has no general knowledge and can't follow instructions. - It often repeats itself and loses track of characters in long generations. - English only, with a 512-token context.