feat(rewards): support batched reward-hook execution (#225) - #435
Open
candy972023 wants to merge 1 commit into
Open
feat(rewards): support batched reward-hook execution (#225)#435candy972023 wants to merge 1 commit into
candy972023 wants to merge 1 commit into
Conversation
Add an optional batch reward interface alongside the existing per-example adapter. Users can define `reward_fn_batch(records) -> list[float]` in the same module as `reward_fn`; when present, AReno calls the batch interface once per batch instead of looping per record. Changes: - rewards.py: add load_reward_fns, validate_batch_rewards, compute_rewards with execution timing for both paths; load_reward_fn delegates to load_reward_fns to avoid duplication - policy_only.py: use compute_rewards in both agentic and rollout paths - ppo.py: pass reward_fn_batch through to PolicyOnlyTrainer - trainer_factory.py: accept and forward reward_fn_batch - cli/train.py: load both functions via load_reward_fns - tests/test_batched_reward_cpu.py: CPU tests covering agreement, cardinality validation, empty batch, backward compat, and module loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #225
Add an optional batch reward interface alongside the existing per-example adapter. Users can define
reward_fn_batch(records) -> list[float]in the same module asreward_fn; when present, AReno calls the batch interface once per batch instead of looping per record. This benefits reward functions with heavy per-call overhead (e.g. external model scoring, batch inference).Files
areno/api/rewards.pyload_reward_fns,validate_batch_rewards,compute_rewardswith cardinality validation and execution timingareno/api/trainers/policy_only.pycompute_rewardsin both agentic and rollout pathsareno/api/trainers/ppo.pyreward_fn_batchtoPolicyOnlyTrainerareno/api/trainer_factory.pyreward_fn_batchareno/cli/train.pyload_reward_fnstests/test_batched_reward_cpu.pyDesign
reward_fn(record) -> float(existing) andreward_fn_batch(records) -> list[float](optional). Users opt in by defining the batch function; no config change needed.validate_batch_rewardschecks output length matches input length. On mismatch, raisesValueErrorwith the batch index so the caller can identify which prompt-group batch failed.time.perf_counter()and log it through the trainer's logger.load_reward_fnpreserved as public API, delegates toload_reward_fns(path)[0]. When no batch function is defined, behavior is identical to before.RewardRecordcontract, no new dependencies.How was it tested?
CPU tests (no GPU required), 15/15 passed:
load_reward_fnsloads both functions, detects absent batch fn, rejects non-callableChecklist