3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL2上のpoetry管理下のpython環境でGPUを使用してGenesisを動かす

Last updated at Posted at 2025-01-08

この記事の内容

n番煎じですがWSL2上でGPU使ってGenesisを動かす方法について書いておきます.
筆者の場合pythonをpoetry環境下で動かしたかったのですが,少し詰まった部分があったので備忘録として投下します.

前提条件

筆者の環境は以下のとおり

条件
CPU Core i9-12900K
GPU GeForce RTX3080
OS Windows 11
WSL2 Ubuntu 22.04

その上で,

  • Windows 11上でWSL2導入済
  • WSL2のUbuntu上でpyenv導入済
  • WSL2のUbuntu上でpoetry導入済

とする.
なお,pyenvで指定するpythonのバージョンは3.10.16にした.

手順

1. WSL2上でのGPU有効化

こちらの記事を参考にWSL2でGPUを利用できるようにする.

具体的には

1.1 Windows上にGPUのドライバをインストール

こちらのサイトの「Get CUDA driver」から
自分が使用するGPU,OSを選択して検索.

筆者はGeForce Game Readyドライバーを選択した.
選択後はダウンロードして画面の指示に従ってインストール

1.2 WSL2上にCUDAドライバをインストール

に従ってWSL2上でコマンドを実行.
実際に打ったコマンドは以下のとおり.

$ sudo apt-key del 7fa2af80
$ wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
$ sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ wget https://developer.download.nvidia.com/compute/cuda/12.6.3/local_installers/cuda-$ repo-wsl-ubuntu-12-6-local_12.6.3-1_amd64.deb
$ sudo dpkg -i cuda-repo-wsl-ubuntu-12-6-local_12.6.3-1_amd64.deb
$ sudo cp /var/cuda-repo-wsl-ubuntu-12-6-local/cuda-*-keyring.gpg /usr/share/keyrings/
$ sudo apt-get update
$ sudo apt-get -y install cuda-toolkit-12-6

最後にnvidia-smiを打ってGPUのモニタリングが出来ればOK.
場合によってはPCの再起動が必要かもしれない.

2. Genesis導入

Genesisの導入はこちらを参考に行った.

2.1 poetryでプロジェクトの作成

適当なフォルダを作成してその中でpoetry initしておく.

$ mkdir genesistest
$ cd genesistest
$ poetry init

2.2 pytorch導入

ここを参考にpytorchを導入.
上だとCUDA12.6を入れているが,CUDA12.4の方法でやった.

$ poetry add torch torchvision torchaudio

2.3 genesis導入

そのままgenesis-worldを入れようとするとdependenciesの問題で怒られるので一工夫必要

具体的にはpyproject.toml内に以下を追記

pyproject.toml
[tool.poetry.dependencies]
python = [
    ">=3.10,<4.0"
]

その後でgenesis-worldを入れるとエラー無く入る.

$ poetry add genesis-world

つぎにgenesisパッケージをcloneする.

$ git clone https://github.com/Genesis-Embodied-AI/Genesis.git

テストコードとして適当な名前で以下のファイルを保存.

test.py
import genesis as gs
gs.init(backend=gs.gpu)

scene = gs.Scene(show_viewer=True)
plane = scene.add_entity(gs.morphs.Plane())
franka = scene.add_entity(
    gs.morphs.MJCF(file='xml/franka_emika_panda/panda.xml'),
)

scene.build()

for i in range(1000):
    scene.step()

ここで,cudaのパスが通らない問題とOpenGLのエラーで起動できない問題を回避するために以下をたたく.
(bashrcに書いておくと吉)

$ export LD_LIBRARY_PATH=/usr/lib/wsl/lib:$LD_LIBRARY_PATH
$ export PYOPENGL_PLATFORM=glx

いよいよ実行してロボットアームが倒れるシミュレーションを表示できればOK

$ poetry run python test.py 

3. 強化学習のテスト

$ git clone https://github.com/leggedrobotics/rsl_rl
$ cd rsl_rl && git checkout v1.0.2
$ cd ..
$ poetry add --editable ./rsl_rl/c
$ cd ..
$ poetry add tensorboard

インストールできたら学習を実行

$ poetry run python Genesis/examples/locomotion/go2_train.py

筆者の環境だと1分くらいで学習が終わった.(はやい)

学習結果を見る

$ poetry run python Genesis/examples/locomotion/go2_eval.py

犬型ロボットが歩いていればOK.

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?