TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 44 of 62 · Post-training

Policy gradient and REINFORCE

Hard

What is the policy gradient, and how does REINFORCE estimate it for an LLM completion?

Why this mattersWhen a reward comes from a unit test or verifier rather than a differentiable loss, the log-derivative trick lets you update token probabilities from sampled rollouts.

1 · Start with the intuition

Think of the language model as a policy that chooses one token at a time. When you score a finished completion with a unit test, a math verifier, or a reward model, you cannot backpropagate through discrete token sampling or through a Python test runner. The policy-gradient identity (the log-derivative trick) gives you a clean way around that: sample completions from the model, score them, and nudge the log-probability of each sampled completion up or down in proportion to how much better or worse it scored than a baseline.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Sample rollouts online

Draw one or more completions y ~ πθ(· | x) from the current policy.

Next, we will look at: Score & subtract a baseline. Move on when this operation makes sense.

Visualizing the behavior

Where this sits: the RL-for-LLMs progression

VPGΨ = returnREINFORCER − baselineActor-criticlearned V(s)PPOclipped ratioGRPOgroup baselineVariantsDAPO · Dr. GRPO
Each step changes one thing: how Ψ (the weight on ∇ log π) is estimated, or how far one batch of samples may move the policy.

Weight on ∇ log π for four completions, rewards [1, 0, 0, 1]

Derived

No baseline: Ψ = R

completion 1
1.0
completion 2
0.0
completion 3
0.0
completion 4
1.0

Mean baseline: Ψ = R − 0.5

completion 1
+0.5
completion 2
-0.5
completion 3
-0.5
completion 4
+0.5
Without a baseline, wrong completions get zero weight and are never pushed down. The baseline centres the weights, so the same samples now push wrong answers down, with no change to the expected gradient.