Skip to content

Docker Support #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third_party/isaacgym"]
path = third_party/isaacgym
url = ../../kscalelabs/isaacgym.git
url = ../../kscalelabs/isaacgym.git
[submodule "sim/genesis/rsl_rl"]
path = sim/genesis/rsl_rl
url = [email protected]:leggedrobotics/rsl_rl.git
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"marscode.chatLanguage": "cn",
"CodeGPT.apiKey": "Ollama"
}
28 changes: 28 additions & 0 deletions analyze_onnx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import onnxruntime as ort
import numpy as np

# 加载 ONNX 模型
model_path = "sim/genesis/logs/zeroth-walking/model_100.onnx"
session = ort.InferenceSession(model_path)

# 获取输入信息
input_name = session.get_inputs()[0].name
input_shape = session.get_inputs()[0].shape
print(f"Input name: {input_name}, shape: {input_shape}")

# 创建随机输入数据
obs_dim = input_shape[1] # 获取观测维度
dummy_input = np.random.randn(1, obs_dim).astype(np.float32)

print(f"Dummy input shape: {dummy_input.shape}")
print(f"Dummy input: {dummy_input}")

# 运行模型
outputs = session.run(None, {input_name: dummy_input})
actions = outputs[0]

# 分析输出
print(f"Output actions shape: {actions.shape}")
print(f"First 5 actions: {actions[0][:5]}")
print(f"Actions mean: {np.mean(actions)}")
print(f"Actions std: {np.std(actions)}")
7 changes: 7 additions & 0 deletions docker/10_nvidia.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_format_version" : "1.0.0",
"ICD" : {
"library_path" : "libEGL_nvidia.so.0"
}
}

75 changes: 75 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 1stly, to build zeroth-bot-sim:v0
# FROM nvidia/cuda:12.1.0-cudnn8-devel-ubuntu20.04

# COPY sources.list /etc/apt/sources.list

# RUN mkdir /root/.pip
# COPY pip.conf /root/.pip/pip.conf

# RUN apt install -y wget zlib1g-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev
# RUN wget https://mirrors.huaweicloud.com/python/3.8.19/Python-3.8.19.tar.xz && tar -xvf Python-3.8.19.tar.xz

# WORKDIR /root/Python-3.8.19
# RUN ./configure --prefix=/usr/local && make && make install

# WORKDIR /usr/local/bin/
# RUN ln -s pip3 pip

# WORKDIR /app/sim/
# RUN make install-dev

# RUN wget https://developer.nvidia.com/isaac-gym-preview-4
# # RUN tar -xvf
# RUN make install-third-party-external

FROM zeroth-bot-sim:v0

WORKDIR /root

RUN apt update

# on vnc client use <your docker ip>:5901
RUN apt update && apt install -y \
--no-install-recommends \
libxcursor-dev \
libxrandr-dev \
libxinerama-dev \
libxi-dev \
mesa-common-dev \
zip \
unzip \
make \
vulkan-utils \
mesa-vulkan-drivers \
pigz \
git \
libegl1

# WAR for eglReleaseThread shutdown crash in libEGL_mesa.so.0 (ensure it's never detected/loaded)
# Can't remove package libegl-mesa0 directly (because of libegl1 which we need)
RUN rm /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0 /usr/lib/x86_64-linux-gnu/libEGL_mesa.so.0.0.0 /usr/share/glvnd/egl_vendor.d/50_mesa.json

COPY ./nvidia_icd.json /usr/share/vulkan/icd.d/nvidia_icd.json
COPY ./10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json


WORKDIR /app/sim

RUN useradd --create-home gymuser
USER gymuser

# copy gym repo to docker
COPY --chown=gymuser . .

# install gym modules
ENV PATH="/home/gymuser/.local/bin:$PATH"

RUN export MODEL_DIR=sim/resources/stompymicro

ENV NVIDIA_VISIBLE_DEVICES=all NVIDIA_DRIVER_CAPABILITIES=all

CMD ["tail","-f", "/dev/null"]

# CMD ["python3", "sim/train.py", "--task=stompymicro", "--num_envs=4"]
# python3 sim/train.py --task=stompymicro --num_envs=4

104 changes: 104 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Preliminaries
```
Ensure nvidia-smi is work on your host machine.
```

There is a prebuilt docker image, tested on a amd64 machine, with Ubuntu 24.04 LTS.
```
docker pull ghcr.io/bigjohnn/zeroth-bot-sim:v1
```

But if that not work, maybe you can build it by yourself.

Make some changes in your Dockerfile && docker-compose.yml.
```
PREBUILD a docker image that have external dependencies

# 1stly, to build zeroth-bot-sim:v0
# FROM nvidia/cuda:12.1.0-cudnn8-devel-ubuntu20.04

# COPY sources.list /etc/apt/sources.list

# RUN mkdir /root/.pip
# COPY pip.conf /root/.pip/pip.conf

# RUN apt install -y wget zlib1g-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev
# RUN wget https://mirrors.huaweicloud.com/python/3.8.19/Python-3.8.19.tar.xz && tar -xvf Python-3.8.19.tar.xz

# WORKDIR /root/Python-3.8.19
# RUN ./configure --prefix=/usr/local && make && make install

# WORKDIR /usr/local/bin/
# RUN ln -s pip3 pip

# WORKDIR /app/sim/
# RUN make install-dev

# RUN wget https://developer.nvidia.com/isaac-gym-preview-4
# # RUN tar -xvf
# RUN make install-third-party-external

```

Then,

Terminal1:
```
docker-compose up --build
```

```
ARNING: Found orphan containers (a55a8ae7a762_docker_my_cuda_service_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Building my-service
[+] Building 1.6s (10/10) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.2s
=> => transferring dockerfile: 348B 0.0s
=> [internal] load metadata for docker.io/nvidia/cuda:12.1.0-cudnn8-devel-ubuntu20.04 0.0s
=> [internal] load .dockerignore 0.2s
=> => transferring context: 2B 0.0s
=> [1/5] FROM docker.io/nvidia/cuda:12.1.0-cudnn8-devel-ubuntu20.04 0.0s
=> [internal] load build context 0.2s
=> => transferring context: 34B 0.0s
=> CACHED [2/5] WORKDIR /app 0.0s
=> CACHED [3/5] COPY sources.list /etc/apt/sources.list 0.0s
=> CACHED [4/5] RUN apt update 0.0s
=> CACHED [5/5] WORKDIR /app/sim/ 0.0s
=> exporting to image 0.2s
=> => exporting layers 0.0s
=> => writing image sha256:8e9c02e6c8b50dcbf7d6d1962d51de926126f132b65b65952ad8dfc74634f8c6 0.0s
=> => naming to docker.io/library/docker_my-service 0.1s
WARNING: Image for service my-service was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating docker_my-service_1 ... done
Attaching to docker_my-service_1
my-service_1 |
my-service_1 | ==========
my-service_1 | == CUDA ==
my-service_1 | ==========
my-service_1 |
my-service_1 | CUDA Version 12.1.0
my-service_1 |
my-service_1 | Container image Copyright (c) 2016-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
my-service_1 |
my-service_1 | This container image and its contents are governed by the NVIDIA Deep Learning Container License.
my-service_1 | By pulling and using the container, you accept the terms and conditions of this license:
my-service_1 | https://developer.nvidia.com/ngc/nvidia-deep-learning-container-license
my-service_1 |
my-service_1 | A copy of this license is made available in this container at /NGC-DL-CONTAINER-LICENSE for your convenience.
my-service_1 |
my-service_1 | *************************
my-service_1 | ** DEPRECATION NOTICE! **
my-service_1 | *************************
my-service_1 | THIS IMAGE IS DEPRECATED and is scheduled for DELETION.
my-service_1 | https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/support-policy.md
my-service_1 |
```

Terminal2:

```
docker exec -it docker_zeroth-sim_1 /bin/bash
```

```
gymuser@06aac36e0751:/app/sim# python3 sim/train.py --task=stompymicro --num_envs=4
```
24 changes: 24 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# version: '3.8'

services:
zeroth-sim:
build:
context: . # Assuming the Dockerfile is in the current directory
dockerfile: Dockerfile
volumes:
- /home/hph/Codes/zeroth-bot:/app # Must have absolute path
- /tmp/.X11-unix:/tmp/.X11-unix
environment:
- DISPLAY=$DISPLAY
privileged: true
cap_add:
- SYS_PTRACE
shm_size: 6g
tty: true
stdin_open: true
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
count: all
7 changes: 7 additions & 0 deletions docker/nvidia_icd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"file_format_version" : "1.0.0",
"ICD": {
"library_path": "libGLX_nvidia.so.0",
"api_version" : "1.1.95"
}
}
3 changes: 3 additions & 0 deletions docker/pip.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[global]
trusted-host=mirrors.aliyun.com
index-url=http://mirrors.aliyun.com/pypi/simple/
4 changes: 4 additions & 0 deletions docker/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
deb http://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse
Binary file added examples/model_100.onnx
Binary file not shown.
Binary file added examples/model_100.pt
Binary file not shown.
7 changes: 3 additions & 4 deletions sim/envs/humanoids/stompymicro_config.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Defines the environment configuration for the Getting up task"""

import numpy as np

from sim.env import robot_urdf_path
from sim.envs.base.legged_robot_config import ( # type: ignore
LeggedRobotCfg,
Expand Down Expand Up @@ -40,7 +38,8 @@ class asset(LeggedRobotCfg.asset):
file = str(robot_urdf_path(name))

foot_name = ["foot_left", "foot_right"]
knee_name = ["left_knee_pitch_motor", "right_knee_pitch_motor"]
# knee_name = ["left_knee_pitch_motor", "right_knee_pitch_motor"]
knee_name = ["ankle_pitch_left", "ankle_pitch_right"]

termination_height = 0.05
default_feet_height = 0.02
Expand Down Expand Up @@ -150,7 +149,7 @@ class ranges:
lin_vel_x = [-0.05, 0.23] # min max [m/s]
lin_vel_y = [-0.04, 0.04] # min max [m/s]
ang_vel_yaw = [-0.1, 0.1] # min max [rad/s]
heading = [-np.pi, np.pi] # min max [rad]
heading = [-3.14, 3.14]

class rewards:
base_height_target = Robot.height
Expand Down
3 changes: 3 additions & 0 deletions sim/genesis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/logs/
/rsl_rl/
zeroth_train_crab.py
34 changes: 34 additions & 0 deletions sim/genesis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 进入genesis目录。
`cd sim/genesis`

# 安装rsl_rl。
```
git clone https://github.com/leggedrobotics/rsl_rl
cd rsl_rl && git checkout v2.2.0 && pip install -e .
```

# 安装tensorboard。
`pip install tensorboard`

安装完成后,通过运行以下命令开始训练:

`python zeroth_train.py`

要监控训练过程,请启动TensorBoard:

`tensorboard --logdir logs`

查看训练结果。

`python zeroth_eval.py`

模型转换。

`cd genesis`

`python3 utils/convert_to_onnx.py --cfg logs/zeroth-walking/cfgs.pkl --model ../../examples/model_100.pt --output ../../examples/model_100.onnx`

注意⚠️
Mac M系列芯片,使用micromamba替换conda使用,例如
`micromamba activate genesis`
然后再调用pip/python等命令
Loading