[reward] math_verify.compute_score: after one worker process dies, every later correct answer scores 0.0 with only a print line
verl/utils/reward_score/math_verify.py:29-39 and :57-67 at 6093e007 (file blob 7071dac, identical to current main):
_pool = None
_pool_lock = threading.Lock()
def _get_pool():
global _pool
if _pool is None:
with _pool_lock:
if _pool is None:
_pool = ProcessPoolExecutor(max_workers=4, mp_context=multiprocessing.get_context("spawn"))
return _pool
def compute_score(model_output: str, ground_truth: str, timeout_score: float = 0, timeout: float = 30.0) -> float:
ret_score = 0.0
ground_truth_boxed = "\\boxed{" + ground_truth + "}"
try:
future = _get_pool().submit(_verify_in_subprocess, ground_truth_boxed, model_output)
ret_score = future.result(timeout=timeout)
except (FuturesTimeoutError, TimeoutException):
ret_score = timeout_score
except Exception as e:
print(f"Error in math_verify compute_score: {e}")
return ret_scoreThree properties combine:
_poolis a process-global singleton that is never replaced. AProcessPoolExecutoris permanently unusable once any worker exits, so every latersubmitraisesBrokenProcessPool.future.result(timeout=...)does not stop the worker. AfterFuturesTimeoutErrorthe worker keeps running its task and stays in the pool.- Every failure, including
BrokenProcessPool, is caught and returned as a plain float (0.0, ortimeout_score), so the reward manager never sees an exception and cannot flag the row.
Scope: this module is opt-in. The default verl/utils/reward_score/__init__.py path keeps the math_verify call commented out; it is reached through a custom reward function or a user override, as in tests/experimental/reward_loop/reward_fn.py, so only runs that use it are affected. Property 1 is the failure observed below (case A1). Properties 2 and 3 are hardening concerns: I did not find a real input that outruns math-verify's own alarm, and the stuck-worker case (B2) is modelled with an injected time.sleep.
Measured
Harness: a byte-identical copy of math_verify.py (renamed so it does not shadow the package), real math-verify 0.9.0 in the workers, Python 3.12.4, macOS, spawn context as in the file. Substitutions: a dying worker is injected with SIGKILL on the pool's pids (what the OOM killer does); a stuck worker is modelled by pool.submit(time.sleep, 1e6) on the module's own pool; timeout=3 instead of the default 30 only to keep the run short.
| Case | Result | Expected |
|---|---|---|
control: \boxed{42} vs gold 42, fresh pool |
1.0 | 1.0 |
control: \boxed{41} vs gold 42 |
0.0 | 0.0 |
control: empty reply vs gold 42 |
0.0 | 0.0 |
intended use: \boxed{\frac{1}{2}} vs gold 0.5 |
1.0 | 1.0 |
A1: after one worker is SIGKILLed, \boxed{42} vs 42, three calls |
0.0, 0.0, 0.0 (each prints A child process terminated abruptly, the process pool is not usable anymore) |
1.0 |
control: same inputs through _verify_in_subprocess in-process |
1.0 | 1.0 |
control: same process after _pool = None |
1.0 | 1.0 |
| control: 3 of 4 workers busy on non-returning tasks, healthy call | 1.0 in 0.0 s | 1.0 |
B2: 4 of 4 workers busy on non-returning tasks, healthy \boxed{42} vs 42, three calls |
0 after 3.0 s, 0 after 3.0 s, 0 after 3.0 s; all four worker pids still alive and still in the pool afterwards | 1.0 |
I did not find an input that makes verify() outrun math-verify's own alarm on 0.9.0 (seven exponent/factorial/product probes were all cut at about 5 s). #7155 reports a real sample where verify ran about 1677 s at 100% CPU, which is the case the outer timeout exists for.
Consequence
- The verifier failing is reported as the score of a wrong answer.
reward_loop/reward_manager/limited.py:451-467recordsreward_extra_info["error"]/["timeout"], but it can only do so if an exception reaches it; here it never does. - After one worker death (#1684 describes a sudden memory blow-up with
math_verifyin the loop) every later row scored by that process is 0.0 for the rest of the run. Reward mean falls the way a policy regression would, with no exception and one print line per row. - If all four workers were ever occupied by non-returning tasks (modelled here, not observed with a real input), every later row would block its caller for the full
timeout(30 s by default) and then score 0. PR #5839 says problematic inputs "are killed after 30s timeout"; the workers are not killed. - This is the same swallow site as #3407 / #5635 (silent all-zero from
signal.alarm), which were fixed for that cause only.
Suggested fix
Follow what the repo already does elsewhere: workers/reward_manager/prime.py:51,65-77 gives each batch its own pool and terminates then kills its workers in a finally, and limited.py:451-467 already turns exceptions into per-row flags.
- Map only
FuturesTimeoutError/TimeoutExceptiontotimeout_score; let other exceptions propagate (or re-raise after a retry) so the manager flags the row. - On
BrokenProcessPool, drop_poolunder_pool_lockand retry once on a fresh pool. - On
FuturesTimeoutError, kill the pool's processes and drop_poolbefore returningtimeout_score.
A sketch of exactly this, run on the same harness: after the SIGKILL the three calls return 1.0, 1.0, 1.0; with all four workers stuck the first call times out (0), the next returns 1.0 (3.6 s, cold worker start), the one after 1.0 in 0.0 s, and the old workers are gone. Controls unchanged.
Happy to open the PR.
Source: verl-project/verl