Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run tests with pytest, not bash #216

Merged
merged 13 commits into from
Aug 31, 2021
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
name: Run Pytorch scripts
command: ./scripts/run_pytorch.sh
no_output_timeout: 1h
- store_test_results:
path: test-results


workflows:
version: 2
Expand Down
2 changes: 2 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ conda install -y pytorch torchvision -c pytorch
# Also install torchaudio
conda install -y -c pytorch torchaudio

conda install -y pytest

# Dependencies required to load models
conda install -y regex pillow tqdm boto3 requests numpy\
h5py scipy matplotlib unidecode ipython pyyaml
Expand Down
42 changes: 15 additions & 27 deletions scripts/run_pytorch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,21 @@ set -e
. ~/miniconda3/etc/profile.d/conda.sh
conda activate base

ALL_FILE=$(find *.md ! -name README.md)
TEMP_PY="temp.py"
CUDAS="nvidia"
ALL_FILES=$(find *.md ! -name README.md)
PYTHON_CODE_DIR="python_code"

for f in $ALL_FILE
do
echo "Running pytorch example in $f"
# FIXME: NVIDIA models checkoints are on cuda
if [[ $f = $CUDAS* ]]; then
echo "...skipped due to cuda checkpoints."
elif [[ $f = "pytorch_fairseq_translation"* ]]; then
echo "...temporarily disabled"
# FIXME: torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse'
elif [[ $f = "ultralytics_yolov5"* ]]; then
echo "...temporarily disabled"
elif [[ $f = "huggingface_pytorch-transformers"* ]]; then
echo "...temporarily disabled"
# FIXME: TypeError: compose() got an unexpected keyword argument 'strict'
elif [[ $f = "pytorch_fairseq_roberta"* ]]; then
echo "...temporarily disabled"
# FIXME: rate limiting
else
sed -n '/^```python/,/^```/ p' < $f | sed '/^```/ d' > $TEMP_PY
python $TEMP_PY
mkdir $PYTHON_CODE_DIR

if [ -f "$TEMP_PY" ]; then
rm $TEMP_PY
fi
fi
# Quick rundown: for each file we extract the python code that's within
# the ``` markers and we put that code in a corresponding .py file in $PYTHON_CODE_DIR
# Then we execute each of these python files with pytest in test_run_python_code.py
for f in $ALL_FILES
do
f_no_ext=${f%.md} # remove .md extension
out_py=$PYTHON_CODE_DIR/$f_no_ext.py
echo "Extracting Python code from $f into $out_py"
sed -n '/^```python/,/^```/ p' < $f | sed '/^```/ d' > $out_py
done

pytest -v -s test_run_python_code.py
rm -r $PYTHON_CODE_DIR
24 changes: 24 additions & 0 deletions test_run_python_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
import glob


ALL_FILES = glob.glob("python_code/*.py")


@pytest.mark.parametrize('file_path', ALL_FILES)
def test_run_file(file_path):
if 'nvidia' in file_path:
# FIXME: NVIDIA models checkoints are on cuda
pytest.skip("temporarily disabled")
if 'pytorch_fairseq_translation' in file_path:
pytest.skip("temporarily disabled")
if 'ultralytics_yolov5' in file_path:
# FIXME torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse
pytest.skip("temporarily disabled")
if 'huggingface_pytorch-transformers' in file_path:
# FIXME torch.nn.modules.module.ModuleAttributeError: 'autoShape' object has no attribute 'fuse
pytest.skip("temporarily disabled")
if 'pytorch_fairseq_roberta' in file_path:
pytest.skip("temporarily disabled")

exec(open(file_path).read())