LeetLLM
My PlanLearnGlossaryTracksPracticeBlog
LeetLLM

Your go-to resource for mastering AI & LLM systems.

Product

  • Learn
  • Glossary
  • Tracks
  • Practice
  • Blog
  • RSS

Legal

  • Terms of Service
  • Privacy Policy

© 2026 LeetLLM. All rights reserved.

All Topics
Your Progress
0%

0 of 177 articles completed

🛠️Computing Foundations0/9
Git, Shell, Linux for AIDocker for Reproducible AIPython for AI EngineeringNumPy and Tensor ShapesCUDA for ML TrainingMPS & Metal for ML on MacData Structures for AISQL and Data ModelingAlgorithms for ML Engineers
📊Math & Statistics0/8
Gradients and BackpropVectors, Matrices & TensorsLinear Algebra for MLAdam, Momentum, SchedulersProbability for Machine LearningStatistics and UncertaintyDistributions and SamplingHypothesis Tests, Intervals, and pass@k
📚Preparation & Prerequisites0/13
Neural Networks from ScratchCNNs from ScratchTraining & BackpropagationSoftmax, Cross-Entropy & OptimizationRNNs, LSTMs, GRUs, and Sequence ModelingAutoencoders and VAEsThe Transformer Architecture End-to-EndLanguage Modeling & Next TokensFrom GPT to Modern LLMsPrompt Engineering FundamentalsCalling LLM APIs in ProductionFirst AI App End-to-EndThe LLM Lifecycle
🧮ML Algorithms & Evaluation0/11
Linear Regression from ScratchLogistic Regression and MetricsDecision Trees, Forests, and BoostingReinforcement Learning BasicsValidation and LeakageClustering and PCACore Retrieval AlgorithmsDecoding AlgorithmsExperiment Design and A/B TestingPyTorch Training LoopsDataset Pipelines and Data Quality
📦Production ML Systems0/6
Feature Engineering for Production MLBatch and Streaming Feature PipelinesGradient Boosted Trees in ProductionRanking and Recommendation SystemsForecasting and Anomaly DetectionMonitoring Predictive Models
🧪Core LLM Foundations0/8
The Bitter Lesson & ComputeBPE, WordPiece, and SentencePieceStatic to Contextual EmbeddingsPerplexity & Model EvaluationFile Ingestion for AIChunking StrategiesLLM Benchmarks & LimitationsInstruction Tuning & Chat Templates
🧰Applied LLM Engineering0/24
Dimensionality Reduction for EmbeddingsCoT, ToT & Self-Consistency PromptingFunction Calling & Tool UseMCP & Tool Protocol StandardsContext EngineeringPrompt Injection DefenseResponsible AI GovernanceData Labeling and Human FeedbackEvaluating AI AgentsProduction RAG PipelinesHybrid Search: Dense + SparseReranking and Cross-Encoders for RAGRAG Evaluation for Reliable AnswersLLM-as-a-Judge EvaluationBias & Fairness in LLMsHallucination Detection & MitigationLLM Observability & MonitoringExperiment Tracking with MLflow and W&BPrompt Optimization with DSPyModel Versioning & DeploymentSemantic Caching & Cost OptimizationLLM Cost Engineering & Token EconomicsModel Gateways, Routing, and FallbacksDesign an Automated Support Agent
🎓Portfolio Capstones0/9
Capstone: Delivery ETA PredictionCapstone: Product RankingCapstone: Demand ForecastingCapstone: Image Damage ClassifierCapstone: Production ML PipelineCapstone: Document QACapstone: Eval DashboardCapstone: Fine-Tuned ClassifierCapstone: Reproducible ML Study
🧠Transformer Deep Dives0/8
Sentence Embeddings & Contrastive LossEmbedding Similarity & QuantizationScaled Dot-Product AttentionVision Transformers and Image EncodersPositional Encoding: RoPE & ALiBiLayer Normalization: Pre-LN vs Post-LNMechanistic InterpretabilityDecoding Strategies: Greedy to Nucleus
🧬Advanced Training & Adaptation0/16
Scaling Laws & Compute-Optimal TrainingPre-training Data at ScaleBuild GPT from Scratch LabJAX for PyTorch ResearchersContinued Pretraining for Domain ShiftSynthetic Data PipelinesSupervised Fine-Tuning PipelineMixed Precision TrainingDistributed Training: FSDP & ZeROLoRA & Parameter-Efficient TuningReward Modeling from Preference DataRLHF & DPO AlignmentConstitutional AI & Red TeamingRLVR & Verifiable RewardsKnowledge Distillation for LLMsModel Merging and Weight Interpolation
🤖Advanced Agents & Retrieval0/16
Vector DB Internals: HNSW & IVFAdvanced RAG: HyDE & Self-RAGGraphRAG & Knowledge GraphsRAG Security & Access ControlStructured Output GenerationReAct & Plan-and-ExecuteGuardrails & Safety FiltersCode Generation & SandboxingComputer-Use / GUI / Browser AgentsHuman-in-the-Loop Agent ArchitectureAI Coding Workflow with AgentsAgent Memory & PersistenceAgent Failure & RecoveryRecursive Language Models (RLM)Multi-Agent OrchestrationCapstone: Production Agent
⚡Inference & Production Scale0/19
Inference: TTFT, TPS & KV CacheMulti-Query & Grouped-Query AttentionKV Cache & PagedAttentionPrefix Caching and Prompt CachingFlashAttention & Memory EfficiencyContinuous Batching & SchedulingScaling LLM InferenceModel Parallelism for LLM InferenceModel Quantization: GPTQ, AWQ & GGUFLocal LLM DeploymentSLM Specialization & Edge DeploymentSpeculative DecodingLong Context Window ManagementMixture of Experts ArchitectureMamba & State Space ModelsReasoning & Test-Time ComputeAdvanced MLOps & DevOps for AIGPU Serving & AutoscalingA/B Testing for LLMs
🏗️System Design Capstones0/9
Content Moderation SystemCode Completion SystemMulti-Tenant LLM PlatformLLM-Powered Search EngineVision-Language Models & CLIPMultimodal LLM ArchitectureDiffusion Models: Images & TextReal-Time Voice AI AgentReasoning Agent System Design
🎤AI Lab Interviewing0/4
AI Lab Coding Interview: Python SystemsAI Lab System Design InterviewAI Lab Behavioral InterviewAI Lab Technical Presentation
🔬Project Deep Dives0/17
Deep Dive - vLLMDeep Dive - SkyRLDeep Dive - FlashAttentionDeep Dive - FlashInferDeep Dive - DeepGEMMDeep Dive - NCCLDeep Dive - MegatronDeep Dive - DeepSpeedDeep Dive - RayDeep Dive - MLflowDeep Dive - PyTorchDeep Dive - TransformersDeep Dive - SGLangDeep Dive - slimeDeep Dive - DeepEPDeep Dive - TinkerDeep Dive - Light-PEFT
Back to Topics
LearnInference & Production ScaleReasoning & Test-Time Compute
📈HardReasoning & Scaling

Reasoning & Test-Time Compute

Understand how reasoning models trade extra inference compute for better answers, and what that means for search, verifiers, KV cache pressure, and routing.

38 min read
Learning path
Step 144 of 177 in the full curriculum
Mamba & State Space ModelsAdvanced MLOps & DevOps for AI

Personalize this lesson

Adapt explanations and teaching visuals to your background and preferred voice.

State Space Models showed one way to keep decode state from growing with context length by compressing history into recurrent state. Reasoning models move in the opposite direction on purpose: spend more inference compute when the task is hard enough to justify it.

Think about two incident agents handling the same failed deployment. The first accepts the first rollback plan that looks plausible. The second checks failing tests, deploy diff, error budget, database migration state, and rollback blast radius before committing. When those checks catch a real mistake, the second plan performs better, not because the agent has different data, but because it spends more compute on the decision.

