lenatriestounderstand

Engineering Understanding

Lena Tries
To Understand

Interactive notes on AI, ML, data, systems, and the beautiful things behind them.

Read . Run . Understand .

  • Py Python-first
  • Run in-browser

Latest long reads

See all 54 notes
ML Systems
Lab inside

Isotonic Regression on GPU

torchisotonic and the paper behind it, in plain words. A curve that may only go up is a ten-line walk on a CPU, and a walk is the one thing a GPU cannot share out: on ten million numbers a far bigger GPU can be even slower. The way out is to stop walking and draw instead, since the fit is a string pulled tight under the running totals, and then to stop copying the pieces of that string that never change.

  • gpu
  • cuda
  • isotonic-regression
  • calibration
  • +4
Read
Oct 27, 2026
ML Systems

PagedAttention: Treating KV Memory Like Virtual Memory

A conversation's key/value cache grows one token at a time and nobody knows how long it will get. Give every request a contiguous buffer sized for the worst case and one Tesla T4 holds 573 of them, most of that memory reserved for answers that never arrive. Hand the same card out in blocks of 16 tokens and it holds several thousand. Measured on vLLM 0.29: what the block table costs the attention kernel, how the engine decides that two requests hold the same block, how much of the card the cache actually gets, and how many sequences all of it makes room for.

  • llm
  • inference
  • kv-cache
  • memory
  • +4
Read
Oct 26, 2026
ML Systems

Where Your Prompt Goes: Inside a Modern AI GPU

Follow one message into a 2026 AI server: through CPU memory, HBM4, compute dies, matrix units and the links between GPUs, then back out as an answer. Original interactive diagrams show where weights already live, what a request creates, and what the hardware waits for. Based on NVIDIA Rubin and AMD CDNA 5.

  • gpu
  • rubin
  • vera
  • cdna-5
  • +4
Read
Oct 26, 2026
Deep Learning
Lab inside

Knowledge Distillation: What a Teacher Actually Teaches

Training a small model on a large model's probabilities instead of the true labels often gives a better small model. Why that works, taken apart one ingredient at a time; what happens when the labels the teacher learned from were wrong; whether a stronger teacher makes a stronger student; what to copy, on which data and about which view of it; how long to train and how big the student should be before any of this matters; why copying the teacher and being right are different numbers; how a student can beat its teacher and which of its flaws it inherits; what changes for language models without logits; and when distillation pays for itself — measured on CIFAR-10 and on a small language model trained on this site's notes.

  • knowledge-distillation
  • model-compression
  • kl-divergence
  • regularization
  • +3
Read
Oct 25, 2026

Shorts

See all 57 shorts

Categories

Labs

See all 15 labs
ML Systems · Lab

Isotonic Regression on GPU

torchisotonic and the paper behind it, in plain words. A curve that may only go up is a ten-line walk on a CPU, and a walk is the one thing a GPU cannot share out: on ten million numbers a far bigger GPU can be even slower. The way out is to stop walking and draw instead, since the fit is a string pulled tight under the running totals, and then to stop copying the pieces of that string that never change.

Read
Oct 27, 2026
ML Systems · Lab

From Python Call to GPU Kernel: The C++ Underneath ML Libraries

One line of Python — index.search(query, k=10) — taken apart layer by layer, with a small nearest-neighbour library written in C++ and CUDA to take it apart with. Where numbers live and who frees them, what a copy of a gigabyte costs, why the order of additions changes both the speed and the answer, when an abstraction is free and when it is ruinous, what a template costs to compile, what happens between the call returning and the GPU finishing — and why the same search runs 25 times faster after eight rewrites that change nothing about what it computes. Measured end to end on a Kaggle T4.

Read
Oct 27, 2026
LLM · Lab

RLCR from Scratch: A One-Pass Decision Model with Honest Probabilities

A model reads a support ticket, picks a department, and returns 0.94. RLCR — training that number with a reward only an honest probability can maximise — and a small typed-decision model built from an ordinary encoder: one forward pass, every option a parallel branch, and the same weights trained seven ways to find out what the reinforcement learning actually adds.

Read
Sep 22, 2026
ML Systems · Lab

How LLM Inference Actually Works: Where the Time Goes on a Real GPU

What a GPU is actually doing while a language model answers: the generation loop, the prefill pass that reads the prompt and the decode steps that write the answer, the two waits a user feels — time to first token and time per output token — and why the second is limited by moving the model's weights through memory. Measured end to end on a Tesla T4, including why a token costs nine times what its bytes say, what a real kernel trace shows instead, and how latency and throughput pull apart when many people share one card.

Read
Sep 19, 2026

Favorites

ML Systems
Lab inside

Isotonic Regression on GPU

torchisotonic and the paper behind it, in plain words. A curve that may only go up is a ten-line walk on a CPU, and a walk is the one thing a GPU cannot share out: on ten million numbers a far bigger GPU can be even slower. The way out is to stop walking and draw instead, since the fit is a string pulled tight under the running totals, and then to stop copying the pieces of that string that never change.

  • gpu
  • cuda
  • isotonic-regression
  • calibration
  • +4
Read
Oct 27, 2026
LLM
Lab inside

RLCR from Scratch: A One-Pass Decision Model with Honest Probabilities

A model reads a support ticket, picks a department, and returns 0.94. RLCR — training that number with a reward only an honest probability can maximise — and a small typed-decision model built from an ordinary encoder: one forward pass, every option a parallel branch, and the same weights trained seven ways to find out what the reinforcement learning actually adds.

  • rlcr
  • calibration
  • reinforcement-learning
  • uncertainty
  • +2
Read
Sep 22, 2026
ML Systems
Lab inside

Matrix Multiplication: The Operation Behind Modern AI

Most of the arithmetic in a neural network is matrix multiplication. Written the obvious way it is correct, and fifty times slower than torch.mm on the same GPU. Where that difference comes from, one change at a time on a Tesla T4: coalescing, tiles, shared memory, registers, tensor cores and precision — and why almost all of it is about where the numbers are kept rather than how they are multiplied.

  • matrix-multiplication
  • cuda
  • tiling
  • shared-memory
  • +3
Read
Sep 12, 2026
ML Systems
Lab inside

How GPUs Actually Run Machine Learning

Why the same GPU is nineteen times faster than the CPU at one operation, eleven times at the next, and slower at a third — worked out on a real Tesla T4, from two numbers per machine: how fast it computes and how fast it moves bytes. Along the way: warps and SIMT, latency hiding, the memory hierarchy, arithmetic intensity, the roofline, and a power limit that moves the ceiling.

  • gpu
  • cuda
  • roofline
  • memory-bandwidth
  • +2
Read
Sep 11, 2026
LLM
Lab inside

Learning Rules from Examples: How Can a Model Discover a Hidden Rule?

A tiny synthetic world where the rule is hidden and the evidence is controlled. Version spaces and what a dataset actually tells you, why a deterministic likelihood makes generalization entirely a matter of prior, shortcut features, expected information gain and active learning, compositional and length generalization, bottom-up program search with observational-equivalence pruning, LLM-guided synthesis, and libraries that grow their own primitives — each turned into a small experiment with a deterministic verifier.

  • induction
  • program-synthesis
  • inductive-bias
  • hypothesis-space
  • +6
Read
Aug 9, 2026
Deep Learning
Lab inside

Mechanistic Interpretability: Looking Inside the Black Box

What it actually means to reverse-engineer a neural network into features and circuits: the residual stream as a linear object, the linear representation hypothesis, superposition and why features outnumber neurons, sparse autoencoders as dictionary learning, the QK/OV decomposition of attention, induction heads, and the causal methods — activation and path patching — that turn a plausible story into a verified mechanism.

  • interpretability
  • mechanistic-interpretability
  • superposition
  • sparse-autoencoders
  • +1
Read
Jul 3, 2026
Classical ML
Lab inside

Text Clustering: Representation Over Algorithm

