Skip to content

Commit 11133dc

Browse files
Initialize CI for code quality and testing (#256)
* Init CI * clarify cpu * style * Check scripts quality too * Drop smi for cpu tests * Run PR tests on cpu docker envs * Update .github/workflows/push_tests.yml Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> * Try minimal python container * Print env, install stable GPU torch * Manual torch install * remove deprecated platform.dist() Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com>
1 parent bb4d605 commit 11133dc

File tree

7 files changed

+174
-40
lines changed

7 files changed

+174
-40
lines changed

.github/workflows/pr_quality.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Run code quality checks
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
check_code_quality:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.7"
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install .[quality]
24+
- name: Check quality
25+
run: |
26+
black --check --preview examples tests src utils scripts
27+
isort --check-only examples tests src utils scripts
28+
flake8 examples tests src utils scripts
29+
doc-builder style src/diffusers docs/source --max_len 119 --check_only --path_to_docs docs/source

.github/workflows/pr_tests.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run non-slow tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
env:
9+
HF_HOME: /mnt/cache
10+
OMP_NUM_THREADS: 8
11+
MKL_NUM_THREADS: 8
12+
PYTEST_TIMEOUT: 60
13+
14+
jobs:
15+
run_tests_cpu:
16+
name: Diffusers tests
17+
runs-on: [ self-hosted, docker-gpu ]
18+
container:
19+
image: python:3.7
20+
options: --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
21+
22+
steps:
23+
- name: Checkout diffusers
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 2
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cpu
32+
python -m pip install -e .[quality,test]
33+
34+
- name: Environment
35+
run: |
36+
python utils/print_env.py
37+
38+
- name: Run all non-slow selected tests on CPU
39+
run: |
40+
python -m pytest -n 2 --max-worker-restart=0 --dist=loadfile -s tests/

.github/workflows/push_tests.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Run all tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
env:
9+
HF_HOME: /mnt/cache
10+
OMP_NUM_THREADS: 8
11+
MKL_NUM_THREADS: 8
12+
PYTEST_TIMEOUT: 1000
13+
RUN_SLOW: yes
14+
15+
jobs:
16+
run_tests_single_gpu:
17+
name: Diffusers tests
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
machine_type: [ single-gpu ]
22+
runs-on: [ self-hosted, docker-gpu, '${{ matrix.machine_type }}' ]
23+
container:
24+
image: nvcr.io/nvidia/pytorch:22.07-py3
25+
options: --gpus 0 --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
26+
27+
steps:
28+
- name: Checkout diffusers
29+
uses: actions/checkout@v3
30+
with:
31+
fetch-depth: 2
32+
33+
- name: NVIDIA-SMI
34+
run: |
35+
nvidia-smi
36+
37+
- name: Install dependencies
38+
run: |
39+
python -m pip install --upgrade pip
40+
python -m pip uninstall -y torch torchvision torchtext
41+
python -m pip install torch --extra-index-url https://download.pytorch.org/whl/cu116
42+
python -m pip install -e .[quality,test]
43+
python -m pip install scipy transformers
44+
45+
- name: Environment
46+
run: |
47+
python utils/print_env.py
48+
49+
- name: Run all (incl. slow) tests on GPU
50+
run: |
51+
python -m pytest -n 2 --max-worker-restart=0 --dist=loadfile -s tests/

.github/workflows/test.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
"modelcards==0.1.4",
9090
"numpy",
9191
"pytest",
92+
"pytest-timeout",
93+
"pytest-xdist",
9294
"regex!=2019.12.17",
9395
"requests",
9496
"tensorboard",
@@ -163,10 +165,10 @@ def run(self):
163165

164166

165167
extras = {}
166-
extras["quality"] = ["black==22.3", "isort >= 5.5.4", "flake8 >= 3.8.3"]
168+
extras["quality"] = ["black==22.3", "isort>=5.5.4", "flake8>=3.8.3", "hf-doc-builder"]
167169
extras["docs"] = ["hf-doc-builder"]
168170
extras["training"] = ["accelerate", "datasets", "tensorboard", "modelcards"]
169-
extras["test"] = ["pytest"]
171+
extras["test"] = ["pytest", "pytest-timeout", "pytest-xdist"]
170172
extras["dev"] = extras["quality"] + extras["test"] + extras["training"] + extras["docs"]
171173

172174
install_requires = [

src/diffusers/dependency_versions_table.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"modelcards": "modelcards==0.1.4",
1616
"numpy": "numpy",
1717
"pytest": "pytest",
18+
"pytest-timeout": "pytest-timeout",
19+
"pytest-xdist": "pytest-xdist",
1820
"regex": "regex!=2019.12.17",
1921
"requests": "requests",
2022
"tensorboard": "tensorboard",

utils/print_env.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
3+
# coding=utf-8
4+
# Copyright 2022 The HuggingFace Inc. team.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# this script dumps information about the environment
19+
20+
import os
21+
import platform
22+
import sys
23+
24+
25+
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
26+
27+
print("Python version:", sys.version)
28+
29+
print("OS platform:", platform.platform())
30+
print("OS architecture:", platform.machine())
31+
32+
try:
33+
import torch
34+
35+
print("Torch version:", torch.__version__)
36+
print("Cuda available:", torch.cuda.is_available())
37+
print("Cuda version:", torch.version.cuda)
38+
print("CuDNN version:", torch.backends.cudnn.version())
39+
print("Number of GPUs available:", torch.cuda.device_count())
40+
except ImportError:
41+
print("Torch version:", None)
42+
43+
try:
44+
import transformers
45+
46+
print("transformers version:", transformers.__version__)
47+
except ImportError:
48+
print("transformers version:", None)

0 commit comments

Comments
 (0)