Augyanix

Complete AI Model Playbook

Build your own AI model, hands-on. Reel lo chusina 6 steps, nee laptop lo.

Tick the boxes as you go: your progress is saved on this device.

Creator: Augyanix · Series: AI with Augyanix · From: Day 5 "How an AI model is built" · Cost: ₹0 (free tools only)

👋
Namaste! Reel lo AI model ela build chestaro chusav. Ippudu nuvve chesi chudu. Ee playbook lo rendu chinna projects unnayi. Project 1 lo zero nundi oka tiny GPT train chestav (all 6 steps). Project 2 lo oka chinna open model ni nee own Q&A tho fine-tune chestav (step 5, the "missing step"). Pedda GPU avasaram ledu: laptop or free Google Colab saripotundi.

The 6 steps (recap)

StepWhat happensPlacement student exampleIn this playbook
1. Collection of dataGather lots of text = training dataCollecting notesYour own input.txt
2. CleaningRemove spam, repeats, junkThrowing away useless pagesA 10-line Python cleaner
3. TokenizationCut text into small pieces = tokensBreaking chapters into pointsprepare.py + tiktoken demo
4. Pre-trainingGuess the next token, check with the actual token, adjust weightsChecking with the answer keytrain.py
5. Fine-tuningTeach it to answer with Q&A examples = fine-tuning dataMock interviewsProject 2 (TRL)
6. TestingExam with questions it never saw = test dataThe final examValidation loss + unseen questions
✓ Final modelAll weights saved in one filePlacement ready!ckpt.pt / model.safetensors

Before you start: pick where to run

Rendu options. Beginners ki Option A (Google Colab) best: install emi ledu, free GPU kuda vastundi.

Option A · Google Colab (recommended, free, runs in the browser)

Colab = Google's free online Python notebook. Code Google computer lo run avtundi, nee laptop lo kaadu.

Colab rules to remember:

Option B · Your own laptop

Colab quick path: copy-paste cells

Colab lo unte, ee cells ni order lo okkokkati run cheyyi. Each cell = one + Code box. What each step means is explained in the projects below.

📓
Shortcut: ready notebook. ⬇ Download the Colab notebook Then open Colab → File → Upload notebook → pick playbook_colab.ipynb → set T4 GPU → run the cells one by one. On your phone (Instagram browser)? Open this page on a laptop for the notebook: Colab works best there.

Project 1 in Colab (tiny GPT from scratch, T4 GPU)

Cell 1 · setup (Colab already has PyTorch):

python
!git clone https://github.com/karpathy/nanoGPT.git
%cd nanoGPT
!pip install -q tiktoken

Cell 2 · Step 1, your data. Run it, click Choose files, pick your raw.txt. No file? Skip this cell: Shakespeare is downloaded automatically.

python
from google.colab import files
files.upload()   # saves raw.txt inside the nanoGPT folder

Cell 3 · Step 2, cleaning (only if you uploaded raw.txt):

python
%%writefile clean.py
lines = open("raw.txt", encoding="utf-8").read().splitlines()
seen, keep = set(), []
for line in lines:
    line = line.strip()
    if len(line) < 20: continue          # too short = junk
    if "http" in line: continue          # links / spam
    if line in seen: continue            # repeat lines
    seen.add(line)
    keep.append(line)
open("data/shakespeare_char/input.txt", "w", encoding="utf-8").write("\n".join(keep))
print(len(lines), "lines in,", len(keep), "lines kept")
python
!python clean.py

Cell 4 · Step 3, tokenization:

python
!python data/shakespeare_char/prepare.py

Cell 5 · Step 4, pre-training on the T4 GPU. It prints the loss every few steps; this can take a while. The model file is saved at every check (every 250 steps, when val loss improves). Want to stop early? Press ■ only after you see a step 250: ... val loss line, otherwise there is no model file yet.

python
!python train.py config/train_shakespeare_char.py --compile=False

Cell 6 · Step 6, testing: generate text from your model:

python
!python sample.py --out_dir=out-shakespeare-char

Cell 7 · ✓ Final model: download your weights file (ckpt.pt) before the runtime disconnects:

python
from google.colab import files
files.download("out-shakespeare-char/ckpt.pt")

Project 2 in Colab (fine-tune a small model, T4 GPU)

Start a new notebook (or Runtime → Restart session), turn on T4 GPU again, then:

Cell 1 · setup:

python
!pip install -q trl

Cell 2 · fine-tuning data: upload your qa.jsonl (format in Project 2 below):

python
from google.colab import files
files.upload()

Cell 3 · fine-tune + save (Step 5):

python
from datasets import load_dataset
from trl import SFTTrainer, SFTConfig

data = load_dataset("json", data_files="qa.jsonl", split="train")
data = data.train_test_split(test_size=0.2, seed=42)   # 20 % kept aside = test data

