Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RLlib] Enhancements for multi-node/multi-GPU training and better EnvRunner error msg. #47705

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rllib/env/multi_agent_env_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,16 +828,22 @@ def make_env(self):
remote=self.config.remote_worker_envs,
)

# No env provided -> Error.
if not self.config.env:
raise ValueError(
"`config.env` is not provided! You should provide a valid environment "
"to your config through `config.environment([env descriptor e.g. "
"'CartPole-v1'])`."
)
# Register env for the local context.
# Note, `gym.register` has to be called on each worker.
if isinstance(self.config.env, str) and _global_registry.contains(
elif isinstance(self.config.env, str) and _global_registry.contains(
ENV_CREATOR, self.config.env
):
entry_point = partial(
_global_registry.get(ENV_CREATOR, self.config.env),
env_ctx,
)

else:
entry_point = partial(
_gym_env_creator,
Expand Down
10 changes: 8 additions & 2 deletions rllib/env/single_agent_env_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,16 +794,22 @@ def make_env(self) -> None:
remote=self.config.remote_worker_envs,
)

# No env provided -> Error.
if not self.config.env:
raise ValueError(
"`config.env` is not provided! You should provide a valid environment "
"to your config through `config.environment([env descriptor e.g. "
"'CartPole-v1'])`."
)
# Register env for the local context.
# Note, `gym.register` has to be called on each worker.
if isinstance(self.config.env, str) and _global_registry.contains(
elif isinstance(self.config.env, str) and _global_registry.contains(
ENV_CREATOR, self.config.env
):
entry_point = partial(
_global_registry.get(ENV_CREATOR, self.config.env),
env_ctx,
)

else:
entry_point = partial(
_gym_env_creator,
Expand Down
13 changes: 8 additions & 5 deletions rllib/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,15 +1392,18 @@ def run_rllib_example_script_experiment(
# Define compute resources used automatically (only using the --num-gpus arg).
# New stack.
if config.enable_rl_module_and_learner:
# Do we have GPUs available in the cluster?
num_gpus = ray.cluster_resources().get("GPU", 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

if args.num_gpus > 0 and num_gpus < args.num_gpus:
raise ValueError(
f"You are running your script with --num-gpus={args.num_gpus}, "
"but your cluster only has {resources['GPU']} GPUs! Will "
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something missing? "Will ... "?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Now, it'll just warn and then run with CPU-based Learners instead.

)
# Define compute resources used.
config.resources(num_gpus=0)
config.learners(
num_learners=args.num_gpus,
num_gpus_per_learner=(
1
if torch and torch.cuda.is_available() and args.num_gpus > 0
else 0
),
num_gpus_per_learner=1 if num_gpus >= args.num_gpus > 0 else 0,
)
config.resources(num_gpus=0)
# Old stack.
Expand Down