Week 7 • Day 7Week 7
Day 7:Week 7, Day 7 (Mini-Project): Coding & Training a Modern `Llama-Style MiniGPT` from Scratch
Battle-tested daily lesson note • 100% runnable code, interview Q&A, test suite & interactive quiz
Week 7, Day 7 (Mini-Project): Coding & Training a Modern Llama-Style MiniGPT from Scratch
1. Architecture of Our Modern MiniGPT (Llama-3 Blueprint)
In this Week 7 capstone mini-project, we assemble all the building blocks we derived across Days 1–5 into a complete, working Llama-style Autoregressive Language Model (MiniGPT) in PyTorch:
RMSNormPre-NormalizationRoPERotary Position EmbeddingsGrouped-Query Attention (GQA)with Causal MaskingSwiGLUFeed-Forward Network- Weight-Tied Token Embedding &
LM Head(self.lm_head.weight = self.tok_emb.weight)
Week 7 Capstone Lab: From Zero Math to Working MiniGPT
Look at what your custom MiniGPT combines inside Tab 2 (Codes) — every modern component used by Llama 3 and Claude:
- Token Embedding Table: Turns word IDs into vectors.
- Causal Multi-Head Attention + RoPE: Lets tokens talk to earlier tokens without peeking ahead.
- Pre-Norm
RMSNorm+SwiGLUMLP + Residual Stream: Stacks clean Transformer blocks stably. - Autoregressive Generation Loop: Generates new tokens step-by-step using Temperature & Softmax!
Step-by-Step Study Checklist
- Read
minigpt_llama.pyin Tab 2 (Codes) top-to-bottom — notice how short (~150 lines!) an entire GPT architecture really is once you understand every piece! - Study the Cross-Entropy Training Loss step: predicting token
t+1from tokens0..t. - Test yourself in Tab 3 (Interview Questions) and Tab 5 (Quiz) before starting Week 8!