Fix crash when reward function is a functools.partial or callable instance#6313
Merged
Conversation
This was referenced Jul 6, 2026
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
Fixes #6133.
What
Reward-function display names were built with an unconditional
func.__name__, which raisesAttributeErrorforfunctools.partialobjects and callable class instances. Exactly the picklable reward forms the Async GRPO docs recommend.AsyncGRPOtherefore crashed at rollout-worker init on a documented API.Fix
Added a small shared helper
get_callable_nameintrl/trainer/utils.pythat unwrapsfunctools.partialand falls back to the class name for callable instances, and used it everywhere reward-func names are resolved:async_rollout_worker.py(the reported crash)grpo_trainer.py,rloo_trainer.py(same latent bug in-process)online_dpo_trainer.py,sdpo_trainer.py(kept consistent)Plain functions and lambdas are unaffected.
Note
Low Risk
Narrow display-name fix at reward registration; behavior for plain functions and model-based rewards is unchanged.
Overview
Fixes init-time crashes when custom reward functions are
functools.partialor callable class instances (patterns Async GRPO and related trainers document as picklable). Those callables lack a reliable__name__, so buildingreward_func_nameswithfunc.__name__raisedAttributeError.Adds shared
get_callable_nameintrl/trainer/utils.py: unwrap nestedpartials, use the wrapped function’s name when present, otherwise the class name (lambdas still report"<lambda>"). GRPO, RLOO, async rollout worker, and experimental Online DPO / SDPO now use it instead of direct__name__access for non-module reward funcs. Unit tests cover functions, partials, callable instances, and lambdas.Reviewed by Cursor Bugbot for commit ace778a. Bugbot is set up for automated code reviews on this repo. Configure here.