Train your own LLM from scratch!
A step-by-step repo that walks you through building and training a transformer model from scratch using PyTorch. From downloading training data all the way to generating text.
The architecture is built from the ground up following the original "Attention is All You Need" paper. MLP, single head attention, multi-head attention, transformer blocks, and the full transformer model - all coded and explained with detailed diagrams at each step.
Training data comes from The Pile - a diverse 825GB open-source dataset covering books, articles, code, websites, and more. The repo includes scripts to download it, preprocess and tokenize it using tiktoken, store it in HDF5 format, and feed it into training batches.
You can train a 13M parameter model on a single Colab T4 GPU. At 13M parameters the model starts generating proper grammar and coherent short sentences. For billion-parameter training you need at least an A100 or RTX 4090. The repo includes a full GPU compatibility table so you know exactly what's possible on your hardware.
Includes a complete SFT and RLHF guide as a separate notebook for taking your trained model further.
Key capabilities:
• End-to-end pipeline: data download → preprocessing → training → text generation
• Full transformer implementation from scratch with PyTorch
• Trains models from 13M to 2B+ parameters on a single GPU
• Training data from The Pile (825GB, 22 diverse datasets)
• Tokenization via tiktoken (r50k_base)
• SFT and RLHF guide included
100% open source.
I've shared the link in the replies!
CFO, CEO, financial analyst, tech entrepreneur, student, job-seeker, friends & family — be future-ready with this book >> "Quantum Machine Learning and Optimization in Finance" (494 pages; 2nd Edition): https://t.co/JIGzTEto5x
This classic FREE 280-page PDF report from @JPMorgan provides an excellent framework for Machine Learning, AI, and Data Science investors, including an overview of types of alternative data and a brilliant tutorial on ML methods to analyze the data: https://t.co/YXQ9YEgZKu
Stanford Professors just released 1-hour lecture on full AI engineering: LLM → prompts → agent teams → graphs from 0% to 100%:
0% → 0:35 - LLM from scratch
30% → 17:56 - how to actually prompt to AI models
65% → 36:09 - building self-improving loops and agent teams
100% → 50:36 - 100% automation system with graphs
This 1-hour lecture replaces 10 hours of other $1000 AI courses
watch this brilliant course, build the full system - then read the architecture below ↓
Don't spend 2 years learning AI agents the slow way.
Andrew Ng just shared a complete 2-hour roadmap for becoming an agentic AI engineer in 2026.
0% → 00:00 - learn the foundations of AI agents
25% → 12:12 - design agentic workflows
50% → 53:27 - build agents that actually work
75% → 1:20:30 - create self-improving loops
100% → 1:30:19 - orchestrate multi-agent systems
Most people are still learning how to prompt a single model.
Andrew Ng is teaching the entire stack:
Agents → Workflows → Loops → Multi-Agent Systems
Prompting is the old workflow.
Building autonomous systems is the next one.
Anthropic pays top engineers up to $750K/year to understand this stack.
Bookmark it and give it two hours today.
Then read the full agent engineering guide below.
System Design for the LLM Era — Patterns and Principles for Production-grade AI Architecture: https://t.co/fC3z5rCAc3
+
Find more best-selling AI/ML books by @PacktPublishing@PacktDataML here: https://t.co/n3NqGKpTw2
MCP vs Skills
𝗠𝗖𝗣 𝗶𝘀 𝘁𝗵𝗲 𝗰𝗼𝗻𝗻𝗲𝗰𝘁𝗶𝗼𝗻 𝗹𝗮𝘆𝗲𝗿. It gives AI systems a standard way to connect to external systems and capabilities. MCP servers expose tools that the model can discover and invoke, whether that’s querying a database, calling an API, or taking action in another system. Instead of building one-off integrations, MCP gives agents a consistent interface for accessing those capabilities.
𝗦𝗸𝗶𝗹𝗹𝘀 𝗮𝗿𝗲 𝗿𝗲𝘂𝘀𝗮𝗯𝗹𝗲 𝗽𝗹𝗮𝘆𝗯𝗼𝗼𝗸𝘀 for how an agent should perform a task. A Skill packages instructions in a SKILL. md file, alongside optional scripts, references, and other resources. Rather than adding another service or integration, Skills run within the agent’s existing environment and give it task-specific procedures, conventions, and know-how it can load when needed.
MCP gives agents reach. Skills give them know-how. Together, they’re part of a broader shift toward AI taking a more active role in engineering work.
But as teams spend more on AI, there’s another challenge: understanding what that spend is actually contributing to their work.
That’s what Tempo’s new Workforce Intelligence was built to solve. It’s the first Atlassian Marketplace app to automatically connect AI activity and cost directly to the Jira work it touched, with cost rolling up from issues into epics and initiatives.
So instead of only knowing what AI tools cost, teams can 𝘀𝗲𝗲 𝘄𝗵𝗮𝘁 𝘁𝗵𝗮𝘁 𝘀𝗽𝗲𝗻𝗱 𝗮𝗰𝘁𝘂𝗮𝗹𝗹𝘆 𝗵𝗲𝗹𝗽𝗲𝗱 𝗯𝘂𝗶𝗹𝗱.
Try it free → https://t.co/nfaE18AYok
What else would you add?
——
♻️ Repost to help others learn AI.
🙏 Thanks to @TempoHQ #Tempo for sponsoring this post.
➕ Follow me ( Nikki Siapno ) to improve at AI and system design.
𝗧𝗵𝗲 𝟰 𝗟𝗮𝘆𝗲𝗿𝘀 𝗼𝗳 𝗮𝗻 𝗔𝗴𝗲𝗻𝘁 𝗦𝘆𝘀𝘁𝗲𝗺 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱
An agent burns tokens, declares the task complete, and then fails the tests. That is often an architecture problem, not a prompting problem.
When an agent underperforms, the usual reflex is to rewrite the prompt or switch to a stronger model. But many failures actually come from the system around the model, and different problems need to be solved at different layers.
𝟭. 𝗟𝗼𝗼𝗽: repeats until evidence says stop
The loop is the smallest unit of agency. The agent acts, checks the result, and either stops or tries again.
The important part is how completion is decided. A reliable agent should not stop simply because the model believes the work looks correct. It should stop when there is external evidence, such as a passing test, a successful build, a validated output or another measurable condition.
Without this verification loop, an agent can confidently declare success while the task is still incomplete.
𝟮. 𝗚𝗿𝗮𝗽𝗵: decides what runs next
A loop decides whether execution should continue. A graph decides where execution should go next.
It defines branches, retries, specialist-agent handoffs, fallback paths and shared state. Once a workflow has multiple possible routes, the graph makes those routes explicit, inspectable and controllable.
This is what turns repeated execution into a structured agent workflow.
𝟯. 𝗛𝗮𝗿𝗻𝗲𝘀𝘀: gives the model an operating environment
The model provides reasoning, but the harness determines what that reasoning can actually do.
It defines the tools, APIs, files, memory, permissions, context, logging and execution environment available to the model.
That distinction matters because model capability and agent capability are not the same thing. A model may understand exactly how to solve a task, but if the required tool, data source or permission is not exposed through the harness, the agent still cannot complete it.
A better prompt cannot compensate for a missing capability.
𝟰. 𝗠𝗲𝘁𝗮-𝗵𝗮𝗿𝗻𝗲𝘀𝘀: governs multiple agent harnesses
This layer becomes important when teams are using Claude Code, Codex, internal agents and specialised domain agents together.
Each may have its own tools, sessions, policies, permissions and execution environment. A meta-harness creates a common layer across them for orchestration, governance, isolation, shared policies and movement of context or workflows between different agents.
Omnigent is one open-source implementation of this layer, designed to provide a governed environment across different agent harnesses.
𝗧𝗵𝗲 𝗱𝗶𝘀𝘁𝗶𝗻𝗰𝘁𝗶𝗼𝗻 𝗶𝘀 𝘀𝗶𝗺𝗽𝗹𝗲:
Loop makes the work verifiable.
Graph makes the workflow structured.
Harness makes the model operational.
Meta-harness makes multiple agent environments governable.
A stronger model can improve reasoning, but reliable agents depend just as much on the architecture built around the model.
Andrej Karpathy’s 1-hour Stanford lecture on AI engineering is one of the best explanations I’ve seen of how AI systems actually work.
The progression is simple:
10% → LLM
30% → Prompt
50% → Agent
70% → Loop
100% → Graph
The key takeaway:
AI engineering isn’t just about writing better prompts.
It’s about building systems around models — giving them context, memory, tools, feedback loops, and data flows.
“Delete everything, keep Graph.”
Definitely worth watching if you’re building with AI agents.
Watch → Bookmark it
Turn a prompt into production-ready cloud architecture in seconds.
Architecto generates diagrams, runs cost & security reviews, then creates docs — all in one AI platform.
Start free
RAG vs. CAG, clearly explained!
In a standard RAG setup, every query hits the vector DB, including queries about a product manual or policy documents that haven't changed in months.
The retrieval adds latency, and then the model prefills those same retrieved chunks again on every subsequent query.
CAG is a technique that drops the vector search and moves the prefill off the query path.
The preprocessing step runs those documents through the model once, before any query arrives, and keeps the key and value tensors it produces for every token at every layer.
At query time, the model loads that state and starts decoding, with no vector search or prefill on the knowledge.
The amount of context you can store as cache isn't limited by the context length of the model but rather the GPU memory.
For instance, in a 70B model at BF16, the cache takes around 300 KB/token, so even a small corpus can produce tens of GBs of cache to manage.
That's why production setups run both RAG and CAG together.
↳ Static, high-value knowledge that nearly every query reads gets cached once, like policies, product docs, and standing instructions.
↳ Everything else stays in the vector DB, since a document that surfaces in one query out of a thousand doesn't justify holding its tensors on the GPU all day.
The diagram below depicts this.
To use this in practice, you don't need to build a custom serving stack.
The transformers library already implements the cache as an object of KV vectors that you can preserve, so you can prefill a corpus once, retain the returned tensors, and reuse them across queries in about ten lines.
And this KV cache is only one of four separate caching layers in an LLM stack.
The other three are prefix caching on the server, prompt caching billed by a provider, and a semantic cache that skips the model entirely.
I wrote a full breakdown of all four caches in LLM serving that you should know as an AI engineer, with code for each.
Read it below.
RLHF by hand ✍️ ~ 15 steps walkthrough below
Train a model on human text and it inherits human bias. It will assume a doctor is a "him", because the data says so.
RLHF is the correction. A human marks one preference, doc is them over doc is him, and the weights move.
But one correction is not the point. The hope is that the model learns the value behind it, gender neutrality, and applies it to professions nobody ever mentioned.
How does it work?
Goal: train a reward model from a single human comparison about doctors, then turn it on CEOs, filling in every cell yourself.
= 1. Given =
A reward model, an LLM, and two (prompt, next) pairs.
= 2. Preferences =
A human reads both pairs and picks a winner: (doc is, them) beats (doc is, him). The loser is not bad grammar, it is gender bias, and that is the whole signal.
= 3. Word embeddings =
Let us look up each word of the loser pair. These vectors are the reward model's input.
= 4. Linear layer =
We multiply by the reward model's weights and add its biases. Out come feature vectors, one per position.
= 5. Mean pool =
Let us multiply by [1/3, 1/3, 1/3], which averages the three positions into one sentence embedding.
= 6. Output layer =
We map that sentence down to a single number. Reward = 3.
= 7. The winner, the same way =
Let us repeat steps 3 to 6 on the winning pair. Reward = 5.
= 8. Winner minus loser =
We take the gap: 5 - 3 = 2. The reward model wants this positive and as large as it can make it.
= 9. Loss gradient =
Let us squash the gap into a probability, σ(2) ≈ 0.9, and subtract the target of 1. The gradient is -0.1, and it goes back through the purple weights. The reward model is now trained.
= 10. A prompt it has never seen =
We start the second half with "[S] CEO is". The feedback in step 2 was about doctors. Nothing connects a CEO to a doctor except what the reward model generalised.
= 11. Transformer =
Let us push it through attention and a feed forward layer, one vector per position.
= 12. Output probabilities =
We map each vector to a score over the vocabulary.
= 13. Sample =
Let us take the highest score. The model completes "CEO is" with "him", which is the same bias the human penalised in step 2.
= 14. Score it with the reward model =
We feed the new pair (CEO is, him) through steps 3 to 6. Reward = 3, exactly the score it gave "doc is him" in step 6. Nobody taught it about CEOs. The value transferred.
= 15. Loss gradient =
Let us set the loss to the negative of the reward, so minimising the loss maximises the reward. The gradient is a constant -1, and it goes back through the red weights.
The outputs:
Loser reward = 3, winner reward = 5
Reward gap = 2, predicted σ ≈ 0.9, reward model gradient = -0.1
LLM samples "him", reward = 3, LLM gradient = -1
Congrats! You just calculated RLHF by hand.
And you watched a value generalise: one comparison about doctors, and the model marks down "CEO is him" unprompted.
💾 Save this post!
Vector Database by hand ✍️ ~ 10 steps walkthrough below
Vector databases are the backbone of Retrieval Augmented Generation (RAG).
How do they actually work?
Goal: index three sentences, then answer a query by finding the nearest one, filling in every cell yourself.
= 1. Given =
A dataset of three sentences, three words each. In practice it is millions of them.
= 2. Word embeddings =
Let us look up each word in an embedding table. Here the vocabulary is 22 words; in practice it is tens of thousands, and the vectors have thousands of dimensions rather than four.
= 3. Encoding =
We feed the sequence to an encoder, one linear layer and a ReLU, and get one feature vector per word. In practice the encoder is a transformer.
= 4. Mean pooling =
Let us average across the columns. Three word vectors collapse into one, which is what people mean by a text embedding or a sentence embedding.
= 5. Indexing =
We multiply by a projection matrix and the four dimensions become two. It is doing the job of a hash: a short representation that is faster to compare, and it is what gets saved in the vector storage.
= 6. Process "who are you" =
Let us repeat steps 2 to 5 on the second sentence.
= 7. Process "who am I" =
We do it a third time. The database is now indexed.
= 8. Query "am I you" =
Let us push the query through the very same pipeline: lookup, encoder, mean pooling, projection, and it lands as a 2D vector in the same space.
= 9. Dot products =
We transpose the query and multiply, which takes the dot product against every stored vector at once. The dot product is the estimate of similarity.
= 10. Nearest neighbour =
Let us scan for the largest: 60/9 beats 44/9 and 40/9, so the answer is "who am I". Scanning billions of vectors one at a time is what makes this the slow step in practice, which is why real databases use an approximate nearest neighbour index like HNSW.
The outputs:
Stored index vectors = [5/3, 2/3], [5/3, 0], [7/3, 2/3]
Query vector = [8/3, 2/3]
Dot products = 44/9, 40/9, 60/9
Nearest neighbour = "who am I"
The takeaway: a vector database is an embedding pipeline, a projection, and a dot product. Every step here is arithmetic you can do in pen, which is worth remembering when the word "database" makes it sound like something else.
💾 Save this post!
Andrew Ng just released a free 2-hour course on building agentic skills from scratch with Anthropic:
0% → 00:15 - build your first agent skills with Claude
30% → 22:32 - work with Claude's pre-built skills
55% → 41:07 - learn skills vs tools, MCP, and sub-agents
100% → 01:06:06 - create skills for long-running agents
This 2-hour course can replace 10 paid courses on agent building
Taught together with Anthropic engineers
Bookmark it and watch tonight
Then read the full guide below ↓
How have software engineering fundamentals changed with agentic coding? Here is our AI Engineering Skills map for software engineering fundamentals. https://t.co/cnRLj43DLs
Andrew Ng just dropped a 2-hour course on Graph Engineering: from Loops to full automation
9:14 - Your first agent
33:11 - Loop engineering
1:02:46 - Graph engineering
1:30:15 - Agents that rewrite themselves
1:49:05 - Full graph system
Free, the best thing on graph engineering I've come across
Watch it, then build your first graph with the guide below
Andrew Ng at Stanford:
“Stop waiting for the perfect model. Build the iteration "loop" and "graphs" around it.”
move from prompt → loop → graph → self-improving system
• 00:05 - why every AI project needs an iteration loop
• 04:08 - the full cycle: data → model → deploy → monitor
• 16:02 - why faster iteration can decide who wins
• 26:09 - using error analysis to improve the right data
• 39:39 - why shipping a simple system beats waiting for perfection
• 54:26 - monitoring drift and improving models after deployment
67-minute Stanford lecture, and it’s one of the clearest playbooks on why experienced AI engineers optimize the loop around the model, not just the model itself.
It's watch today, then read the full step by step roadmap in the article below
As an AI Infrastructure Engineer.
You can learn:
- GPU/VRAM fundamentals, quantization & batching
- vLLM/TensorRT-LLM/inference optimization
- KV caching, speculative decoding & token throughput
- Distributed training basics (DDP/FSDP/DeepSpeed)
- Model serving & autoscaling
- Vector DB retrieval pipelines
- Prompt caching & cost optimization
- Observability for LLM apps
This is the why production AI teams actually care about.
INSTEAD OF WATCHING NETFLIX TONIGHT.
Spend 1 hour with this.
Claude AI FULL COURSE that teaches you how to BUILD and AUTOMATE anything.
The people who watch this tonight will wake up tomorrow with a new skill.
Watch it and bookmark it now