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 . If those steps happen to contain the right sub-results, the answer distribution moves. The steps are not checked. A fluent wrong derivation moves the answer too, sometimes away from the correct one. On very easy items, forcing a long derivation can lower accuracy. The method is a bias, not a guarantee.

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 , where is the last-position logit vector. Sampling needs a distribution.

Definition 4.1 (Temperature).

For temperature ,

Definition 4.1 does not change the identity of the mode when is finite and the top logit is unique. It changes the gaps. is the model’s own softmax. sharpens it, so samples concentrate on the top tokens. flattens it. The limit recovers the greedy choice, which is why a temperature of zero in code should be implemented as argmax rather than as a division.

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 to are the usual range to search. Report the value. It is part of the method.

The figure rescales a fixed logit vector. Lower the temperature and the tallest bar takes the mass. Lower top- and the short bars are removed, then what remains is renormalized. The two controls compose: temperature first, then the nucleus cutoff on that distribution.

Top- sampling

Temperature still assigns leftover mass to the whole vocabulary. Top-, or nucleus sampling, throws that tail away.

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 keeps every token. With and probabilities , the cumulative sums are , , , , so . After renormalizing, the sampler sees .

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 and then take softmax, you must not also divide by a second time.

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 copies of one mistake. between and is enough to see the effect on a small model. Accuracy usually rises and then flattens. The cost is linear in .

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.

RunPrompt
Greedy baselineanswer only
Chain of thoughtsteps, then box
Sampled votesteps, then boxsearchedsearched

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