Skip to content

Commit 87eff97

Browse files
committed
Add unittest to CI
1 parent cd2b7f0 commit 87eff97

File tree

16 files changed

+699
-134
lines changed

16 files changed

+699
-134
lines changed

.circleci/config.yml

Lines changed: 282 additions & 87 deletions
Large diffs are not rendered by default.

.circleci/config.yml.in

Lines changed: 159 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -225,36 +225,6 @@ jobs:
225225
docker run --gpus all --ipc=host -v $(pwd):/remote -w /remote ${VARS_TO_PASS} ${DOCKER_IMAGE} ./packaging/build_conda.sh
226226

227227
binary_win_conda:
228-
<<: *binary_common
229-
executor: windows-cpu
230-
steps:
231-
- checkout_merge
232-
- run:
233-
command: |
234-
set -ex
235-
source packaging/windows/internal/vc_install_helper.sh
236-
eval "$('/C/tools/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
237-
conda activate base
238-
conda install -yq conda-build "conda-package-handling!=1.5.0"
239-
packaging/build_conda.sh
240-
- store_test_results:
241-
path: build_results/
242-
243-
binary_win_conda_cuda:
244-
<<: *binary_common
245-
executor: windows-gpu
246-
steps:
247-
- checkout_merge
248-
- run:
249-
command: |
250-
set -ex
251-
source packaging/windows/internal/vc_install_helper.sh
252-
eval "$('/C/tools/miniconda3/Scripts/conda.exe' 'shell.bash' 'hook')"
253-
conda activate base
254-
conda install -yq conda-build "conda-package-handling!=1.5.0"
255-
packaging/build_conda.sh
256-
257-
binary_win_conda_release:
258228
<<: *binary_common
259229
executor: windows-cpu
260230
steps:
@@ -279,7 +249,7 @@ jobs:
279249
- store_test_results:
280250
path: build_results/
281251

282-
binary_win_wheel_release:
252+
binary_win_wheel:
283253
<<: *binary_common
284254
executor: windows-cpu
285255
steps:
@@ -385,34 +355,182 @@ jobs:
385355
aws s3 cp "$pkg" "s3://pytorch/whl/${UPLOAD_CHANNEL}/<< parameters.subfolder >>" --acl public-read
386356
done
387357

