2020-03-04 20:05:36 -05:00
|
|
|
|
#!/usr/bin/env bash
|
2019-07-12 21:19:42 -04:00
|
|
|
|
#
|
|
|
|
|
|
# This script runs through the code in each of the python examples.
|
2022-01-20 23:19:54 +08:00
|
|
|
|
# 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.
|
2019-07-12 21:19:42 -04:00
|
|
|
|
#
|
|
|
|
|
|
# Optionally specify a comma separated list of examples to run.
|
|
|
|
|
|
# can be run as:
|
|
|
|
|
|
# ./run_python_examples.sh "install_deps,run_all,clean"
|
2022-01-20 23:19:54 +08:00
|
|
|
|
# to pip install dependencies (other than pytorch), run all examples, and remove temporary/changed data files.
|
2020-07-02 00:43:39 +03:00
|
|
|
|
# Expects pytorch, torchvision to be installed.
|
2019-07-12 21:19:42 -04:00
|
|
|
|
|
|
|
|
|
|
BASE_DIR=`pwd`"/"`dirname $0`
|
|
|
|
|
|
EXAMPLES=`echo $1 | sed -e 's/ //g'`
|
|
|
|
|
|
|
2020-07-02 00:43:39 +03:00
|
|
|
|
USE_CUDA=$(python -c "import torchvision, torch; print(torch.cuda.is_available())")
|
|
|
|
|
|
case $USE_CUDA in
|
|
|
|
|
|
"True")
|
|
|
|
|
|
echo "using cuda"
|
|
|
|
|
|
CUDA=1
|
|
|
|
|
|
CUDA_FLAG="--cuda"
|
|
|
|
|
|
;;
|
|
|
|
|
|
"False")
|
|
|
|
|
|
echo "not using cuda"
|
|
|
|
|
|
CUDA=0
|
|
|
|
|
|
CUDA_FLAG=""
|
|
|
|
|
|
;;
|
|
|
|
|
|
"")
|
|
|
|
|
|
exit 1;
|
|
|
|
|
|
;;
|
|
|
|
|
|
esac
|
2019-07-12 21:19:42 -04:00
|
|
|
|
|
|
|
|
|
|
ERRORS=""
|
|
|
|
|
|
|
|
|
|
|
|
function error() {
|
|
|
|
|
|
ERR=$1
|
|
|
|
|
|
ERRORS="$ERRORS\n$ERR"
|
|
|
|
|
|
echo $ERR
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function install_deps() {
|
|
|
|
|
|
echo "installing requirements"
|
|
|
|
|
|
cat $BASE_DIR/*/requirements.txt | \
|
|
|
|
|
|
sort -u | \
|
|
|
|
|
|
# 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; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function start() {
|
|
|
|
|
|
EXAMPLE=${FUNCNAME[1]}
|
|
|
|
|
|
cd $BASE_DIR/$EXAMPLE
|
|
|
|
|
|
echo "Running example: $EXAMPLE"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function dcgan() {
|
|
|
|
|
|
start
|
2022-09-20 16:18:33 -07:00
|
|
|
|
python main.py --dataset fake $CUDA_FLAG --mps --dry-run || error "dcgan failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-01 16:02:03 -07:00
|
|
|
|
function distributed() {
|
2022-12-02 17:57:37 -06:00
|
|
|
|
start
|
2023-05-10 18:14:07 +00:00
|
|
|
|
python tensor_parallelism/tensor_parallel_example.py || error "tensor parallel example failed"
|
|
|
|
|
|
python tensor_parallelism/sequence_parallel_example.py || error "sequence parallel example failed"
|
|
|
|
|
|
python tensor_parallelism/two_d_parallel_example.py || error "2D parallel example failed"
|
2022-12-02 17:57:37 -06:00
|
|
|
|
python ddp/main.py || error "ddp example failed"
|
2022-07-01 16:02:03 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-12 21:19:42 -04:00
|
|
|
|
function fast_neural_style() {
|
|
|
|
|
|
start
|
|
|
|
|
|
if [ ! -d "saved_models" ]; then
|
|
|
|
|
|
echo "downloading saved models for fast neural style"
|
|
|
|
|
|
python download_saved_models.py
|
|
|
|
|
|
fi
|
|
|
|
|
|
test -d "saved_models" || { error "saved models not found"; return; }
|
|
|
|
|
|
|
|
|
|
|
|
echo "running fast neural style model"
|
2022-09-20 16:18:33 -07:00
|
|
|
|
python neural_style/neural_style.py eval --content-image images/content-images/amber.jpg --model saved_models/candy.pth --output-image images/output-images/amber-candy.jpg --cuda $CUDA --mps || error "neural_style.py failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function imagenet() {
|
|
|
|
|
|
start
|
|
|
|
|
|
if [[ ! -d "sample/val" || ! -d "sample/train" ]]; then
|
|
|
|
|
|
mkdir -p sample/val/n
|
|
|
|
|
|
mkdir -p sample/train/n
|
2022-09-20 16:18:33 -07:00
|
|
|
|
curl -O "https://upload.wikimedia.org/wikipedia/commons/5/5a/Socks-clinton.jpg" || { error "couldn't download sample image for imagenet"; return; }
|
2019-07-12 21:19:42 -04:00
|
|
|
|
mv Socks-clinton.jpg sample/train/n
|
|
|
|
|
|
cp sample/train/n/* sample/val/n/
|
|
|
|
|
|
fi
|
|
|
|
|
|
python main.py --epochs 1 sample/ || error "imagenet example failed"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function mnist() {
|
|
|
|
|
|
start
|
2020-07-02 00:43:39 +03:00
|
|
|
|
python main.py --epochs 1 --dry-run || error "mnist example failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
2023-02-27 05:17:16 +05:30
|
|
|
|
function mnist_forward_forward() {
|
|
|
|
|
|
start
|
|
|
|
|
|
python main.py --epochs 1 --no_mps --no_cuda || error "mnist forward forward failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
|
2023-02-27 05:17:16 +05:30
|
|
|
|
}
|
2019-07-12 21:19:42 -04:00
|
|
|
|
function mnist_hogwild() {
|
|
|
|
|
|
start
|
2020-07-02 00:43:39 +03:00
|
|
|
|
python main.py --epochs 1 --dry-run $CUDA_FLAG || error "mnist hogwild failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-10-27 14:31:20 -07:00
|
|
|
|
function mnist_rnn() {
|
|
|
|
|
|
start
|
|
|
|
|
|
python main.py --epochs 1 --dry-run || error "mnist rnn example failed"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-12 21:19:42 -04:00
|
|
|
|
function regression() {
|
|
|
|
|
|
start
|
|
|
|
|
|
python main.py --epochs 1 $CUDA_FLAG || error "regression failed"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-07 19:10:31 -07:00
|
|
|
|
function siamese_network() {
|
|
|
|
|
|
start
|
|
|
|
|
|
python main.py --epochs 1 --dry-run || error "siamese network example failed"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-12 21:19:42 -04:00
|
|
|
|
function reinforcement_learning() {
|
|
|
|
|
|
start
|
2022-03-22 18:25:58 -04:00
|
|
|
|
python reinforce.py || error "reinforcement learning reinforce failed"
|
|
|
|
|
|
python actor_critic.py || error "reinforcement learning actor_critic failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function snli() {
|
|
|
|
|
|
start
|
|
|
|
|
|
echo "installing 'en' model if not installed"
|
|
|
|
|
|
python -m spacy download en || { error "couldn't download 'en' model needed for snli"; return; }
|
|
|
|
|
|
echo "training..."
|
2020-07-02 00:43:39 +03:00
|
|
|
|
python train.py --epochs 1 --dev_every 1 --no-bidirectional --dry-run || error "couldn't train snli"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-15 10:55:35 -07:00
|
|
|
|
function fx() {
|
|
|
|
|
|
start
|
2022-04-15 12:45:08 -07:00
|
|
|
|
# python custom_tracer.py || error "fx custom tracer has failed" UnboundLocalError: local variable 'tabulate' referenced before assignment
|
2022-04-15 10:55:35 -07:00
|
|
|
|
python invert.py || error "fx invert has failed"
|
|
|
|
|
|
python module_tracer.py || error "fx module tracer has failed"
|
|
|
|
|
|
python primitive_library.py || error "fx primitive library has failed"
|
|
|
|
|
|
python profiling_tracer.py || error "fx profiling tracer has failed"
|
|
|
|
|
|
python replace_op.py || error "fx replace op has failed"
|
|
|
|
|
|
python subgraph_rewriter_basic_use.py || error "fx subgraph has failed"
|
2022-04-15 12:45:08 -07:00
|
|
|
|
python wrap_output_dynamically.py || error "vmap output dynamically has failed"
|
2022-04-15 10:55:35 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-12 21:19:42 -04:00
|
|
|
|
function super_resolution() {
|
|
|
|
|
|
start
|
2022-09-20 16:18:33 -07:00
|
|
|
|
python main.py --upscale_factor 3 --batchSize 4 --testBatchSize 100 --nEpochs 1 --lr 0.001 --mps || error "super resolution failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-09 22:08:19 -07:00
|
|
|
|
function time_sequence_prediction() {
|
2019-07-12 21:19:42 -04:00
|
|
|
|
start
|
|
|
|
|
|
python generate_sine_wave.py || { error "generate sine wave failed"; return; }
|
2020-07-02 00:43:39 +03:00
|
|
|
|
python train.py --steps 2 || error "time sequence prediction training failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function vae() {
|
|
|
|
|
|
start
|
|
|
|
|
|
python main.py --epochs 1 || error "vae failed"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-04-26 21:24:13 +05:30
|
|
|
|
function vision_transformer() {
|
|
|
|
|
|
start
|
|
|
|
|
|
python main.py --epochs 1 --dry-run || error "vision transformer example failed"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-07-12 21:19:42 -04:00
|
|
|
|
function word_language_model() {
|
|
|
|
|
|
start
|
2022-09-20 16:18:33 -07:00
|
|
|
|
python main.py --epochs 1 --dry-run $CUDA_FLAG --mps || error "word_language_model failed"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function clean() {
|
|
|
|
|
|
cd $BASE_DIR
|
2020-07-05 18:20:41 +03:00
|
|
|
|
echo "running clean to remove cruft"
|
2022-08-23 17:06:15 -07:00
|
|
|
|
rm -rf dcgan/fake_samples_epoch_000.png \
|
|
|
|
|
|
dcgan/netD_epoch_0.pth \
|
|
|
|
|
|
dcgan/netG_epoch_0.pth \
|
2020-07-02 00:43:39 +03:00
|
|
|
|
dcgan/real_samples.png \
|
|
|
|
|
|
fast_neural_style/saved_models.zip \
|
|
|
|
|
|
fast_neural_style/saved_models/ \
|
|
|
|
|
|
imagenet/checkpoint.pth.tar \
|
|
|
|
|
|
imagenet/lsun/ \
|
|
|
|
|
|
imagenet/model_best.pth.tar \
|
|
|
|
|
|
imagenet/sample/ \
|
|
|
|
|
|
snli/.data/ \
|
|
|
|
|
|
snli/.vector_cache/ \
|
|
|
|
|
|
snli/results/ \
|
|
|
|
|
|
super_resolution/dataset/ \
|
|
|
|
|
|
super_resolution/model_epoch_1.pth \
|
|
|
|
|
|
time_sequence_prediction/predict*.pdf \
|
|
|
|
|
|
time_sequence_prediction/traindata.pt \
|
|
|
|
|
|
word_language_model/model.pt || error "couldn't clean up some files"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
|
|
|
|
|
|
git checkout fast_neural_style/images/output-images/amber-candy.jpg || error "couldn't clean up fast neural style image"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function run_all() {
|
2020-07-02 00:43:39 +03:00
|
|
|
|
# cpp
|
2019-07-12 21:19:42 -04:00
|
|
|
|
dcgan
|
2020-07-02 00:43:39 +03:00
|
|
|
|
# distributed
|
2019-07-12 21:19:42 -04:00
|
|
|
|
fast_neural_style
|
2022-07-01 16:02:03 -07:00
|
|
|
|
distributed
|
2019-07-12 21:19:42 -04:00
|
|
|
|
imagenet
|
|
|
|
|
|
mnist
|
2023-02-27 05:17:16 +05:30
|
|
|
|
mnist_forward_forward
|
2019-07-12 21:19:42 -04:00
|
|
|
|
mnist_hogwild
|
2022-10-27 14:31:20 -07:00
|
|
|
|
mnist_rnn
|
2019-07-12 21:19:42 -04:00
|
|
|
|
regression
|
|
|
|
|
|
reinforcement_learning
|
2022-05-07 19:10:31 -07:00
|
|
|
|
siamese_network
|
2019-07-12 21:19:42 -04:00
|
|
|
|
super_resolution
|
|
|
|
|
|
time_sequence_prediction
|
|
|
|
|
|
vae
|
2023-04-26 21:24:13 +05:30
|
|
|
|
vision_transformer
|
2019-07-12 21:19:42 -04:00
|
|
|
|
word_language_model
|
2022-04-15 10:55:35 -07:00
|
|
|
|
fx
|
2019-07-12 21:19:42 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# by default, run all examples
|
|
|
|
|
|
if [ "" == "$EXAMPLES" ]; then
|
|
|
|
|
|
run_all
|
|
|
|
|
|
else
|
|
|
|
|
|
for i in $(echo $EXAMPLES | sed "s/,/ /g")
|
|
|
|
|
|
do
|
2020-07-05 18:20:41 +03:00
|
|
|
|
echo "Starting $i"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
$i
|
2020-07-05 18:20:41 +03:00
|
|
|
|
echo "Finished $i, status $?"
|
2019-07-12 21:19:42 -04:00
|
|
|
|
done
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if [ "" == "$ERRORS" ]; then
|
2020-07-05 18:20:41 +03:00
|
|
|
|
echo "Completed successfully with status $?"
|
2020-03-04 20:05:36 -05:00
|
|
|
|
else
|
2019-07-12 21:19:42 -04:00
|
|
|
|
echo "Some examples failed:"
|
|
|
|
|
|
printf "$ERRORS"
|
2022-01-16 02:15:13 +02:00
|
|
|
|
#Exit with error (0-255) in case of failure in one of the tests.
|
2022-01-14 05:19:58 +02:00
|
|
|
|
exit 1
|
2022-01-16 02:15:13 +02:00
|
|
|
|
|
2019-07-12 21:19:42 -04:00
|
|
|
|
fi
|