Skip to content

Commit f496123

Browse files
committed
[CI] Fix gym rendering issues
1 parent 16b70be commit f496123

File tree

9 files changed

+114
-36
lines changed

9 files changed

+114
-36
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"file_format_version" : "1.0.0",
3+
"ICD" : {
4+
"library_path" : "libEGL_nvidia.so.0"
5+
}
6+
}

.github/unittest/linux_libs/scripts_gym/run_test.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ lib_dir="${env_dir}/lib"
1818
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$lib_dir
1919
export MKL_THREADING_LAYER=GNU
2020

21+
# Start Xvfb with specific OpenGL configuration
22+
export DISPLAY=:99
23+
Xvfb :99 -screen 0 1400x900x24 -ac +extension GLX +render -noreset > /dev/null 2>&1 &
24+
sleep 3 # Give Xvfb time to start
25+
26+
# Verify OpenGL/EGL setup
27+
glxinfo -B || true
28+
echo "EGL_PLATFORM=$EGL_PLATFORM"
29+
echo "MUJOCO_GL=$MUJOCO_GL"
30+
echo "PYOPENGL_PLATFORM=$PYOPENGL_PLATFORM"
31+
32+
# Run the tests
2133
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test.py -v --durations 200
2234
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test_deps.py -v --durations 200 -k 'test_gym'
2335

2436
unset LD_PRELOAD
25-
export DISPLAY=:99
26-
Xvfb :99 -screen 0 1400x900x24 > /dev/null 2>&1 &
2737
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/test_libs.py --instafail -v --durations 200 -k "gym and not isaac" --error-for-skips --mp_fork
2838
coverage combine
2939
coverage xml -i

.github/unittest/linux_libs/scripts_gym/setup_env.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,28 @@
55
#
66
# Do not install PyTorch and torchvision here, otherwise they also get cached.
77

8+
unset PYTORCH_VERSION
9+
# For unittest, nightly PyTorch is used as the following section,
10+
# so no need to set PYTORCH_VERSION.
11+
# In fact, keeping PYTORCH_VERSION forces us to hardcode PyTorch version in config.
12+
apt-get update && apt-get install -y \
13+
git wget gcc g++ \
14+
libglfw3 libgl1-mesa-glx libosmesa6 libglew-dev \
15+
libglvnd0 libgl1 libglx0 libegl1 libgles2 \
16+
xvfb libegl-dev libx11-dev freeglut3-dev \
17+
mesa-utils mesa-common-dev \
18+
libsdl2-dev libsdl2-2.0-0
19+
820
set -e
21+
set -v
922

1023
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
11-
# Avoid error: "fatal: unsafe repository"
12-
apt-get update && apt-get install -y git wget gcc g++
13-
apt-get install -y libglfw3 libgl1-mesa-glx libosmesa6 libglew-dev libsdl2-dev libsdl2-2.0-0
14-
apt-get install -y libglvnd0 libgl1 libglx0 libegl1 libgles2 xvfb libegl-dev libx11-dev freeglut3-dev
1524

25+
# Setup EGL
26+
mkdir -p /usr/share/glvnd/egl_vendor.d
27+
cp $this_dir/10_nvidia.json /usr/share/glvnd/egl_vendor.d/10_nvidia.json
28+
29+
# Avoid error: "fatal: unsafe repository"
1630
git config --global --add safe.directory '*'
1731
root_dir="$(git rev-parse --show-toplevel)"
1832
conda_dir="${root_dir}/conda"
@@ -79,13 +93,15 @@ conda env config vars set \
7993
SDL_VIDEODRIVER=dummy \
8094
DISPLAY=:99 \
8195
PYOPENGL_PLATFORM=egl \
82-
LD_PRELOAD=$glew_path \
96+
__GLX_VENDOR_LIBRARY_NAME=nvidia \
97+
MESA_GL_VERSION_OVERRIDE=3.3 \
98+
EGL_PLATFORM=x11 \
99+
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libGLEW.so:/usr/lib/x86_64-linux-gnu/libGL.so \
83100
NVIDIA_PATH=/usr/src/nvidia-470.63.01 \
84101
MUJOCO_PY_MJKEY_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/mjkey.txt \
85102
MUJOCO_PY_MUJOCO_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/linux/mujoco210 \
86-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/pytorch/rl/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin
103+
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/pytorch/rl/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin \
87104
TOKENIZERS_PARALLELISM=true
88-
# LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/circleci/project/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin
89105

