verl icon indicating copy to clipboard operation
verl copied to clipboard

prime_math reward gives full credit to wrong intervals and to 100x, 1/100x and off-by-one numbers, and gives 0 to many correct equation answers

Open jimmy-holdout opened this issue 1 month ago • 4 comments

System Info

  • verl main at d430157d15516d89e0cc853fd10fcd21d9234c44 (verl.__version__ = 0.10.0.dev). The counts below were first measured at dc709afb7a74fd2645640a4e5f2fdf40166b4fbb. verl/utils/reward_score/prime_math/ has not changed between the two commits, and the results are the same on both.
  • Ubuntu 24.04, Python 3.12.3, CPU only.
  • Environment built from the repo lockfile with uv sync --frozen --all-packages --extra cpu: sympy 1.14.0, pylatexenc 2.10, antlr4-python3-runtime 4.9.3.

Information

  • [ ] The official example scripts
  • [x] My own modified scripts

Tasks

  • [ ] An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • [x] My own task or dataset (give details below)

The data is the validation split of PRIME-RL/Eurus-2-RL-Data, which is the dataset the PRIME recipe points to. Its first 1,024 rows have numina_* data sources, and default_compute_score sends those rows to prime_math.compute_score. The snippet below calls default_compute_score directly, with nothing patched.

Reproduction

prime_math has three grading errors:

  1. Interval endpoints. An interval with a wrong endpoint bracket gets full credit. For example, (-\infty, \frac{1}{2}) scores 1 against the gold (-\infty, \frac{1}{2}], and [1,2] scores 1 against [1,2).
  2. Numeric tolerance. For a numeric gold, 100x and 1/100x the gold both score 1. For integer golds of 10,000 or more, an off-by-one answer also scores 1 (for example 22501 against 22500), even though grade_answer says integer golds need an exact match.
  3. Equation golds rejected. Many golds score 0 when the gold string itself is given as the answer. Most of them are equations, such as x - \sqrt{3}y + 2 = 0, \dfrac{x^{2}}{18} + \dfrac{y^{2}}{9} = 1 and S_{max}=-6. Simple equations such as y = x - 1 do score correctly.
from verl.utils.reward_score import default_compute_score

# every numina_* data source (Eurus-2-RL-Data math rows) is routed to prime_math.compute_score
DATA_SOURCE = "numina_cn_k12"

cases = [
    # (case, ground truth, answer, expected score)
    ("wrong interval", "[1,2)", "[1,2]", 0),
    ("wrong interval", "(-\\infty, \\frac{1}{2}]", "(-\\infty, \\frac{1}{2})", 0),
    ("correct interval", "[1,2)", "[1,2)", 1),
    ("100x gold", "22500", "2250000", 0),
    ("1/100x gold", "22500", "225", 0),
    ("gold + 1", "22500", "22501", 0),
    ("correct integer", "22500", "22500", 1),
    ("equation gold echoed", "x - \\sqrt{3}y + 2 = 0", "x - \\sqrt{3}y + 2 = 0", 1),
    ("equation gold echoed", "\\dfrac{x^{2}}{18} + \\dfrac{y^{2}}{9} = 1", "\\dfrac{x^{2}}{18} + \\dfrac{y^{2}}{9} = 1", 1),
    ("equation gold echoed", "S_{max}=-6", "S_{max}=-6", 1),
    ("equation gold echoed", "y = x - 1", "y = x - 1", 1),
]

for case, gold, answer, expected in cases:
    response = f"The answer is $\\boxed{{{answer}}}$."
    score = default_compute_score(DATA_SOURCE, response, gold)
    print(f"{case:21} expected={expected} score={score}  gold={gold!r}  answer={answer!r}")

Output on main (d430157d):

