pytorch / rl

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

[BUG] ImportError: dlopen(...): Symbol not found when import torchrl on MacOS apple chip #1638

Closed FrankTianTT closed 1 year ago

FrankTianTT commented 1 year ago

Describe the bug

I tried to install the compiled torchrl on the apple chip and encountered a problem:

IImportError: dlopen(/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/_torchrl.so, 0x0002): Symbol not found: __ZN5torch8autograd13_wrap_outputsERKNSt3__16vectorIN2at6TensorENS1_9allocatorIS4_EEEERKNS1_13unordered_setIPN3c1010TensorImplENS1_4hashISD_EENS1_8equal_toISD_EENS5_ISD_EEEESL_NSB_8ArrayRefINSB_8optionalIS4_EEEERKNS1_10shared_ptrINS0_4NodeEEERKNS1_8functionIFS7_S7_S7_EEESL_RKNSV_IFS4_S4_EEE
  Referenced from: <8552E3F0-1AEE-3F35-A976-0E08118BC1F7> /Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/_torchrl.so
  Expected in:     <66FB8649-BB87-3CD6-A177-462038DCAE02> /Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torch/lib/libtorch_cpu.dylib

BTW, in the latest release, torchrl already supports apple chips, but the README still requires users to install it locally. I don't know if installing from pip is supported now.

To Reproduce

import torchrl
>>> import torchrl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/__init__.py", line 38, in <module>
    import torchrl.collectors
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/collectors/__init__.py", line 6, in <module>
    from .collectors import (
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/collectors/collectors.py", line 42, in <module>
    from torchrl.data.tensor_specs import CompositeSpec, TensorSpec
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/data/__init__.py", line 6, in <module>
    from . import datasets
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/data/datasets/__init__.py", line 1, in <module>
    from .d4rl import D4RLExperienceReplay
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/data/datasets/d4rl.py", line 21, in <module>
    from torchrl.data.replay_buffers import TensorDictReplayBuffer
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/data/replay_buffers/__init__.py", line 6, in <module>
    from .replay_buffers import (
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/data/replay_buffers/replay_buffers.py", line 25, in <module>
    from torchrl.data.replay_buffers.samplers import (
  File "/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/data/replay_buffers/samplers.py", line 13, in <module>
    from torchrl._torchrl import (
ImportError: dlopen(/Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/_torchrl.so, 0x0002): Symbol not found: __ZN5torch8autograd13_wrap_outputsERKNSt3__16vectorIN2at6TensorENS1_9allocatorIS4_EEEERKNS1_13unordered_setIPN3c1010TensorImplENS1_4hashISD_EENS1_8equal_toISD_EENS5_ISD_EEEESL_NSB_8ArrayRefINSB_8optionalIS4_EEEERKNS1_10shared_ptrINS0_4NodeEEERKNS1_8functionIFS7_S7_S7_EEESL_RKNSV_IFS4_S4_EEE
  Referenced from: <8552E3F0-1AEE-3F35-A976-0E08118BC1F7> /Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torchrl/_torchrl.so
  Expected in:     <66FB8649-BB87-3CD6-A177-462038DCAE02> /Users/frank/opt/anaconda3/envs/torch_rl/lib/python3.9/site-packages/torch/lib/libtorch_cpu.dylib

System info

Describe the characteristic of your environment:

Reason and Possible fixes

According to the troubleshooting in the README, I installed the latest version of XCode, while it is does not help.

Checklist

Jianye-Xu commented 1 year ago

I have encountered exactly the same issue. System info

vmoens commented 1 year ago

I will correct the README asap and look into this, thanks for reporting!

Which PyTorch version are you using?

FrankTianTT commented 1 year ago

Which PyTorch version are you using?

@vmoens I installed torchrl directly without manually installing torch, and this default torch version is 2.1.0

Jianye-Xu commented 1 year ago

@vmoens I tried both torch 2.0.1 and torch 2.1.0.

vmoens commented 1 year ago

It should work with PT 2.1.0 (and no other). I'll try to reproduce this and push a fix!

abdulmuneer commented 1 year ago

I have the same issue.

Platform: Apple M1 Pro Python==3.11.5 torch==2.1.0

Installed torchrl through command pip install torchrl

vmoens commented 1 year ago

This will be resolved by #1642 which I will push soon!

abdulmuneer commented 1 year ago

@vmoens , I couldn't follow how this issue is resolved in #1642 . The PR is removing support for Apple silicon in the Readme. Is there a solution that will help users of torchrl run the library on apple silicon?

vmoens commented 1 year ago

I'm pushing the fixed binaries in a couple of hours top! This PR is the release branch for 0.2.1 which will fix the osx binaries

vmoens commented 1 year ago

I have pushed the binaries, you can now install torchrl with a pip install on apple silicon! Sorry for the mess

Jianye-Xu commented 1 year ago

Thanks, it works now!

abdulmuneer commented 1 year ago

Thank you @vmoens . It works for me too!