90106
# make env variables apparent
91107
conda deactivate && conda activate "${env_dir}"

.github/unittest/linux_olddeps/scripts_gym_0_13/environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies:
2424
- mujoco
2525
- patchelf
2626
- pyopengl==3.1.4
27+
- pyglet<1.5.0
2728
- ray
2829
- av
2930
- h5py

.github/unittest/linux_olddeps/scripts_gym_0_13/run_test.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/pytorch/rl/mujoco-py/mujoco_py/binaries
2222
export MKL_THREADING_LAYER=GNU
2323
export BATCHED_PIPE_TIMEOUT=60
2424

25-
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test.py -v --durations 200
26-
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test_deps.py -v --durations 200 -k 'test_gym'
27-
25+
# Start Xvfb with specific OpenGL configuration
2826
export DISPLAY=:99
2927
Xvfb :99 -screen 0 1400x900x24 > /dev/null 2>&1 &
28+
sleep 3 # Give Xvfb time to start
29+
30+
# Verify OpenGL setup
31+
glxinfo -B || true
32+
echo "MUJOCO_GL=$MUJOCO_GL"
33+
echo "PYOPENGL_PLATFORM=$PYOPENGL_PLATFORM"
34+
35+
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test.py -v --durations 200
36+
python .github/unittest/helpers/coverage_run_parallel.py -m pytest test/smoke_test_deps.py -v --durations 200 -k 'test_gym'
3037

31-
CKPT_BACKEND=torch MUJOCO_GL=egl python .github/unittest/helpers/coverage_run_parallel.py -m pytest \
38+
MUJOCO_GL=osmesa python .github/unittest/helpers/coverage_run_parallel.py -m pytest \
3239
--instafail -v \
3340
--durations 200 \
3441
--ignore test/test_distributed.py \

.github/unittest/linux_olddeps/scripts_gym_0_13/setup_env.sh

Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,63 @@
88
set -e
99
set -v
1010

11-
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
12-
13-
apt-get update && apt-get upgrade -y
14-
printf "* Installing vim - git - wget\n"
15-
apt-get install -y vim git wget
11+
# Make apt-get non-interactive
12+
export DEBIAN_FRONTEND=noninteractive
13+
# Pre-configure timezone data
14+
ln -fs /usr/share/zoneinfo/UTC /etc/localtime
15+
echo "UTC" > /etc/timezone
1616

17-
printf "* Installing glfw - glew - osmesa part 1\n"
18-
apt-get install -y libglvnd0 libgl1 libglx0 libegl1 libgles2 xvfb libx11-dev libegl-dev
17+
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1918

20-
#printf "* Installing glfw - glew - osmesa part 2\n"
21-
#apt-get install -y libglfw3 libgl1-mesa-glx libosmesa6 libglew-dev libsdl2-dev libsdl2-2.0-0
19+
# Add NVIDIA repository for drivers
20+
apt-get update && apt-get install -y --no-install-recommends \
21+
software-properties-common \
22+
wget \
23+
ca-certificates
24+
25+
# Install basic build tools first
26+
apt-get install -y vim git wget build-essential
27+
28+
# Install system libraries to fix version conflicts
29+
apt-get install -y --no-install-recommends \
30+
libffi7 \
31+
libffi-dev \
32+
libtinfo6 \
33+
libtinfo-dev \
34+
libncurses5-dev \
35+
libncursesw5-dev
36+
37+
# Install OpenGL packages with focus on OSMesa
38+
apt-get install -y --no-install-recommends \
39+
libosmesa6-dev \
40+
libgl1-mesa-dev \
41+
libgl1-mesa-glx \
42+
libglew-dev \
43+
libglfw3-dev \
44+
libglvnd0 \
45+
libgl1 \
46+
libglx0 \
47+
libegl1 \
48+
libgles2 \
49+
xvfb \
50+
mesa-utils \
51+
mesa-common-dev \
52+
libglu1-mesa-dev \
53+
libsdl2-dev \
54+
libsdl2-2.0-0 \
55+
pkg-config
2256

