2021-03-26 17:04:59 +00:00
|
|
|
#!/bin/bash
|
2020-12-07 12:55:49 +00:00
|
|
|
# Copyright The Lightning AI 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-09-01 22:13:12 +00:00
|
|
|
# THIS FILE ASSUMES IT IS RUN INSIDE THE tests/tests_<package> DIRECTORY
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2022-07-27 12:36:22 +00:00
|
|
|
# Batch size for testing: Determines how many standalone test invocations run in parallel
|
2022-07-28 23:33:22 +00:00
|
|
|
# It can be set through the env variable PL_STANDALONE_TESTS_BATCH_SIZE and defaults to 6 if not set
|
|
|
|
test_batch_size="${PL_STANDALONE_TESTS_BATCH_SIZE:-6}"
|
2023-02-02 10:06:45 +00:00
|
|
|
source="${PL_STANDALONE_TESTS_SOURCE:-"lightning.pytorch"}"
|
2022-07-27 12:36:22 +00:00
|
|
|
|
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
|
2022-11-05 03:29:38 +00:00
|
|
|
defaults="-m coverage run --source $source --append -m pytest --no-header -v -s"
|
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-09-04 18:57:28 +00:00
|
|
|
# remove the "tests/tests_pytorch/" path suffixes
|
|
|
|
path_suffix=$(basename "$(dirname "$(pwd)")")/$(basename "$(pwd)")"/" # https://stackoverflow.com/a/8223345
|
|
|
|
parametrizations=${parametrizations//$path_suffix/}
|
2021-11-17 15:46:14 +00:00
|
|
|
parametrizations_arr=($parametrizations)
|
2021-03-26 17:04:59 +00:00
|
|
|
|
|
|
|
report=''
|
2022-07-18 12:10:35 +00:00
|
|
|
|
|
|
|
rm -f standalone_test_output.txt # in case it exists, remove it
|
|
|
|
function show_batched_output {
|
|
|
|
if [ -f standalone_test_output.txt ]; then # if exists
|
|
|
|
cat standalone_test_output.txt
|
2022-11-05 03:29:38 +00:00
|
|
|
# heuristic: stop if there's mentions of errors. this can prevent false negatives when only some of the ranks fail
|
2023-02-14 19:07:29 +00:00
|
|
|
if grep -iE 'error|exception|traceback|failed' standalone_test_output.txt | grep -qvE 'on_exception|xfailed'; then
|
2022-11-05 03:29:38 +00:00
|
|
|
echo "Potential error! Stopping."
|
|
|
|
rm standalone_test_output.txt
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-07-18 12:10:35 +00:00
|
|
|
rm standalone_test_output.txt
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
trap show_batched_output EXIT # show the output on exit
|
2021-03-26 17:04:59 +00:00
|
|
|
|
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
|
2022-09-29 14:01:59 +00:00
|
|
|
if [[ "${parametrization}" == *"test_pytorch_profiler_nested_emit_nvtx"* ]]; then
|
|
|
|
echo "Skipping $parametrization"
|
2021-11-17 15:46:14 +00:00
|
|
|
report+="Skipped\t$parametrization\n"
|
2022-07-18 12:10:35 +00:00
|
|
|
# do not continue the loop because we might need to wait for batched jobs
|
|
|
|
else
|
|
|
|
echo "Running $parametrization"
|
|
|
|
# execute the test in the background
|
|
|
|
# redirect to a log file that buffers test output. since the tests will run in the background, we cannot let them
|
|
|
|
# output to std{out,err} because the outputs would be garbled together
|
|
|
|
python ${defaults} "$parametrization" &>> standalone_test_output.txt &
|
|
|
|
# save the PID in an array
|
|
|
|
pids[${i}]=$!
|
|
|
|
# add row to the final report
|
|
|
|
report+="Ran\t$parametrization\n"
|
2021-11-17 15:46:14 +00:00
|
|
|
fi
|
2021-03-26 17:04:59 +00:00
|
|
|
|
2022-07-18 12:10:35 +00:00
|
|
|
if ((($i + 1) % $test_batch_size == 0)); then
|
|
|
|
# wait for running tests
|
|
|
|
for pid in ${pids[*]}; do wait $pid; done
|
|
|
|
unset pids # empty the array
|
|
|
|
show_batched_output
|
|
|
|
fi
|
2021-03-26 17:04:59 +00:00
|
|
|
done
|
2022-07-18 12:10:35 +00:00
|
|
|
# wait for leftover tests
|
|
|
|
for pid in ${pids[*]}; do wait $pid; done
|
|
|
|
show_batched_output
|
2021-07-14 11:25:36 +00:00
|
|
|
|
2021-03-26 17:04:59 +00:00
|
|
|
# echo test report
|
|
|
|
printf '=%.s' {1..80}
|
|
|
|
printf "\n$report"
|
|
|
|
printf '=%.s' {1..80}
|
|
|
|
printf '\n'
|