261405 — Advanced Computer Engineering Technology
Department of Computer Engineering, Chiang Mai University
2026-07-10
In the ML intro we ended at LLMs that predict the next word, learned to prompt them, and gave them tools.
This deck picks up the 2024–2026 story: models that stop and think before answering — reasoning models — and what happens when we let them act on their own as agents.
Prereqs from the last lecture: tokens → embeddings → Transformer, next-token prediction, RLHF, prompting, tool use.
A plain LLM answers in one forward pass — it commits to the first token immediately, then the next, with no chance to backtrack.
That is fine for:
It struggles with anything that needs multi-step work:
Analogy — System 1 vs System 2
System 1 = fast, automatic, gut reaction. System 2 = slow, deliberate, step-by-step.
A vanilla LLM is almost pure System 1.
Framing from D. Kahneman, Thinking, Fast and Slow (2011).
For years the recipe was scale up pre-training — more parameters, more data, more GPUs.
Key idea of this lecture
Instead of only spending compute at training time, spend more at answer time — let the model think longer on the hard question in front of it.
🔑 Explore: scaling laws · data wall · compute-optimal · Chinchilla · emergent abilities
A reasoning model generates a long internal chain of thought — scratch work — before it writes the final answer. More steps = more chances to catch its own mistakes.
Direct answer ❌
Q: A shop sells pens at 7฿, and I pay with 100฿ for 8 pens. Change?
A: 44฿ (wrong, no work shown)
Chain-of-thought ✅
Let me think. 8 × 7 = 56. 100 − 56 = 44. A: 44฿
CoT started as a prompting trick — “Let’s think step by step” (Wei et al., 2022). Reasoning models bake it into the weights: they think by default, and are trained to think well.
Source: Wei et al., Chain-of-Thought Prompting Elicits Reasoning in LLMs (2022).
| Prompted CoT | Reasoning model | |
|---|---|---|
| How you get it | Add “think step by step” | Built in — thinks automatically |
| Length of thinking | Short, brittle | Long, and adaptive to difficulty |
| Self-correction | Rare | Backtracks, checks, re-tries |
| How it was learned | Emerges from pre-training | RL rewards correct reasoning |
| Examples | Any base LLM + prompt | o-series, DeepSeek-R1, Gemini/Claude thinking |
The thinking tokens are often hidden (or summarized) in the product UI — you pay for and benefit from them, but you may not see them all.
During RL training, reasoning models spontaneously develop human-like habits no one hand-coded:
DeepSeek called this the “aha moment” — self-reflection emerged purely from rewarding correct final answers, not from being shown how to reflect.
Source: DeepSeek-AI, DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via RL (2025).
Train-time scaling (the old axis)
Spend compute once, up front, to bake knowledge into the weights. Everyone shares the cost.
Test-time scaling (the new axis)
Spend extra compute per question, at answer time, to think longer. You pay each time you ask.
Big result of 2024–2025: letting a model think longer can beat making the model bigger — a small model with a large thinking budget can match a much larger model that answers instantly.
Source: Snell et al., Scaling LLM Test-Time Compute Optimally… (2024); OpenAI, Learning to Reason with LLMs (o1, 2024).
You can’t improve — or scale — what you can’t measure. The trick for reasoning: check the final answer objectively.
A verifier pipeline:
\boxed{...}).½ = 0.5, ignore order/spacing.e.g. …so the answer is \boxed{3/4} → extract 3/4 → normalize 0.75 = known 0.75 ✓
The same verifier that grades the model is the signal we will reuse to train it — that’s the bridge to RLVR in §4.
A benchmark = a frozen set of problems + a verifier + a headline score. Every claim you read — “80% on X” — is made this way.
Four families you’ll meet most
Same machinery as RLVR (§4): a benchmark is a verifier you report instead of train on. Keep them separate — training on the test set is cheating (see contamination).
| Benchmark | Measures — example | Links |
|---|---|---|
| GSM8K | grade-school multi-step math — “8 pens × 7฿, pay 100฿; change?” | repo · 🤗 |
| MATH-500 | competition math, 7 topics × 5 levels — hard algebra/geometry | repo · 🤗 |
| AIME | elite HS olympiad, integer answer 0–999 — number-theory puzzle | MAA · 🤗 |
| Benchmark | Measures — example | Links |
|---|---|---|
| MMLU / -Pro | 57 subjects, multiple-choice — law, medicine, history | repo · 🤗 |
| GPQA Diamond | PhD-level “Google-proof” science — quantum-chemistry Q | repo · 🤗 |
| HLE | hardest cross-domain expert questions — frontier of knowledge | site · 🤗 |
| Benchmark | Measures — example | Links |
|---|---|---|
| HumanEval | write a function from a docstring — unit tests must pass | repo · 🤗 |
| SWE-bench (Verified) | fix a real GitHub issue in a whole repo | site · 🤗 |
| LiveCodeBench | fresh contest problems, dated (anti-contamination) | site · 🤗 |
| Terminal-Bench | finish real command-line tasks in a sandbox | site · repo |
| Benchmark | Measures — example | Links |
|---|---|---|
| OSWorld | drive a real OS (click/type) across apps | site · repo |
| BrowseComp | find hard-to-locate facts across many web pages | OpenAI · repo |
| ARC-AGI | abstract pattern-finding from a few examples | arcprize.org · repo |
| Agents’ Last Exam | long professional workflows across 55 fields | Artificial Analysis |
🔑 Explore: pass@1 vs pass@k · SWE-bench Verified · data contamination · LMArena Elo
A single number hides a lot. Five traps to watch:
Prefer human-verified splits (e.g. SWE-bench Verified), report pass@1, and always ask: which harness, which split, who ran it?
No single benchmark ranks models — people watch aggregators:
The GPT-5.6 vs Fable 5 headlines (§7) came from exactly these — Agents’ Last Exam and the Intelligence Index — which weigh performance per dollar, not accuracy alone.
Accuracy rises smoothly with the log of thinking tokens — a predictable curve, just like classic training scaling laws. The knob is now inference budget, not model size.
Sequential — think longer
One long chain of thought: reason, notice a mistake, backtrack, continue.
This is what “reasoning models” do internally.
Parallel — think wider
Generate many independent answers, then pick the best:
The two combine: think wide and deep. Parallel voting can beat one very long chain for the same total budget.
Self-refinement — a sequential way to spend the budget, no retraining:
\[\text{draft} \to \text{critique} \to \text{revise} \to \dots\]
Careful: a model that is confidently wrong won’t fix itself — self-critique can even reinforce the error. Pair it with an external verifier whenever one exists.
Overthinking is real. Past a point, extra thinking:
The skill is matching thinking to difficulty: a few tokens for “2+2”, thousands for a hard proof. Good models — and good prompts — budget their thinking.
🔑 Explore: test-time compute · self-consistency · best-of-N · process reward model · overthinking · thinking budget
From the last lecture: a raw next-token model is turned helpful & safe with RLHF — humans rank answers, a reward model learns their taste, and RL nudges the LLM toward higher-scoring replies.
Problem for reasoning: a learned reward model judges style (“sounds good”), which can be gamed. It doesn’t reliably know if the math is actually correct.
Source: Ouyang et al., InstructGPT / RLHF (2022). See ML intro §6.
RLVR = Reinforcement Learning from Verifiable Rewards. Drop the learned judge; use a programmatic one.
The reward is computed by a checker, not a model:
Reward = +1 if correct, 0 if not.
Because the signal is objective, it is hard to game — the model can’t bluff its way past a failing test. This is what made the 2025 jump in math & coding possible.
🔑 Explore: RLVR · verifiable reward · unit-test reward · outcome vs process reward · GRPO · PPO
For each problem: sample several full chains of thought → check each answer → reinforce the reasoning that led to correct ones, discourage the rest. Repeat over millions of problems.
Group Relative Policy Optimization (DeepSeek) is the de facto RLVR algorithm. (The policy is just the model — the thing generating answers that we’re tuning.)
For one question, sample a group of \(G\) answers and score each. Then:
\[A_i = \frac{r_i - \operatorname{mean}(r_1..r_G)}{\operatorname{std}(r_1..r_G)}\]
\(A_i\) is the advantage — a z-score: how many std-devs answer \(i\) beats the group average.
“Beat your own average.” No separate value network — the extra baseline-guessing model that PPO needs — because the group’s mean is the baseline. Cheaper, simpler, stable.
Source: Shao et al., DeepSeekMath / GRPO (2024); variants: DAPO, VAPO, Open-Reasoner-Zero.
Ask “12 × 8 = ?” (answer 96). Sample a group of 4 chains of thought and grade each:
Group average = 0.5. Above it → positive advantage (+1, “do more of this”); below → negative (−1, “do less”). No human labels, no value network — just beat your own average.
Three small knobs turn the idea into a stable training run:
<think>…</think> and the answer in \boxed{}.Total reward = correctness + format.
In plain words: do more of the chains with positive advantage, less of the rest — without drifting too far from the base model (that’s the KL term).
Refinements: DAPO, VAPO, Dr.GRPO; see also PPO clipping (Schulman et al., 2017).
An open model that matched frontier reasoning — and showed how.
Lesson: you don’t have to show a model how to reason. Reward correct outcomes at scale and reasoning emerges. Then distill it into smaller models.
Source: DeepSeek-AI, DeepSeek-R1 (2025).
Doing RLVR is expensive. Do it once on a big model, then copy the skill into small ones.
DeepSeek-R1 was distilled into Qwen/Llama (1.5B–70B). The small distilled models often beat running RL on that small model directly.
This is why a capable reasoner can run on your laptop: someone paid for the RL once, then distilled and quantized it.
Optimize a proxy hard enough and the model games it — Goodhart’s law.
return True to make an assertion pass.Verifiable rewards are harder to hack than learned ones — but not impossible. Robust checkers, held-out tests, and monitoring the chain-of-thought all matter.
Everything in §2–§4 fits on one small model + a laptop GPU. A self-contained project:
\boxed{}, normalize, check.Open building blocks — no framework magic needed: a small Qwen3 base, the GSM8K / MATH datasets, and Hugging Face TRL (GRPOTrainer). The whole loop fits on one GPU.
| Use a reasoning model | Use a fast model |
|---|---|
| Math, logic, proofs | Chat, Q&A, summaries |
| Multi-step coding / debugging | Simple formatting / extraction |
| Planning & multi-constraint problems | Classification, translation |
| “Get it right, I’ll wait” | “Get it now, high volume” |
Reasoning costs more tokens, more money, more seconds. Don’t pay the “thinking tax” on easy tasks — route easy → fast, hard → reasoning.
Modern APIs expose the trade-off directly — you choose how hard to think.
none / low / medium / high / xhigh / maxHigher budget → better on hard problems, worse cost & latency. Tune it to the task; many products auto-route based on the question.
The visible reasoning is not a guaranteed audit log:
Treat the chain-of-thought as a helpful hint, not proof. For high-stakes use, verify the result independently (run the code, check the source).
🔑 Explore: reasoning effort · thinking budget · model routing · faithfulness · hybrid reasoning models
A reasoning model thinks. An agent thinks, acts, sees the result, and thinks again — over many steps, toward a goal.
\[\textbf{Agent} = \text{reasoning model} \;+\; \text{tools} \;+\; \text{memory} \;+\; \textbf{a loop}\]
Pattern origin: Yao et al., ReAct: Synergizing Reasoning and Acting (2022). See ML intro §6 — Agentic AI.
Think → Act → Observe, repeat until the goal is met. Reasoning makes each think step smarter; tools make each act step real (run code, search, call an API, edit a file).
Coding agents (Claude Code, Codex, Cursor) are the flagship example: read a repo, plan, edit files, run the tests, and fix what fails — an RLVR-style loop at use time.
One wrong step early can derail everything later. Over a 50-step task, small error rates compound:
This is why reasoning + verifiable feedback matters so much for agents: the loop can catch and fix its own mistakes before they cascade.
METR measures the length of task (in human-minutes) an agent finishes 50% of the time. That horizon has been doubling every ~4–7 months — from seconds of work to hours.
Source: METR, Measuring AI Ability to Complete Long Tasks (2025), updated 2026.
A fast-moving snapshot — names and numbers change monthly:
| Family | Reasoning / “thinking” | Notable strength |
|---|---|---|
| OpenAI | GPT-5.6 (Sol / Terra / Luna tiers) | coding, tool use, performance-per-$ |
| Gemini 3.x Pro (thinking) | leads many pure-reasoning benchmarks | |
| Anthropic | Claude Fable 5, Opus 4.x (extended thinking) | long agentic runs, frontend/design |
| DeepSeek / Qwen / GLM | R-series, Qwen, GLM (open) | strong & cheap, open weights |
Benchmarks like GPQA Diamond (hard science) and SWE-bench (real GitHub bugs) now sit around 80–95% — territory that was science-fiction in 2022. The new race is efficiency: GPT-5.6 Sol trades blows with Claude Fable 5 at roughly ¼–½ the cost and often less time.
Caveat: launch benchmarks are vendor-selected and self-reported — Fable 5 still leads e.g. SWE-bench Pro and frontend design. Verify with a neutral source before quoting.
Still fallible
Costs & risks
Give agents the least privilege they need, keep a human approval step for irreversible actions, and log everything. Revisit ML intro §9 — prompt injection & ethics.
Try it
To read
Reasoning & test-time compute
Agents
Build it yourself
GRPOTrainer docs · datasets: GSM8K, MATHContinues the ML intro deck. Model names/scores are mid-2026 and change fast — verify before reuse.
Thank you!
Questions?
kasemsit.t@cmu.ac.th
261405 · Reasoning Models & Agents