358+
unittest_linux_cpu:
359+
<<: *binary_common
360+
docker:
361+
- image: "pytorch/manylinux-cuda102"
362+
resource_class: 2xlarge+
363+
steps:
364+
- checkout
365+
- run:
366+
name: Generate cache key
367+
# This will refresh cache on Sundays, nightly build should generate new cache.
368+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
369+
- restore_cache:
370+
{% raw %}
371+
keys:
372+
- env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
373+
{% endraw %}
374+
- run:
375+
name: Setup
376+
command: .circleci/unittest/linux/scripts/setup_env.sh
377+
- save_cache:
378+
{% raw %}
379+
key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
380+
{% endraw %}
381+
paths:
382+
- conda
383+
- env
384+
- run:
385+
name: Install torchvision
386+
command: .circleci/unittest/linux/scripts/install.sh
387+
- run:
388+
name: Run tests
389+
command: .circleci/unittest/linux/scripts/run_test.sh
390+
- run:
391+
name: Post process
392+
command: .circleci/unittest/linux/scripts/post_process.sh
393+
- store_test_results:
394+
path: test-results
395+
396+
unittest_linux_gpu:
397+
<<: *binary_common
398+
machine:
399+
image: ubuntu-1604-cuda-10.1:201909-23
400+
resource_class: gpu.small
401+
environment:
402+
image_name: "pytorch/manylinux-cuda101"
403+
steps:
404+
- checkout
405+
- run:
406+
name: Generate cache key
407+
# This will refresh cache on Sundays, nightly build should generate new cache.
408+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
409+
- restore_cache:
410+
{% raw %}
411+
keys:
412+
- env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
413+
{% endraw %}
414+
- run:
415+
name: Setup
416+
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/setup_env.sh
417+
- save_cache:
418+
{% raw %}
419+
key: env-v2-linux-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/linux/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
420+
{% endraw %}
421+
paths:
422+
- conda
423+
- env
424+
- run:
425+
name: Install torchvision
426+
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/install.sh
427+
- run:
428+
name: Run tests
429+
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/run_test.sh
430+
- run:
431+
name: Post Process
432+
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/post_process.sh
433+
- store_test_results:
434+
path: test-results
435+
436+
unittest_windows_cpu:
437+
<<: *binary_common
438+
executor:
439+
name: windows-cpu
440+
steps:
441+
- checkout
442+
- run:
443+
name: Generate cache key
444+
# This will refresh cache on Sundays, nightly build should generate new cache.
445+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
446+
- restore_cache:
447+
{% raw %}
448+
keys:
449+
- env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
450+
{% endraw %}
451+
- run:
452+
name: Setup
453+
command: .circleci/unittest/windows/scripts/setup_env.sh
454+
- save_cache:
455+
{% raw %}
456+
key: env-v2-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
457+
{% endraw %}
458+
paths:
459+
- conda
460+
- env
461+
- run:
462+
name: Install torchvision
463+
command: .circleci/unittest/windows/scripts/install.sh
464+
- run:
465+
name: Run tests
466+
command: .circleci/unittest/windows/scripts/run_test.sh
467+
- run:
468+
name: Post process
469+
command: .circleci/unittest/windows/scripts/post_process.sh
470+
- store_test_results:
471+
path: test-results
472+
473+
unittest_windows_gpu:
474+
<<: *binary_common
475+
executor:
476+
name: windows-gpu
477+
environment:
478+
CUDA_VERSION: "10.1"
479+
steps:
480+
- checkout
481+
- run:
482+
name: Generate cache key
483+
# This will refresh cache on Sundays, nightly build should generate new cache.
484+
command: echo "$(date +"%Y-%U")" > .circleci-weekly
485+
- restore_cache:
486+
{% raw %}
487+
keys:
488+
- env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
489+
{% endraw %}
490+
- run:
491+
name: Setup
492+
command: .circleci/unittest/windows/scripts/setup_env.sh
493+
- save_cache:
494+
{% raw %}
495+
key: env-v1-windows-{{ arch }}-py<< parameters.python_version >>-{{ checksum ".circleci/unittest/windows/scripts/environment.yml" }}-{{ checksum ".circleci-weekly" }}
496+
{% endraw %}
497+
paths:
498+
- conda
499+
- env
500+
- run:
501+
name: Install torchvision
502+
command: .circleci/unittest/windows/scripts/install.sh
503+
- run:
504+
name: Run tests
505+
command: .circleci/unittest/windows/scripts/run_test.sh
506+
- run:
507+
name: Post process
508+
command: .circleci/unittest/windows/scripts/post_process.sh
509+
- store_test_results:
510+
path: test-results
388511

389512
workflows:
390513
build:
391514
{%- if True %}
392515
jobs:
393516
- circleci_consistency
394-
{{ workflows(windows_latest_only=True) }}
517+
{{ build_workflows(windows_latest_only=True) }}
395518
- binary_linux_conda_cuda:
396519
name: torchvision_linux_py3.8_cu102_cuda
397520
python_version: "3.8"
398521
cu_version: "cu102"
399-
- binary_win_conda:
400-
name: torchvision_win_py3.6_cpu
401-
python_version: "3.6"
402-
cu_version: "cpu"
403-
- binary_win_conda_cuda:
404-
name: torchvision_win_py3.6_cu101
405-
python_version: "3.6"
406-
cu_version: "cu101"
407522
- python_lint
408523
- python_type_check
409524
- clang_format
410525

526+
unittest:
527+
jobs:
528+
{{ unittest_workflows() }}
411529
nightly:
412530
{%- endif %}
413531
jobs:
414532
- circleci_consistency
415533
- python_lint
416534
- python_type_check
417535
- clang_format
418-
{{ workflows(prefix="nightly_", filter_branch="nightly", upload=True) }}
536+
{{ build_workflows(prefix="nightly_", filter_branch="nightly", upload=True) }}

.circleci/regenerate.py

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
import os.path
2020

2121

