33# This script runs through the code in each of the python examples.
44# The purpose is just as an integrtion test, not to actually train
55# models in any meaningful way. For that reason, most of these set
6- # epochs = 1.
6+ # epochs = 1 and --dry-run .
77#
88# Optionally specify a comma separated list of examples to run.
99# can be run as:
1010# ./run_python_examples.sh "install_deps,run_all,clean"
1111# to pip install dependencies (other than pytorch), run all examples,
1212# and remove temporary/changed data files.
13- # Expects pytorch to be installed.
13+ # Expects pytorch, torchvision to be installed.
1414
1515BASE_DIR=` pwd` " /" ` dirname $0 `
1616EXAMPLES=` echo $1 | sed -e ' s/ //g' `
1717
18- if which nvcc ; then
19- echo " using cuda"
20- CUDA=1
21- CUDA_FLAG=" --cuda"
22- else
23- echo " not using cuda"
24- CUDA=0
25- CUDA_FLAG=" "
26- fi
18+ USE_CUDA=$( python -c " import torchvision, torch; print(torch.cuda.is_available())" )
19+ case $USE_CUDA in
20+ " True" )
21+ echo " using cuda"
22+ CUDA=1
23+ CUDA_FLAG=" --cuda"
24+ ;;
25+ " False" )
26+ echo " not using cuda"
27+ CUDA=0
28+ CUDA_FLAG=" "
29+ ;;
30+ " " )
31+ exit 1;
32+ ;;
33+ esac
2734
2835ERRORS=" "
2936
@@ -63,7 +70,7 @@ function dcgan() {
6370 unzip ${DATACLASS} _train_lmdb.zip || { error " couldn't unzip $DATACLASS " ; return ; }
6471 popd
6572 fi
66- python main.py --dataset lsun --dataroot lsun --classes $DATACLASS --niter 1 $CUDA_FLAG || error " dcgan failed"
73+ python main.py --dataset lsun --dataroot lsun --classes $DATACLASS --niter 1 $CUDA_FLAG --dry-run || error " dcgan failed"
6774}
6875
6976function fast_neural_style() {
@@ -92,12 +99,12 @@ function imagenet() {
9299
93100function mnist() {
94101 start
95- python main.py --epochs 1 || error " mnist example failed"
102+ python main.py --epochs 1 --dry-run || error " mnist example failed"
96103}
97104
98105function mnist_hogwild() {
99106 start
100- python main.py --epochs 1 $CUDA_FLAG || error " mnist hogwild failed"
107+ python main.py --epochs 1 --dry-run $CUDA_FLAG || error " mnist hogwild failed"
101108}
102109
103110function regression() {
@@ -115,7 +122,7 @@ function snli() {
115122 echo " installing 'en' model if not installed"
116123 python -m spacy download en || { error " couldn't download 'en' model needed for snli" ; return ; }
117124 echo " training..."
118- python train.py --epochs 1 --no-bidirectional || error " couldn't train snli"
125+ python train.py --epochs 1 --dev_every 1 -- no-bidirectional --dry-run || error " couldn't train snli"
119126}
120127
121128function super_resolution() {
@@ -126,7 +133,7 @@ function super_resolution() {
126133function time_sequence_prediction() {
127134 start
128135 python generate_sine_wave.py || { error " generate sine wave failed" ; return ; }
129- python train.py || error " time sequence prediction training failed"
136+ python train.py --steps 2 || error " time sequence prediction training failed"
130137}
131138
132139function vae() {
@@ -136,18 +143,38 @@ function vae() {
136143
137144function word_language_model() {
138145 start
139- python main.py --epochs 1 $CUDA_FLAG || error " word_language_model failed"
146+ python main.py --epochs 1 --dry-run $CUDA_FLAG || error " word_language_model failed"
140147}
141148
142149function clean() {
143150 cd $BASE_DIR
144- rm -rf dcgan/_cache_lsun_classroom_train_lmdb dcgan/fake_samples_epoch_000.png dcgan/lsun/ dcgan/netD_epoch_0.pth dcgan/netG_epoch_0.pth 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 word_language_model/model.pt || error " couldn't clean up some files"
151+ rm -rf dcgan/_cache_lsun_classroom_train_lmdb \
152+ dcgan/fake_samples_epoch_000.png dcgan/lsun/ \
153+ dcgan/_cache_lsunclassroomtrainlmdb \
154+ dcgan/netD_epoch_0.pth dcgan/netG_epoch_0.pth \
155+ dcgan/real_samples.png \
156+ fast_neural_style/saved_models.zip \
157+ fast_neural_style/saved_models/ \
158+ imagenet/checkpoint.pth.tar \
159+ imagenet/lsun/ \
160+ imagenet/model_best.pth.tar \
161+ imagenet/sample/ \
162+ snli/.data/ \
163+ snli/.vector_cache/ \
164+ snli/results/ \
165+ super_resolution/dataset/ \
166+ super_resolution/model_epoch_1.pth \
167+ time_sequence_prediction/predict* .pdf \
168+ time_sequence_prediction/traindata.pt \
169+ word_language_model/model.pt || error " couldn't clean up some files"
145170
146171 git checkout fast_neural_style/images/output-images/amber-candy.jpg || error " couldn't clean up fast neural style image"
147172}
148173
149174function run_all() {
175+ # cpp
150176 dcgan
177+ # distributed
151178 fast_neural_style
152179 imagenet
153180 mnist
0 commit comments