Skip to content

Commit 194a5ff

Browse files
author
Vincent Moens
authored
[CI] Fix benchmark workflows (#2488)
1 parent ad14594 commit 194a5ff

File tree

3 files changed

+126
-73
lines changed

3 files changed

+126
-73
lines changed

.github/workflows/benchmarks.yml

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,36 @@ jobs:
2424
name: CPU Pytest benchmark
2525
runs-on: ubuntu-20.04
2626
steps:
27-
- uses: actions/checkout@v3
28-
- uses: actions/setup-python@v4
27+
- name: Who triggered this?
28+
run: |
29+
echo "Action triggered by ${{ github.event.pull_request.html_url }}"
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
with:
33+
fetch-depth: 50 # this is to make sure we obtain the target base commit
34+
- name: Python Setup
35+
uses: actions/setup-python@v4
2936
with:
30-
python-version: 3.9
37+
python-version: '3.10'
3138
- name: Setup Environment
3239
run: |
40+
python3.10 -m venv ./py310
41+
source ./py310/bin/activate
42+
3343
python3 -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu -U
3444
python3 -m pip install git+https://github.com/pytorch/tensordict
3545
python3 setup.py develop
3646
python3 -m pip install pytest pytest-benchmark
3747
python3 -m pip install "gym[accept-rom-license,atari]"
3848
python3 -m pip install "dm_control" "mujoco"
39-
export TD_GET_DEFAULTS_TO_NONE=1
40-
- name: Run benchmarks
41-
run: |
49+
4250
cd benchmarks/
4351
export TORCHDYNAMO_INLINE_INBUILT_NN_MODULES=1
44-
python -m pytest --benchmark-json output.json
52+
export TD_GET_DEFAULTS_TO_NONE=1
53+
python3 -m pytest -vvv --rank 0 --benchmark-json output.json --ignore test_collectors_benchmark.py
4554
- name: Store benchmark results
46-
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
4755
uses: benchmark-action/github-action-benchmark@v1
56+
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}
4857
with:
4958
name: CPU Benchmark Results
5059
tool: 'pytest'
@@ -68,48 +77,73 @@ jobs:
6877
image: nvidia/cuda:12.3.0-base-ubuntu22.04
6978
options: --gpus all
7079
steps:
71-
- name: Install deps
80+
- name: Set GITHUB_BRANCH environment variable
7281
run: |
73-
export TZ=Europe/London
74-
export DEBIAN_FRONTEND=noninteractive # tzdata bug
75-
apt-get update -y
76-
apt-get install software-properties-common -y
77-
add-apt-repository ppa:git-core/candidate -y
78-
apt-get update -y
79-
apt-get upgrade -y
80-
apt-get -y install libglu1-mesa libgl1-mesa-glx libosmesa6 gcc curl g++ unzip wget libglfw3-dev libgles2-mesa-dev libglew-dev sudo git cmake libz-dev
82+
if [ "${{ github.event_name }}" == "push" ]; then
83+
export GITHUB_BRANCH=${{ github.event.branch }}
84+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
85+
export GITHUB_BRANCH=${{ github.event.pull_request.head.ref }}
86+
else
87+
echo "Unsupported event type"
88+
exit 1
89+
fi
90+
echo "GITHUB_BRANCH=$GITHUB_BRANCH" >> $GITHUB_ENV
91+
- name: Who triggered this?
92+
run: |
93+
echo "Action triggered by ${{ github.event.pull_request.html_url }}"
8194
- name: Check ldd --version
8295
run: ldd --version
8396
- name: Checkout
8497
uses: actions/checkout@v3
98+
with:
99+
fetch-depth: 50 # this is to make sure we obtain the target base commit
85100
- name: Python Setup
86101
uses: actions/setup-python@v4
87102
with:
88-
python-version: 3.9
103+
python-version: '3.10'
104+
- name: Setup Environment
105+
run: |
106+
export TZ=Europe/London
107+
export DEBIAN_FRONTEND=noninteractive # tzdata bug
108+
apt-get update -y
109+
apt-get install software-properties-common -y
110+
add-apt-repository ppa:git-core/candidate -y
111+
apt-get update -y
112+
apt-get upgrade -y
113+
apt-get -y install libglu1-mesa libgl1-mesa-glx libosmesa6 gcc curl g++ unzip wget libglfw3-dev libgles2-mesa-dev libglew-dev sudo git cmake libz-dev libpython3.10-dev
89114
- name: Setup git
90115
run: git config --global --add safe.directory /__w/rl/rl
91116
- name: setup Path
92117
run: |
93118
echo /usr/local/bin >> $GITHUB_PATH
94-
- name: Setup Environment
119+
- name: Setup benchmarks
95120
run: |
96-
python3 -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu121 -U
97-
python3 -m pip install git+https://github.com/pytorch/tensordict
98-
python3 setup.py develop
99-
python3 -m pip install pytest pytest-benchmark
100-
python3 -m pip install "gym[accept-rom-license,atari]"
101-
python3 -m pip install "dm_control" "mujoco"
102-
export TD_GET_DEFAULTS_TO_NONE=1
103-
- name: check GPU presence
121+
echo "BASE_SHA=$(echo ${{ github.event.pull_request.base.sha }} | cut -c1-8)" >> $GITHUB_ENV
122+
echo "HEAD_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)" >> $GITHUB_ENV
123+
echo "BASELINE_JSON=$(mktemp)" >> $GITHUB_ENV
124+
echo "CONTENDER_JSON=$(mktemp)" >> $GITHUB_ENV
125+
echo "PR_COMMENT=$(mktemp)" >> $GITHUB_ENV
126+
- name: Run
104127
run: |
105-
python -c """import torch
128+
python3.10 -m venv --system-site-packages ./py310
129+
source ./py310/bin/activate
130+
export PYTHON_INCLUDE_DIR=/usr/include/python3.10
131+
132+
python3.10 -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu124 -U
133+
python3.10 -m pip install cmake ninja pytest pytest-benchmark mujoco dm_control "gym[accept-rom-license,atari]"
134+
python3.10 -m pip install git+https://github.com/pytorch/tensordict
135+
python3.10 setup.py develop
136+
# python3.10 -m pip install git+https://github.com/pytorch/rl@$GITHUB_BRANCH
137+
138+
# test import
139+
python3 -c """import torch
106140
assert torch.cuda.device_count()
107141
"""
108-
- name: Run benchmarks
109-
run: |
142+
110143
cd benchmarks/
111144
export TORCHDYNAMO_INLINE_INBUILT_NN_MODULES=1
112-
python3 -m pytest --benchmark-json output.json
145+
export TD_GET_DEFAULTS_TO_NONE=1
146+
python3 -m pytest -vvv --rank 0 --benchmark-json output.json --ignore test_collectors_benchmark.py
113147
- name: Store benchmark results
114148
uses: benchmark-action/github-action-benchmark@v1
115149
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }}

.github/workflows/benchmarks_pr.yml

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Continuous Benchmark (PR)
2-
32
on:
43
pull_request:
54

@@ -12,6 +11,7 @@ concurrency:
1211
cancel-in-progress: true
1312

1413
jobs:
14+
1515
benchmark_cpu:
1616
name: CPU Pytest benchmark
1717
runs-on: ubuntu-20.04
@@ -26,28 +26,30 @@ jobs:
2626
- name: Python Setup
2727
uses: actions/setup-python@v4
2828
with:
29-
python-version: 3.9
30-
- name: Setup Environment
31-
run: |
32-
python3 -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu -U
33-
python3 -m pip install git+https://github.com/pytorch/tensordict
34-
python3 setup.py develop
35-
python3 -m pip install pytest pytest-benchmark
36-
python3 -m pip install "gym[accept-rom-license,atari]"
37-
python3 -m pip install "dm_control" "mujoco"
38-
export TD_GET_DEFAULTS_TO_NONE=1
29+
python-version: '3.10'
3930
- name: Setup benchmarks
4031
run: |
4132
echo "BASE_SHA=$(echo ${{ github.event.pull_request.base.sha }} | cut -c1-8)" >> $GITHUB_ENV
4233
echo "HEAD_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)" >> $GITHUB_ENV
4334
echo "BASELINE_JSON=$(mktemp)" >> $GITHUB_ENV
4435
echo "CONTENDER_JSON=$(mktemp)" >> $GITHUB_ENV
4536
echo "PR_COMMENT=$(mktemp)" >> $GITHUB_ENV
46-
- name: Run benchmarks
37+
- name: Setup Environment and tests
4738
run: |
39+
python3.10 -m venv ./py310
40+
source ./py310/bin/activate
41+
42+
python3 -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu -U
43+
python3 -m pip install git+https://github.com/pytorch/tensordict
44+
python3 setup.py develop
45+
python3 -m pip install pytest pytest-benchmark
46+
python3 -m pip install "gym[accept-rom-license,atari]"
47+
python3 -m pip install "dm_control" "mujoco"
48+
4849
cd benchmarks/
4950
export TORCHDYNAMO_INLINE_INBUILT_NN_MODULES=1
50-
RUN_BENCHMARK="pytest --rank 0 --benchmark-json "
51+
export TD_GET_DEFAULTS_TO_NONE=1
52+
RUN_BENCHMARK="python3 -m pytest -vvv --rank 0 --ignore test_collectors_benchmark.py --benchmark-json "
5153
git checkout ${{ github.event.pull_request.base.sha }}
5254
$RUN_BENCHMARK ${{ env.BASELINE_JSON }}
5355
git checkout ${{ github.event.pull_request.head.sha }}
@@ -71,22 +73,23 @@ jobs:
7173
run:
7274
shell: bash -l {0}
7375
container:
74-
image: nvidia/cuda:12.3.0-base-ubuntu22.04
76+
image: nvidia/cuda:12.4.1-cudnn-runtime-ubuntu22.04
7577
options: --gpus all
7678
steps:
79+
- name: Set GITHUB_BRANCH environment variable
80+
run: |
81+
if [ "${{ github.event_name }}" == "push" ]; then
82+
export GITHUB_BRANCH=${{ github.event.branch }}
83+
elif [ "${{ github.event_name }}" == "pull_request" ]; then
84+
export GITHUB_BRANCH=${{ github.event.pull_request.head.ref }}
85+
else
86+
echo "Unsupported event type"
87+
exit 1
88+
fi
89+
echo "GITHUB_BRANCH=$GITHUB_BRANCH" >> $GITHUB_ENV
7790
- name: Who triggered this?
7891
run: |
7992
echo "Action triggered by ${{ github.event.pull_request.html_url }}"
80-
- name: Install deps
81-
run: |
82-
export TZ=Europe/London
83-
export DEBIAN_FRONTEND=noninteractive # tzdata bug
84-
apt-get update -y
85-
apt-get install software-properties-common -y
86-
add-apt-repository ppa:git-core/candidate -y
87-
apt-get update -y
88-
apt-get upgrade -y
89-
apt-get -y install libglu1-mesa libgl1-mesa-glx libosmesa6 gcc curl g++ unzip wget libglfw3-dev libgles2-mesa-dev libglew-dev sudo git cmake libz-dev
9093
- name: Check ldd --version
9194
run: ldd --version
9295
- name: Checkout
@@ -96,38 +99,50 @@ jobs:
9699
- name: Python Setup
97100
uses: actions/setup-python@v4
98101
with:
99-
python-version: 3.9
102+
python-version: '3.10'
103+
- name: Setup Environment
104+
run: |
105+
export TZ=Europe/London
106+
export DEBIAN_FRONTEND=noninteractive # tzdata bug
107+
apt-get update -y
108+
apt-get install software-properties-common -y
109+
add-apt-repository ppa:git-core/candidate -y
110+
apt-get update -y
111+
apt-get upgrade -y
112+
apt-get -y install libglu1-mesa libgl1-mesa-glx libosmesa6 gcc curl g++ unzip wget libglfw3-dev libgles2-mesa-dev libglew-dev sudo git cmake libz-dev libpython3.10-dev
100113
- name: Setup git
101114
run: git config --global --add safe.directory /__w/rl/rl
102115
- name: setup Path
103116
run: |
104117
echo /usr/local/bin >> $GITHUB_PATH
105-
- name: Setup Environment
106-
run: |
107-
python3 -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu121 -U
108-
python3 -m pip install git+https://github.com/pytorch/tensordict
109-
python3 setup.py develop
110-
python3 -m pip install pytest pytest-benchmark
111-
python3 -m pip install "gym[accept-rom-license,atari]"
112-
python3 -m pip install "dm_control" "mujoco"
113-
export TD_GET_DEFAULTS_TO_NONE=1
114-
- name: check GPU presence
115-
run: |
116-
python -c """import torch
117-
assert torch.cuda.device_count()
118-
"""
119118
- name: Setup benchmarks
120119
run: |
121120
echo "BASE_SHA=$(echo ${{ github.event.pull_request.base.sha }} | cut -c1-8)" >> $GITHUB_ENV
122121
echo "HEAD_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8)" >> $GITHUB_ENV
123122
echo "BASELINE_JSON=$(mktemp)" >> $GITHUB_ENV
124123
echo "CONTENDER_JSON=$(mktemp)" >> $GITHUB_ENV
125124
echo "PR_COMMENT=$(mktemp)" >> $GITHUB_ENV
126-
- name: Run benchmarks
125+
- name: Run
127126
run: |
127+
python3.10 -m venv --system-site-packages ./py310
128+
source ./py310/bin/activate
129+
export PYTHON_INCLUDE_DIR=/usr/include/python3.10
130+
131+
python3.10 -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cu124 -U
132+
python3.10 -m pip install cmake ninja pytest pytest-benchmark mujoco dm_control "gym[accept-rom-license,atari]"
133+
python3.10 -m pip install git+https://github.com/pytorch/tensordict
134+
python3.10 setup.py develop
135+
# python3.10 -m pip install git+https://github.com/pytorch/rl@$GITHUB_BRANCH
136+
137+
# test import
138+
python3 -c """import torch
139+
assert torch.cuda.device_count()
140+
"""
141+
128142
cd benchmarks/
129143
export TORCHDYNAMO_INLINE_INBUILT_NN_MODULES=1
130-
RUN_BENCHMARK="pytest --rank 0 --benchmark-json "
144+
export TD_GET_DEFAULTS_TO_NONE=1
145+
RUN_BENCHMARK="python3 -m pytest -vvv --rank 0 --ignore test_collectors_benchmark.py --benchmark-json "
131146
git checkout ${{ github.event.pull_request.base.sha }}
132147
$RUN_BENCHMARK ${{ env.BASELINE_JSON }}
133148
git checkout ${{ github.event.pull_request.head.sha }}

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,15 @@ def get_extensions():
152152
}
153153
sources = list(extension_sources)
154154

155+
include_dirs = [this_dir]
156+
python_include_dir = os.getenv("PYTHON_INCLUDE_DIR")
157+
if python_include_dir is not None:
158+
include_dirs.append(python_include_dir)
155159
ext_modules = [
156160
extension(
157161
"torchrl._torchrl",
158162
sources,
159-
include_dirs=[this_dir],
163+
include_dirs=include_dirs,
160164
extra_compile_args=extra_compile_args,
161165
extra_link_args=extra_link_args,
162166
)

0 commit comments

Comments
 (0)