22-
def workflows(prefix='', filter_branch=None, upload=False, indentation=6, windows_latest_only=False):
22+
PYTHON_VERSIONS = ["3.6", "3.7", "3.8"]
23+
24+
25+
def build_workflows(prefix='', filter_branch=None, upload=False, indentation=6, windows_latest_only=False):
2326
w = []
2427
for btype in ["wheel", "conda"]:
2528
for os_type in ["linux", "macos", "win"]:
26-
python_versions = ["3.6", "3.7", "3.8"]
29+
python_versions = PYTHON_VERSIONS
2730
cu_versions = (["cpu", "cu92", "cu101", "cu102"] if os_type == "linux" or os_type == "win" else ["cpu"])
2831
for python_version in python_versions:
2932
for cu_version in cu_versions:
@@ -88,10 +91,14 @@ def generate_base_workflow(base_workflow_name, python_version, cu_version,
8891
if filter_branch is not None:
8992
d["filters"] = {"branches": {"only": filter_branch}}
9093

91-
w = f"binary_{os_type}_{btype}_release" if os_type == "win" else f"binary_{os_type}_{btype}"
94+
w = f"binary_{os_type}_{btype}"
9295
return {w: d}
9396

9497

98+
def gen_filter_branch_tree(*branches):
99+
return {"branches": {"only": [b for b in branches]}}
100+
101+
95102
def generate_upload_workflow(base_workflow_name, os_type, btype, cu_version, *, filter_branch=None):
96103
d = {
97104
"name": f"{base_workflow_name}_upload",
@@ -122,6 +129,27 @@ def indent(indentation, data_list):
122129
yaml.dump(data_list, default_flow_style=False).splitlines())
123130

124131

132+
def unittest_workflows(indentation=6):
133+
jobs = []
134+
for os_type in ["linux", "windows"]:
135+
for device_type in ["cpu", "gpu"]:
136+
for i, python_version in enumerate(PYTHON_VERSIONS):
137+
job = {
138+
"name": f"unittest_{os_type}_{device_type}_py{python_version}",
139+
"python_version": python_version,
140+
}
141+
142+
if device_type == 'gpu':
143+
job['filters'] = gen_filter_branch_tree('master', 'nightly')
144+
job['cu_version'] = 'cu101'
145+
else:
146+
job['cu_version'] = 'cpu'
147+
148+
jobs.append({f"unittest_{os_type}_{device_type}": job})
149+
150+
return indent(indentation, jobs)
151+
152+
125153
if __name__ == "__main__":
126154
d = os.path.dirname(__file__)
127155
env = jinja2.Environment(
@@ -131,4 +159,7 @@ def indent(indentation, data_list):
131159
)
132160

133161
with open(os.path.join(d, 'config.yml'), 'w') as f:
134-
f.write(env.get_template('config.yml.in').render(workflows=workflows))
162+
f.write(env.get_template('config.yml.in').render(
163+
build_workflows=build_workflows,
164+
unittest_workflows=unittest_workflows,
165+
))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
channels:
2+
- defaults
3+
dependencies:
4+
- numpy
5+
- pytest
6+
- pytest-cov
7+
- codecov
8+
- pip
9+
- ca-certificates
10+
- pip:
11+
- future
12+
- pillow>=4.1.1
13+
- scipy
14+
- av
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
unset PYTORCH_VERSION
4+
# For unittest, nightly PyTorch is used as the following section,
5+
# so no need to set PYTORCH_VERSION.
6+
# In fact, keeping PYTORCH_VERSION forces us to hardcode PyTorch version in config.
7+
8+
set -e
9+
10+
eval "$(./conda/bin/conda shell.bash hook)"
11+
conda activate ./env
12+
13+
if [ -z "${CUDA_VERSION:-}" ] ; then
14+
cudatoolkit="cpuonly"
15+
else
16+
version="$(python -c "print('.'.join(\"${CUDA_VERSION}\".split('.')[:2]))")"
17+
cudatoolkit="cudatoolkit=${version}"
18+
fi
19+
printf "Installing PyTorch with %s\n" "${cudatoolkit}"
20+
conda install -y -c pytorch-nightly pytorch "${cudatoolkit}"
21+
22+
printf "* Installing torchvision\n"
23+
python setup.py develop
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
eval "$(./conda/bin/conda shell.bash hook)"
6+
conda activate ./env
7+
8+
codecov
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
eval "$(./conda/bin/conda shell.bash hook)"
6+
conda activate ./env
7+
8+
python -m torch.utils.collect_env
9+
pytest --cov=torchvision --junitxml=test-results/junit.xml -v --durations 20 test

0 commit comments

Comments
 (0)