Skip to content

Fixed install_deps so that it happens before each test run + checking for the deps that are required separately #1323

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/main_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
# pip install --pre torch torchvision -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
- name: Run Tests
run: |
./run_python_examples.sh "install_deps,run_all,clean"
./run_python_examples.sh "run_all,clean"
- name: Open issue on failure
if: ${{ failure() && github.event_name == 'schedule' }}
uses: rishabhgupta/git-action-issue@v2
Expand Down
11 changes: 5 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ If you're new, we encourage you to take a look at issues tagged with [good first
## For bug fixes

1. Fork the repo and create your branch from `main`.
2. Make sure you have a GPU-enabled machine, either locally or in the cloud. `g4dn.4xlarge` is a good starting point on AWS.
3. Make your code change.
4. First, install all dependencies with `./run_python_examples.sh "install_deps"`.
5. Then, make sure that `./run_python_examples.sh` passes locally by running the script end to end.
6. If you haven't already, complete the Contributor License Agreement ("CLA").
7. Address any feedback in code review promptly.
1. Make sure you have a GPU-enabled machine, either locally or in the cloud. `g4dn.4xlarge` is a good starting point on AWS.
1. Make your code change.
1. Then, make sure that `./run_python_examples.sh` passes locally by running the script end to end.
1. If you haven't already, complete the Contributor License Agreement ("CLA").
1. Address any feedback in code review promptly.

## Contributor License Agreement ("CLA")

Expand Down
4 changes: 2 additions & 2 deletions run_distributed_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#
# Optionally specify a comma separated list of examples to run.
# can be run as:
# ./run_python_examples.sh "install_deps,run_all,clean"
# to pip install dependencies (other than pytorch), run all examples, and remove temporary/changed data files.
# ./run_python_examples.sh "run_all,clean"
# run all examples, and remove temporary/changed data files.
# Expects pytorch, torchvision to be installed.

BASE_DIR="$(pwd)/$(dirname $0)"
Expand Down
30 changes: 28 additions & 2 deletions run_python_examples.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,42 @@
#!/usr/bin/env bash
set -eo pipefail
DEBUG=${DEBUG:-false}
[[ $DEBUG == true ]] && set -x
#
# This script runs through the code in each of the python examples.
# The purpose is just as an integration test, not to actually train models in any meaningful way.
# For that reason, most of these set epochs = 1 and --dry-run.
#
# Optionally specify a comma separated list of examples to run.
# can be run as:
# ./run_python_examples.sh "install_deps,run_all,clean"
# to pip install dependencies (other than pytorch), run all examples, and remove temporary/changed data files.
# ./run_python_examples.sh "run_all,clean"
# run all examples, and remove temporary/changed data files.
# Expects pytorch, torchvision to be installed.

BASE_DIR="$(pwd)/$(dirname $0)"
source $BASE_DIR/utils.sh

echo "] Running Python examples"
# Check if required packages are installed
echo "Checking for required packages..."
if ! pip show torch; then
echo "torch is not installed. Please install PyTorch."
exit 1
fi

if ! pip show torchvision; then
echo "torchvision is not installed. Please install torchvision."
exit 1
fi

if ! pip show pillow; then
echo "Pillow is not installed. Please install Pillow."
exit 1
fi

echo "All required packages are installed!"

echo "Checking CUDA availability"
USE_CUDA=$(python -c "import torchvision, torch; print(torch.cuda.is_available())")
case $USE_CUDA in
"True")
Expand Down Expand Up @@ -215,9 +239,11 @@ if [ "" == "$EXAMPLES" ]; then
else
for i in $(echo $EXAMPLES | sed "s/,/ /g")
do
echo "==============="
echo "Starting $i"
$i
echo "Finished $i, status $?"
echo "==============="
done
fi

Expand Down
21 changes: 12 additions & 9 deletions utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ function error() {
}

function install_deps() {
echo "installing requirements"
cat $BASE_DIR/*/requirements.txt | \
sort -u | \
EXAMPLE_NAME=$1
echo "] $EXAMPLE_NAME: installing requirements"
[[ -f requirements.txt ]] || return
for req in $(cat requirements.txt); do
# testing the installed version of torch, so don't pip install it.
grep -vE '^torch$' | \
pip install -r /dev/stdin || \
{ error "failed to install dependencies"; exit 1; }
if [[ "$req" != "torch" ]]; then
pip install "$req" || { error "failed to install $req"; exit 1; }
fi
done
}

function start() {
EXAMPLE=${FUNCNAME[1]}
cd $BASE_DIR/$EXAMPLE
echo "Running example: $EXAMPLE"
EXAMPLE_NAME=${FUNCNAME[1]}
cd $BASE_DIR/$EXAMPLE_NAME
install_deps $EXAMPLE_NAME
echo "] $EXAMPLE_NAME: running"
}