Fix async grpo picklable reward functions#6136
Conversation
|
Follow-up to #5293, which introduced AsyncGRPO and the rollout-worker reward metric naming path. cc @qgallouedec , since this affects the original AsyncGRPO implementation. Also cc @AmineDiro because #5749 recently documented support for picklable reward callables such as functools.partial, which exposes this incompatibility. The current reward metric-name initialization assumes every callable has name, but functools.partial objects and common callable class instances do not. |
There was a problem hiding this comment.
Pull request overview
This PR fixes AsyncGRPO rollout-worker initialization when reward functions are valid picklable callables that don’t expose __name__ (e.g., functools.partial and callable class instances), by introducing a helper to derive stable metric names and adding regression tests for the naming behavior.
Changes:
- Add
_get_callable_nameto resolve reward metric names for partials and callable instances. - Use
_get_callable_namewhen buildingreward_func_namesin the spawned rollout worker. - Add focused regression tests covering partials, callable instances (named/unnamed), and builtin callables.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
trl/experimental/async_grpo/async_rollout_worker.py |
Adds a callable-name resolver and uses it to build reward metric keys without assuming __name__ exists. |
tests/experimental/test_async_grpo_trainer.py |
Adds regression tests ensuring callable-name resolution works for documented picklable reward callable types. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Related to #6134, which addresses the same issue. This implementation additionally preserves an explicitly assigned name on functools.partial values. That allows users to distinguish metrics for multiple configured partial rewards wrapping the same underlying function, instead of collapsing them under one metric key. |
|
Could I please get a quick review on this short PR whenever you have a moment? |
|
Could I please get a quick review on this short PR whenever you have a moment? |
|
thanks, this one is superseded by #6313 |
What does this PR do?
Fixes #6133
AsyncGRPO supports picklable reward callables in its spawned rollout worker,
including
functools.partialvalues and callable class instances. The workerpreviously assumed every reward exposed
__name__, which caused initializationto fail for valid unnamed callables.
This PR resolves metric names by unwrapping partials, preserving any existing
__name__, and falling back to the callable class name only when no name exists.Before submitting
AI writing disclosure
Who can review?
Community reviewers are welcome.
Note
Low Risk
Narrow change to reward metric naming at worker init; reward scoring behavior is unchanged.
Overview
Fixes rollout worker startup when reward functions are valid picklable callables that do not expose
__name__(e.g. unnamedfunctools.partialor callable class instances).The async rollout worker now derives per-reward metric keys via
_get_callable_name: unwrappartialobjects (using an explicit__name__when set), otherwise use__name__, and fall back to the callable’s class name.reward_func_namesis built with this helper instead of assuming every reward has__name__.Adds a parametrized test covering partials, named partials, callable instances, and builtins like
operator.add.Reviewed by Cursor Bugbot for commit 03bf68a. Bugbot is set up for automated code reviews on this repo. Configure here.