Repository navigation
fix(rec): handle groups with a single experience - #638
Open
flyingdoubleG wants to merge 1 commit into
Open
flyingdoubleG wants to merge 1 commit into
flyingdoubleG wants to merge 1 commit into
Conversation
RECGroupedAdvantage.calculate_group_advantage only builds `rewards` when the group has more than one experience, but uses it right after for both branches, so a group of one (repeat_times=1, or a partial group) raises UnboundLocalError. Build `rewards` before the branch; a single experience keeps the existing no-baseline convention (mean 0, std 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Description
RECGroupedAdvantage.calculate_group_advantage(trinity/algorithm/advantage_fn/rec_advantage.py) buildsrewardsonly in thelen(exps) > 1branch, then uses it for every group:So the
recadvantage crashes withUnboundLocalError: cannot access local variable 'rewards'whenever a task group has a single experience (repeat_times: 1, or a partial group).The fix builds
rewardsbefore the branch. A single experience keeps the existing convention of thelen(exps) == 1branch (mean 0, std 1, as in GRPO), so its advantage is its reward.Test:
tests/algorithm/advantage_fn_test.py::test_rec_advantage_single_experience_groupcovers the default args,std_normalize=Trueanddrop="balance". It fails before the change; the file passes after (9 tests, CPU).Checklist
🤖 Generated with Claude Code