A model that writes its own exam drifts into its own mistakes. SPICE grounds the exam in 20,000 real documents and lifts Qwen3-4B-Base from 35.8 to 44.9. Self-Play SWE-RL grounds it in real code repositories and adds 10.4 points on SWE-bench Verified.
Pick the rule that pays the question writer. Watch where it aims the difficulty, and watch eight answers land at that pass rate. Then we build, piece by piece, the variance reward, the bug-injection game and the ways both can break.
You need a little Python and what a probability is. We build the rest from zero.
Session 14 of Georgia Tech CS 8803, LLM seminar. Paper one: Liu, Jin, Kim, Yuan, Zhao, Kulikov, Li, Sukhbaatar, Lanchantin and Weston, SPICE: Self-Play In Corpus Environments Improves Reasoning (2025). Paper two: Wei, Sun, McMilin, Gehring, Zhang, Synnaeve, Fried, Zhang and Wang, Toward Training Superintelligent Software Agents through Self-Play SWE-RL (ICML 2026). Every idea is re-taught here in our own words and devices.
Dots: the reward at k correct out of 8. Curve: the expected reward when each answer passes with chance p, computed live. Overall scores are SPICE Table 4 (Qwen3-4B-Base). The injector rule is SSR Eq. 1; SSR reports its best target near 0.2.
Chapter 0
See why a model that grades its own questions drifts
Session 13's Absolute Zero let one model write coding puzzles and solve them. A Python interpreter graded every answer. Nobody can fool it: run the program and you get the one true output.
Now take the interpreter away. A model writes a physics question, writes its own answer key, and then answers. If the key is wrong, the model learns the wrong answer. Next round it writes more questions on that wrong physics. Self-play means one model plays both sides of a game. With no outside check, its errors feed its next round.
The SPICE paper names two failures:
Each bar is one round. Green is the share of answer keys that are right, red the share that are wrong. Choose a loop and press Run.
Toy model: each round, training spreads the wrong keys at rate 0.21. Grounded keys keep a fixed 5% checker error. The 79% start and the fall to about 63% by round 4 match the R-Zero numbers that SPICE cites (Section 5). The curve shape is ours.
The real numbers: SPICE cites R-Zero, a self-play method with no documents. Its pseudo-label accuracy, the share of its own answer keys that are right, starts at 79% and falls to 63% after 3 to 4 iterations. On Qwen3-4B-Base, R-Zero ends at 39.5 overall and SPICE at 44.9, from a base of 35.8 (SPICE Table 1).
Failure. The two roles agree more each round, yet benchmark scores stall. Measure: each round, check a sample of the model's own answer keys against a trusted source. Fix: give the question writer something real that it did not write. That is this session's subject.
Chapter 1
Give the question writer a document that the solver never sees
SPICE stands for Self-Play In Corpus Environments. One model plays two roles, and only the prompt tells it which.
This split is information asymmetry: one role holds a fact that the other lacks. The answer key comes from text that neither role wrote, which blocks hallucination amplification. The document is new to the Reasoner, which breaks information symmetry.
One rollout on the paper's solar-system passage. The Reasoner answers 8 times. Leak the document and watch the 8 answers and the Challenger's reward.
The passage and question are from SPICE Figure 5. The split of 4 right out of 8 is illustrative. The reward values come from the Chapter 2 formula.
| Setting | Value in SPICE |
|---|---|
| Corpus | 20,000 documents: half Nemotron-CC-Math, half NaturalReasoning (a DCLM subset) |
| Document length | segments up to 5,992 tokens |
| Question formats | 4-option multiple choice, or free form with an integer, expression or string answer |
| Answer check | Math-Verify (rule based) in training |
| Attempts per document | up to N = 1,024 to get one valid question |
| Invalid question | penalty ρ = −0.1 |
The Challenger's prompt also demands questions that are self-contained. "According to the passage above" would point the Reasoner at nothing.
Both roles train together on one set of weights θ. Call the Challenger's reward for a question rC, and the Reasoner's reward for an answer rR: 1 if right, 0 if wrong. SPICE maximizes their sum.
J of theta equals the average over documents d drawn from D of: the average Challenger reward r-C for questions drawn from pi-theta given d, plus the average Reasoner reward r-R for answers drawn from pi-theta given q.
Sample a document d. Let the Challenger write q and a* from it, and score that with r-C. Let the Reasoner answer q, and score each answer a-hat with r-R. Add the two average scores. Raise J by changing theta.
With made-up numbers: over a batch, r-C averages 0.80 and r-R averages 0.55. J is about 0.80 + 0.55 = 1.35. A step that raises either average raises J.
Failure. A bug passes the document into the Reasoner's prompt. Symptom: the Reasoner passes almost every question and the Challenger's reward falls to 0.044. Measure: log the Reasoner's prompt length; it should be tens or hundreds of tokens, not thousands. Fix: build that prompt from the question alone.
Chapter 2
Pay the Challenger for questions that split the Reasoner's answers
Which question is worth asking? If all 8 answers are right, the question teaches nothing. If all 8 are wrong, the Reasoner sees no correct answer to learn from, and the question may be broken. A useful question splits the answers.
For each valid question, SPICE samples K = 8 Reasoner answers. Score answer i with li: 1 if it matches the gold answer, else 0. Call the share of right answers the pass rate p. The spread of the eight scores is their variance.
The variance of l-one through l-K equals p times one minus p.
Each score l-i is 0 or 1, so l-i squared equals l-i. The average of the squares is p, and the square of the average is p squared. Variance is the first minus the second: p minus p squared.
With 6 right out of 8: p = 0.75 and the variance is 0.75 × 0.25 = 0.1875. With 4 out of 8: 0.5 × 0.5 = 0.25, the largest it can be.
SPICE does not pay the variance itself. It pays closeness to 0.25 with a bell curve. A temperature τ = 0.01 sets its width.
r-C equals e to the minus: Var minus 0.25, squared, over two tau, if the question is valid; otherwise rho.
Take the variance Var. Subtract 0.25 and square the gap. Divide by two tau and put a minus sign in front. Raise e to that power. If the Challenger wrote a malformed question, pay rho instead.
With 7 right out of 8: p = 0.875, Var = 0.1094. The gap is −0.1406; squared, 0.01977; over 0.02, 0.988. So r-C = e−0.988 = 0.372. A question at 4 out of 8 earns 1.000.
Drag k, the number of right answers. The dot rides the reward curve. Then narrow or widen τ and watch a near-miss lose or keep its pay.
The formula is SPICE Eq. 1 with τ from Appendix D. Widths other than 0.01 are ours, to show the knob.
| Challenger rule | Pays | k = 1 | k = 7 | Overall |
|---|---|---|---|---|
| Absolute Zero | 1 − p | 0.875 | 0.125 | 40.7 |
| Threshold | 1 unless all right or all wrong | 1 | 1 | 41.4 |
| R-Zero | 1 − 2|p − 0.5| | 0.250 | 0.250 | 43.6 |
| Variance (SPICE) | the bell curve above | 0.372 | 0.372 | 44.9 |
Overall scores are SPICE Table 4, all on Qwen3-4B-Base with one setup. Only the rule changes from row to row.
Failure. With τ = 0.0025, a question at 7 out of 8 earns 0.019, near nothing. Symptom: the Challenger's reward stays low and its questions bunch at one difficulty. Measure: a histogram of k per batch. Fix: widen τ until near-misses still pay.
Chapter 3
Compare each rollout only with others of its own role
A reward says how good a rollout was. A policy gradient needs to know if it was better or worse than usual. That signed number is the advantage.
The two roles' rewards live on different scales. The Challenger's reward is a smooth number from 0.04 to 1. The Reasoner's is exactly 0 or 1. SPICE uses DrGRPO: it compares each role's rewards with the mean of that role's own group. Call the reward of rollout i in a group ri, and the group mean r̄ (say "r-bar").
A-hat-i equals r-i minus the mean over j of r-j.
Average the rewards r-j of one role's group. Subtract that mean from each reward r-i. Do not divide by the spread. Do the Challenger group and the Reasoner group separately.
Four Challenger questions land at 4, 7, 8 and 1 right out of 8. Their rewards are 1.000, 0.372, 0.044 and 0.372. The mean is 1.788 / 4 = 0.447. The advantages are +0.553, −0.075, −0.403 and −0.075. They add to 0.
Pick a group of four questions. Bars above the line get pushed up, bars below get pushed down. Then turn on the GRPO division and compare.
Rewards from the Chapter 2 formula. SPICE uses the centering only (Eq. 3 and 4). We show the division for contrast.
Why no division? Plain GRPO divides by the group's standard deviation. In the nearly equal group, the rewards differ by 0.012, yet the division turns that into advantages of +0.58 and −1.73. SPICE says centering alone makes updates "reflect genuine learning signals rather than difficulty-induced noise".
| Training setting | SPICE value |
|---|---|
| Iterations, batch, group | T = 640, B = 128 documents, G = 8 answers |
| KL penalty | β = 0, none |
| Learning rate | 1 × 10−6, constant |
| Hardware | 8 H200 GPUs per run, ZeRO Stage 2 |
| System | Oat actor-learner, vLLM for generation, temperature 1.0 |
The same 8 Reasoner answers do two jobs. They give the Challenger its pass rate, and they form the Reasoner's own group for its update.
Failure. All four questions land at 4 out of 8. Every advantage is 0 and that group gives no gradient. Measure: the share of groups with zero spread. Fix: nothing breaks; the group carries no contrast, so it teaches nothing that step.
Chapter 4
Check that both roles improve, then read the scores on four base models
A curriculum is real only if the target moves. SPICE tests this by freezing one role at its step-200 checkpoint and letting the other advance to step 640, on 128 held-out documents.
| Setup | Step 200 | Step 640 | Meaning |
|---|---|---|---|
| Fixed Reasoner, later Challengers | 55% | 35% | the questions got harder |
| Fixed Challenger, later Reasoners | 55% | 85% | the answers got better |
The questions change in kind, too. On one passage about the Sun and Moon, the step-50 question is "What is the diameter of the Moon?". At step 480 it asks how far an alien star must be for a perfect eclipse (SPICE Figure 5).
The late Reasoner sets equal angular sizes: Moon diameter over Moon distance equals star diameter over star distance. So d = 1,391,000 × 374,000 / 3,475 = 149,707,626 km, about option B, 149,600,000 km. The paper's transcript writes 149,708,489, a small slip that still picks B (Figure 6).
Pick a base model. Each bar is the overall score across 11 benchmarks. Teal is SPICE.
SPICE Table 1, overall column. "Strong Challenger" is a fixed Qwen3-32B-Instruct writing the questions. All baselines were re-run by the SPICE authors on the same setup.
SPICE wins on all four models, in math (average +8.9) and general reasoning (+9.8). A frozen 32B Challenger helps, but less: +7.2 against +9.1 on Qwen3-4B. A frozen writer cannot follow a Reasoner that improves.
| Ablation on Qwen3-4B | Math | General | Overall |
|---|---|---|---|
| NaturalReasoning only | 44.4 | 37.0 | 41.7 |
| Nemotron-CC-Math only | 53.4 | 29.8 | 43.2 |
| Multiple choice only | 46.9 | 35.7 | 42.0 |
| Free form only | 52.5 | 31.8 | 43.7 |
| Both corpora, both formats | 50.6 | 35.0 | 44.9 |
SPICE Tables 2 and 3. Each corpus helps its own domain most; the mix wins overall. Without any corpus, training ends at 40.7 against 43.9 with it (Figure 4).
Failure. A benchmark near its ceiling hides gains. Qwen3-8B-Base already scores 91.2 on GSM8K, so SPICE can add only 1.5. Measure: the headroom, 100 minus the base score. Fix: read hard benchmarks; AIME'25 on Qwen3-4B goes from 6.7 to 19.1.
Chapter 5
Ground the game in real repositories, where a bug is a set of files
The SSR paper asks: what can a person learn by talking only to a Python interpreter? Every corner of Python, but not the knowledge inside real codebases. Self-Play SWE-RL (SSR) grounds the game in real repositories instead.
One policy plays two roles: a bug-injection agent and a bug-solving agent. Both use Bash and a search-replace editor. The model is CWM-sft, the 32B Code World Model before its RL stage. The only input is a Docker image with the code and its dependencies. SSR assumes no tests, no test command, no test parser and no knowledge of the language.
| File in the bug artifact | What it does |
|---|---|
| test_script.sh | runs the tests; the injector must discover how |
| test_parser.py | turns test output into JSON: each test, passed or failed |
| test_files.txt | the oracle test files, reset to the original before scoring |
| bug_inject.diff | a patch on code files that adds the bug |
| test_weaken.diff | a patch on test files that hides the bug; reversed, it is the solver's task |
Seven consistency checks decide if the artifact is valid:
That last check reverts each bug file alone. If no failing test passes again, that file is noise, and the artifact fails.
Six tests, one row of the pipeline per step. Press Step. Then turn on a cheat and step again.
The step order is SSR Figures 5 and 7. Six tests and which ones fail are illustrative.
Before the solver starts, SSR removes the .git folder and makes a fresh commit. The injector may read the git log to revert an old change; the solver must not find the answer there. The solver's prompt holds only the reversed test_weaken.diff, never an issue written in English.
A failed solver patch is not thrown away. SSR applies it on top of the bug to make a higher-order bug and asks for another repair. It stops at second order, because higher layers tend to overlap with bugs it already has.
Failure. The solver edits the tests instead of the code. Symptom: the weakened tests pass, but the bug is still there. Measure: score only after you restore the tests in test_files.txt. Fix: SSR restores them after the patch, every time, so the cheat earns −1.
Chapter 6
Pay the injector for hard bugs, and find the solve rate it should aim for
The solver tries each bug G = 8 times. Call the share of attempts that pass every test the solve rate s. An attempt earns +1 if all tests pass, −1 if not.
The expected r-solve equals s times plus one, plus one minus s times minus one, which is two s minus one.
Weight +1 by its chance s and −1 by its chance 1 − s, then add. The solver wants s high.
With 3 of 8 attempts passing: s = 0.375 and the average is 2 × 0.375 − 1 = −0.25.
The injector's reward (SSR Eq. 1) points the other way. Its penalty knob α is 0.8.
r-inject equals minus one if the artifact is invalid; minus alpha if s is zero or one; otherwise one minus one-plus-alpha times s.
A failed check pays −1. A bug never solved or always solved pays minus alpha. Otherwise pay 1 minus one-plus-alpha times s.
At s = 3/8: 1 − 1.8 × 0.375 = 0.325, while the solver averages −0.25. At 1 of 8 the injector gets 0.775; at 0 of 8 it drops to −0.8.
Eight attempts cannot tell a bug solved 2% of the time from one never solved. And the injector does not pick k: it picks the chance p that each attempt passes, and luck picks k.
R of p equals the sum over k from zero to G of: G choose k, times p to the k, times one minus p to the G minus k, times r of k over G.
For each count k, multiply the chance of exactly k passes by the reward r at that count. Add the nine products.
At p = 0.1, all 8 attempts fail with chance 0.98 = 0.43, so R = 0.045. At p = 0.2, R = 0.338. Our sum peaks at p ≈ 0.26, R = 0.37.
Warm bars: r-inject at each of the 9 outcomes. Curve: the expected reward R(p). Drag p to aim; drag α to reshape.
r-inject is SSR Eq. 1; the expected reward is the sum in Appendix A.1. SSR reports a peak "around 0.2" (Figure 10); our exact sum for G = 8 peaks near 0.26 with a flat top.
A shortcut from SSR: for a reward shaped like sa(1 − s)b, the best target is about a / (a + b). Its Figure 10 fits Eq. 1 with curves such as a = 0.5, b = 2, which gives 0.2.
Failure. A larger group would sharpen s, but each attempt is a full agent run. Symptom: the learner waits on the slowest of 8 rollouts. SSR keeps G = 8 "for acceptable rollout latency".
Chapter 7
Test the self-taught agent on real issues it never trained on
SSR's authors score it on two sets of real GitHub issues. SWE-bench Verified has 500 human-checked issues. SWE-Bench Pro (public split) has 731 harder, enterprise-scale problems. The model gets one attempt per problem, at temperature 1.0 and top-p 0.95.
The rival is baseline RL. It uses the same images and settings, but it gets human-written issues, the real pass-to-pass and fail-to-pass tests, and ready test scripts. SSR gets bare images.
Each bar is the resolve rate after 150 training steps. Pick a comparison.
Endpoint labels from SSR Figure 8 (Verified, Pro) and Figure 9 (the other three, averaged over all 1,231 tasks). The 29.2 start in Figure 9 is our weighted average of the two base scores.
Verified rises from 41.0 to 51.4, which is +10.4; baseline RL ends at 49.0. Pro rises from 21.1 to 28.9, which is +7.8; baseline RL ends at 25.3. The gains come on English issues, yet the solver trained only on test diffs.
Is +10.4 just noise? SSR reports about 2% paired standard error on Verified. So 10.4 / 2 = 5.2 standard errors. Noise alone is a poor explanation for that.
| Ablation (Figure 9) | Finding |
|---|---|
| Self-play parts | full self-play 38.0; repair only 33.5; injection only 25.2, worse than the start |
| Injection method | direct prompting gives one-line edits like var = 0 to var = 1 (35.4); removal 36.0; removal plus history 38.0 |
| Solver feedback | a {−1, +1} validity-only reward ends at 35.3; the paper calls the gain from feedback "slight and largely negligible" |
Repair-only trains on a fixed pool of old self-play bugs, so it never gets bugs matched to its current skill. The cost: 512 H100 GPUs per run, 64 to train and 448 to roll out. Each run takes 150 steps of 16M tokens, about 2.5B tokens, with a 131,072-token context.
Failure. On Pro, baseline RL meets SSR near step 125 and ends 3.6 points behind. Symptom: one checkpoint says the methods tie. Measure: compare whole curves and the 2% noise floor, not one point. Fix: report the trend over training, as the paper does.
Chapter 8
See how a clever challenger can win while the solver learns nothing
Grounding fixes drift. It does not make the game safe. SSR's Appendix A shows that a smart enough challenger has a dominant strategy: a move that earns its best reward whatever the solver does.
The injector may edit tests. So it can write a test that passes at random with its favourite chance p. To look fixed, it seeds the coin with a hash of the code: if rand(seed=hash(current_code)) < p: pass(). To pass the "original must pass" check, it adds a case for the original code's hash. Hide all that by obfuscating the code, and the solver cannot improve its odds. Its best reply is to do nothing.
Drag the solver's skill. On an honest bug, skill moves the pass rate. On a rigged test, watch the line stay flat.
Toy: the honest pass chance is a logistic curve of skill; the rigged one is fixed at 0.26, the best target from Chapter 6. Rewards use SSR Eq. 1 and its expected value.
A milder trap needs no cheating. The tunnel-vision challenger finds one knob of difficulty and turns only that. SSR's example: if long multiplication is hard, just lengthen the numbers. The pass rate sits at the target, the reward looks healthy, and the solver never sees a new kind of problem.
SSR proposes three mitigations:
| SSR Appendix E | What the authors report |
|---|---|
| No hidden oracle | the solver sees all the tests; overfitting to them was not observed, but public and private splits are the next step |
| Unit tests only | a narrow check of real engineering |
| One model for both roles | nobody has tried larger MoE models or separate policies yet |
| Issues in English (failed) | generated issues copied test patches, were incoherent and collapsed to one pattern |
| 23 repositories only (failed) | did not beat broad training: too little variety |
| Scale (failed) | training became unstable, "manifesting as gibberish outputs" |
SPICE calls its corpus "near-inexhaustible". It is still 20,000 documents, each used about 2 to 3 times over 640 iterations.
Failure. The reward curve looks perfect while the curriculum narrows. Measure: sample the generated tasks and count their kinds, not only their pass rates. Fix: the three mitigations above.
Chapter 9
Keep the terms, the numbers, the code and the open questions in one place
Self-play needs a referee the model did not write. SPICE uses documents that the Reasoner never sees, and pays the Challenger for questions that split the answers. SSR uses real repositories, a five-file bug artifact, seven checks and a reward that pays the injector for hard but solvable bugs.
| Term | Meaning | Number to remember |
|---|---|---|
| Pseudo-label accuracy | share of self-made answer keys that are right | R-Zero: 79% to 63% |
| Information asymmetry | the Challenger reads d; the Reasoner does not | 20,000 docs, up to 5,992 tokens |
| Variance reward | exp(−(p(1−p) − 0.25)2 / 0.02) | 1.000 at 4/8; 0.372 at 7/8 |
| DrGRPO advantage | reward minus own-role group mean | +0.553, −0.075, −0.403, −0.075 |
| SPICE gain | overall, Qwen3-4B-Base | 35.8 to 44.9 |
| Co-evolution | frozen step-200 opponent | 55% to 35%; 55% to 85% |
| Bug artifact | script, parser, test list, bug patch, weakening patch | 7 checks |
| Injector reward | −1, −α, or 1 − (1 + α)s | α = 0.8; 0.775 at 1/8 |
| Best target | peak of the expected reward | paper: about 0.2 |
| SSR gain | CWM-sft, one attempt | Verified +10.4; Pro +7.8 |
| Absolute Zero | SPICE | SSR | |
|---|---|---|---|
| Referee | a Python executor | a document corpus | real repositories and their tests |
| Hidden from the solver | nothing | the document | the original code and git history |
| Writer's pay | 1 − p | bell curve at p = 0.5 | piecewise, aims near 0.2 |
| Cost per check | run a snippet | rule-based answer match | a full agent run in a sandbox |
pythonimport math from math import comb def spice_reward(k, G=8, tau=0.01, valid=True, rho=-0.1): if not valid: return rho p = k / G return math.exp(-(p * (1 - p) - 0.25) ** 2 / (2 * tau)) def drgrpo_adv(rewards): # one role's group only m = sum(rewards) / len(rewards) return [r - m for r in rewards] # no division by std def r_inject(k, G=8, alpha=0.8, valid=True): if not valid: return -1.0 if k in (0, G): return -alpha return 1 - (1 + alpha) * k / G def expected(p, r, G=8): # R(p): average over k ~ Binomial(G, p) return sum(comb(G, k) * p**k * (1 - p)**(G - k) * r(k) for k in range(G + 1)) print(round(spice_reward(7), 3)) # 0.372 print(max(range(1, 100), key=lambda i: expected(i / 100, r_inject)) / 100) # 0.26
Credit: Session 14 of Georgia Tech CS 8803, LLM seminar. Paper one: SPICE: Self-Play In Corpus Environments Improves Reasoning (Liu et al., arXiv 2510.24684, v1). Paper two: Toward Training Superintelligent Software Agents through Self-Play SWE-RL (Wei et al., ICML 2026, arXiv 2512.18552, v3). The drift curve, the rigged-test curve, the four-question groups and all made-up numbers are ours.
Teach it back: open Present or Teach. Explain why the variance reward peaks at 4 out of 8, and why the injector aims near 0.2. Then go back to the five pay rules and predict where each one aims before you press it.