Files
PaddleOCR/.github/workflows/test_gpu.yml
cuicheng01 811e0c59e3 docs: organize research papers and unify multilingual citations (#18357)
* docs: organize research papers and unify multilingual citations

* ci: retry PaddleX installation and stop GPU tests on setup failure

Retry PaddleX installation up to three times with 10s and 20s backoff. Stop the container script when environment setup fails so pytest does not run without required dependencies. Preserve the explicit diagnostic for an unrecognized PaddleX requirement.

Validation: YAML parsing, bash syntax, git diff --check, and six simulated setup scenarios including retry success, retry exhaustion, early dependency failure, and import failure.

* ci: build PaddleX wheel on hosted runner for GPU tests

The GPU container repeatedly fails to clone PaddleX from GitHub even after retries. Build the same release-branch source as a wheel on ubuntu-latest, transfer it within the workflow using an artifact, and mount it read-only into the GPU container for installation. Preserve dependency resolution, retries, fail-fast behavior, and the required GPU check.

Validation: built paddlex-3.7.2-py3-none-any.whl from release/3.7; checked wheel metadata, YAML and shell syntax, artifact wiring, three preparation scenarios, and five GPU setup scenarios. Full GPU validation runs in CI.
2026-09-16 11:26:01 +08:00

159 lines
6.2 KiB
YAML

name: PaddleOCR PR Tests GPU
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch:
env:
PR_ID: ${{ github.event.pull_request.number }}
COMMIT_ID: ${{ github.event.pull_request.head.sha || github.sha }}
work_dir: /workspace/PaddleOCR
PADDLENLP_ROOT: /workspace/PaddleOCR
TASK: paddleocr-CI-${{ github.event.pull_request.number }}
BRANCH: ${{ github.event.pull_request.base.ref }}
AGILE_COMPILE_BRANCH: ${{ github.event.pull_request.base.ref }}
DIR_NAME: ${{ github.repository }}
permissions:
contents: read
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
docs_only: ${{ steps.detect.outputs.docs_only }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- id: detect
uses: ./.github/actions/detect-docs-only
prepare-paddlex:
runs-on: ubuntu-latest
needs: detect-changes
if: needs.detect-changes.outputs.docs_only != 'true'
steps:
- uses: actions/checkout@v6
with:
ref: ${{ env.COMMIT_ID }}
- uses: actions/setup-python@v6
with:
python-version: "3.10"
- name: Build PaddleX wheel
run: |
PADDLEX_SERIES=$(grep -oE 'paddlex\[[^]]+\]>=[0-9]+\.[0-9]+' pyproject.toml | head -1 | grep -oE '[0-9]+\.[0-9]+') || PADDLEX_SERIES=""
if [ -z "$PADDLEX_SERIES" ]; then
echo "Failed to determine PaddleX version requirement from pyproject.toml" >&2
exit 1
fi
PADDLEX_BRANCH="release/${PADDLEX_SERIES}"
echo "Building PaddleX from branch: ${PADDLEX_BRANCH}"
python -m pip wheel --no-deps --wheel-dir paddlex-wheel "paddlex@git+https://github.com/PaddlePaddle/PaddleX.git@${PADDLEX_BRANCH}"
- uses: actions/upload-artifact@v4
with:
name: paddlex-wheel
path: paddlex-wheel/*.whl
if-no-files-found: error
overwrite: true
test-pr-gpu-impl:
runs-on: [self-hosted, GPU-2Card-OCR]
needs: [detect-changes, prepare-paddlex]
if: needs.detect-changes.outputs.docs_only != 'true'
steps:
- uses: actions/download-artifact@v4
with:
name: paddlex-wheel
path: ${{ runner.temp }}/paddlex-wheel-${{ github.run_id }}-${{ github.run_attempt }}
- name: run test
env:
PADDLEX_WHEEL_DIR: ${{ runner.temp }}/paddlex-wheel-${{ github.run_id }}-${{ github.run_attempt }}
py_version: "3.10"
paddle_whl: https://paddle-qa.bj.bcebos.com/paddle-pipeline/Develop-GpuSome-LinuxCentos-Gcc82-Cuda118-Cudnn86-Trt85-Py310-CINN-Compile/latest/paddlepaddle_gpu-0.0.0-cp310-cp310-linux_x86_64.whl
docker_image: ccr-2vdh3abv-pub.cnc.bj.baidubce.com/paddlepaddle/paddle:latest-dev-cuda11.8-cudnn8.6-trt8.5-gcc82
run: |
work_dir=$RANDOM
mkdir $work_dir
cd $work_dir
git clone --depth=1 https://github.com/PaddlePaddle/PaddleOCR.git -b main
cd PaddleOCR
if [ -n "${PR_ID}" ]; then
git fetch origin pull/${PR_ID}/head:ci_build
git checkout ci_build
else
git fetch --depth=1 origin "${COMMIT_ID}"
git checkout "${COMMIT_ID}"
fi
docker run --gpus all --rm -i --name PaddleOCR_CI_$RANDOM \
--shm-size=128g --net=host \
-v $PWD:/workspace -w /workspace \
-v "${PADDLEX_WHEEL_DIR}:/paddlex-wheel:ro" \
-e "py_version=${py_version}" \
-e "paddle_whl=${paddle_whl}" \
${docker_image} /bin/bash -c '
set -e
ldconfig;
nvidia-smi
df -hl
echo ${py_version}
rm -rf run_env
mkdir run_env
ln -s $(which python${py_version}) run_env/python
ln -s $(which python${py_version}) run_env/python3
ln -s $(which pip${py_version}) run_env/pip
export PATH=$PWD/run_env:${PATH}
git config --global --add safe.directory /workspace
python -m pip install paddlepaddle-gpu==3.1.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
python -c "import paddle; paddle.version.show()"
python -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
python -m pip install pytest
if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi
echo "Installing PaddleX from the prepared wheel"
for attempt in 1 2 3; do
if python -m pip install -e ".[all]" /paddlex-wheel/*.whl; then
break
else
install_status=$?
fi
if [ "$attempt" -eq 3 ]; then
echo "PaddleX installation failed after ${attempt} attempts." >&2
exit "$install_status"
fi
echo "PaddleX installation attempt ${attempt} failed; retrying in $((attempt * 10)) seconds." >&2
sleep "$((attempt * 10))"
done
python -c "import paddlex; print(f\"Installed paddlex version: {paddlex.__version__}\")"
python -m pytest --verbose tests/
'
# Aggregator: produces a single check named `test-pr-gpu` so branch
# protection (which requires the literal context `test-pr-gpu`) is satisfied
# even when the heavy GPU job is skipped (e.g. docs-only changes). Without
# this, a SKIPPED conclusion on the GPU job leaves the required check
# unsatisfied and blocks merge.
test-pr-gpu:
runs-on: ubuntu-latest
needs: [detect-changes, test-pr-gpu-impl]
if: always()
steps:
- name: Verify required jobs
run: |
if [ "${{ needs.detect-changes.result }}" != "success" ]; then
echo "detect-changes did not succeed: ${{ needs.detect-changes.result }}"
exit 1
fi
if [ "${{ needs.detect-changes.outputs.docs_only }}" = "true" ]; then
echo "Docs-only change; treating GPU tests as not required."
exit 0
fi
if [ "${{ needs.test-pr-gpu-impl.result }}" != "success" ]; then
echo "test-pr-gpu-impl concluded with: ${{ needs.test-pr-gpu-impl.result }}"
exit 1
fi
echo "GPU tests passed."