Skip to content

[RLlib] Add custom_resources_per_learner config#63303

Merged
ArturNiederfahrenhorst merged 7 commits into
ray-project:masterfrom
ArturNiederfahrenhorst:custom-resources-per-learner
May 15, 2026
Merged

[RLlib] Add custom_resources_per_learner config#63303
ArturNiederfahrenhorst merged 7 commits into
ray-project:masterfrom
ArturNiederfahrenhorst:custom-resources-per-learner

Conversation

@ArturNiederfahrenhorst
Copy link
Copy Markdown
Contributor

Description

Mirror of custom_resources_per_env_runner: lets users attach custom Ray resource requirements to each Learner worker. Plumbed into learner_group.py's resources_per_learner dict so the custom resources are claimed alongside CPU/GPU when Ray Train schedules Learners.

Mirror of `custom_resources_per_env_runner`: lets users attach
custom Ray resource requirements to each Learner worker. Plumbed
into `learner_group.py`'s `resources_per_learner` dict so the
custom resources are claimed alongside CPU/GPU when Ray Train
schedules Learners.

Signed-off-by: Artur Niederfahrenhorst <artur@anyscale.com>
Copy link
Copy Markdown
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 introduces the custom_resources_per_learner configuration to AlgorithmConfig, allowing users to allocate custom Ray resources to learner workers. The changes include updating the LearnerGroup to incorporate these resources and adding a new test suite to verify the functionality. Review feedback recommends adding a ValueError to prevent users from including "CPU" or "GPU" in the custom resources dictionary and adjusting the resource dictionary construction to ensure explicit CPU and GPU settings are not overwritten.

Comment thread rllib/algorithms/algorithm_config.py
Comment thread rllib/core/learner/learner_group.py
Signed-off-by: Artur Niederfahrenhorst <artur@anyscale.com>
@ArturNiederfahrenhorst ArturNiederfahrenhorst marked this pull request as ready for review May 12, 2026 15:44
@ArturNiederfahrenhorst ArturNiederfahrenhorst requested a review from a team as a code owner May 12, 2026 15:44
@ArturNiederfahrenhorst ArturNiederfahrenhorst added rllib RLlib related issues go add ONLY when ready to merge, run all tests rllib-learners Things related to Learner and Learner Group. labels May 12, 2026
Comment thread rllib/algorithms/algorithm_config.py
Comment thread rllib/core/learner/learner_group.py
Signed-off-by: Artur Niederfahrenhorst <artur@anyscale.com>
Signed-off-by: Artur Niederfahrenhorst <artur@anyscale.com>
Comment thread rllib/algorithms/utils.py Outdated
Signed-off-by: Artur Niederfahrenhorst <artur@anyscale.com>
@pseudo-rnd-thoughts pseudo-rnd-thoughts changed the title [RLlib] Add custom_resources_per_learner config knob [RLlib] Add custom_resources_per_learner config May 13, 2026
Copy link
Copy Markdown
Member

@pseudo-rnd-thoughts pseudo-rnd-thoughts left a comment

Choose a reason for hiding this comment

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

Overall looks good, just two small requests

or "GPU" in custom_resources_per_learner
):
raise ValueError(
"Do not include 'CPU' or 'GPU' in "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Include the custom_resources_per_learner in the error message

Comment thread rllib/algorithms/algorithm_config.py Outdated
if num_gpus_per_learner is not NotProvided:
self.num_gpus_per_learner = num_gpus_per_learner
if custom_resources_per_learner is not NotProvided:
if custom_resources_per_learner and (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't the first part be isinstance(custom_resources_per_learner, dict) or remove it

Comment thread rllib/algorithms/utils.py Outdated
ArturNiederfahrenhorst and others added 2 commits May 15, 2026 14:27
- Drop truthiness guard on validation check so non-dict inputs raise
  clearly instead of silently passing
- Include the offending value in the ValueError message
- Add None guard in utils.py to match learner_group.py

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 0773167. Configure here.

if custom_resources_per_learner is not NotProvided:
if (
"CPU" in custom_resources_per_learner
or "GPU" in custom_resources_per_learner
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing dict type guard before in operator check

Medium Severity

The custom_resources_per_learner parameter is typed Optional[Dict[str, float]], so None is a valid input. When None is passed, None is not NotProvided evaluates to True, causing the code to execute "CPU" in None, which raises an unhelpful TypeError instead of a clear validation error. An isinstance(custom_resources_per_learner, dict) guard is needed before the in check, as the PR reviewer also flagged.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0773167. Configure here.

@ArturNiederfahrenhorst ArturNiederfahrenhorst merged commit 8972cfd into ray-project:master May 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go add ONLY when ready to merge, run all tests rllib RLlib related issues rllib-learners Things related to Learner and Learner Group.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants