---
title: "Triton and hand-rolled kernels"
lesson_id: "10"
---

# Triton and hand-rolled kernels

- **Lesson ID:** 10
- **Goal:** If you cannot write a vector add, you cannot reason about FlashAttention. Start with Triton, then read why fused attention wins.
- **Human lesson:** [10-triton-and-hand-rolled-kernels.html](10-triton-and-hand-rolled-kernels.html)
- **Phase:** Phase 5 Inference

## Prerequisites

- The previous week's artifact, or a written note if this is week 1.
- Python 3.11+ and a laptop. CUDA is useful from week 5 onward and not required to read.

## Inputs, outputs, and artifacts

- **Inputs:** The replica from the prior week.
- **Outputs:** Add a Triton kernel and a naive-vs-fused timing note to project 7.
- **Artifacts:** Lesson notes plus the code named in the human page.

## Agent build steps

1. State the week 1 principle: you do not need to pretrain an 800B model to understand the shape of the problem; you do need progressively realistic replicas.
2. Teach the topics on the human page without inventing paper URLs or news claims.
3. Keep starter code in fenced blocks that match the human lesson.
4. End with the assignment and the opinion checkpoint.
5. Use Edge FDE tone: ship, do not sightseeing. Opinion checkpoints matter.

## Constraints

Plain spoken English. No quizzes. No em dashes. No invented metrics, dates, or citations. Brand Edge FDE only. Name well-known papers by title only: Attention Is All You Need, InstructGPT, Direct Preference Optimization, ZeRO, PagedAttention/vLLM, FlashAttention, Scaling Laws for Neural Language Models.

## Key concepts

- A Triton program maps a grid of blocks over data with a tail mask.
- HBM traffic, not FLOP myths, often sets the runtime.
- FlashAttention is fused attention that avoids a full score matrix in HBM.
- TinyGPT attention is the correct naive replica.

## Takeaways

- Type vector_add and check it against PyTorch.
- Write SRAM vs HBM in your own words.
- Do not invent a speedup. Time what you ran.

## Acceptance checks

- Human HTML has Key concepts and Takeaways.
- Opinion checkpoint is present.
- No em dash and no fake URL.
- [ ] Proceed to [lesson 11 brief](11-cluster-orchestration.llms.md).
