From cd22bf7312108443b7240b2f620d31753eb152bb Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Fri, 17 May 2024 16:13:07 +0530 Subject: [PATCH 1/5] add a more secure way to run tests from a PR. --- .github/workflows/run_tests_from_a_pr.yml | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 .github/workflows/run_tests_from_a_pr.yml diff --git a/.github/workflows/run_tests_from_a_pr.yml b/.github/workflows/run_tests_from_a_pr.yml new file mode 100644 index 000000000000..63f8499bb0e6 --- /dev/null +++ b/.github/workflows/run_tests_from_a_pr.yml @@ -0,0 +1,60 @@ +name: Check running SLOW tests from a PR (only GPU) + +on: + workflow_dispatch: + inputs: + docker_image: + default: 'diffusers/diffusers-pytorch-cuda' + description: 'Name of the Docker image' + required: true + branch: + description: 'PR Branch to test on' + required: true + test: + description: 'Tests to run (e.g.: `tests/models`).' + required: true + +env: + DIFFUSERS_IS_CI: yes + IS_GITHUB_CI: "1" + HF_HOME: /mnt/cache + OMP_NUM_THREADS: 8 + MKL_NUM_THREADS: 8 + PYTEST_TIMEOUT: 600 + RUN_SLOW: yes + +jobs: + run_tests: + name: "Run a test on our runner from a PR" + runs-on: [ self-hosted, intel-cpu, 8-cpu, ci ] + container: + image: ${{ github.event.inputs.docker_image }} + options: --gpus all --privileged --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ + + steps: + - name: Validate test files input + id: validate_test_files + run: | + if [[ ! "${{ github.event.inputs.test }}" =~ ^[a-zA-Z0-9_/.-\ ]+$ ]]; then + echo "Invalid characters detected in test files input" + exit 1 + fi + echo ${{ github.event.inputs.test }} + + + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + ref: ${{ github.event.inputs.branch }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + + - name: Install pytest + run: | + python -m venv /opt/venv && export PATH="/opt/venv/bin:$PATH" + python -m uv pip install -e [quality,test] + python -m uv pip install peft + + - name: Run tests + run: | + pytest ${{ github.event.inputs.test }} \ No newline at end of file From ccb53eb9e6597887ef9bb4307905f13bb441121f Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Fri, 17 May 2024 16:27:05 +0530 Subject: [PATCH 2/5] make pytest more secure. --- .github/workflows/run_tests_from_a_pr.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run_tests_from_a_pr.yml b/.github/workflows/run_tests_from_a_pr.yml index 63f8499bb0e6..6267b6848fe5 100644 --- a/.github/workflows/run_tests_from_a_pr.yml +++ b/.github/workflows/run_tests_from_a_pr.yml @@ -56,5 +56,7 @@ jobs: python -m uv pip install peft - name: Run tests + env: + PY_TEST: ${{ github.event.inputs.test }} run: | - pytest ${{ github.event.inputs.test }} \ No newline at end of file + pytest $PY_TEST \ No newline at end of file From 9b534b113103f59fed5d758b11e32852a110c7ac Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Wed, 22 May 2024 13:03:16 +0530 Subject: [PATCH 3/5] address dhruv's comments. --- .github/workflows/run_tests_from_a_pr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_tests_from_a_pr.yml b/.github/workflows/run_tests_from_a_pr.yml index 6267b6848fe5..232a1188c58e 100644 --- a/.github/workflows/run_tests_from_a_pr.yml +++ b/.github/workflows/run_tests_from_a_pr.yml @@ -26,10 +26,10 @@ env: jobs: run_tests: name: "Run a test on our runner from a PR" - runs-on: [ self-hosted, intel-cpu, 8-cpu, ci ] + runs-on: [single-gpu, nvidia-gpu, t4, ci] container: image: ${{ github.event.inputs.docker_image }} - options: --gpus all --privileged --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ + options: --gpus 0 --privileged --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ steps: - name: Validate test files input From 51aeb35727ad84d7752c29699906c51121ba19a6 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Fri, 24 May 2024 06:42:53 +0530 Subject: [PATCH 4/5] improve validation check. --- .github/workflows/run_tests_from_a_pr.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_tests_from_a_pr.yml b/.github/workflows/run_tests_from_a_pr.yml index 232a1188c58e..5c95ee5d86b4 100644 --- a/.github/workflows/run_tests_from_a_pr.yml +++ b/.github/workflows/run_tests_from_a_pr.yml @@ -34,13 +34,24 @@ jobs: steps: - name: Validate test files input id: validate_test_files + env: + PY_TEST: ${{ github.event.inputs.test }} run: | - if [[ ! "${{ github.event.inputs.test }}" =~ ^[a-zA-Z0-9_/.-\ ]+$ ]]; then - echo "Invalid characters detected in test files input" + if [[ ! "$PY_TEST" =~ ^tests/ ]]; then + echo "Error: The input string must start with 'tests/'." exit 1 fi - echo ${{ github.event.inputs.test }} - + + if [[ ! "$PY_TEST" =~ ^tests/(models|pipelines) ]]; then + echo "Error: The input string must contain either 'models' or 'pipelines' after 'tests/'." + exit 1 + fi + + if [[ "$PY_TEST" == *";"* ]]; then + echo "Error: The input string must not contain ';'." + exit 1 + fi + echo "$PY_TEST" - name: Checkout PR branch uses: actions/checkout@v4 From 3fcfeefb8ff8508e02f9eb54ee5061fce76a9b32 Mon Sep 17 00:00:00 2001 From: Sayak Paul Date: Mon, 27 May 2024 13:35:02 +0530 Subject: [PATCH 5/5] Update .github/workflows/run_tests_from_a_pr.yml Co-authored-by: Dhruv Nair --- .github/workflows/run_tests_from_a_pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests_from_a_pr.yml b/.github/workflows/run_tests_from_a_pr.yml index 5c95ee5d86b4..782c0db417ff 100644 --- a/.github/workflows/run_tests_from_a_pr.yml +++ b/.github/workflows/run_tests_from_a_pr.yml @@ -70,4 +70,4 @@ jobs: env: PY_TEST: ${{ github.event.inputs.test }} run: | - pytest $PY_TEST \ No newline at end of file + pytest "$PY_TEST" \ No newline at end of file