Fix: allow num_envs override from trainer config#148
Conversation
There was a problem hiding this comment.
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) ontogym_env_cfg.num_envsprior 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 |
There was a problem hiding this comment.
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).
| 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 |
| if num_envs is not None: | ||
| gym_env_cfg.num_envs = num_envs |
There was a problem hiding this comment.
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).
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
Screenshots
Checklist
black .command to format the code base.