Skip to content

Conversation

@fshp971
Copy link
Contributor

@fshp971 fshp971 commented Sep 8, 2025

What does this PR do?

This PR attempts to fix issue #3150, where custom reward function cannot be used with reward_model.reward_manager=prime.

The main cause of issue #3150 is that when using verl.trainer.ppo.reward.get_custom_reward_fn to create reward_fn and val_reward_fn for the RayPPOTrainer, the custom reward code file is loaded twice under the same module name "custom_module".

This results in the actual reward functions reward_fn.compute_score and val_reward_fn.compute_score having the same module-function name (i.e., "custom_module") but different id() values in memory, and only val_reward_fn.compute_score has the correct, latest id() address.

Therefore, when using the "prime" reward manager, since it tries to use concurrent.futures.ProcessPoolExecutor to pickle the reward functions for multiprocessing, the ProcessPoolExecutor finds that reward_fn.compute_score has an incorrect id() compared to its global "custom_module"'s recorded id(), and thus fails to pickle reward_fn.compute_score.

The solution for this bug is to simply avoid loading duplicate modules from the same custom file in verl.trainer.ppo.reward.get_custom_reward_fn.

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses issue #3150 by preventing the duplicate loading of a custom reward function module. The change checks sys.modules before importing the module from a file, which resolves pickling errors with ProcessPoolExecutor. I've added one suggestion to further improve the robustness of this fix by ensuring the specified reward function is validated in the module, whether it's newly loaded or was pre-existing.

@vermouth1992
Copy link
Collaborator

Could you comment on Gemini's review?

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@fshp971
Copy link
Contributor Author

fshp971 commented Sep 8, 2025

Hi,

I think the suggestion made by Gemini would make the code more robust.
I have committed that.

@vermouth1992 vermouth1992 merged commit 491e636 into volcengine:main Sep 8, 2025
56 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants