Skip to content

Conversation

@ParamThakkar123
Copy link
Contributor

@ParamThakkar123 ParamThakkar123 commented Jan 19, 2026

Description

Describe your changes in detail.

Motivation and Context

Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax close #15213 if this solves the issue #15213

  • I have raised an issue to propose this change (required for new features and bug fixes)

Types of changes

What types of changes does your code introduce? Remove all that do not apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)
  • Example (update in the folder of examples)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 19, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3343

Note: Links to docs will display an error until the docs builds have been completed.

❌ 1 New Failure, 1 Cancelled Job, 3 Pending

As of commit 2d34456 with merge base 736d6aa (image):

NEW FAILURE - The following job has failed:

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 19, 2026
@ParamThakkar123 ParamThakkar123 changed the title [Feature] Added num_envs parameter in GymEnv to call multiple environments in o… [Feature] Added num_envs parameter in GymEnv to call multiple environments in one call Jan 19, 2026
@vmoens vmoens added the enhancement New feature or request label Jan 19, 2026
Comment on lines 1733 to 1734
``1`` (a single env is to be run). When ``num_envs > 1``, a :class:`~torchrl.envs.ParallelEnv`
will be returned.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is bc-breaking, let's not do that. If a PEnv needs to be used let's let the users ask for it explicitly in some way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Agree on this. I will keep it similar to my last PR

Copy link
Collaborator

@vmoens vmoens Jan 19, 2026

Choose a reason for hiding this comment

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

Hmm not sure what you mean. Maybe we don't need it for gym since it already exists? Alternatively we can change the arg name to make it explicit it's torchrl-parallel (since it's nightly we can also change it in dm-control for consistency)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Like what I actually meant was following the same structure or flow we did for DMControl but as you said that gym already has the feature for running multiple envs we can do it for other environments instead of this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And yes your latter idea for torchrl-parallel seems awesome and we can go ahead with it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

let's just convene on a kwarg name?
num_envs: gym API
num_workers: torchrl?
Maybe not super explicit

Copy link
Contributor Author

@ParamThakkar123 ParamThakkar123 Jan 19, 2026

Choose a reason for hiding this comment

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

Yes. Seems good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vmoens

Should I close this one in that case as gym envs already have num_envs parameter ? and start on the ones that don't have it ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought we said we'd keep the new feature but with a different name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. sorry. I lost some track on that. Yes. I will keep the feature

Comment on lines 1733 to 1734
``1`` (a single env is to be run). When ``num_envs > 1``, a :class:`~torchrl.envs.ParallelEnv`
will be returned.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought we said we'd keep the new feature but with a different name?

@ParamThakkar123
Copy link
Contributor Author

@vmoens All changes noted 🫡

@vmoens
Copy link
Collaborator

vmoens commented Jan 20, 2026

FAILED test/test_libs.py::TestGym::test_num_workers_returns_parallel_env - RuntimeError: Trying to access attributes of closed/non started environments. Check that the batched environment has been started (e.g. by calling env.reset)

from the CI

@ParamThakkar123
Copy link
Contributor Author

@vmoens I fixed the failing tests

@vmoens
Copy link
Collaborator

vmoens commented Jan 20, 2026

@ParamThakkar123

From https://github.com/pytorch/rl/actions/runs/21169673684/job/60889590869?pr=3343

❌ The following gym/gymnasium versions had test failures:

   - gym==0.13
   - gym==0.19
   - gym==0.20
   - gym==0.25
   - gym==0.26
   - gymnasium==0.27
   - gymnasium>=1.1.0
   - gymnasium-latest

Total: 8 version(s) failed

@ParamThakkar123
Copy link
Contributor Author

Tests give really weird errors on gym 0.19:

 pytest test/test_libs.py::TestGym::test_num_workers_returns_parallel_env -q -s -p no:randomly
Windows fatal exception: code 0xc0000139

Current thread 0x000034ec (most recent call first):
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1166 in create_module
  File "<frozen importlib._bootstrap>", line 556 in module_from_spec
  File "<frozen importlib._bootstrap>", line 657 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\data\replay_buffers\samplers.py", line 13 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\data\replay_buffers\replay_buffers.py", line 25 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\data\replay_buffers\__init__.py", line 6 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\data\datasets\d4rl.py", line 14 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\data\datasets\__init__.py", line 1 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1042 in _handle_fromlist
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\data\__init__.py", line 6 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 961 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\collectors\collectors.py", line 38 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\collectors\__init__.py", line 6 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "e:\miniconda3\envs\gym019\lib\site-packages\torchrl\__init__.py", line 32 in <module>
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 843 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 961 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 961 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "E:\rl\test\test_libs.py", line 15 in <module>
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\assertion\rewrite.py", line 185 in exec_module
  File "<frozen importlib._bootstrap>", line 671 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 975 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 991 in _find_and_load
  File "<frozen importlib._bootstrap>", line 1014 in _gcd_import
  File "e:\miniconda3\envs\gym019\lib\importlib\__init__.py", line 127 in import_module
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\pathlib.py", line 587 in import_path
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\python.py", line 493 in importtestmodule
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\python.py", line 546 in _getobj
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\python.py", line 284 in obj
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\python.py", line 562 in _register_setup_module_fixture
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\python.py", line 549 in collect
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 389 in collect
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 341 in from_call
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 391 in pytest_make_collect_report
  File "e:\miniconda3\envs\gym019\lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "e:\miniconda3\envs\gym019\lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "e:\miniconda3\envs\gym019\lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 567 in collect_one_node
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\main.py", line 835 in _collect_one_node
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\main.py", line 912 in collect
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 389 in collect
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 341 in from_call
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 391 in pytest_make_collect_report
  File "e:\miniconda3\envs\gym019\lib\site-packages\pluggy\_callers.py", line 103 in _multicall
  File "e:\miniconda3\envs\gym019\lib\site-packages\pluggy\_manager.py", line 120 in _hookexec
  File "e:\miniconda3\envs\gym019\lib\site-packages\pluggy\_hooks.py", line 513 in __call__
  File "e:\miniconda3\envs\gym019\lib\site-packages\_pytest\runner.py", line 567 in collect_one_node
  ...

@ParamThakkar123
Copy link
Contributor Author

Got similar error on gym==0.20 as well

@ParamThakkar123
Copy link
Contributor Author

The code I just pushed works for all versions except gym==0.19 and 0.20 maybe because of the windows compatibility error

@ParamThakkar123
Copy link
Contributor Author

might work on CI but didn't work locally

@vmoens
Copy link
Collaborator

vmoens commented Jan 20, 2026

might work on CI but didn't work locally

No it did not haha
https://github.com/pytorch/rl/actions/runs/21175386951/job/60904886450?pr=3343

@ParamThakkar123
Copy link
Contributor Author

🥲🥲🥲

- Remove incorrect CUDA skip decorator (test doesn't use CUDA)
- Use Pendulum-v1 instead of CartPole-v1 because CartPole can terminate
  early due to pole falling, especially with frame_skip=4, causing the
  rollout assertion to fail (expected 5 steps, got 3)
Use PENDULUM_VERSIONED() instead of hardcoded "Pendulum-v1" to support
older gym versions that only have "Pendulum-v0".
- Fix import ordering
- Add missing space after ==
- Add newline at end of file
- Remove trailing whitespace
@vmoens vmoens merged commit 2e130dc into pytorch:main Jan 21, 2026
108 of 110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants