CoolFace
Modelpublic

bhautikv/mini-gpt-tinystories

sourceHugging Facemitupdated 2mo agoView on Hugging Face
1likes215downloads
Model Card

Mini-GPT TinyStories

A compact GPT-2-style language model (~17.7M parameters) trained from scratch on the TinyStories dataset — a collection of 2.1M synthetically generated short stories designed for small-scale language model training.

<a href="https://huggingface.co/spaces/bhautikv/huggingface-static-f06c8a" target="_blank"><img src="https://raw.githubusercontent.com/gradio-app/trackio/refs/heads/main/trackio/assets/badge.png" alt="Visualize in Trackio" title="Visualize in Trackio" style="height: 40px;"/></a>

Model Details

ParameterValue
ArchitectureGPT-2 (decoder-only transformer)
Parameters17.7M
Layers6
Hidden dimension256
Attention heads8
Vocabulary size50,257 (GPT-2 BPE)
Context length256 tokens
TokenizerGPT-2
Training dataTinyStories (2,119,719 stories)
Training frameworkHugging Face Transformers + Accelerate

Evaluation Results

MetricScoreInterpretation
Validation Loss1.5902Cross-entropy on held-out stories
Avg Loss (2K samples)1.5700Independent re-evaluation
Perplexity4.81Excellent — model confidently predicts next tokens
BLEU0.1082Reasonable for open-ended generation
Distinct-10.4108Diverse vocabulary usage (>0.3 = good)
Distinct-20.7896Highly diverse phrase generation (>0.5 = good)
A perplexity of 4.81 is excellent for TinyStories — the model has learned the simple vocabulary and story structure well. For comparison, random prediction would yield perplexity ~50,257 (vocab size).

Usage

Quick Start

python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch

model_id = "bhautikv/mini-gpt-tinystories"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16)
model.to("cuda" if torch.cuda.is_available() else "cpu")

prompt = "Once upon a time, a little girl named Lily"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)

output = model.generate(
    **inputs,
    max_new_tokens=150,
    do_sample=True,
    temperature=0.7,
    top_p=0.9,
    repetition_penalty=1.1,
    pad_token_id=tokenizer.eos_token_id,
)

print(tokenizer.decode(output, skip_special_tokens=True))

Batch Generation

python
prompts = [
    "Once upon a time, a little girl named Lily",
    "The brave knight approached the dragon and",
    "One day, a small bird found a shiny",
]

for prompt in prompts:
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    output = model.generate(
        **inputs,
        max_new_tokens=120,
        do_sample=True,
        temperature=0.7,
        top_p=0.9,
        repetition_penalty=1.1,
        pad_token_id=tokenizer.eos_token_id,
    )
    print(tokenizer.decode(output, skip_special_tokens=True))
    print("---")

Training Procedure

Training Hyperparameters

HyperparameterValue
Learning rate3e-4
Train batch size (per device)32
Eval batch size (per device)32
Gradient accumulation steps2
Total effective batch size128
OptimizerAdamW (betas=(0.9, 0.999), eps=1e-8)
LR schedulerCosine
Warmup steps1,000
Number of epochs3
Total training steps43,179
Mixed precisionfp16 (Native AMP)
Seed42
Distributed typeMulti-GPU (2× T4)
Total eval batch size64

Training Results

Training LossEpochStepValidation Loss
3.15020.069510003.0154
2.45820.139020002.3299
2.22080.208430002.1053
2.10850.277940001.9927
2.02660.347450001.9238
1.97360.416960001.8746
1.93610.486470001.8391
1.91760.555880001.8104
1.89220.625390001.7867
1.87430.6948100001.7685
1.85300.7643110001.7514
1.83900.8338120001.7365
1.82450.9032130001.7248
1.81750.9727140001.7126
1.79691.0422150001.7037
1.79731.1117160001.6945
1.78341.1811170001.6860
1.76941.2506180001.6797
1.76231.3201190001.6723
1.75791.3896200001.6650
1.75141.4591210001.6569
1.75041.5285220001.6508
1.74171.5980230001.6460
1.73091.6675240001.6404
1.73351.7370250001.6354
1.72061.8065260001.6304
1.72091.8759270001.6256
1.72191.9454280001.6209
1.71102.0149290001.6172
1.70222.0843300001.6134
1.70072.1538310001.6100
1.68812.2233320001.6062
1.69692.2928330001.6029
1.69832.3623340001.6006
1.69402.4318350001.5985
1.68752.5012360001.5960
1.69482.5707370001.5946
1.69212.6402380001.5927
1.67952.7097390001.5918
1.68202.7792400001.5912
1.67992.8486410001.5906
1.68192.9181420001.5902
1.68482.9876430001.5902
1.67923.0431791.5902

Training Infrastructure

  • Platform: Kaggle Notebook (GPU T4 x2)
  • GPUs: 2× NVIDIA T4 (16GB each)
  • Distributed strategy: Accelerate launch with DistributedDataParallel
  • Experiment tracking: Trackio (Hugging Face)
  • Training time: ~6 hours (including data preprocessing)

Data Preprocessing

  1. 1.Loaded 2,119,719 training stories and 21,990 validation stories from TinyStories
  2. 2.Tokenized using GPT-2 BPE tokenizer (vocab size 50,257)
  3. 3.Concatenated all tokens and grouped into fixed 256-token blocks
  4. 4.Used DataCollatorForLanguageModeling with dynamic padding for training

Intended Uses & Limitations

Intended Uses

  • Educational demonstration of small-scale language model training
  • Generating simple children's stories with coherent structure
  • Baseline for experimenting with GPT-2 architecture modifications
  • Learning resource for distributed training with Hugging Face Accelerate

Limitations

  • Only trained on TinyStories — limited to simple vocabulary and short narratives
  • Small model size (17.7M params) limits complexity of generated stories
  • Context length of 256 tokens restricts long-form generation
  • Not suitable for production use, real-world text generation, or handling complex topics
  • May produce repetitive or nonsensical text outside the TinyStories domain

Framework Versions

  • Transformers 5.14.1
  • Pytorch 2.10.0+cu128
  • Datasets 5.0.0
  • Tokenizers 0.22.2
  • Accelerate (latest)
  • Trackio (latest)