Skip to content

[BUG] Data collection error on M1 Macs #3066

@itwasabhi

Description

@itwasabhi

Describe the bug

SyncDataCollector RuntimeError on Mac-M1 when using mps device.

To Reproduce

from pettingzoo.butterfly import pistonball_v6
from torchrl.collectors import SyncDataCollector
from torchrl.envs import ParallelEnv
from torchrl.envs.libs.pettingzoo import PettingZooWrapper


DEVICE = "mps"

kwargs = {"n_pistons": 21, "continuous": True}
inner_env_fn = lambda: PettingZooWrapper(
    env=pistonball_v6.parallel_env(**kwargs),
    return_state=True,
    group_map=None,
    device=DEVICE,
)
collector_env = lambda: ParallelEnv(num_workers=2, create_env_fn=inner_env_fn)
collector = SyncDataCollector(collector_env, frames_per_batch=100)

collector.reset()
print(next(iter(collector)))
collector.shutdown()
  File ".../.venv/lib/python3.11/site-packages/torch/storage.py", line 447, in wrapper
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../.venv/lib/python3.11/site-packages/torch/storage.py", line 526, in _share_filename_cpu_
    return super()._share_filename_cpu_(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: _share_filename_: only available on CPU

Expected behavior

Should be able to create env on mps and collect data.

Screenshots

If applicable, add screenshots to help explain your problem.

System info

>>> print(torchrl.__version__, numpy.__version__, sys.version, sys.platform)
0.8.0+83cb41d 2.0.2 3.11.8 (main, Feb 25 2024, 03:55:37) [Clang 17.0.6 ] darwin
>>> platform.platform()
'macOS-15.5-arm64-arm-64bit'

Running via uv

Additional context

  • No issue when collecting directly on cpu or cuda
  • No issue when using SerialEnv over ParallelEnv

Reason and Possible fixes

Seems related to pytorch/pytorch#87688

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions