Skip to content
SurogateSurogateDocs
↑↓ to move↵ to openesc to close

Countdown: learning to reason from scratch

Qwen3.5-0.8B learns Countdown: reach a target number using each given number exactly once with + − × ÷. With thinking off, the base model solves 1% of 200 held-out puzzles. After 80 GRPO steps on one GPU it solves 69.5%. It gets there by learning to try a combination, compute it and check it before answering.

StepsTime on one L40SBeforeAfterHeld-out setAdapter
8067 min1.0%69.5%200 puzzlesHub ↗

The environment generates the puzzles, so there is no dataset licence to consider, and every puzzle is solvable by construction: 3 or 4 numbers, a whole-number target from 1 to 999. Training and evaluation use different seeds.

Reward: 1 when the expression in <answer>...</answer> uses exactly the given numbers and equals the target, else 0.

No. It skips the working and guesses an expression, often with a wrong value written next to it:

Numbers: 2, 8, 20, 31 · Target: 252

Before: <answer>(20 + 31) * 2 - 8</answer> (that is 94)

bash
CUDA_VISIBLE_DEVICES=0 surogate grpo-colocate \
--train examples/kits/countdown/train.yaml \
--infer examples/kits/countdown/infer.yaml \
--orch examples/kits/countdown/orch.yaml

16 puzzles × 8 rollouts a step, answers up to 1,536 tokens, thinking off, LoRA rank 16. 67 minutes for 80 steps on one L40S.

Solved, 200 held-out puzzles
Base Qwen3.5-0.8B1.0%
After 20 steps61.5%
After 40 steps54.0%
After 60 steps62.0%
After 80 steps69.5%

Greedy decoding, the same prompt and budget as training, one run. The dip at step 40 is real, and the run recovered from it.

Checked outside the engine with plain transformers + peft on the first 24 held-out puzzles: 0% before, 66.7% after.

The trained model works the puzzle in plain text before it answers:

Numbers: 2, 8, 20, 31 · Target: 252

After:

- (31 - 2) = 29
- 29 * 8 = 232
- 232 + 20 = 252
Expression: (31 - 2) * 8 + 20
<answer>(31 - 2) * 8 + 20</answer>

A first run cut answers at 1,024 tokens. It reached 61% and then fell to 48.5%. Long attempts were cut off before the answer and scored 0, so the model learned that working things out does not pay. At 1,536 tokens it kept improving to the end.

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
tok = AutoTokenizer.from_pretrained("Qwen/Qwen3.5-0.8B")
base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-0.8B", torch_dtype="bfloat16")
model = PeftModel.from_pretrained(base, "cetusian/qwen3.5-0.8b-countdown-grpo")
stop = [tok.convert_tokens_to_ids(t) for t in ("<|im_end|>", "<|endoftext|>")]
# model.generate(..., eos_token_id=stop)

Use the system prompt from environments/countdown and enable_thinking=False. This adapter ends its turn with <|endoftext|>, so stop on both tokens as above; the Surogate server does that already.

  • Countdown only. It is a clean test of whether RL can teach a small model to reason, not a general maths model.
  • About 30% of puzzles are still wrong, mostly the four-number ones (in the 24-puzzle check: 11 of 12 three-number puzzles solved, 5 of 12 four-number ones).
  • One run, one seed.

Next: compare the other GRPO kits, or read RL Environments to build a reward of your own.