One corpus of arXiv abstracts, clustered nine ways — and the finding that on real text the representation usually decides more than the algorithm.

  • clustering
  • text
  • embeddings
  • tf-idf
  • +2
Read
Jun 28, 2026
LLM

Why LLMs Sound Emotional — and Whether They Understand Emotion

Two halves of one question. Why an LLM's emotional language is generated, not felt, and where it comes from — preference data, reward models, safety tuning, system prompts; and whether it can actually understand emotion in others — theory of mind, the recognition benchmarks, and where the fluent performance turns brittle.

  • emotion
  • empathy
  • safety-tuning
  • theory-of-mind
Read
Jun 15, 2026
LLM

Why Different Models Feel Like Different Personalities

Same engine, different knobs: why one model reads as warm and another as businesslike. Traces 'personality' to concrete training choices — data mix, preference guidelines, reward model, safety tuning, character training — and folds in sycophancy as a personality artifact of RLHF.

  • personality
  • rlhf
Read
Jun 15, 2026
Embeddings and Retrieval
Lab inside

Embeddings: How Geometry Pretends to Be Meaning

Embeddings aren't an encoding of text — they're an attempt to make geometry behave as if it carried meaning. What it means to compress text into a fixed-length vector, how contrastive learning turns statistical structure into distances and directions, why cosine similarity works (and when it stops), how dimension, chunking, context window, and reranking change the physics of a retrieval pipeline, and where embeddings lie usefully.

  • embeddings
Read
Jun 8, 2026
Econometrics

Pricing and Elasticity

Pricing as the worked-example for the Econometrics track — why price is endogenous, the identification strategies (IV, FE, RD, DML, CATE), cross-price elasticity and cannibalization, and what-if analysis with its constant-elasticity caveats.

  • pricing
  • elasticity
  • demand
  • causal-inference
Read
Jun 7, 2026
Econometrics

Causal ML Beyond Econometrics

Causal ML at the meeting point of econometrics and ML — ATE vs CATE, uplift modelling, DML and orthogonal-moments inference, causal forests, counterfactual prediction, off-policy evaluation, and the standard mistakes from treating predictive models as causal.

  • causal-ml
  • uplift
  • dml
  • cate
Read
Jun 7, 2026
LLM

Fine-Tuning LLMs: When the Weight Delta Is Worth It

Fine-tuning is not prompt repair. It is a decision to write a reusable parameter delta into an existing checkpoint. That delta changes future logits, defaults, and trade-offs. This note is about when that is worth doing: what fine-tuning actually buys, how to tell whether a gap belongs in the weights, and why data, evals, forgetting, and probability shape matter more than the slogan 'just fine-tune it'.

  • fine-tuning
  • residual-stream
Read
May 30, 2026
Embeddings and Retrieval
Lab inside

Chunking Strategies

Chunking turns out to be more architectural than it looks. A walk through what a chunk has to satisfy at six different stages simultaneously, what RecursiveCharacterTextSplitter actually does under the hood, and what the 2024–2026 toolbox — late chunking, contextual retrieval, contextualized chunk embeddings, BGE-M3 multi-functionality, ColBERT late interaction — is actually for.

  • chunking
  • rag
Read
May 26, 2026
Embeddings and Retrieval

How Text Became Geometry

Sixty years of incremental work behind the modern embedding vector. From bag-of-words and BM25, through Word2Vec's distributional hypothesis, to contextual embeddings and contrastive retrieval models. The point isn't trivia — it's that each older idea is still in production today, and the picture only makes sense once you've seen the road that led here.

  • embeddings
  • history
  • retrieval
Read
May 21, 2026
LLM

The Hindsight Corpus: Time in LLM Pretraining Data

Saying a model was 'trained on text written before T' invites a picture of human knowledge as of T. The actual corpus is volumetrically skewed toward recent years, dominated by retroactively-edited sources like Wikipedia, missing reliable per-document timestamps, and survivor-biased for older periods. The mechanisms, the failure modes that fall out, what's silently absent from datasheets, and what time-aware pretraining would have to do differently.

  • pretraining
  • training-data
  • temporal
Read
May 13, 2026