Skip to content

Commit a69eb74

Browse files
Fix runners GPU isolation
1 parent 72d01a0 commit a69eb74

1 file changed

Lines changed: 111 additions & 69 deletions

File tree

.github/workflows/rocm-ci.yml

Lines changed: 111 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,19 @@ jobs:
147147
run: |
148148
DEVICE_FLAG="$(cat /etc/podinfo/gha-render-devices 2>/dev/null || echo --device=/dev/dri)"
149149
test -n "$DEVICE_FLAG"
150+
mapfile -t RENDER_DEVICES < <(grep -oE '/dev/dri/renderD[0-9]+' <<< "$DEVICE_FLAG" || true)
151+
GPU_COUNT="${#RENDER_DEVICES[@]}"
152+
GPU_ENV=()
153+
if [ "$GPU_COUNT" -gt 0 ]; then
154+
GPU_IDS="$(seq -s, 0 $((GPU_COUNT - 1)))"
155+
GPU_ENV=(-e "ROCR_VISIBLE_DEVICES=$GPU_IDS" -e "HIP_VISIBLE_DEVICES=$GPU_IDS")
156+
fi
150157
docker run -dt \
151158
--rm \
152159
--name te-runner \
153160
--network=host \
154161
--device=/dev/kfd $DEVICE_FLAG \
162+
"${GPU_ENV[@]}" \
155163
--shm-size=16G \
156164
--pid=host \
157165
--group-add $(getent group render | cut -d: -f3) \
@@ -182,9 +190,6 @@ jobs:
182190
183191
- name: Run sGPU tests in parallel (pytorch, jax, examples, core)
184192
id: run-tests
185-
# Below the job's timeout-minutes so an overrun kills only this step;
186-
# the `if: always()` report + upload steps still run (artifacts survive).
187-
timeout-minutes: 180
188193
env:
189194
HF_TOKEN: ${{ secrets.HF_TOKEN }}
190195
run: |
@@ -194,97 +199,132 @@ jobs:
194199
# exists in both the torch and jax suites and runs in parallel).
195200
rm -rf test-results && mkdir -p test-results/torch test-results/jax test-results/core
196201
197-
docker exec \
198-
-e TEST_SGPU=1 \
199-
-e TEST_LEVEL=${{ env.TEST_LEVEL }} \
200-
-e JUNITXML_PREFIX=/workspace/test-results/ \
201-
-e JUNITXML_SUFFIX=.xml \
202-
-e HF_TOKEN="$HF_TOKEN" \
203-
te-runner bash -c "$(cat <<'EOF'
204-
#!/usr/bin/bash
205-
set -x -o pipefail
206-
ulimit -c 0 # Disable core dumps
207-
208-
# Each suite appends its own subdir to the inherited base prefix so the
209-
# base path is defined once in the docker-exec env above (inline VAR=val
210-
# applies only to that backgrounded subprocess; the sourced _utils.sh
211-
# reads it from the env).
212-
HIP_VISIBLE_DEVICES=0 JUNITXML_PREFIX=${JUNITXML_PREFIX}torch/ ci/pytorch.sh > /workspace/torch.log 2>&1 &
213-
TORCH_PID=$!
214-
215-
HIP_VISIBLE_DEVICES=1 JUNITXML_PREFIX=${JUNITXML_PREFIX}jax/ ci/jax.sh > /workspace/jax.log 2>&1 &
216-
JAX_PID=$!
217-
218-
(
219-
set -e
220-
python -c "import os; print('HF_TOKEN set:', bool(os.environ.get('HF_TOKEN')))"
202+
INSTALLED_IMAGE="te-runner-installed:${{ github.run_id }}-${{ matrix.arch_label }}"
203+
docker commit te-runner "$INSTALLED_IMAGE" >/dev/null
221204
222-
JAX_CONSTRAINTS=/tmp/jax-constraints.txt
223-
pip freeze | grep -iE '^(jax|jaxlib|jax[_-]rocm|jax[_-]plugins)[=@]' > "$JAX_CONSTRAINTS" || true
224-
225-
export HIP_VISIBLE_DEVICES=2
226-
227-
cd /workspace/examples/pytorch/mnist
228-
python main.py
229-
python main.py --use-te
230-
python main.py --use-fp8
205+
mapfile -t RENDER_DEVICES < <(grep -oE '/dev/dri/renderD[0-9]+' /etc/podinfo/gha-render-devices 2>/dev/null || true)
206+
if [ "${#RENDER_DEVICES[@]}" -eq 0 ]; then
207+
mapfile -t RENDER_DEVICES < <(find /dev/dri -maxdepth 1 -name 'renderD*' | sort | head -4)
208+
fi
209+
if [ "${#RENDER_DEVICES[@]}" -lt 4 ]; then
210+
echo "::error::Expected at least 4 render devices, found ${#RENDER_DEVICES[@]}."
211+
exit 1
212+
fi
231213
232-
cd /workspace/examples/jax/mnist
233-
pip3 install -c "$JAX_CONSTRAINTS" -r requirements.txt
234-
python test_single_gpu_mnist.py
235-
python test_single_gpu_mnist.py --use-te
236-
python test_single_gpu_mnist.py --use-fp8
214+
cat > .te-ci-torch.sh <<'EOF'
215+
set -x -o pipefail
216+
ulimit -c 0
217+
JUNITXML_PREFIX=${JUNITXML_PREFIX}torch/ ci/pytorch.sh
218+
EOF
237219
238-
cd /workspace/examples/jax/encoder
239-
pip3 install -c "$JAX_CONSTRAINTS" -r requirements.txt
240-
python test_single_gpu_encoder.py
241-
python test_single_gpu_encoder.py --use-fp8
242-
) > /workspace/examples.log 2>&1 &
243-
EXAMPLES_PID=$!
220+
cat > .te-ci-jax.sh <<'EOF'
221+
set -x -o pipefail
222+
ulimit -c 0
223+
JUNITXML_PREFIX=${JUNITXML_PREFIX}jax/ ci/jax.sh
224+
EOF
244225
245-
HIP_VISIBLE_DEVICES=3 JUNITXML_PREFIX=${JUNITXML_PREFIX}core/ ci/core.sh > /workspace/core.log 2>&1 &
246-
CORE_PID=$!
226+
cat > .te-ci-examples.sh <<'EOF'
227+
set -ex -o pipefail
228+
ulimit -c 0
229+
python -c "import os; print('HF_TOKEN set:', bool(os.environ.get('HF_TOKEN')))"
230+
231+
JAX_CONSTRAINTS=/tmp/jax-constraints.txt
232+
pip freeze | grep -iE '^(jax|jaxlib|jax[_-]rocm|jax[_-]plugins)[=@]' > "$JAX_CONSTRAINTS" || true
233+
234+
cd /workspace/examples/pytorch/mnist
235+
python main.py
236+
python main.py --use-te
237+
python main.py --use-fp8
238+
239+
cd /workspace/examples/jax/mnist
240+
pip3 install -c "$JAX_CONSTRAINTS" -r requirements.txt
241+
python test_single_gpu_mnist.py
242+
python test_single_gpu_mnist.py --use-te
243+
python test_single_gpu_mnist.py --use-fp8
244+
245+
cd /workspace/examples/jax/encoder
246+
pip3 install -c "$JAX_CONSTRAINTS" -r requirements.txt
247+
python test_single_gpu_encoder.py
248+
python test_single_gpu_encoder.py --use-fp8
249+
EOF
247250
248-
wait $TORCH_PID; torch_rc=$?
249-
wait $JAX_PID; jax_rc=$?
250-
wait $EXAMPLES_PID; examples_rc=$?
251-
wait $CORE_PID; core_rc=$?
251+
cat > .te-ci-core.sh <<'EOF'
252+
set -x -o pipefail
253+
ulimit -c 0
254+
JUNITXML_PREFIX=${JUNITXML_PREFIX}core/ ci/core.sh
255+
EOF
252256
253-
if [ $torch_rc -ne 0 ]; then
257+
run_gpu_suite() {
258+
local name="$1"
259+
local gpu_index="$2"
260+
local log_file="$3"
261+
local script_path="$4"
262+
docker rm -f "te-runner-$name" >/dev/null 2>&1 || true
263+
docker run -d \
264+
--name "te-runner-$name" \
265+
--network=host \
266+
--device=/dev/kfd \
267+
--device="${RENDER_DEVICES[$gpu_index]}" \
268+
--shm-size=16G \
269+
--pid=host \
270+
--group-add "$(getent group render | cut -d: -f3)" \
271+
--group-add "$(getent group video | cut -d: -f3)" \
272+
-e TEST_SGPU=1 \
273+
-e TEST_LEVEL=${{ env.TEST_LEVEL }} \
274+
-e JUNITXML_PREFIX=/workspace/test-results/ \
275+
-e JUNITXML_SUFFIX=.xml \
276+
-e HF_TOKEN="$HF_TOKEN" \
277+
-e ROCR_VISIBLE_DEVICES=0 \
278+
-e HIP_VISIBLE_DEVICES=0 \
279+
-v "${{ github.workspace }}:/workspace" \
280+
-w /workspace \
281+
"$INSTALLED_IMAGE" \
282+
bash -lc "bash $script_path > $log_file 2>&1"
283+
}
284+
285+
TORCH_CID="$(run_gpu_suite torch 0 /workspace/torch.log /workspace/.te-ci-torch.sh)"
286+
JAX_CID="$(run_gpu_suite jax 1 /workspace/jax.log /workspace/.te-ci-jax.sh)"
287+
EXAMPLES_CID="$(run_gpu_suite examples 2 /workspace/examples.log /workspace/.te-ci-examples.sh)"
288+
CORE_CID="$(run_gpu_suite core 3 /workspace/core.log /workspace/.te-ci-core.sh)"
289+
290+
torch_rc="$(docker wait "$TORCH_CID")"
291+
jax_rc="$(docker wait "$JAX_CID")"
292+
examples_rc="$(docker wait "$EXAMPLES_CID")"
293+
core_rc="$(docker wait "$CORE_CID")"
294+
295+
if [ "$torch_rc" -ne 0 ]; then
254296
echo "::group::[FAILED] PyTorch Log"
255-
cat /workspace/torch.log
297+
cat torch.log || true
256298
echo "::endgroup::"
257299
echo "::error::PyTorch tests FAILED."
258-
touch /workspace/FAIL_TORCH
300+
touch FAIL_TORCH
259301
fi
260302
261-
if [ $jax_rc -ne 0 ]; then
303+
if [ "$jax_rc" -ne 0 ]; then
262304
echo "::group::[FAILED] JAX Log"
263-
cat /workspace/jax.log
305+
cat jax.log || true
264306
echo "::endgroup::"
265307
echo "::error::JAX tests FAILED."
266-
touch /workspace/FAIL_JAX
308+
touch FAIL_JAX
267309
fi
268310
269-
if [ $examples_rc -ne 0 ]; then
311+
if [ "$examples_rc" -ne 0 ]; then
270312
echo "::group::[FAILED] Examples Log"
271-
cat /workspace/examples.log
313+
cat examples.log || true
272314
echo "::endgroup::"
273315
echo "::error::Examples FAILED."
274-
touch /workspace/FAIL_EXAMPLES
316+
touch FAIL_EXAMPLES
275317
fi
276318
277-
if [ $core_rc -ne 0 ]; then
319+
if [ "$core_rc" -ne 0 ]; then
278320
echo "::group::[FAILED] Core Log"
279-
cat /workspace/core.log
321+
cat core.log || true
280322
echo "::endgroup::"
281323
echo "::error::Core tests FAILED."
282-
touch /workspace/FAIL_CORE
324+
touch FAIL_CORE
283325
fi
284326
285-
test $torch_rc -eq 0 -a $jax_rc -eq 0 -a $examples_rc -eq 0 -a $core_rc -eq 0
286-
EOF
287-
)"
327+
test "$torch_rc" -eq 0 -a "$jax_rc" -eq 0 -a "$examples_rc" -eq 0 -a "$core_rc" -eq 0
288328
289329
- name: Generate test report
290330
if: always()
@@ -335,7 +375,9 @@ jobs:
335375

336376
- name: Cleanup container
337377
if: always()
338-
run: docker rm -f te-runner || true
378+
run: |
379+
docker rm -f te-runner te-runner-torch te-runner-jax te-runner-examples te-runner-core || true
380+
docker image rm "te-runner-installed:${{ github.run_id }}-${{ matrix.arch_label }}" || true
339381
340382
mgpu_tests:
341383
name: mGPU ${{ matrix.framework == 'pytorch' && 'Torch' || 'JAX' }} (${{ matrix.arch_label }})

0 commit comments

Comments
 (0)