wrong interval        expected=0 score=1.0  gold='[1,2)'  answer='[1,2]'
wrong interval        expected=0 score=1.0  gold='(-\\infty, \\frac{1}{2}]'  answer='(-\\infty, \\frac{1}{2})'
correct interval      expected=1 score=1.0  gold='[1,2)'  answer='[1,2)'
100x gold             expected=0 score=1.0  gold='22500'  answer='2250000'
1/100x gold           expected=0 score=1.0  gold='22500'  answer='225'
gold + 1              expected=0 score=1.0  gold='22500'  answer='22501'
correct integer       expected=1 score=1.0  gold='22500'  answer='22500'
equation gold echoed  expected=1 score=0.0  gold='x - \\sqrt{3}y + 2 = 0'  answer='x - \\sqrt{3}y + 2 = 0'
equation gold echoed  expected=1 score=0.0  gold='\\dfrac{x^{2}}{18} + \\dfrac{y^{2}}{9} = 1'  answer='\\dfrac{x^{2}}{18} + \\dfrac{y^{2}}{9} = 1'
equation gold echoed  expected=1 score=0.0  gold='S_{max}=-6'  answer='S_{max}=-6'
equation gold echoed  expected=1 score=1.0  gold='y = x - 1'  answer='y = x - 1'

How many validation rows are affected. These counts cover all 1,024 numina_* rows of the Eurus-2-RL-Data validation split. Every answer was wrapped in \boxed{} and scored with default_compute_score.

Problem Affected golds
A wrong endpoint bracket scores 1 9 of the 29 valid interval golds (rows 85, 176, 214, 460, 463, 499, 653, 656, 990)
100x the gold scores 1 452 of 452 nonzero numeric golds
1/100x the gold scores 1 452 of 452 nonzero numeric golds
gold + 1 scores 1 7 of 7 integer golds of 10,000 or more (rows 0, 52, 145, 334, 352, 544, 819)
The gold itself scores 0 61 of 1,024 golds. 52 of these contain =, which is 52 of the 73 golds that contain =; nearly all of them are equations. The other 9 are prose answers.

The interval count leaves out row 77, whose gold (0, \infty] is not a valid interval. Every interval gold and every numeric gold scores 1 when it is given back unchanged.

Where it happens.

  1. grade_answer does check that tuples and intervals use the same brackets. When that check fails, compute_score falls back to grader.math_equal. If the prediction is wrapped in brackets and the reference does not start with the opposite opening bracket, math_equal strips []() from both strings. So [1,2] and [1,2) both become 1,2 and compare equal.
  2. compute_score calls math_equal with the default include_percentage=True. That accepts reference / 100, reference and reference * 100, each with rel_tol=1e-4. For |gold| >= 10,000, a difference of 1 falls inside that tolerance. This goes against the comment in grade_answer: "if the ground truth answer is an integer, we require the given answer to be a strict match".
  3. match_answer cuts the boxed content after the last = (and after is , : and similar markers). So x - \sqrt{3}y + 2 = 0 is graded as 0 against the full gold string. y = x - 1 passes only because the MATH normalizer drops a left-hand side of at most two characters.

Impact. default_compute_score sends the data sources numina_aops_forum, numina_synthetic_math, numina_amc_aime, numina_synthetic_amc, numina_cn_k12 and numina_olympiads to prime_math. Those are the math rows of Eurus-2-RL-Data. The PRIME recipe in verl-recipe (prime/run_prime_qwen.sh, which uses PrimeRewardManager with default_compute_score) trains on that data. The rep_exp recipe's reward router also calls prime_math.compute_score for the same sources. During RL, problems 1 and 2 reward wrong answers, and problem 3 gives 0 to correct equation answers such as lines and conics.

Expected behavior

  • An interval whose endpoint brackets differ from the gold should score 0.
  • A plain number should not get credit for being 100x or 1/100x the gold. A percent conversion should only apply in the direction the % sign implies: 83\% can match 83 or 0.83, but not 8300. An integer gold should need an exact match.
  • A boxed equation that is the same equation as the gold should score 1.

I have a fix ready for problems 1 and 2. It does the following:

  • In math_equal, return False when both answers are interval-shaped and their bracket sequences differ. This runs before the step that strips the brackets.
  • Treat the bracket at an infinite endpoint as irrelevant, so (0, \infty) and (0, \infty] stay equivalent.
  • Read ∞ the same as \infty.
  • Compare integer literals exactly, including above 2^53, and also when they are written with a zero fraction such as 22500.0. Other decimals keep the existing 1e-4 relative tolerance.
  • Apply 100x or 1/100x only according to which answer carries the % sign.

On the validation split, the wrong-bracket, 100x, 1/100x and gold + 1 counts above all drop to 0. Among the variants I checked, no correct answer loses credit and no wrong answer gains it.

