math_utils.grade_answer 会忽略单位,如果参考值和预测值都带有单位,则带有错误单位(或错误比率)的正确数值也会被评为正确。
作者: shaurya416创建于 2026年9月24日更新于 2026年9月24日
The unit-stripping loop in _normalize (openrlhf/utils/math_utils.py:220-238, function defined at :205) runs on the reference and the prediction independently. It never checks that the two units match. Its output is compared at :377 in grade_answer_sympy (defined at :372). That function is reached from grade_answer (:411, return at :425) and from examples/Python/math_reward_func.py:36-38.
for unit in [
"degree", "cm", "centimeter", "meter", "mile", "second", "minute",
"hour", "day", "week", "month", "year", "foot", "feet", "inch", "yard",
]:
expr = re.sub(f"{unit}(es)?(s)? *(\\^[0-9]+)?", "", expr) ground_truth_normalized = _normalize(ground_truth)
given_normalized = _normalize(given_answer)
...
if ground_truth_normalized == given_normalized:
return True
if not given_normalized:
return FalseThe loop exists so that 5 matches 5 hours. When both sides carry a unit, though, both units are erased and only what is left gets compared.
内容来源: OpenRLHF/OpenRLHF