2021-03-26 17:04:59 +00:00
|
|
|
#!/bin/bash
|
2020-12-07 12:55:49 +00:00
|
|
|
# Copyright The PyTorch Lightning team.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2021-01-05 10:01:59 +00:00
|
|
|
set -e
|
2022-06-15 22:10:49 +00:00
|
|
|
# THIS FILE ASSUMES IT IS RUN INSIDE THE tests/tests_pytorch DIRECTORY
|
2021-03-26 17:04:59 +00:00
|
|
|
|
|
|
|
# this environment variable allows special tests to run
|
2021-11-26 17:13:14 +00:00
|
|
|
export PL_RUN_STANDALONE_TESTS=1
|
2021-03-26 17:04:59 +00:00
|
|
|
# python arguments
|
2021-11-17 15:46:14 +00:00
|
|
|
defaults='-m coverage run --source pytorch_lightning --append -m pytest --capture=no'
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2021-11-26 17:13:14 +00:00
|
|
|
# find tests marked as `@RunIf(standalone=True)`. done manually instead of with pytest because it is faster
|
2022-07-15 11:51:23 +00:00
|
|
|
grep_output=$(grep --recursive --word-regexp . --regexp 'standalone=True' --include '*.py')
|
2021-11-17 15:46:14 +00:00
|
|
|
|
|
|
|
# file paths, remove duplicates
|
|
|
|
files=$(echo "$grep_output" | cut -f1 -d: | sort | uniq)
|
|
|
|
|
|
|
|
# get the list of parametrizations. we need to call them separately. the last two lines are removed.
|
|
|
|
# note: if there's a syntax error, this will fail with some garbled output
|
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
2022-05-30 22:14:33 +00:00
|
|
|
parametrizations=$(python -m pytest $files --collect-only --quiet "$@" | tail -r | sed -e '1,3d' | tail -r)
|
2021-11-17 15:46:14 +00:00
|
|
|
else
|
2022-05-30 22:14:33 +00:00
|
|
|
parametrizations=$(python -m pytest $files --collect-only --quiet "$@" | head -n -2)
|
2021-11-17 15:46:14 +00:00
|
|
|
fi
|
2022-06-15 22:10:49 +00:00
|
|
|
# remove the "tests/tests_pytorch" path suffixes
|
|
|
|
parametrizations=${parametrizations//"tests/tests_pytorch/"/}
|
2021-11-17 15:46:14 +00:00
|
|
|
parametrizations_arr=($parametrizations)
|
2021-03-26 17:04:59 +00:00
|
|
|
|
|
|
|
# tests to skip - space separated
|
2022-06-22 14:36:31 +00:00
|
|
|
blocklist='profilers/test_profiler.py::test_pytorch_profiler_nested_emit_nvtx utilities/test_warnings.py'
|
2021-03-26 17:04:59 +00:00
|
|
|
report=''
|
|
|
|
|
2021-11-17 15:46:14 +00:00
|
|
|
for i in "${!parametrizations_arr[@]}"; do
|
|
|
|
parametrization=${parametrizations_arr[$i]}
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2021-11-17 15:46:14 +00:00
|
|
|
# check blocklist
|
|
|
|
if echo $blocklist | grep -F "${parametrization}"; then
|
|
|
|
report+="Skipped\t$parametrization\n"
|
|
|
|
continue
|
|
|
|
fi
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2021-11-17 15:46:14 +00:00
|
|
|
# run the test
|
2022-06-15 22:10:49 +00:00
|
|
|
echo "Running $parametrization"
|
|
|
|
python ${defaults} "$parametrization"
|
2021-03-30 17:39:02 +00:00
|
|
|
|
2021-11-17 15:46:14 +00:00
|
|
|
report+="Ran\t$parametrization\n"
|
2021-03-26 17:04:59 +00:00
|
|
|
done
|
|
|
|
|
2021-06-04 17:53:09 +00:00
|
|
|
if nvcc --version; then
|
2022-06-22 14:36:31 +00:00
|
|
|
nvprof --profile-from-start off -o trace_name.prof -- python ${defaults} profilers/test_profiler.py::test_pytorch_profiler_nested_emit_nvtx
|
2021-06-04 17:53:09 +00:00
|
|
|
fi
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2021-06-21 16:51:53 +00:00
|
|
|
# needs to run outside of `pytest`
|
2022-06-15 22:10:49 +00:00
|
|
|
python utilities/test_warnings.py
|
2021-06-21 16:51:53 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
2022-06-15 22:10:49 +00:00
|
|
|
report+="Ran\tutilities/test_warnings.py\n"
|
2021-06-21 16:51:53 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-02 19:48:43 +00:00
|
|
|
# test deadlock is properly handled with TorchElastic.
|
2022-06-15 22:10:49 +00:00
|
|
|
LOGS=$(PL_RUN_STANDALONE_TESTS=1 PL_RECONCILE_PROCESS=1 python -m torch.distributed.run --nproc_per_node=2 --max_restarts 0 -m coverage run --source pytorch_lightning -a plugins/environments/torch_elastic_deadlock.py | grep "SUCCEEDED")
|
2022-06-15 00:46:44 +00:00
|
|
|
if [ -z "$LOGS" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-06-15 22:10:49 +00:00
|
|
|
report+="Ran\tplugins/environments/torch_elastic_deadlock.py\n"
|
2021-08-02 19:48:43 +00:00
|
|
|
|
2021-07-14 11:25:36 +00:00
|
|
|
# test that a user can manually launch individual processes
|
2021-11-19 14:38:42 +00:00
|
|
|
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
|
2021-11-02 08:04:29 +00:00
|
|
|
args="--trainer.gpus 2 --trainer.strategy ddp --trainer.max_epochs=1 --trainer.limit_train_batches=1 --trainer.limit_val_batches=1 --trainer.limit_test_batches=1"
|
2022-06-15 22:10:49 +00:00
|
|
|
MASTER_ADDR="localhost" MASTER_PORT=1234 LOCAL_RANK=1 python ../../examples/convert_from_pt_to_pl/image_classifier_5_lightning_datamodule.py ${args} &
|
|
|
|
MASTER_ADDR="localhost" MASTER_PORT=1234 LOCAL_RANK=0 python ../../examples/convert_from_pt_to_pl/image_classifier_5_lightning_datamodule.py ${args}
|
2021-07-14 11:25:36 +00:00
|
|
|
report+="Ran\tmanual ddp launch test\n"
|
|
|
|
|
2021-03-26 17:04:59 +00:00
|
|
|
# echo test report
|
|
|
|
printf '=%.s' {1..80}
|
|
|
|
printf "\n$report"
|
|
|
|
printf '=%.s' {1..80}
|
|
|
|
printf '\n'
|