The same idea now shapes how frontier large language models (LLMs) are built and evaluated. Classic scaling work focused on train-time compute: more parameters, more data, and more pretraining FLOPs (floating-point operations).[1]Reference 1Scaling Laws for Neural Language Modelshttps://arxiv.org/abs/2001.08361 Work from 2024 onward made a second axis impossible to ignore: on hard reasoning tasks, you can often get better answers by spending more compute during generation itself.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314[3]Reference 3Learning to reason with LLMshttps://openai.com/index/learning-to-reason-with-llms/ This is test-time compute scaling. Reasoning-model APIs from OpenAI and open-weight systems such as DeepSeek-R1 made this shift visible, and Snell et al. showed that, on tasks where a smaller model already has a non-trivial chance of success, extra inference-time compute can beat a much larger single-pass model.[3]Reference 3Learning to reason with LLMshttps://openai.com/index/learning-to-reason-with-llms/[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314

Current open-weight systems expose this choice directly. GLM-5.2 supports thinking and effort controls on a 744B-A40B MoE with 1M text context. DeepSeek V4 Flash 0731 offers low, high, and max effort on a 284B/13B core with 1M text context. Both are MIT-licensed, cluster-scale models. More effort can improve difficult work, but it also increases latency, output volume, and GPU occupancy.[6]Reference 6GLM-5.2 Model Cardhttps://huggingface.co/zai-org/GLM-5.2[7]Reference 7GLM-5 Repositoryhttps://github.com/zai-org/GLM-5[8]Reference 8GLM-5.2 Model Documentationhttps://docs.z.ai/guides/llm/glm-5.2[9]Reference 9Use DeepSeek with Codexhttps://api-docs.deepseek.com/quick_start/agent_integrations/codex/

Provider controls are model-specific and they change. OpenAI documents reasoning.effort; Google's Gemini docs distinguish Interactions API generation_config.thinking_level from GenerateContent thinkingConfig.thinkingLevel for Gemini 3 and thinkingConfig.thinkingBudget for Gemini 2.5; Anthropic's current Claude Opus 4.8 and 4.7 docs use adaptive thinking with an effort parameter, while older Claude models use manual extended thinking with budget_tokens.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning[10]Reference 10Gemini thinkinghttps://ai.google.dev/gemini-api/docs/thinking[11]Reference 11Building with extended thinkinghttps://docs.claude.com/en/docs/build-with-claude/extended-thinking The durable skill is deciding how much compute a request deserves, because more thinking isn't always better.[12]Reference 12Does Thinking More Always Help? Mirage of Test-Time Scaling in Reasoning Modelshttps://arxiv.org/abs/2506.04210

Some problems need deliberate reasoning instead of fast pattern matching, and test-time compute scaling turns that extra work into a production design choice. You'll need a basic mental model of how transformers predict the next token (covered earlier in the preparation path). The practical goal is to choose between single-pass, best-of-N, and guided-search strategies, then explain why routing and token budgets matter as much as the algorithms.

Inference budget router showing easy requests sent to single pass, uncertain requests to best-of-N sampling, and hard verifiable requests to guided search, alongside a quality frontier that rises with more test-time compute.
Test-time compute is a routing choice: easy requests stay cheap, uncertain requests buy samples, and hard verifiable requests may justify guided search.

What does test-time compute scaling add that train-time scaling alone doesn't?

Answer

Train-time scaling spends compute before deployment to improve the model. Test-time scaling spends extra compute during generation through longer traces, more samples, revision, or search, so hard tasks can get more deliberation than easy tasks.

System 1 and System 2 thinking

Psychologist Daniel Kahneman's framework is a useful starting point. System 1 is fast, instinctive, and pattern-driven. When you read the word "strawberry" and immediately know it's a fruit, that's System 1. System 2 is slow, deliberate, and step-by-step. When you count how many times the letter "r" appears in "strawberry," you have to switch to System 2 because your gut reaction ("two?") is often wrong. The correct answer is three, but you only get there by checking each letter deliberately.

The System 1/System 2 distinction is an analogy for serving behavior, not an architectural taxonomy. A low-budget single-pass call may answer from strong patterns; a model or surrounding system with more budget can check intermediate work, sample alternatives, or run tools. On tasks that require counting, lookahead, or multi-step deduction, that extra verification path can matter.

Reasoning-oriented models and systems are designed to make deliberate behavior easier to buy at inference time. Depending on the model and wrapper, they may spend non-visible reasoning tokens, sample alternatives, run an external verifier, or revise a candidate. Compare an agent that accepts the first patch with one that reproduces the failing test, checks the diff, verifies side effects, and only then commits.

This shift from pure pattern matching to deliberate reasoning is what makes test-time compute scaling possible.

Why is counting the "r" letters in "strawberry" a System 2 task for a model?

Answer

The answer isn't a stored fact or a fluent association. The model must deliberately inspect positions and verify the count before answering, which is exactly the kind of work extra reasoning tokens can support.

Why low-budget generation can fail on hard problems

Here's a concrete example. Ask a model: "How many times does the letter 'r' appear in the word 'strawberry'?" A rushed answer can be "two," because the third "r" in "strawberry" is easy to miss without a check.

The problem isn't that the model lacks knowledge. It's that the task requires deliberate step-by-step verification, not fast association. Pretraining optimizes next-token prediction, which rewards fluent continuations more directly than checked final answers. On problems like complex math, code debugging, or incident triage, the same dynamic appears: the model produces a plausible-looking answer that collapses under scrutiny.

Test-time compute scaling can address this failure mode by spending budget before committing. Instead of one shot, the model or the system around it can explore multiple approaches, verify intermediate steps, and select a candidate. The extra compute only helps when exploration or verification changes the result for the better.

When does extra inference compute help most?

Answer

It helps when the task requires verifiable multi-step reasoning, search, or correction. It helps much less for fluent pattern-matching tasks such as simple extraction, translation, or sentiment classification.

The two axes of compute scaling

The operational distinction is simple: train-time compute is spent before deployment to improve the model. Test-time compute is spent during a live request: trying alternate fixes, checking evidence, and verifying the answer before committing.

Classic scaling emphasized the pre-season tuning. Evaluations on reasoning tasks now show that inference-time allocation can sometimes compete with moving to a larger single-pass model.

Traditional scaling focuses on train-time compute, increasing model parameters NNN or training tokens DDD. The relationship between compute and loss follows a power law:

Ltrain(C)∝C−α,C=6NDL_{\text{train}}(C) \propto C^{-\alpha}, \quad C = 6NDLtrain​(C)∝C−α,C=6ND

Empirical scaling studies fit loss with an approximate power law of compute CCC, where training compute is often estimated as roughly 6 × model parameters NNN × training tokens DDD.[1]Reference 1Scaling Laws for Neural Language Modelshttps://arxiv.org/abs/2001.08361 Within the measured regime, increasing training compute reduces loss predictably enough to guide training decisions.

Test-time compute scaling adds a second axis, inference compute CinferC_{\text{infer}}Cinfer​. Treat accuracy as a function of inference compute, task shape, policy, and verifier quality:

accuracy=g(Cinfer,task,policy,verifier)\text{accuracy} = g(C_{\text{infer}}, \text{task}, \text{policy}, \text{verifier})accuracy=g(Cinfer​,task,policy,verifier)

In a measured operating range, more inference compute can improve accuracy with diminishing returns. It can also plateau or reduce accuracy when a trace overthinks, sampled candidates are correlated, or a verifier selects the wrong branch. That extra compute can come from longer reasoning traces, repeated sampling, revision loops, or explicit search with a verifier.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314[12]Reference 12Does Thinking More Always Help? Mirage of Test-Time Scaling in Reasoning Modelshttps://arxiv.org/abs/2506.04210

Snell et al.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314 don't claim one universal law for every model and every benchmark. Their more useful result is operational: if you allocate inference compute well, test-time scaling is strong enough that it can outperform buying a larger model and sampling once.

Why does test-time compute have diminishing returns?

Answer

Early extra samples or reasoning steps often find obvious mistakes. Later compute tends to explore correlated candidates, repeat work, or hit verifier limits, so each additional token or branch buys less improvement.

This changes how systems spend compute on hard prompts:

text
1Traditional approach: Train bigger → Answer once → Done 2Reasoning approach: Train reasoner → Think longer → Search for best answer
measured-budget-sweet-spot.py
1budgets = [0, 128, 512, 2048] 2verified_accuracy = [0.71, 0.78, 0.83, 0.80] 3latency_ms = [220, 310, 610, 1840] 4latency_limit_ms = 1000 5 6eligible = [ 7 (accuracy, budget, latency) 8 for budget, accuracy, latency in zip(budgets, verified_accuracy, latency_ms) 9 if latency <= latency_limit_ms 10] 11accuracy, budget, latency = max(eligible) 12print(f"chosen_budget={budget} accuracy={accuracy:.0%} latency_ms={latency}") 13print(f"max_budget_is_best={verified_accuracy[-1] == max(verified_accuracy)}")
Output
1chosen_budget=512 accuracy=83% latency_ms=610 2max_budget_is_best=False

This evaluation table encodes the production question: choose the best measured quality under the service-level objective, rather than assuming the longest trace is best.

How reasoning models work

Reasoning-oriented training and inference policies allocate additional tokens or branches before returning an answer. The visible behavior can include decomposition, checks, or revision, but those behaviors are capabilities to evaluate rather than guarantees of every response.

Extended chain-of-thought

Reasoning models often generate long scratchpads or intermediate traces around a final answer. Sometimes that trace is exposed, sometimes it's summarized, and sometimes it's hidden entirely by provider policy. Some current APIs can interleave non-visible reasoning with visible output or tool calls. What matters isn't whether the user sees every token, but whether the model is allowed to spend additional inference-time compute while solving the task.

This built-in reasoning process differs from prompted chain-of-thought (CoT)[13]Reference 13Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.https://arxiv.org/abs/2201.11903 in several key ways:

  1. Usually learned during post-training via Reinforcement Learning (RL), distillation, or both, rather than relying on prompt wording alone.
  2. Potentially variable-length: the API or serving policy can permit different budgets by request
  3. Can include self-correction: a trace may backtrack, recognize dead ends, and revise earlier steps
  4. Often hidden or summarized: providers may not expose the raw reasoning tokens directly

Current reasoning APIs make this concrete. OpenAI's reasoning docs describe reasoning tokens as non-visible output tokens that still consume context budget and count as billed output tokens. The docs also describe interleaved thinking for some current models, where visible output or tool calls can appear between reasoning steps.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning

The thinking budget is now a primary control surface, even though providers expose it with model-specific knobs. OpenAI's reasoning.effort sets an effort level for reasoning models.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning Gemini's Interactions API uses generation_config.thinking_level; GenerateContent uses thinkingConfig.thinkingLevel for Gemini 3 and thinkingConfig.thinkingBudget for Gemini 2.5, with SDK-specific casing such as Python thinking_config.thinking_level and thinking_budget.[10]Reference 10Gemini thinkinghttps://ai.google.dev/gemini-api/docs/thinking Claude Opus 4.8 and 4.7 use adaptive thinking plus effort; Anthropic documents budget_tokens for older Claude extended-thinking models.[11]Reference 11Building with extended thinkinghttps://docs.claude.com/en/docs/build-with-claude/extended-thinking Provider prompting guidance also differs by model, so start with a clear task and constraints, tune the supported knob, and evaluate instead of assuming a chain-of-thought prompt helps.

Test-time compute can mean either a longer single trace or multiple sampled traces. OpenAI's o1 launch post made this visible at the benchmark level: on AIME 2024 (a math competition benchmark), reported accuracy improved when the system moved from a single sample to consensus over 64 samples and then to learned reranking over 1000 samples.[3]Reference 3Learning to reason with LLMshttps://openai.com/index/learning-to-reason-with-llms/ Treat this as one reported evaluation result, not a guarantee for other tasks or selection rules.

Why can provider-reported non-visible reasoning tokens affect cost and capacity even when users never see them?

Answer

When the provider accounts for non-visible reasoning tokens, they still consume billed output tokens and context budget. They can also add wall-clock work. Transformer runtimes that materialize them autoregressively retain temporary key-value (KV) state while generating them, so a short visible answer can still be expensive.

Deliberation and search at inference time

Test-time compute is an umbrella term, not a single algorithm. Some systems sample many complete answers and pick a winner. Some iteratively critique and revise one candidate. Others run explicit search over partial reasoning states using a verifier or reward model. All of these patterns branch from the same idea: spend extra compute to explore, score, and refine before returning an answer.

Reasoning search tree: one prompt branches into three candidate paths, a verifier prunes two low-scoring paths, and one selected answer returns.
Reasoning delays commitment: extend, sample, revise, score, then choose the path worth trusting.

Not every reasoning model literally runs beam search or a PRM at inference time. The shared pattern is optional inference compute allocation. A good routing policy keeps easy requests cheap and assigns more tokens, branches, or verification only where evaluation shows a payoff.

What is the shared pattern behind longer traces, best-of-N, revision loops, and tree search?

Answer

They allocate more inference compute before committing to an answer. The system explores, verifies, revises, or selects among candidates instead of returning the first plausible completion.

Provider-reported hidden reasoning

Some hosted reasoning APIs report non-visible reasoning tokens in usage accounting while returning only a final visible answer. Others can interleave visible output or tool calls with non-visible work. OpenAI's reasoning-token documentation describes both patterns.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning Don't generalize this into one universal architecture: an open-weight deployment, explicit search wrapper, or provider with summarized thinking can expose and account for intermediate work differently.

Illustrative provider usage accounting where 2,400 non-visible reasoning tokens plus 600 visible answer tokens total 3,000 billed output tokens.
In this illustrative usage report, non-visible reasoning is 80% of 3,000 billed output tokens. Visible text alone understates output budget and temporary KV state for runtimes that materialize those tokens.

For such APIs, non-visible tokens matter because they consume context window space and may count toward billing even though users never see them.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning In transformer runtimes that materialize those tokens autoregressively, they also add decode work and temporary key-value (KV) cache state while generation is in progress. Exact cache behavior is provider- and engine-specific.

Why should prompts for a hosted reasoning model usually start simple and direct?

Answer

Clear task constraints, success criteria, and output requirements give a good evaluation baseline. Then follow the selected model's prompting guidance rather than assuming visible chain-of-thought instructions improve its non-visible reasoning.

hidden-token-accounting.py
1visible_tokens = 180 2reasoning_tokens = 1220 3output_price_per_million = 10.0 4 5billed_output_tokens = visible_tokens + reasoning_tokens 6cost = billed_output_tokens / 1_000_000 * output_price_per_million 7print(f"visible={visible_tokens} billed_output={billed_output_tokens}") 8print(f"visible_fraction={visible_tokens / billed_output_tokens:.1%} output_cost=${cost:.4f}")
Output
1visible=180 billed_output=1400 2visible_fraction=12.9% output_cost=$0.0140

Use the provider's usage schema and pricing table when implementing this calculation; the example demonstrates why billing and capacity dashboards can't count visible text alone.

Test-time compute strategies

Inference-time compute usually appears in a few patterns:

1. Best-of-N sampling

The simplest pattern is to generate 16 candidate fixes for a failed test and keep the one with the best verifier score. Each candidate is sampled separately, and more attempts raise your ceiling as long as they add useful diversity and your verifier or selection rule can reliably identify the best one. Shared model biases make the attempts correlated, not truly independent.

Best-of-N samples a generative model NNN times on the same prompt, then returns one winner by reward-model score or self-consistency (majority vote on extracted final answers).

  • Cost note: This method is easily parallelizable (all N attempts can run simultaneously), making it simple to implement but potentially expensive since you pay for all N completions.
1-best-of-n-sampling.py
1from collections import Counter 2 3def extract_answer(completion: str) -> str: 4 lines = [line.strip() for line in completion.splitlines() if line.strip()] 5 return lines[-1] if lines else "" 6 7def best_of_n( 8 model, 9 prompt: str, 10 n: int = 16, 11 reward_model=None 12) -> str: 13 """Generate N responses and return the best-scored candidate completion. 14 15 Cost: O(N) forward passes, embarrassingly parallel. 16 Best for: Problems with verifiable correctness (math, code). 17 """ 18 candidates = [model.generate(prompt) for _ in range(n)] 19 20 if reward_model: 21 scores = [reward_model.score(prompt, c) for c in candidates] 22 return candidates[scores.index(max(scores))] 23 else: 24 # Self-consistency: majority vote on final answer 25 answers = [extract_answer(c) for c in candidates] 26 answer_counts = Counter(answers) 27 best_answer = answer_counts.most_common(1)[0][0] 28 return next(c for c in candidates if extract_answer(c) == best_answer)

Scaling behavior

