Genesisという面白いものを見つけたので、Unitree Go2のサンプルプログラムを動かそうと思ったのですが、途中でいくつかエラーがでたのでその解決法をまとめました。
これからMacBookAirでGenesis動かしたいと思っている人の参考になったら嬉しいです。
環境
- MacBookAir(M4)
- Sequoia 15.5
- Python3.10
はじめにこちらの記事を参考に環境構築を行いました。ありがとうございます。
1. rendered_envs_idxエラー
[Genesis] [17:43:30] [ERROR] Unrecognized attribute: rendered_envs_idx
examples/locomotion/go2_train.py
を実行したところ、上記のエラーが出ました。
GenesisのIssue#1020に同様の質問が上がっており、そこには
pip install genesis-world
ではなく、
pip install git+https://github.com/Genesis-Embodied-AI/Genesis.git
の方法であれば何故だかよく分からんが上手くいく、ということが書いてあったので早速試してみましたが………
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
genesis-world 0.2.1 requires mujoco==3.2.5, but you have mujoco 3.3.3 which is incompatible.
今度はインストールの途中で上記のエラーが出てしまいました。
どうやら、mujocoは3.2.5でなければいけないのですが、3.3以上がインストールされるようになっているため、依存関係でコンフリクトが起きてしまったようです。
そのため、Genesisのレポジトリをクローンして、pyproject.toml
を直接書き換える必要があります。
$ git clone https://github.com/Genesis-Embodied-AI/Genesis.git
次に、pyproject.toml
の以下の行を修正します。(25行目)
- "mujoco >= 3.3.0, < 3.4.0",
+ "mujoco == 3.2.5",
これで以下のコマンドで再インストールすればOK
$ cd Genesis
$ pip install -e ".[dev]"
2. MPS未対応エラー
[Genesis] [18:13:19] [ERROR] NotImplementedError: The operator 'aten::isin.Tensor_Tensor_out' is not currently implemented for the MPS device. If you want this op to be added in priority during the prototype phase of this feature, please comment on https://github.com/pytorch/pytorch/issues/77764. As a temporary fix, you can set the environment variable `PYTORCH_ENABLE_MPS_FALLBACK=1` to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.
端的に言えばMPSでは使えないぞというエラーらしいのですが、一時的な修正案として環境変数にPYTORCH_ENABLE_MPS_FALLBACK=1
を設定したらいけますえ〜ということを書いてくれています。
$ echo 'export PYTORCH_ENABLE_MPS_FALLBACK=1' >> ~/.zshrc
$ source ~/.zshrc
上記が環境変数を恒久的に設定する方法なのですが、ちょっとめんどくさいなと思ったので、なぜだか自分でもよく分かりませんが「中のコードを編集してデバイス指定をCPUにしてまえ!」と思ったのです。
genesis/__init__.py
の以下の行を(無理矢理)変更します。(83行目)
- backend = gs_backend.gpu
+ backend = gs_backend.cpu
うまく学習が回るようになり、以下のような結果を得ることができました。
(Total time: 2677.96s)
まとめ
# 1. リポジトリをクローン
$ git clone https://github.com/Genesis-Embodied-AI/Genesis.git
$ cd Genesis
# 2. pyproject.tomlを編集(mujocoを3.2.5指定に)
# 3. 環境構築
$ conda create -n genesis python=3.10
$ conda activate genesis
$ pip install -e ".[dev]"
$ conda install pytorch torchvision torchaudio -c pytorch
$ pip uninstall -y torch && pip install torch
$ pip install rsl-rl-lib==2.2.4
$ pip install tensorboard
$ brew install ffmpeg
# 4. 環境変数の設定(PYTORCH_ENABLE_MPS_FALLBACK=1) または __init__.pyを編集(gpuの記述をcpuに)
# 5. 学習を回す
$ cd examples/locomotion
$ python go2_train.py
# 6. 学習結果を見る
$ python go2_eval.py