pytorch / rl

A modular, primitive-first, python-first PyTorch library for Reinforcement Learning.
https://pytorch.org/rl
MIT License
2.27k stars 302 forks source link

[BUG] Failing to Create Isaac Gym Environments #2292

Open ErcBunny opened 3 months ago

ErcBunny commented 3 months ago

Describe the bug

The lateset stable relase (0.4) fails to create Isaac Gym Preview 4 environments.

To Reproduce

import isaacgym
from torchrl.envs import IsaacGymEnv
env = IsaacGymEnv(task="Ant", num_envs=2000, device="cuda:0")
+++ Using GPU PhysX
Physics Engine: PhysX
Physics Device: cuda:0
GPU Pipeline: enabled
num envs 2000 env spacing 5
/home/lyq/Developer/isaacgym_workspace/IsaacGymEnvs/isaacgymenvs/tasks/ant.py:151: DeprecationWarning: an integer is required (got type isaacgym._bindings.linux-x86_64.gym_38.DofDriveMode).  Implicit conversion to integers using __int__ is deprecated, and may be removed in a future version of Python.
  asset_options.default_dof_drive_mode = gymapi.DOF_MODE_NONE
/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/isaacgym.py:49: UserWarning: IsaacGym environment support is an experimental feature that may change in the future.
  warnings.warn(
/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/common.py:2989: DeprecationWarning: Your wrapper was not given a device. Currently, this value will default to 'cpu'. From v0.5 it will default to `None`. With a device of None, no device casting is performed and the resulting tensordicts are deviceless. Please set your device accordingly.
  warnings.warn(
Traceback (most recent call last):
  File "trl.py", line 4, in <module>
    env = IsaacGymEnv(task="Ant", num_envs=2000, device="cuda:0")
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/gym.py", line 543, in __call__
    instance: GymWrapper = super().__call__(*args, **kwargs)
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/common.py", line 175, in __call__
    instance: EnvBase = super().__call__(*args, **kwargs)
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/isaacgym.py", line 188, in __init__
    super().__init__(envs, **kwargs)
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/isaacgym.py", line 53, in __init__
    super().__init__(
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/gym.py", line 729, in __init__
    super().__init__(**kwargs)
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/common.py", line 3019, in __init__
    self._make_specs(self._env)  # writes the self._env attribute
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/isaacgym.py", line 61, in _make_specs
    super()._make_specs(env, batch_size=self.batch_size)
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/envs/libs/gym.py", line 962, in _make_specs
    observation_spec = CompositeSpec(
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/data/tensor_specs.py", line 3647, in __init__
    self.set(key, value)
  File "/home/lyq/mambaforge/envs/rlgpu/lib/python3.8/site-packages/torchrl/data/tensor_specs.py", line 3630, in set
    raise ValueError(
ValueError: The shape of the spec and the CompositeSpec mismatch: the first 2 dimensions should match but got spec.shape=torch.Size([60]) and CompositeSpec.shape=torch.Size([2000, 2000]).

Expected behavior

The example should be executed without error.

System info

torchrl and tensordict are installed using pip in a conda environment with python=3.8.

import torchrl, numpy, sys
print(torchrl.__version__, numpy.__version__, sys.version, sys.platform)
0.4.0 1.19.5 3.8.19 | packaged by conda-forge | (default, Mar 20 2024, 12:47:35) 
[GCC 12.3.0] linux

Additional context

I saw some bug fixes regarding the wrapper, but encountered other errors when trying the newest version after installing using python setup.py develop.

Checklist