With an oracle verifier and independent samples, the chance of generating at least one correct answer in NNN tries follows:

Psuccess=1−(1−p)NP_{\text{success}} = 1 - (1 - p)^NPsuccess​=1−(1−p)N

Where ppp is the base probability of the model generating a correct answer on a single attempt. Real systems do worse than this idealized formula because samples are correlated and verifiers make mistakes, but the equation explains why best-of-N works at all. OpenAI's o1 launch post reports the same pattern on AIME 2024: o1 improved from 74% with one sample to 83% with 64-sample consensus and 93% when reranking 1000 samples with a learned scorer.[3]Reference 3Learning to reason with LLMshttps://openai.com/index/learning-to-reason-with-llms/

best_of_n_budget.py
1def success_probability(p: float, n: int) -> float: 2 return 1 - (1 - p) ** n 3 4base_hit_rate = 0.25 5tokens_per_attempt = 800 6 7for n in [1, 4, 16, 64]: 8 success = success_probability(base_hit_rate, n) 9 output_tokens = n * tokens_per_attempt 10 print(f"N={n:>2} success={success:5.1%} output_tokens={output_tokens:>5}")
Output
1N= 1 success=25.0% output_tokens= 800 2N= 4 success=68.4% output_tokens= 3200 3N=16 success=99.0% output_tokens=12800 4N=64 success=100.0% output_tokens=51200

The toy calculation shows why best-of-N is attractive and dangerous. The idealized success curve rises quickly, but cost rises linearly with every sampled completion. Real systems also plateau earlier because samples share model biases and verifiers make mistakes.

best-of-n-with-selection-errors.py
1def selected_success_probability(candidate_success: float, selector_recall: float, n: int) -> float: 2 return candidate_success if n == 1 else candidate_success * selector_recall 3 4base_hit_rate = 0.25 5selector_recall = 0.80 6for n in [1, 4, 16]: 7 oracle_success = 1 - (1 - base_hit_rate) ** n 8 deployed_success = selected_success_probability(oracle_success, selector_recall, n) 9 print(f"N={n:>2} oracle={oracle_success:5.1%} with_selector={deployed_success:5.1%}")
Output
1N= 1 oracle=25.0% with_selector=25.0% 2N= 4 oracle=68.4% with_selector=54.7% 3N=16 oracle=99.0% with_selector=79.2%

This toy selector is deliberately simple. With one candidate, there's nothing to select. Once multiple candidates exist, generating a correct candidate and selecting it become separate failure surfaces.

Best-of-N success probability curves showing fast early gains and diminishing returns for base hit rates of 10%, 25%, and 45% under idealized oracle selection.
Best-of-N helps most when the base model already has a meaningful hit rate and selection is reliable. If either condition fails, more samples mostly buy more repeated errors.

What must be true for best-of-N to pay off?

Answer

The base model must have a non-trivial chance of producing a correct candidate, the samples must add useful diversity, and the verifier or selection rule must reliably identify better answers.

Train for the test-time policy you plan to use

Ordinary supervised fine-tuning with cross-entropy (CE) rewards putting more probability on each demonstrated target. That is a sensible pass@1 objective, but a best-of-N system also needs useful coverage across samples. If training makes the model too confident in one narrow trace family, more samples can become near-duplicates and pass@N stops buying exploration.

Chen et al. show this mismatch on mathematical reasoning and theorem-proving settings: longer CE training can increase overconfidence while reducing pass@N, and a confidence-limiting objective better aligned training with later search.[14]Reference 14Rethinking Fine-Tuning when Scaling Test-Time Compute: Limiting Confidence Improves Mathematical Reasoninghttps://proceedings.neurips.cc/paper_files/paper/2025/hash/e8f4eae0a41cab67fdead3aa6b77f083-Abstract-Conference.html CE doesn't always hurt reasoning. Co-design training and search by evaluating the objective against the deployed metric, sample budget, next-token loss, and pass@1.

Why can cross-entropy SFT improve pass@1 yet hurt a best-of-N search policy?

Answer

CE can concentrate probability on one demonstrated trace and make samples less diverse. Pass@N needs coverage of at least one correct candidate, so training should be evaluated against the deployed sample budget and selection policy.

2. Sequential revision

This is like drafting a rollback plan, checking it against logs and migration state, then revising the weak steps before committing. Unlike best-of-N (where each attempt is independent), each revision builds on the previous one.

Sequential revision starts with one draft, then loops: critique the draft, and if the critique finds issues, regenerate an improved version. The sketch stops when the critique reports "no errors found". Production systems usually replace that string match with a trained verifier or structured critique schema.

2-sequential-revision.py
1def iterative_refinement(model, prompt: str, max_rounds: int = 5) -> str: 2 """Generate, critique, and refine until convergence. 3 4 Cost: O(rounds) sequential passes, each building on previous. 5 Best for: Open-ended tasks (writing, analysis, planning). 6 """ 7 response = model.generate(prompt) 8 9 for _ in range(max_rounds): 10 critique = model.generate( 11 f"Find errors or improvements in this response:\n" 12 f"Question: {prompt}\nResponse: {response}" 13 ) 14 15 if "no errors found" in critique.lower(): 16 break 17 18 response = model.generate( 19 f"Question: {prompt}\n" 20 f"Previous response: {response}\n" 21 f"Critique: {critique}\n" 22 f"Provide an improved response:" 23 ) 24 25 return response

When is sequential revision a better fit than best-of-N?

Answer

Use sequential revision when each pass can improve a draft through critique, editing, or repair. Use best-of-N when candidates are independent and the answer can be scored directly.

revision-early-stop.py
1verified_scores = [0.61, 0.76, 0.78, 0.781, 0.781] 2minimum_gain = 0.01 3used_rounds = 1 4 5for previous, current in zip(verified_scores, verified_scores[1:]): 6 if current - previous < minimum_gain: 7 break 8 used_rounds += 1 9 10print(f"used_rounds={used_rounds} selected_score={verified_scores[used_rounds - 1]:.3f}") 11print(f"skipped_rounds={len(verified_scores) - used_rounds}")
Output
1used_rounds=3 selected_score=0.780 2skipped_rounds=2

3. Tree search with process reward models

Tree search is heavier: a repair agent considers multiple patch paths, evaluates each action, and prunes bad branches early. Instead of scoring just the final answer ("did the fix pass?"), a process reward model scores each intermediate step ("was the failing test reproduced?" or "does this diff touch the right module?").

A simplified beam search using a PRM accepts a model and a PRM, taking a prompt as the initial state. At each step, it generates multiple possible next steps (the beam width), scores them with the PRM, and keeps only the highest-scoring paths. The function outputs the best completed reasoning chain. This is a conceptual interface sketch; it assumes model.generate_step, prm.score_step, and is_final_answer exist.

3-tree-search-with-process-reward-models.py
1def beam_search_with_prm( 2 model, 3 prm, 4 prompt: str, 5 beam_width: int = 4, 6 branch_factor: int = 4, 7 max_steps: int = 20 8): 9 """Guided tree search using per-step reward scores. 10 11 Cost: O(beam_width × branch_factor × max_steps) forward passes. 12 Best for: Multi-step mathematical or logical reasoning. 13 """ 14 beams = [{"steps": [], "score": 0.0, "text": prompt}] 15 16 for step in range(max_steps): 17 candidates = [] 18 for beam in beams: 19 # Generate next reasoning step 20 new_steps = [ 21 model.generate_step(beam["text"]) 22 for _ in range(branch_factor) 23 ] 24 25 for new_step in new_steps: 26 # Score each step with the process reward model 27 step_score = prm.score_step( 28 prompt, beam["steps"], new_step 29 ) 30 candidates.append({ 31 "steps": beam["steps"] + [new_step], 32 "score": beam["score"] + step_score, 33 "text": beam["text"] + "\n" + new_step, 34 }) 35 36 # Keep top-k beams 37 beams = sorted(candidates, key=lambda x: x["score"], reverse=True)[:beam_width] 38 39 # Check if any beam has reached a final answer 40 if any(is_final_answer(b["steps"][-1]) for b in beams): 41 break 42 43 return beams[0]

Beam search is easiest to explain, but it has a well-known weakness for reasoning: beams can collapse onto near-duplicate traces. Stronger systems inject diversity, allow backtracking, or use Monte Carlo Tree Search-style expansion policies. Building the tree is straightforward compared with building a verifier good enough to prune bad branches early.

Why is verifier quality the bottleneck in search-based reasoning?

Answer

Search only helps if bad branches are pruned and good branches survive. A weak verifier can reward fluent wrong steps, discard correct paths, or collapse the search into near-duplicate traces.

Process reward models vs. outcome reward models

The choice of reward model changes search efficiency:

Outcome reward model versus process reward model: ORM scores only the final answer after a full rollout, while a reliable PRM scores intermediate steps and prunes a low-scoring branch early.
ORMs grade completed answers. A sufficiently reliable PRM can score intermediate steps and prune low-scoring branches before they burn a full rollout.

Final CI audit and step audit answer different questions. An ORM only checks whether the final answer works: "tests passed" or "tests failed." You have no idea where the plan broke. A PRM checks each intermediate decision: "failure reproduced," "right module selected," "unsafe migration path rejected." The per-step feedback is much more expensive to provide, and its own mistakes can discard a good path. When it's reliable enough, it can catch errors early and avoid wasting time on low-quality paths.

Outcome reward models (ORMs)

Outcome Reward Models (ORMs) evaluate a completed trajectory rather than its intermediate steps. The outcome signal can be binary correctness, a probability or scalar score, or a preference-derived comparison. Exact-answer math makes binary grading convenient, but that isn't part of the ORM definition.

  • Score completed trajectories: The model receives an outcome signal after the answer or trajectory is complete, such as exact correctness, a scalar reward, or a preference comparison.
  • Simpler supervision boundary: Labels attach to completed outputs rather than every reasoning step. Verifiable tasks can supply these labels automatically; subjective tasks may need learned or human preference signals.
  • Search limitation: They can't guide intermediate reasoning steps. A generator might make a fatal error in step 1 but continue generating 100 more steps before the ORM finally rejects it.
  • Delayed feedback: The system must generate complete solutions before any evaluation can happen, heavily limiting the usefulness of tree search.

How PRMs work

Process Reward Models (PRMs), in contrast, evaluate the validity of each intermediate step in a chain of thought. By providing step-by-step guidance, they allow search algorithms to quickly abandon incorrect reasoning paths before wasting compute on them.

  • Granular evaluation: They score each reasoning step conditioned on the problem and preceding steps, identifying where a path first becomes weak or invalid.
  • Early pruning: They can prune low-scoring paths before completion, improving search efficiency when their intermediate scores predict final correctness.
  • Complex data requirements: They need step-level supervision from some source. Lightman et al. trained their strongest PRM with human step labels, while methods such as Math-Shepherd derive process targets automatically from rollout outcomes.[15]Reference 15Let's Verify Step by Step.https://arxiv.org/abs/2305.20050[16]Reference 16Math-Shepherd: Verify and Reinforce LLMs Step-by-step without Human Annotationshttps://arxiv.org/abs/2312.08935
  • Denser guidance: A process score gives a search controller earlier evidence for keeping or abandoning a branch, but it's not proof that a kept step is correct.

This side-by-side pseudocode shows when each model can act. The labels are qualitative so they don't imply calibrated probabilities from an unevaluated scorer:

how-prms-work.py
1# ORM: can only evaluate after the full solution is generated. 2orm_decision = orm.evaluate( 3 question="What is 847 × 293?", 4 full_solution="847 × 293 = 248,271", 5) # "fail", but only after the complete rollout 6 7# PRM: evaluates each step given the question and preceding steps. 8# This lets the search algorithm prune bad paths before they grow. 9step_decisions = prm.evaluate_steps( 10 question="What is 847 × 293?", 11 steps=[ 12 "Break this into 847 × 300 - 847 × 7", # pass 13 "847 × 300 = 254,100", # pass 14 "254,100 - 5,929 = 248,271", # low 15 ], 16) # ["pass", "pass", "low"] -> prune branch

Snell et al.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314 reported that compute-optimal test-time scaling can be more than 4× as efficient as a best-of-N baseline in their math-reasoning evaluation. Lightman et al.[15]Reference 15Let's Verify Step by Step.https://arxiv.org/abs/2305.20050 reported that process supervision outperformed outcome supervision on MATH. These results motivate testing PRM-guided pruning on verifiable workloads; they don't establish that every PRM or task benefits.

Not every reasoning system uses a learned PRM or ORM. DeepSeek-R1-Zero trained with rule-based accuracy and format rewards rather than a neural reward model, which is one reason you should treat test-time compute as a family of techniques, not a single stack.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948

What is the practical difference between an ORM and a PRM during search?

Answer

An ORM scores only the final answer, so it cannot prune based on intermediate evidence. A PRM scores intermediate steps, so a search policy can prune low-scoring branches early when the process scores are reliable.

prm-pruning-budget.py
1branch_lengths = [8, 8, 8, 8] 2prune_at_step = [None, 2, 3, 1] 3 4orm_scored_steps = sum(branch_lengths) 5prm_scored_steps = sum( 6 full_length if stop is None else stop 7 for full_length, stop in zip(branch_lengths, prune_at_step) 8) 9print(f"orm_steps={orm_scored_steps} prm_steps={prm_scored_steps}") 10print(f"saved_steps={orm_scored_steps - prm_scored_steps}")
Output
1orm_steps=32 prm_steps=14 2saved_steps=18

This is the upside case in which the process scorer prunes the right paths. A deployment evaluation must also count false pruning of branches that would have ended correct.

DeepSeek-R1-Zero and DeepSeek-R1

DeepSeek's contribution is easiest to understand as two related results. DeepSeek-R1-Zero showed that large-scale RL with verifiable rewards can induce strong reasoning behaviors without a supervised cold start.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948 DeepSeek-R1 then added cold-start data and additional post-training to make those behaviors more stable and readable.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948

Training pipeline

The final DeepSeek-R1 pipeline isn't "pure RL" end to end. The paper explicitly describes two supervised fine-tuning (SFT) stages and two RL stages:

  1. Base model: Start with DeepSeek-V3-Base[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948, a 671B Mixture-of-Experts (MoE) model with 37B active parameters per token.
  2. Cold-start Supervised Fine-Tuning (SFT): Collect thousands of long CoT examples and fine-tune the base model. This helps avoid the readability and language-mixing issues reported for R1-Zero.
  3. Reasoning-oriented RL: Run GRPO (Group Relative Policy Optimization)-based RL on reasoning tasks with verifiable, rule-based rewards, similar in spirit to R1-Zero.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948
  4. Rejection sampling + second SFT: Use the RL checkpoint to generate high-quality reasoning traces, mix them with supervised data from DeepSeek-V3 for non-reasoning domains, and retrain the base model.
  5. Final RL for all scenarios: Run another RL stage across a broader prompt mix to produce DeepSeek-R1.

That sequence matters because people often summarize R1 as "pure RL." Only R1-Zero fits that description.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948

Why is "DeepSeek-R1 was pure RL" an inaccurate summary?

Answer

DeepSeek-R1-Zero was trained with large-scale RL without a supervised cold start. DeepSeek-R1 added cold-start SFT, reasoning RL, rejection sampling plus another SFT stage, and final broad RL.

Emergent reasoning

R1-Zero displayed behaviors such as self-verification, backtracking, and longer rollouts, but the paper also reports readability issues and occasional language mixing.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948 That detail matters. It means verifiable rewards can induce useful reasoning behavior, but raw RL rollouts still need cleanup before they become a general-purpose product.

What did R1-Zero prove, and what did it not solve by itself?

Answer

It showed that verifiable rewards can induce reasoning behaviors like self-verification and backtracking. It didn't by itself solve readability, language mixing, or broad product polish.

Compute-optimal inference: when to think harder

Not all problems benefit equally from extended reasoning, and on some tasks extra thinking actively hurts. Ghosal et al. studied this directly: across reasoning models, accuracy often rises with a little more thinking and then falls as the trace grows, an inverted-U rather than a monotonic climb.[12]Reference 12Does Thinking More Always Help? Mirage of Test-Time Scaling in Reasoning Modelshttps://arxiv.org/abs/2506.04210 They attribute the apparent early gains partly to higher output variance instead of genuinely better reasoning, and they recommend parallel sampling (best-of-N) over endlessly extending one trace. An Anthropic study found the same inverse-scaling effect on several tasks, where longer reasoning amplified distractions and errors rather than fixing them.[17]Reference 17Inverse Scaling in Test-Time Computehttps://alignment.anthropic.com/2025/inverse-scaling/ The lesson for production is that thinking budget is a real tuning parameter with a sweet spot, not a slider you turn to maximum.

The optimal test-time compute allocation depends on problem difficulty:

Problem TypeCandidate strategy to evaluateExample
Factual recallSingle pass"What is the CLI flag for dry-run deploys?"
Simple reasoningShort reasoning budget or brief scratchpad"Can this migration run after the schema lock is released?"
Multi-step mathLonger scratchpad or best-of-NGPU capacity or request-rate calculation
Complex codeDeliberation plus search or repair loopsMulti-file debugging and repair
Open-ended analysisSequential revisionIncident review or rollout-risk analysis

The cross-over point

A task family may have a measured compute budget where a smaller model plus a test-time policy beats a larger single-pass model:

Qsmall+policy(C∗)>Qlarge,singleQ_{\text{small+policy}}(C^*) > Q_{\text{large,single}}Qsmall+policy​(C∗)>Qlarge,single​

Here, QQQ is measured quality and C∗C^*C∗ is one evaluated inference budget. Finding a crossover at C∗C^*C∗ doesn't mean every larger budget keeps helping. Quality can plateau or fall, and the preferred path can change with task difficulty, latency limits, verifier quality, and how many requests you expect to serve.

Snell et al.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314 observed that in FLOPs-matched evaluations, a smaller model with additional test-time compute can outperform a model roughly 14× larger answering in a single pass on problems where the small model already achieves non-trivial success rates. This makes longer thinking a candidate for compensating for model size on similar evaluated tasks, not a general replacement for larger models.

Compute allocation router: task signals feed a route decision that sends easy work to single pass, uncertain work to best-of-N, and hard verifiable work to guided search.
A production router should decide whether the request earns the expensive path. Difficulty, stakes, latency budget, and verifier availability matter as much as the model name.

What is the compute-optimal routing question for a reasoning workload?

Answer

Ask whether extra inference compute on a smaller or cheaper model beats a larger model answering once for this task family, latency budget, verifier quality, and target accuracy.

Production systems often use a routing layer to handle varying difficulty without exploding cost. The router evaluates task complexity and directs the request to the appropriate model and test-time path, balancing latency, quality, and computational cost.

measured-routing-policy.py
1routes = [ 2 {"name": "single-pass", "quality": 0.78, "latency_ms": 240, "cost": 0.002}, 3 {"name": "bounded-reasoning", "quality": 0.86, "latency_ms": 780, "cost": 0.010}, 4 {"name": "guided-search", "quality": 0.90, "latency_ms": 2600, "cost": 0.045}, 5] 6latency_slo_ms = 1000 7minimum_quality = 0.84 8 9eligible = [ 10 route for route in routes 11 if route["latency_ms"] <= latency_slo_ms and route["quality"] >= minimum_quality 12] 13chosen = min(eligible, key=lambda route: route["cost"]) 14print(f"route={chosen['name']} quality={chosen['quality']:.0%}") 15print(f"latency_ms={chosen['latency_ms']} cost=${chosen['cost']:.3f}")
Output
1route=bounded-reasoning quality=86% 2latency_ms=780 cost=$0.010

Why should a production system route tasks before invoking an expensive reasoning path?

Answer

Reasoning paths add latency, output tokens, KV cache pressure, and cost. Routing reserves that budget for tasks where extra reasoning is likely to improve verifiable quality.

Production considerations

Reasoning traffic changes capacity planning. Longer traces and more branches raise cache residency, first-token delay, and cost even when the visible answer stays short.

KV cache pressure and prefix sharing

Reasoning workloads stress inference engines differently from ordinary chat because they can generate far more intermediate tokens before or between visible outputs.

For every generated token, the server appends a Key vector and a Value vector for every layer:

KV bytes per token=2×L×nkv×dh×b\text{KV bytes per token} = 2 \times L \times n_{kv} \times d_h \times bKV bytes per token=2×L×nkv​×dh​×b

Where LLL is the number of layers, nkvn_{kv}nkv​ is the number of KV heads, dhd_hdh​ is the head dimension, and bbb is bytes per value. The important scaling fact is simple: KV cache memory grows linearly with sequence length. A rollout that spends 10,000 tokens thinking creates roughly 10,000 tokens' worth of KV state, which can collapse batch size long before raw FLOPs become the bottleneck.

PagedAttention stores KV cache in fixed-size blocks to reduce fragmentation and make scheduling practical at long context lengths.[18]Reference 18Efficient Memory Management for Large Language Model Serving with PagedAttention.https://arxiv.org/abs/2309.06180 When multiple rollouts share the same prompt or partial trace, prefix-sharing runtimes can reuse that cached prefix instead of duplicating it across every branch. SGLang's RadixAttention is a good example.[19]Reference 19SGLang: Efficient Execution of Structured Language Model Programshttps://arxiv.org/abs/2312.07104 This matters a lot for best-of-N, self-consistency, and tree search, where many candidates share the same long prompt and diverge only near the leaves.

prefix-sharing-cache-accounting.py
1prompt_tokens = 4000 2continuation_tokens = 1000 3branches = 8 4kv_bytes_per_token = 128 * 1024 5 6without_sharing = branches * (prompt_tokens + continuation_tokens) 7with_sharing = prompt_tokens + branches * continuation_tokens 8saved_gib = (without_sharing - with_sharing) * kv_bytes_per_token / 1024 ** 3 9print(f"tokens_without_sharing={without_sharing:,}") 10print(f"tokens_with_sharing={with_sharing:,} saved_kv_gib={saved_gib:.2f}")
Output
1tokens_without_sharing=40,000 2tokens_with_sharing=12,000 saved_kv_gib=3.42

Why do reasoning workloads stress KV cache more than ordinary chat?

Answer

Non-visible-token modes and branching search can generate many extra tokens before or between visible outputs. In transformer serving paths that materialize those tokens, each one appends K/V state across layers, reducing batch size and concurrency unless the runtime pages, shares, or evicts cache efficiently.

TTFT vs. inter-token latency

Test-time compute distorts user-facing latency metrics. For a provider or wrapper that generates non-visible reasoning before revealing the answer, TTFT (time to first token) can increase substantially.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning An interleaved mode can also add pauses between visible chunks or tool calls. ITL (inter-token latency) can still be fine once answer text starts streaming. A reasoning system can feel slow even when decode throughput is healthy.

Those reasoning tokens are still decode load for the fleet, even when the user never sees them. Under continuous batching they occupy KV residency and memory bandwidth, raise other tenants' ITL, and reduce goodput (offered request rate under joint TTFT and decode SLOs). A reasoning router is therefore also a capacity-control device: routing hard queries to long rollouts must leave headroom for co-tenant latency as well as the request's own TTFT budget.

Why can a reasoning model feel slow even if decode tokens per second are healthy?

Answer

In a mode that generates non-visible reasoning first, those tokens raise TTFT. In an interleaved mode, additional thinking can also create pauses between visible chunks or tool calls. ITL during answer streaming can still look normal.

ttft-budget-slo.py
1base_ttft_ms = 180 2decode_tokens_per_second = 80 3budgets = [0, 128, 512, 1024] 4ttft_slo_ms = 3000 5 6for budget in budgets: 7 ttft_ms = base_ttft_ms + budget / decode_tokens_per_second * 1000 8 status = "fits" if ttft_ms <= ttft_slo_ms else "reject" 9 print(f"budget={budget:>4} ttft_ms={ttft_ms:>7.0f} {status}")
Output
1budget= 0 ttft_ms= 180 fits 2budget= 128 ttft_ms= 1780 fits 3budget= 512 ttft_ms= 6580 reject 4budget=1024 ttft_ms= 12980 reject

Latency vs. quality trade-off

Reasoning models add latency, but the exact numbers depend on hardware, batching policy, and provider implementation:

StrategyUser-visible behaviorBest fit
Single-pass generationLow TTFT, short answersChat, extraction, classification
Reasoning or search-heavy generationHigher TTFT, variable token budget, sometimes hidden intermediate workMath, code, planning, verification

For strict interactive latency budgets, a long reasoning path may be unacceptable unless measured gains justify it. Candidates for larger budgets include:

  • Batch processing (code review, data analysis)
  • High-stakes analyst workflows (incident review, safety analysis, compliance analysis)
  • Asynchronous workflows (software engineering, research)

Cost implications

Extended reasoning is expensive even when the final answer is short. Hosted APIs may charge directly for hidden reasoning tokens. OpenAI's reasoning docs, for example, note that these tokens are billed as output tokens even though they aren't returned verbatim in the API response.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning Open-weight deployments pay through longer wall-clock time, lower throughput, and higher KV cache residency. Either way, longer rollouts reduce how many concurrent requests the same GPU can serve.

Production systems usually combine three controls:

  1. Routing: send only hard or high-stakes tasks to expensive reasoning paths
  2. Token budgets: cap how long a rollout may think before the marginal gain stops being worth it
  3. Early stopping: terminate search when verifier scores stop improving

Without those controls, ambiguous or unsolvable prompts can burn a large amount of inference budget without producing a better answer.

What three controls keep reasoning costs bounded in production?

Answer

Route only hard or high-stakes tasks to reasoning paths, cap reasoning tokens or branches, and stop early when verifier scores or expected gains plateau.

Distillation: making reasoning affordable

Distillation is like having a senior incident engineer write detailed recovery traces, then training a smaller model to solve similar outages the same way. The smaller model won't match the source model everywhere, but it can inherit much of the solution style while being much cheaper to serve.

DeepSeek-R1 showed that reasoning capabilities can be distilled into much smaller models:

Distilled ModelSourceAIME 2024 (pass@1: accuracy on first attempt)
DeepSeek-R1-Distill-Qwen-1.5BR1 → Qwen2.5-Math-1.5B28.9%
DeepSeek-R1-Distill-Qwen-7BR1 → Qwen2.5-Math-7B55.5%
DeepSeek-R1-Distill-Qwen-32BR1 → Qwen2.5-32B72.6%
DeepSeek-R1 (full)-79.8%

In DeepSeek's reported AIME evaluation, the 7B and 32B distilled models retain substantial benchmark accuracy at lower parameter counts than R1. Parameter count is only a proxy, though. Real deployment cost still depends on active parameters, quantization, batch size, and engine choice. Distillation can make reasoning cheaper, but it doesn't remove the need for routing and token budgets.

What can reasoning distillation transfer, and what can it fail to transfer?

Answer

It can transfer solution traces, formats, and many task patterns from a stronger teacher. It may not transfer the teacher's full search policy, verifier behavior, or reliability on unfamiliar tasks.

Trace cloning also has a scaling ceiling. Setlur et al. compare verifier-free methods that distill or clone successful traces with verifier-based methods that use rewards, RL, or search.[20]Reference 20Scaling Test-Time Compute Without Verification or RL is Suboptimalhttps://arxiv.org/abs/2502.12118 Under the paper's assumptions and evaluated reasoning tasks, verifier-free methods become increasingly suboptimal as rollout length and test-time budget grow because the student learns observed traces without learning which alternative traces a verifier would reward.

That result doesn't make distillation useless. The DeepSeek numbers above show that a smaller student can gain substantial capability. It means long-rollout scaling should not assume more teacher traces will reproduce verifier-guided improvement indefinitely. Filter traces with reliable checks, retain a verifier at evaluation time, or train with verifier-guided RL when the workload supports trustworthy rewards.

Why doesn't cloning more reasoning traces guarantee the same scaling as verifier-guided RL or search?

Answer

Cloning teaches the student to imitate observed successful traces. It doesn't directly teach a reward over alternative traces, so the gap can widen as rollout length and search budget grow. Distillation remains useful, but its ceiling should be measured with a verifier-backed evaluation.

serving-budget-gate.py
1requests = [ 2 {"kind": "extract", "verifiable": True, "predicted_gain": 0.00}, 3 {"kind": "capacity_math", "verifiable": True, "predicted_gain": 0.09}, 4 {"kind": "creative_copy", "verifiable": False, "predicted_gain": 0.03}, 5] 6minimum_gain = 0.05 7 8for request in requests: 9 use_reasoning = request["verifiable"] and request["predicted_gain"] >= minimum_gain 10 route = "reasoning" if use_reasoning else "single-pass" 11 print(f"{request['kind']}: {route}")
Output
1extract: single-pass 2capacity_math: reasoning 3creative_copy: single-pass

What to remember and where to go next

  1. Test-time compute adds a second scaling axis: spending more compute at inference can outperform moving to a larger single-pass model on hard reasoning tasks.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314

  2. Test-time compute is an umbrella, not one algorithm: longer scratchpads, repeated sampling, revision loops, and explicit search all fit under the same idea.

  3. Good verifiers and compute-optimal policies matter: Snell et al. report more than 4× better test-time compute efficiency than a best-of-N baseline in their evaluation, and PRMs can support earlier pruning because they score intermediate steps instead of waiting for the end.[2]Reference 2Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.https://arxiv.org/abs/2408.03314[15]Reference 15Let's Verify Step by Step.https://arxiv.org/abs/2305.20050

  4. DeepSeek-R1-Zero and DeepSeek-R1 aren't the same result: R1-Zero showed emergent reasoning from pure RL, while DeepSeek-R1 added cold-start data plus additional SFT and RL stages to make that behavior readable and broadly usable.[5]Reference 5DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learninghttps://arxiv.org/abs/2501.12948

  5. Thinking is now a dial, and the sweet spot isn't always the maximum: current providers expose model- and API-specific effort or thinking controls, and accuracy can follow an inverted-U as the trace grows, so tune the supported knob rather than maxing it.[4]Reference 4Reasoning modelshttps://developers.openai.com/api/docs/guides/reasoning[10]Reference 10Gemini thinkinghttps://ai.google.dev/gemini-api/docs/thinking[11]Reference 11Building with extended thinkinghttps://docs.claude.com/en/docs/build-with-claude/extended-thinking[12]Reference 12Does Thinking More Always Help? Mirage of Test-Time Scaling in Reasoning Modelshttps://arxiv.org/abs/2506.04210

  6. Serving bottlenecks matter as much as algorithms: KV cache memory grows linearly with long reasoning traces, so prefix sharing, routing, and token budgets are core production tools.[18]Reference 18Efficient Memory Management for Large Language Model Serving with PagedAttention.https://arxiv.org/abs/2309.06180[19]Reference 19SGLang: Efficient Execution of Structured Language Model Programshttps://arxiv.org/abs/2312.07104

Explain why a single-pass model can miss "How many r's in strawberry," why a smaller model with traces, search, or distillation can recover much of a larger model's math performance, and why a production stack needs a routing layer before it needs a bigger GPU.

Complete the lesson

Mastery Check

Answer every question, then check your score. Score 75% or higher to mark this lesson complete.

1.A team routes sentiment classification and ticket-ID extraction to a reasoning model. Evaluation shows the same accuracy as a single-pass baseline, but median latency rises from 400 ms to 8 s and cost quadruples. Which diagnosis fits?

Correct answer: The team is paying an intelligence tax: extra reasoning cost on tasks with no measured multi-step benefit.

The intelligence tax is the extra latency and cost from using reasoning on tasks that do not need it. Sentiment classification and simple extraction usually have strong single-pass baselines, so the reasoning route should be justified by measured gains, not by the model seeming more capable.

2.A deployed planner model is unchanged. For easy CLI-flag lookups it answers once; for failed-deploy incidents it samples several rollback plans, checks tests and migration state, then returns a selected plan. Which scaling view explains this setup?

Correct answer: It is test-time compute scaling because extra inference work is allocated during generation based on request difficulty.

Train-time scaling spends compute before deployment by changing model size, data, or pretraining FLOPs. Here the weights are fixed, and the system spends extra per-request inference compute through sampling and verification only when the incident is hard enough to justify it.

3.A team uses cross-entropy SFT to clone one accepted reasoning trace per problem, then expects pass@N to keep improving as it samples longer student rollouts. Which risk should it test?

Correct answer: CE can over-concentrate probability and reduce pass@N diversity, while trace cloning may not inherit the verifier-guided reward or search policy needed for longer-rollout scaling.

Pass@1 and pass@N are different objectives. CE can improve likelihood on demonstrated traces while making independent samples less diverse, and verifier-free cloning teaches imitation rather than a reward over alternative traces. The team should measure candidate coverage at its deployed N and compare against a verifier-guided training or search baseline.

4.An engineer says, "DeepSeek-R1 was trained purely with RL from start to finish, just like DeepSeek-R1-Zero." Which correction accurately distinguishes DeepSeek-R1-Zero from DeepSeek-R1?

Correct answer: R1-Zero used RL without cold-start SFT; R1 added cold-start SFT, rejection-sampling SFT, and additional RL.

Only R1-Zero fits the pure-RL shorthand. DeepSeek-R1 added supervised cold-start data, a reasoning RL stage, rejection sampling followed by another SFT stage, and final broader RL to improve usability and stability.

5.A reasoning budget evaluation gives accuracies and latencies: 0 tokens: 71%, 220 ms; 128 tokens: 78%, 310 ms; 512 tokens: 83%, 610 ms; 2048 tokens: 80%, 1840 ms. The latency limit is 1000 ms. Which budget should be selected if the objective is highest measured accuracy within the limit?

Correct answer: 512 tokens.

Only 0, 128, and 512 tokens satisfy the 1000 ms latency limit. Among those eligible budgets, 512 tokens has the highest measured accuracy at 83%. The 2048-token budget is both over the latency limit and less accurate, showing why the maximum thinking budget is not automatically optimal.

6.A hosted reasoning API reports 180 visible output tokens and 1,220 non-visible reasoning tokens. Its docs bill both as output tokens, and transformer serving materializes the hidden tokens autoregressively. At $10 per million output tokens, what should a dashboard count for output cost and why?

Correct answer: 1,400 billed output tokens costing $0.0140, and the hidden tokens can also add decode work and temporary KV state.

The dashboard should add visible and reasoning tokens: 180 + 1,220 = 1,400 billed output tokens. At 10permillionoutputtokens,thatcosts1,400/1,000,000x10 per million output tokens, that costs 1,400 / 1,000,000 x 10permillionoutputtokens,thatcosts1,400/1,000,000x10 = $0.0140. If the runtime materializes those hidden tokens, they also consume decode work and temporary KV cache state even though users never see them.

7.Four reasoning branches would each take 8 steps to complete. An outcome reward model can score only completed branches. A reliable process reward model prunes three bad branches at steps 2, 3, and 1 while one branch runs all 8 steps. How many generated steps are avoided compared with the outcome-only approach?

Correct answer: 18 steps.

The outcome-only approach must generate all four full branches, so it uses 4 x 8 = 32 steps. With reliable process pruning, the system generates 8 + 2 + 3 + 1 = 14 steps. The avoided work is 32 - 14 = 18 steps. This saving depends on the PRM pruning the right branches; false pruning can discard a correct path.

8.A model has a 25% chance to generate a correct answer per attempt. With N=4 independent attempts, an oracle would have a 68.4% chance to include a correct answer. In deployment, the selector finds a correct candidate only 80% of the time when one exists. What success rate should be used for the selected answer?

Correct answer: 54.7%, because generating a correct candidate and selecting it are separate failure surfaces.

The oracle chance of including a correct answer is 68.4%, but the deployed system also has to select that candidate. Multiplying by 80% selector recall gives 0.684 x 0.80 = 0.547, or 54.7%. Best-of-N only pays off when sampling adds useful candidates and the selector can identify them reliably.

9.A team is improving long incident-review analyses. There is no single final answer to majority-vote, but each draft can be critiqued for omissions and repaired over a few passes. Which test-time strategy matches that workload?

Correct answer: Sequential revision, because each pass can critique and repair the previous draft before stopping.

Sequential revision is a fit when later passes can improve a prior draft through critique, editing, or repair. Best-of-N is better suited to independent candidates with directly scored answers, while PRM-guided search is for workloads where intermediate steps can be scored reliably.

10.Eight search branches share a 4,000-token prompt and then each generate a 1,000-token continuation. Without prefix sharing, KV storage is counted for 8 x (4,000 + 1,000) tokens. With prefix sharing, it is counted for 4,000 + 8 x 1,000 tokens. What does prefix sharing avoid?

Correct answer: 28,000 duplicate prompt-token KV entries, about 3.42 GiB if each token's KV state is 128 KiB.

Without sharing, the branches count 40,000 KV-token entries. With sharing, they count 12,000: one shared 4,000-token prompt plus eight 1,000-token continuations. The avoided duplicate prompt work is 28,000 entries, and 28,000 x 128 KiB is about 3.42 GiB.

10 questions remaining.

Next Step
Continue to Advanced MLOps & DevOps for AI

You now understand why reasoning workloads need careful routing, token budgets, verification, and serving signals. The next chapter turns those signals into operational practice: GitOps, <span data-glossary="feature-store">feature stores</span>, shadow traffic, canaries, lineage, and automated rollback for production AI systems.

PreviousMamba & State Space Models
Share this article
XFacebookLinkedInBlueskyRedditHacker NewsEmail
References

Scaling Laws for Neural Language Models

Kaplan et al. · 2020

https://arxiv.org/abs/2001.08361

Scaling LLM Test-Time Compute Optimally Can Be More Effective Than Scaling Model Parameters.

Snell, C., et al. · 2024 · arXiv preprint

https://arxiv.org/abs/2408.03314

Learning to reason with LLMs

OpenAI · 2024

https://openai.com/index/learning-to-reason-with-llms/

Reasoning models

OpenAI · 2026

https://developers.openai.com/api/docs/guides/reasoning

DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning

DeepSeek-AI · 2025

https://arxiv.org/abs/2501.12948

GLM-5.2 Model Card

Z.AI · 2026

https://huggingface.co/zai-org/GLM-5.2

GLM-5 Repository

Z.AI · 2026

https://github.com/zai-org/GLM-5

GLM-5.2 Model Documentation

Z.AI · 2026

https://docs.z.ai/guides/llm/glm-5.2

Use DeepSeek with Codex

DeepSeek · 2026

https://api-docs.deepseek.com/quick_start/agent_integrations/codex/

Gemini thinking

Google · 2025

https://ai.google.dev/gemini-api/docs/thinking

Building with extended thinking

Anthropic · 2025

https://docs.claude.com/en/docs/build-with-claude/extended-thinking

Does Thinking More Always Help? Mirage of Test-Time Scaling in Reasoning Models

Ghosal, S. S., Chakraborty, S., Reddy, S., et al. · 2025

https://arxiv.org/abs/2506.04210

Chain-of-Thought Prompting Elicits Reasoning in Large Language Models.

Wei, J., et al. · 2022 · NeurIPS

https://arxiv.org/abs/2201.11903

Rethinking Fine-Tuning when Scaling Test-Time Compute: Limiting Confidence Improves Mathematical Reasoning

Chen, F., Raventos, A., Cheng, N., Ganguli, S., & Druckmann, S. · 2025 · NeurIPS 2025

https://proceedings.neurips.cc/paper_files/paper/2025/hash/e8f4eae0a41cab67fdead3aa6b77f083-Abstract-Conference.html

Let's Verify Step by Step.

Lightman, H., et al. · 2023 · ICLR

https://arxiv.org/abs/2305.20050

Math-Shepherd: Verify and Reinforce LLMs Step-by-step without Human Annotations

Wang, P., et al. · 2023

https://arxiv.org/abs/2312.08935

Inverse Scaling in Test-Time Compute

Anthropic · 2025

https://alignment.anthropic.com/2025/inverse-scaling/

Efficient Memory Management for Large Language Model Serving with PagedAttention.

Kwon, W., et al. · 2023 · SOSP 2023

https://arxiv.org/abs/2309.06180

SGLang: Efficient Execution of Structured Language Model Programs

Zheng, L., Yin, L., Xie, Z., et al. · 2023 · arXiv:2312.07104

https://arxiv.org/abs/2312.07104

Scaling Test-Time Compute Without Verification or RL is Suboptimal

Setlur, A., Rajaraman, N., Levine, S., & Kumar, A. · 2025

https://arxiv.org/abs/2502.12118

Discussion

Questions and insights from fellow learners.

Discussion loads when you reach this section.