r1_distill_qwen_math_reward_fn returns 0.0, not incorrect_reward, when </think> is missing or appears twice
In oat/utils/math_grader.py, r1_distill_qwen_math_reward_fn ends with return {"formatted": False}, 0.0 when the response does not contain exactly one </think>. The incorrect_reward argument is ignored on that branch. boxed_reward_fn and answer_tag_reward_fn return incorrect_reward for unformatted responses.
With incorrect_reward=-1 (for example MATHOracle(template='r1_distill_qwen', ..., incorrect_reward=-1)), a response with a wrong answer after </think> scores -1, while a response with no </think> scores 0, which is better. With a positive incorrect_reward the order flips the other way. Only a setting of 0.0 hides it.
Reproduction
From a checkout. The module imports sympy and math_verify, so the script pulls out the three functions it needs with ast (standard library only):
import ast
# the module imports sympy, math_verify etc., so pull out just the three functions
src = open("oat/utils/math_grader.py").read()
names = {"extract_answer", "boxed_reward_fn", "r1_distill_qwen_math_reward_fn"}
fns = [n for n in ast.parse(src).body if isinstance(n, ast.FunctionDef) and n.name in names]
ns = {}
exec(compile(ast.Module(fns, []), "math_grader.py", "exec"), ns)
reward = ns["r1_distill_qwen_math_reward_fn"]
for completion in ["I do not know.</think>I do not know.", "I do not know.", "I do not know.</think></think>I do not know."]:
info, r = reward(completion, "2", fast=True, correct_reward=1.0, incorrect_reward=-1.0)
print(f"{completion!r}: reward={r} info={info}")
Expected: reward=-1.0 on all three lines, since none of the responses is correct.
Actual:
'I do not know.</think>I do not know.': reward=-1.0 info={'formatted': False}
'I do not know.': reward=0.0 info={'formatted': False}
'I do not know.</think></think>I do not know.': reward=0.0 info={'formatted': False}
A fix would return incorrect_reward instead of 0.0 in the else branch.
Version
Reproduces on 869706620a35ec5304fa80a0c74f0c566cc2bc57, the current head of main (checked 2026-10-28).