Skip to content

Fix: allow num_envs override from trainer config#148

Merged
yangchen73 merged 2 commits intomainfrom
yc/fix_env_num
Feb 26, 2026
Merged

Fix: allow num_envs override from trainer config#148
yangchen73 merged 2 commits intomainfrom
yc/fix_env_num

Conversation

@yangchen73
Copy link
Collaborator

Description

When num_envs is set in trainer config, it overrides gym_config's num_envs
so users can change parallel env count without editing gym config.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots

Before After
Screenshot from 2026-02-26 12-49-37 Screenshot from 2026-02-26 12-51-16

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

Copilot AI review requested due to automatic review settings February 26, 2026 05:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Allows trainer.num_envs in the trainer JSON config to override the environment’s num_envs loaded from gym_config, enabling users to change parallelism without editing the gym config file.

Changes:

  • Apply trainer.num_envs (when set) onto gym_env_cfg.num_envs prior to environment construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)

if num_envs is not None:
gym_env_cfg.num_envs = num_envs
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

num_envs is taken from JSON as-is and assigned directly to gym_env_cfg.num_envs. Since EnvCfg.num_envs is an int, this should be validated/cast (e.g., int(num_envs)) and rejected if it’s <= 0 to avoid creating an invalid environment count (or accidentally accepting a string).

Suggested change
gym_env_cfg.num_envs = num_envs
try:
parsed_num_envs = int(num_envs)
except (TypeError, ValueError) as exc:
raise ValueError(f"Invalid num_envs value in config: {num_envs!r}") from exc
if parsed_num_envs <= 0:
raise ValueError(f"num_envs must be a positive integer, got {parsed_num_envs}")
gym_env_cfg.num_envs = parsed_num_envs

Copilot uses AI. Check for mistakes.
Comment on lines +140 to +141
if num_envs is not None:
gym_env_cfg.num_envs = num_envs
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

This change adds new behavior (trainer config overriding gym config for num_envs), but there’s no assertion-level test coverage verifying the override actually takes effect (e.g., gym_config has one value while trainer has another, and the env is constructed with the trainer value). Consider extending the existing RL training test to confirm the override is honored (can be done by monkeypatching build_env to capture the passed base_env_cfg.num_envs).

Copilot uses AI. Check for mistakes.
@yangchen73 yangchen73 merged commit f87f284 into main Feb 26, 2026
8 checks passed
@yangchen73 yangchen73 deleted the yc/fix_env_num branch February 26, 2026 05:36
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