2357
if [ "${CU_VERSION:-}" == cpu ] ; then
24-
# solves version `GLIBCXX_3.4.29' not found for tensorboard
25-
# apt-get install -y gcc-4.9
2658
apt-get upgrade -y libstdc++6
2759
apt-get dist-upgrade -y
2860
else
2961
apt-get install -y g++ gcc
3062
fi
3163

64+
# Remove conflicting libraries from conda environment if they exist
65+
rm -f "${env_dir}/lib/libtinfo.so"* || true
66+
rm -f "${env_dir}/lib/libffi.so"* || true
67+
3268
git config --global --add safe.directory '*'
3369
root_dir="$(git rev-parse --show-toplevel)"
3470
conda_dir="${root_dir}/conda"
@@ -93,19 +129,20 @@ printf "* Installing dependencies (except PyTorch)\n"
93129
echo " - python=${PYTHON_VERSION}" >> "${this_dir}/environment.yml"
94130
cat "${this_dir}/environment.yml"
95131

96-
export MUJOCO_GL=egl
132+
# Use OSMesa for rendering
133+
export MUJOCO_GL=osmesa
97134
conda env config vars set \
98135
MAX_IDLE_COUNT=1000 \
99-
MUJOCO_GL=egl \
136+
MUJOCO_GL=osmesa \
100137
SDL_VIDEODRIVER=dummy \
101-
DISPLAY=unix:0.0 \
102-
PYOPENGL_PLATFORM=egl \
103-
LD_PRELOAD=$glew_path \
104-
NVIDIA_PATH=/usr/src/nvidia-470.63.01 \
138+
DISPLAY=:99 \
139+
PYOPENGL_PLATFORM=osmesa \
140+
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libOSMesa.so.6:/usr/lib/x86_64-linux-gnu/libGL.so \
105141
MUJOCO_PY_MJKEY_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/mjkey.txt \
106142
MUJOCO_PY_MUJOCO_PATH=${root_dir}/mujoco-py/mujoco_py/binaries/linux/mujoco210 \
107-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/circleci/project/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin \
108-
TOKENIZERS_PARALLELISM=true
143+
LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH:/home/circleci/project/mujoco-py/mujoco_py/binaries/linux/mujoco210/bin \
144+
TOKENIZERS_PARALLELISM=true \
145+
PYGLET_GRAPHICS=opengl3
109146

110147
# make env variables apparent
111148
conda deactivate && conda activate "${env_dir}"

test/_utils_internal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def get_available_devices():
182182
def get_default_devices():
183183
num_cuda = torch.cuda.device_count()
184184
if num_cuda == 0:
185-
# if torch.mps.is_available():
185+
# if getattr(torch.mps, "is_available", lambda: False)():
186186
# return [torch.device("mps:0")]
187187
return [torch.device("cpu")]
188188
elif num_cuda == 1:

test/test_collector.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def test_no_deepcopy_policy(self, collector_type):
10701070
shared_device = torch.device("cpu")
10711071
if torch.cuda.is_available():
10721072
original_device = torch.device("cuda:0")
1073-
elif torch.mps.is_available():
1073+
elif getattr(torch.mps, "is_available", lambda: False)():
10741074
original_device = torch.device("mps")
10751075
else:
10761076
pytest.skip("No GPU or MPS device")
@@ -2614,7 +2614,8 @@ def test_multi_collector_consistency(
26142614

26152615

26162616
@pytest.mark.skipif(
2617-
not torch.cuda.is_available() and not torch.mps.is_available(),
2617+
not torch.cuda.is_available()
2618+
and not getattr(torch.mps, "is_available", lambda: False)(),
26182619
reason="No casting if no cuda",
26192620
)
26202621
class TestUpdateParams:

torchrl/data/replay_buffers/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,6 @@ def tree_iter(pytree): # noqa: F811
10361036
def _auto_device() -> torch.device:
10371037
if torch.cuda.is_available():
10381038
return torch.device("cuda:0")
1039-
elif torch.mps.is_available():
1039+
elif getattr(torch.mps, "is_available", lambda: False)():
10401040
return torch.device("mps:0")
10411041
return torch.device("cpu")

0 commit comments

Comments
 (0)