The fix does not change problem 3 (equation golds). The 61 of 1,024 golds that score 0 when given back, 52 of which contain =, are left as they are. A possible approach would be this: when the gold contains =, compare the boxed answer with the gold side by side instead of grading only the text after the last =. A naive version of that creates new false credits, though, because the existing per-answer normalization is lenient. I tried one, and it showed these problems:

  • Units and text get dropped: AC = 8 \text{ feet} would match the row 450 gold AC = 8 \text{ meters}, because everything after \text{ is cut.
  • Variable names get lost: the row 67 gold x_{1} = -1 \text{ and } x_{2} = -2 would accept x_{3} in place of x_{2}.
  • Function calls get read as multiplication: 0g=-a would match the row 616 gold g(0)=-a, and -2f=-1 would match the row 484 gold f(-2)=-1.

An equation comparison would need to keep units, \text{} content, variable names and function application intact. That is probably better as a separate change with its own tests.

AI assistance was used to prepare this report; the reproduction and counts above were run and checked by me.

Happy to help test a fix. Found while auditing public RL environments.

jimmy-holdout avatar Oct 23 '26 05:10 jimmy-holdout

I'd like to contribute a conservative follow-up for the equation case left outside #8347.

On main at 3c6d9b43, match_answer reduces a boxed equation such as x - \\sqrt{3}y + 2 = 0 to the text after the final =. My local patch accepts the final boxed/fbox content only when the gold contains = and that content exactly matches the gold (apart from outer whitespace). Every non-identical answer still follows the existing extraction and grading path. It does not add equation normalization, unit removal or symbolic equivalence.

The regression cases include units, variable subscripts and function application from your warning examples. They check that non-identical answers still reach the existing graders. I also found that the box selector prefers any \\boxed over a later \\fbox; the patch selects the last of either command so an intermediate correct box cannot override a final wrong answer.

The final 27-case CPU test file includes two public default_compute_score routing cases: unchanged main gives 18 failed / 9 passed; the local patch gives 27 passed. These runs load the real reward modules with the local harness bypassing only the top-level Ray driver import. SymPy and timeout functions are not replaced by the harness; the seven fallback-routing cases explicitly mock the grading functions. The baseline also emits existing Windows multiprocessing errors, so I am not claiming Linux or full-suite validation. Normal reward-directory collection stops on missing Ray (3 collection errors).

Open-PR searches for match_answer, fbox, prime_math and this issue did not identify the same fix. #8347 addresses interval/numeric comparison; this patch leaves those changes untouched. AI assistance was used for implementation and testing. I have not opened a PR yet.

Would this exact-text-only scope be welcome, and is anyone already working on the equation follow-up?

JianhaoYu-AI avatar Oct 26 '26 07:10 JianhaoYu-AI

Thanks for picking this up. Nobody on our side is working on the equation case, so please go ahead.

Exact-text matching when the gold contains = sounds like the right conservative scope. It avoids the false credits from units, variable subscripts and function calls noted above. Good catch on the \boxed vs later \fbox selection, too.

One thing to know: #8347 was closed, so the interval-bracket and 100x / 1/100x / integer problems from this issue are still open. Your patch doesn't need to wait on it.

Once you open the PR, I'm happy to run it on Linux against the 1,024 numina_* validation rows and post the before/after counts, including the 61 golds that currently score 0 when given back unchanged.

jimmy-holdout avatar Oct 26 '26 07:10 jimmy-holdout

verl is not going to maintain any specific reward including prime_math, since the reward is specific to dataset. Instead, verl provide interface to define and plugin your own reward, please refer to: https://verl.readthedocs.io/en/latest/advance/reward_loop.html#reward-loop

wuxibin89 avatar Oct 26 '26 08:10 wuxibin89

Thanks @wuxibin89 for clarifying the maintenance scope. Understood—I'll leave #8385 closed and keep dataset-specific grading changes outside verl, using the documented custom-reward interface.

@jimmy-holdout, thank you for the detailed analysis and the offer to validate. The focused patch and regression tests remain available in my fork for reference: https://github.com/JianhaoYu-AI/verl/tree/fix/prime-math-boxed-equations .

JianhaoYu-AI avatar Oct 26 '26 08:10 JianhaoYu-AI