feat(reward): support composable reasoning rewards with format verification and length regulation - #1698
feat(reward): support composable reasoning rewards with format verification and length regulation#1698hsusul wants to merge 1 commit into
Conversation
…cation and length regulation
- Add FormatReward with <think>...</think> structure validation and answer delimiter extraction (\boxed{}, <answer>, ####)
- Add LengthPenalty with threshold, linear, and soft-tanh penalty modes to prevent length hacking in RLVR reasoning models
- Add CompositeReward combining task accuracy, format compliance, and length regulation with stats_tracker metric reporting
- Add get_deepseek_r1_math_reward factory helper for standard R1-style reasoning workflows
- Add comprehensive unit test suite in tests/test_reasoning_reward.py
Le8r0nJames
left a comment
There was a problem hiding this comment.
The claimed MultiTurnWorkflow compatibility needs a regression test. Its retry loop continues only while reward == 0, but this composite returns a positive reward for an incorrect, well-formatted answer, ending retries prematurely. Could we separate task success from the shaped training reward, or explicitly document this incompatibility?
| if cfg.answer_format == "boxed": | ||
| extracted_ans = extract_boxed_content(answer or text) | ||
| valid_ans = extracted_ans is not None |
There was a problem hiding this comment.
Could we validate a non-empty answer outside the thinking block? answer or text falls back to the full completion when the answer is missing, so <think>...\boxed{42}</think> receives full format reward. An empty \boxed{} is also accepted. Please add negative tests for both cases.
| except Exception: | ||
| logger.warning("Exception in accuracy_fn", exc_info=True) | ||
| acc_reward = 0.0 |
There was a problem hiding this comment.
Could we propagate accuracy scorer exceptions by default? Returning zero accuracy while still awarding format rewards can turn a broken scorer into format-only training without stopping training. If this fallback is intentional, please make it opt-in and distinguish scorer failures from incorrect answers.
Description
In reasoning RL post-training and RLVR (Reinforcement Learning with Verifiable Rewards, e.g. DeepSeek-R1 style training on GSM8K, MATH, and Olympiad tasks), models trained exclusively on binary task accuracy suffer from two critical failure modes:
</think>), generate multiple unclosed<think>blocks, output empty thinking traces, or fail to structure their final answer into standard delimiters (\boxed{...},<answer>...</answer>,####).As highlighted in community discussion (#162), AReaL previously lacked modular support for format rewards, length penalties, and composable reward functions.
This PR introduces a clean, composable reasoning reward module in
areal.reward:FormatReward&FormatRewardConfig:<think>...</think>tag structure (detects unclosed, missing, duplicate, or reversed tags).\boxed{...}with robust balanced brace parsing), XML tags (<answer>...</answer>), and GSM8K delimiters (####).extract_reasoning_and_answerutility to isolate the reasoning chain from the scoreable final answer.LengthPenalty&LengthPenaltyConfig:threshold($-\alpha \max(0, L - L_{\text{target}})$),linear, andsoft_tanhmodes.completion_ids) or decoded text.CompositeReward:reward_accuracy,reward_format,reward_length_penalty,reward_composite) tostats_trackerfor real-time training observability.RLVRWorkflowandMultiTurnWorkflow.get_deepseek_r1_math_reward:Related Issue
Relates to #162
Type of Change
Checklist
pre-commit run --all-files)./docs/build_all.sh)main/review-prcommand/create-prAdditional Context
tests/test_reasoning_reward.pypassing cleanly.