Mini-GPT From Scratch (PyTorch + Django) — AI Final Year Project With Live Demo
Back to ProjectTake this slow the first time. Once you've done it end to end, re-running is a 30-second job. I'm assuming you've never deployed anything before, so I'll spell everything out.
Open a terminal inside the project folder and run:
python -m venv venv
Then activate it. On Windows:
venv\Scripts\activate
On macOS or Linux:
source venv/bin/activate
You'll know it worked when you see (venv) at the start of your terminal line.
pip install -r requirements.txt
This pulls in the CPU build of PyTorch plus Django. Heads up — PyTorch is a chunky download, so give it a minute or two on slower internet. It's normal.
python -m model.train
This runs the default 3000 iterations. It prints a tokenizer demo, an untrained sample (pure gibberish — that's expected), the loss dropping every 250 steps, and finally a trained sample. When it finishes it writes checkpoints/model.pt and the log files the web demo reads. In a hurry? Run python -m model.train --max_iters 1000 for a faster, rougher run.
python manage.py migrate
This creates db.sqlite3 with Django's auth tables and the GenerationLog table that records each generation.
python manage.py runserver
Now open http://127.0.0.1:8000/ in your browser. Type a prompt, adjust temperature and top-k, and hit Generate.
python manage.py runserver 8001 and open http://127.0.0.1:8001/ instead.checkpoints/model.pt to exist, so run Step 3 before Step 5. And if you swapped in a new data/input.txt, retrain so the checkpoint's vocab matches the new text — otherwise decoding goes weird.Two quick checks. During training, the untrained sample should look like random junk and the trained sample should look at least a little more like real text — that gap means it learned. On the web page, all six panels should load: generation box, tokenization, loss curve, before-vs-after, next-character probabilities, and the attention heatmap. If you want to see the logging in action, create an admin user with python manage.py createsuperuser, then check /admin/ after a couple of generations.
Our team is here to assist you with installation and setup.