trainer = SFTTrainer(
    model="HuggingFaceTB/SmolLM2-135M-Instruct",
    train_dataset=data["train"],
    eval_dataset=data["test"],
    args=SFTConfig(output_dir="my-model", num_train_epochs=3, report_to="none"),
)
trainer.train()
trainer.save_model("my-model")

Cell 4 · testing (Step 6), before vs after:

python
from transformers import pipeline
for name in ["HuggingFaceTB/SmolLM2-135M-Instruct", "my-model"]:
    chat = pipeline("text-generation", model=name)
    out = chat([{"role": "user", "content": "How should I prepare for an HR round?"}], max_new_tokens=80)
    print(name, "→", out[0]["generated_text"][-1]["content"])

Cell 5 · ✓ Final model: zip and download it:

python
!zip -r my-model.zip my-model
from google.colab import files
files.download("my-model.zip")

If Colab asks for a "WANDB" or "HF_TOKEN" key: you don't need one for this playbook. Click Cancel / skip; report_to="none" already turns off logging.

Project 1 · Train a tiny GPT from scratch (steps 1 to 6)

Time: one weekend. Machine: any laptop (CPU is fine, just slower).

We use nanoGPT by Andrej Karpathy: small, readable code. Note: the author now marks nanoGPT as old/deprecated and points to his newer nanochat (that one needs big rented GPUs). For learning the 6 steps on a laptop, nanoGPT is still the simplest.

Setup

Step 1 · Collection of data

Rule: never collect private data of other people or paid content you don't own.

Step 2 · Cleaning

python
lines = open("raw.txt", encoding="utf-8").read().splitlines()
seen, keep = set(), []
for line in lines:
    line = line.strip()
    if len(line) < 20: continue          # too short = junk
    if "http" in line: continue          # links / spam
    if line in seen: continue            # repeat lines
    seen.add(line)
    keep.append(line)
open("data/shakespeare_char/input.txt", "w", encoding="utf-8").write("\n".join(keep))
print(len(lines), "lines in,", len(keep), "lines kept")

Step 3 · Tokenization

python
import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
ids = enc.encode("I am ready for the interview")
print(ids, [enc.decode([i]) for i in ids])

Step 4 · Pre-training

bash
python train.py config/train_shakespeare_char.py --device=cpu --compile=False --eval_iters=20 --log_interval=1 --block_size=64 --batch_size=12 --n_layer=4 --n_head=4 --n_embd=128 --max_iters=2000 --lr_decay_iters=2000 --dropout=0.0

Apple Silicon Mac: use --device=mps instead of --device=cpu (faster).

Step 5 · Fine-tuning

Step 6 · Testing

✓ Final model

Project 2 · Fine-tune a small open model (step 5, the missing step)

Time: 1-2 hours. Machine: free Colab T4 GPU recommended.

Instead of training from zero, take a small open model and teach it YOUR style of answers with your own Q&A examples. We use SmolLM2-135M-Instruct (Apache-2.0 license, tiny) and Hugging Face TRL.

Setup

Fine-tuning data (Q&A examples)

json
{"messages": [{"role": "user", "content": "Tell me about yourself"}, {"role": "assistant", "content": "Hi, I'm a final-year CS student. I love building small Python projects..."}]}
{"messages": [{"role": "user", "content": "Placements ki tips?"}, {"role": "assistant", "content": "1. Basics revise cheyyi. 2. Mock interviews cheyyi. 3. Resume ready chesko."}]}

Train (fine-tune)

python
from datasets import load_dataset
from trl import SFTTrainer, SFTConfig

data = load_dataset("json", data_files="qa.jsonl", split="train")
data = data.train_test_split(test_size=0.2, seed=42)   # 20 % kept aside = test data

trainer = SFTTrainer(
    model="HuggingFaceTB/SmolLM2-135M-Instruct",
    train_dataset=data["train"],
    eval_dataset=data["test"],
    args=SFTConfig(output_dir="my-model", num_train_epochs=3, report_to="none"),
)
trainer.train()
trainer.save_model("my-model")

Test (step 6)

python
from transformers import pipeline
for name in ["HuggingFaceTB/SmolLM2-135M-Instruct", "my-model"]:
    chat = pipeline("text-generation", model=name)
    out = chat([{"role": "user", "content": "How should I prepare for an HR round?"}], max_new_tokens=80)
    print(name, "→", out[0]["generated_text"][-1]["content"])

✓ Final model

Mistakes beginners make

Learn more (free)

Practice offline

🚀
Next: Day 6, "Which model for which job?": ChatGPT, Claude, Gemini, ye doubt ki edi vaadali. Follow Augyanix, miss avvaku! Full roadmap: "Complete AI Roadmap" (link in bio).