Skip to content

[RLlib] fix: Support custom eval functions that return zero eval_results, env_steps, or agent_steps {}, 0, 0#61563

Open
petern48 wants to merge 3 commits intoray-project:masterfrom
petern48:custom_eval_returns_falsy_vals
Open

[RLlib] fix: Support custom eval functions that return zero eval_results, env_steps, or agent_steps {}, 0, 0#61563
petern48 wants to merge 3 commits intoray-project:masterfrom
petern48:custom_eval_returns_falsy_vals

Conversation

@petern48
Copy link
Contributor

@petern48 petern48 commented Mar 7, 2026

Description

Custom evaluation functions are expected to return the following return values: eval_results, env_steps, agent_steps. Sometimes, users may want to return an output of {}, 0, 0 to skip the iteration (see the issue for an example). However, the code would raise a ValueError because it checks for falsy values. This PR updates the validation to check for the exact types instead.

Additionally, I found that the code would throw a KeyError when the custom evaluation didn't write to the metrics store. To handle this, I added a default={} to the peek call. The same peek call a few lines down already does the same.

Related issues

Fixed #61513

Additional information

The following validation logic was originally added in this PR: #45652. It looks like the intention of the PR was to validate the inputs, not to prevent 0 or {} values.

if not env_steps or not agent_steps:
raise ValueError(
"Custom eval function must return "
"`Tuple[ResultDict, int, int]` with `int, int` being "
f"`env_steps` and `agent_steps`! Got {env_steps}, {agent_steps}."

petern48 added 2 commits March 7, 2026 09:13
Signed-off-by: Peter Nguyen <petern0408@gmail.com>
Signed-off-by: Peter Nguyen <petern0408@gmail.com>
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 addresses an issue where custom evaluation functions could not return falsy values like an empty dictionary {} or 0. The changes correctly adjust the validation logic to check for types instead of truthiness, allowing these valid return values. A new test case has been added to verify this fix. The implementation looks correct and effectively solves the described problem.

Note: Security Review did not run due to the size of the PR.

@petern48 petern48 marked this pull request as ready for review March 7, 2026 18:00
@petern48 petern48 requested a review from a team as a code owner March 7, 2026 18:00
@petern48 petern48 changed the title [RLlib] Allow custom eval functions to return falsy values {} and 0 [RLlib] Support custom eval functions that return falsy values {} and 0 or that don't write to metrics store Mar 7, 2026
@ray-gardener ray-gardener bot added rllib RLlib related issues community-contribution Contributed by the community labels Mar 7, 2026
Signed-off-by: Peter Nguyen <petern0408@gmail.com>
@petern48 petern48 force-pushed the custom_eval_returns_falsy_vals branch from 386b1fd to 098b286 Compare March 7, 2026 22:12
@petern48 petern48 changed the title [RLlib] Support custom eval functions that return falsy values {} and 0 or that don't write to metrics store [RLlib] fix: Support custom eval functions that return zero eval_results, env_steps, or agent_steps {}, 0, 0 Mar 8, 2026
@petern48
Copy link
Contributor Author

petern48 commented Mar 8, 2026

cc @simonsays1980 as original author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community rllib RLlib related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[RLlib] Custom evaluation functions trigger a ValueError if they don't run any steps in a given iteration.

1 participant