danijar / dreamerv3

Mastering Diverse Domains through World Models
https://danijar.com/dreamerv3
MIT License
1.36k stars 231 forks source link

Mac M1 conda env #30

Open edwhu opened 1 year ago

edwhu commented 1 year ago

Hello,

I wanted to get this running on my M1 laptop for local development. The installation process deviated quite a bit from the README.

In particular, I had to setup tensorflow and jax differently than the README workflow. It went something like this:

conda create -n dreamerv3 python=3.8
conda activate dreamerv3

conda install -c apple tensorflow-deps
conda install jax -c conda-forge
pip install tensorflow-macos tensorflow_probability

pip install -r requirements.txt # comment out tensorflow-cpu in requirements.txt first.

I verified this environment by running example.py and by repeating the whole process again (conda installation and running example.py).

To make things easier for future users, I exported the conda env file. Then they don't need to manually install the conda dependencies and edit the requirements.txt.

Perhaps this will be useful for others?

giteverything commented 1 year ago

really nice work! When I run the example.py, some error occurs:

RuntimeError: Unknown backend: 'gpu' requested, but no platforms that are instances of gpu are present. Platforms present are: interpreter,cpu

any idea how to fix it?

more details here: ╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮ │ /Users/arthur/src/dreamerv3/example.py:53 in │ │ │ │ 50 │ │ 51 │ │ 52 if name == 'main': │ │ ❱ 53 main() │ │ 54 │ │ │ │ /Users/arthur/src/dreamerv3/example.py:42 in main │ │ │ │ 39 env = dreamerv3.wrap_env(env, config) │ │ 40 env = embodied.BatchEnv([env], parallel=False) │ │ 41 │ │ ❱ 42 agent = dreamerv3.Agent(env.obs_space, env.act_space, step, config) │ │ 43 replay = embodied.replay.Uniform( │ │ 44 │ config.batch_length, config.replay_size, logdir / 'replay') │ │ 45 args = embodied.Config( │ │ │ │ /Users/arthur/src/dreamerv3/dreamerv3/jaxagent.py:20 in init │ │ │ │ 17 │ configs = agent_cls.configs │ │ 18 │ inner = agent_cls │ │ 19 │ def init(self, *args, *kwargs): │ │ ❱ 20 │ super().init(agent_cls, args, **kwargs) │ │ 21 return Agent │ │ 22 │ │ 23 │ │ │ │ /Users/arthur/src/dreamerv3/dreamerv3/jaxagent.py:35 in init │ │ │ │ 32 │ self.agent = agent_cls(obs_space, act_space, step, config, name='agent') │ │ 33 │ self.rng = np.random.default_rng(config.seed) │ │ 34 │ │ │ ❱ 35 │ available = jax.devices(self.config.platform) │ │ 36 │ self.policy_devices = [available[i] for i in self.config.policy_devices] │ │ 37 │ self.train_devices = [available[i] for i in self.config.train_devices] │ │ 38 │ self.single_device = (self.policy_devices == self.train_devices) and ( │ │ │ │ /Users/arthur/miniconda3/envs/dreamerv3/lib/python3.8/site-packages/jax/_src/lib/xla_bridge.py:4 │ │ 83 in devices │ │ │ │ 480 Returns: │ │ 481 │ List of Device subclasses. │ │ 482 """ │ │ ❱ 483 return get_backend(backend).devices() │ │ 484 │ │ 485 │ │ 486 def default_backend() -> str: │ │ │ │ /Users/arthur/miniconda3/envs/dreamerv3/lib/python3.8/site-packages/jax/_src/lib/xla_bridge.py:4 │ │ 25 in get_backend │ │ │ │ 422 │ │ 423 @lru_cache(maxsize=None) # don't use util.memoize because there is no X64 dependence. │ │ 424 def get_backend(platform=None): │ │ ❱ 425 return _get_backend_uncached(platform) │ │ 426 │ │ 427 │ │ 428 def get_device_backend(device=None): │ │ │ │ /Users/arthur/miniconda3/envs/dreamerv3/lib/python3.8/site-packages/jax/_src/lib/xla_bridge.py:4 │ │ 11 in _get_backend_uncached │ │ │ │ 408 │ │ 409 bs = backends() │ │ 410 if platform is not None: │ │ ❱ 411 │ platform = canonicalize_platform(platform) │ │ 412 │ backend = bs.get(platform, None) │ │ 413 │ if backend is None: │ │ 414 │ if platform in _backends_errors: │ │ │ │ /Users/arthur/miniconda3/envs/dreamerv3/lib/python3.8/site-packages/jax/_src/lib/xla_bridge.py:2 │ │ 94 in canonicalize_platform │ │ │ │ 291 for p in platforms: │ │ 292 │ if p in b.keys(): │ │ 293 │ return p │ │ ❱ 294 raise RuntimeError(f"Unknown backend: '{platform}' requested, but no " │ │ 295 │ │ │ │ │ f"platforms that are instances of {platform} are present. " │ │ 296 │ │ │ │ │ "Platforms present are: " + ",".join(b.keys())) │ │ 297 │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────╯ RuntimeError: Unknown backend: 'gpu' requested, but no platforms that are instances of gpu are present. Platforms present are: interpreter,cpu

edwhu commented 1 year ago

Hi, if you are on M1 mac, there is no GPU as the error message says. Just specify cpu instead of gpu in the config.