The weights stay where they are. The only thing that changes is how the generation loop spends tokens. Two patterns cover most of what helps on math: write a longer solution before the answer, or draw several solutions and keep the answer that appears most often. Both cost more inference compute. On the Qwen3 0.6B base model they more than double MATH-500 accuracy relative to a short greedy answer, which is a large gain for a prompt and a sampler.
Chain-of-thought prompting
Ask for the intermediate steps in the prompt, and require the final answer in the same \boxed{} form the verifier already extracts. The model then conditions the answer on tokens it just generated.
Why this can help is mechanical. Under Definition 2.1, the answer token is drawn from
Keep the instruction short and stable. A paragraph of advice about “thinking carefully” is a different prompt from “show the steps, then box the answer,” and you will not know which change moved the score.
Temperature
Greedy decoding always picks
Definition 4.1 (Temperature).For temperature
,
Definition 4.1 does not change the identity of the mode when
A numerical picture: logits
The ordering is unchanged. The probability of the runner-up dropped by half. Self-consistency needs the opposite direction: enough spread that independent samples disagree, and not so much spread that the samples are nonsense. Values around
The figure rescales a fixed logit vector. Lower the temperature and the tallest bar takes the mass. Lower top-
Top- sampling
Temperature still assigns leftover mass to the whole vocabulary. Top-
Definition 4.2 (Nucleus).Sort tokens so that
. Let be the smallest index with . Sample from the renormalized distribution on , and set every other token to probability zero.
Definition 4.2 with
Apply the cutoff after the temperature scaling, on the probabilities, not on the raw logits. A common implementation detail: if you mask logits by setting the dropped ones to
Self-consistency
Definition 4.3 (Self-consistency).Draw
completions at temperature with nucleus . Extract each boxed answer. Return the answer that occurs most often. Break a tie by the completion with the highest length-normalized log probability.
Definition 4.3 is a vote over final answers, not over traces. Two solutions that differ in wording and box the same value count as one vote. This is why the extractor from Module 3 has to be shared: a vote on raw strings splits \frac{1}{2} from 1/2.
The method helps when the correct answer is the mode of the sampled answers even though it is not the greedy answer. It does not help when every sample fails in the same way. In that case you have bought
A useful diagnostic is the agreement rate: the fraction of samples that match the winner. High agreement and a wrong winner means the model is confidently wrong, and more samples will not fix it. Low agreement means the temperature is high or the problem is unstable, and the vote is doing real work.
What to hold fixed
When you ablate this module, change one switch at a time.
| Run | Prompt | |||
|---|---|---|---|---|
| Greedy baseline | answer only | |||
| Chain of thought | steps, then box | |||
| Sampled vote | steps, then box | searched | searched |
The first row is the module 3 number. The second row isolates the prompt. The third isolates sampling. Comparing the third row to the first and calling the gap “self-consistency” mixes three changes.
Exercises: Homework 4.
Code
- Notebook: ch04_main.ipynb
- MATH-500 scaling scripts: ch04/02_math500-inference-scaling-scripts
- The sampling paper: Wang et al., 2022, self-consistency improves chain-of-thought reasoning.