Skip to content

Commit 6361592

Browse files
authored
Merge pull request #2 from lisa-lab/master
Updating my fork
2 parents a57165b + ea2c59f commit 6361592

35 files changed

Lines changed: 620 additions & 520 deletions

.jenkins/jenkins_buildbot_dlt.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
# CUDA
4+
export PATH=/usr/local/cuda/bin:$PATH
5+
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
6+
export LIBRARY_PATH=/usr/local/cuda/lib64:$LIBRARY_PATH
7+
8+
BUILDBOT_DIR=$WORKSPACE/nightly_build
9+
10+
mkdir -p ${BUILDBOT_DIR}
11+
12+
date
13+
COMPILEDIR=$HOME/.theano/lisa_theano_buildbot_deeplearning
14+
NOSETESTS=${BUILDBOT_DIR}/Theano/bin/theano-nose
15+
XUNIT="--with-xunit --xunit-file="
16+
# name test suites
17+
SUITE="--xunit-testsuite-name="
18+
19+
FLAGS=warn.ignore_bug_before=0.5,compiledir=${COMPILEDIR}
20+
export PYTHONPATH=${BUILDBOT_DIR}/Theano:${BUILDBOT_DIR}/Pylearn:$PYTHONPATH
21+
22+
# Install libgpuarray and pygpu
23+
cd ${BUILDBOT_DIR}
24+
25+
# Make fresh clone (with no history since we don't need it)
26+
rm -rf libgpuarray
27+
git clone "https://github.com/Theano/libgpuarray.git"
28+
29+
(cd libgpuarray && echo "libgpuarray commit" && git rev-parse HEAD)
30+
31+
# Clean up previous installs (to make sure no old files are left)
32+
rm -rf local
33+
mkdir local
34+
35+
# Build libgpuarray and run C tests
36+
mkdir libgpuarray/build
37+
(cd libgpuarray/build && cmake .. -DCMAKE_BUILD_TYPE=${GPUARRAY_CONFIG} -DCMAKE_INSTALL_PREFIX=${BUILDBOT_DIR}/local && make)
38+
39+
# Finally install
40+
(cd libgpuarray/build && make install)
41+
export LD_LIBRARY_PATH=${BUILDBOT_DIR}/local/lib:${LD_LIBRARY_PATH}
42+
export LIBRARY_PATH=${BUILDBOT_DIR}/local/lib:${LIBRARY_PATH}
43+
export CPATH=${BUILDBOT_DIR}/local/include:${CPATH}
44+
45+
# Build the pygpu modules
46+
(cd libgpuarray && python setup.py build_ext --inplace -I${BUILDBOT_DIR}/local/include -L${BUILDBOT_DIR}/local/lib)
47+
48+
mkdir ${BUILDBOT_DIR}/local/lib/python
49+
export PYTHONPATH=${PYTHONPATH}:${BUILDBOT_DIR}/local/lib/python
50+
# Then install
51+
(cd libgpuarray && python setup.py install --home=${BUILDBOT_DIR}/local)
52+
53+
# Install Theano
54+
cd ${BUILDBOT_DIR}
55+
if [ ! -d ${BUILDBOT_DIR}/Theano ]; then
56+
git clone git://github.com/Theano/Theano.git
57+
fi
58+
# update repo
59+
cd ${BUILDBOT_DIR}/Theano; git pull
60+
61+
cd ${WORKSPACE}/data
62+
./download.sh
63+
64+
cd ${BUILDBOT_DIR}/Theano
65+
echo "git version for Theano:" `git rev-parse HEAD`
66+
cd ${WORKSPACE}/code
67+
echo "git version:" `git rev-parse HEAD`
68+
69+
echo "==== Executing nosetests speed with mode=FAST_RUN"
70+
NAME=dlt_speed
71+
FILE=${BUILDBOT_DIR}/${NAME}_tests.xml
72+
THEANO_FLAGS=${FLAGS},mode=FAST_RUN ${NOSETESTS} ${XUNIT}${FILE} ${SUITE}${NAME} test.py:speed
73+
74+
echo "==== Executing nosetests with mode=FAST_RUN,floatX=float32"
75+
NAME=dlt_float32
76+
FILE=${BUILDBOT_DIR}/${NAME}_tests.xml
77+
THEANO_FLAGS=${FLAGS},mode=FAST_RUN,floatX=float32 ${NOSETESTS} ${XUNIT}${FILE} ${SUITE}${NAME}
78+
79+
echo "==== Executing nosetests with mode=FAST_RUN,floatX=float32,device=cuda"
80+
NAME=dlt_float32_cuda
81+
FILE=${BUILDBOT_DIR}/${NAME}_tests.xml
82+
PYTHONPATH=${BUILDBOT_DIR}/Theano:${BUILDBOT_DIR}/DeepLearningTutorials/code:${PYTHONPATH} THEANO_FLAGS=${FLAGS},mode=FAST_RUN,floatX=float32,device=cuda nosetests test.py ${XUNIT}${FILE} ${SUITE}${NAME}

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
# After changing this file, check it on:
22
# http://lint.travis-ci.org/
3+
sudo: false
34

45
language: python
56
#python:
6-
# - "2.7"
7-
# - "3.2"
7+
# - "2.6"
8+
# - "3.3"
89
# command to install dependencies
910
before_install:
1011
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
1112
- chmod +x miniconda.sh
1213
- ./miniconda.sh -b
13-
- export PATH=/home/travis/miniconda/bin:$PATH
14+
- export PATH=/home/travis/miniconda/bin:/home/travis/miniconda2/bin:$PATH
1415
- conda update --yes conda
1516

1617
install:
17-
- conda create --yes -q -n pyenv mkl python=2.7 numpy scipy pip nose yaml pyflakes pillow pyparsing=1.5
18+
- conda create --yes -q -n pyenv mkl python=2.7 numpy=1.10 scipy=0.16.1 pip nose yaml pyflakes pillow pyparsing=1.5
1819
- source activate pyenv
1920
- pip install git+git://github.com/Theano/Theano.git
2021

2122
env:
2223
- PART="test.py:test_logistic_sgd test.py:test_logistic_cg test.py:test_mlp test.py:test_convolutional_mlp test.py:test_dA"
23-
- PART="test.py:test_SdA"
24+
- PART="test.py:test_SdA test.py:test_lstm"
2425
- PART="test.py:test_dbn"
25-
- PART="test.py:test_rbm test.py:test_rnnrbm"
26+
- PART="test.py:test_rbm test.py:test_rnnrbm test.py:test_rnnslu"
2627
- PART="-e test.py"
2728

2829
#i7-2600K CPU @ 3.40GHz

code/DBN.py

Lines changed: 58 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""
22
"""
3+
from __future__ import print_function, division
34
import os
45
import sys
56
import timeit
@@ -61,9 +62,12 @@ def __init__(self, numpy_rng, theano_rng=None, n_ins=784,
6162
theano_rng = MRG_RandomStreams(numpy_rng.randint(2 ** 30))
6263

6364
# allocate symbolic variables for the data
64-
self.x = T.matrix('x') # the data is presented as rasterized images
65-
self.y = T.ivector('y') # the labels are presented as 1D vector
66-
# of [int] labels
65+
66+
# the data is presented as rasterized images
67+
self.x = T.matrix('x')
68+
69+
# the labels are presented as 1D vector of [int] labels
70+
self.y = T.ivector('y')
6771
# end-snippet-1
6872
# The DBN is an MLP, for which all weights of intermediate
6973
# layers are shared with a different RBM. We will first
@@ -75,7 +79,7 @@ def __init__(self, numpy_rng, theano_rng=None, n_ins=784,
7579
# training the DBN by doing stochastic gradient descent on the
7680
# MLP.
7781

78-
for i in xrange(self.n_layers):
82+
for i in range(self.n_layers):
7983
# construct the sigmoidal layer
8084

8185
# the size of the input is either the number of hidden
@@ -156,8 +160,6 @@ def pretraining_functions(self, train_set_x, batch_size, k):
156160
index = T.lscalar('index') # index to a minibatch
157161
learning_rate = T.scalar('lr') # learning rate to use
158162

159-
# number of batches
160-
n_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size
161163
# begining of a batch, given `index`
162164
batch_begin = index * batch_size
163165
# ending of a batch given `index`
@@ -174,7 +176,7 @@ def pretraining_functions(self, train_set_x, batch_size, k):
174176

175177
# compile the theano function
176178
fn = theano.function(
177-
inputs=[index, theano.Param(learning_rate, default=0.1)],
179+
inputs=[index, theano.In(learning_rate, value=0.1)],
178180
outputs=cost,
179181
updates=updates,
180182
givens={
@@ -211,9 +213,9 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate):
211213

212214
# compute number of minibatches for training, validation and testing
213215
n_valid_batches = valid_set_x.get_value(borrow=True).shape[0]
214-
n_valid_batches /= batch_size
216+
n_valid_batches //= batch_size
215217
n_test_batches = test_set_x.get_value(borrow=True).shape[0]
216-
n_test_batches /= batch_size
218+
n_test_batches //= batch_size
217219

218220
index = T.lscalar('index') # index to a [mini]batch
219221

@@ -267,11 +269,11 @@ def build_finetune_functions(self, datasets, batch_size, learning_rate):
267269

268270
# Create a function that scans the entire validation set
269271
def valid_score():
270-
return [valid_score_i(i) for i in xrange(n_valid_batches)]
272+
return [valid_score_i(i) for i in range(n_valid_batches)]
271273

272274
# Create a function that scans the entire test set
273275
def test_score():
274-
return [test_score_i(i) for i in xrange(n_test_batches)]
276+
return [test_score_i(i) for i in range(n_test_batches)]
275277

276278
return train_fn, valid_score, test_score
277279

@@ -307,11 +309,11 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
307309
test_set_x, test_set_y = datasets[2]
308310

309311
# compute number of minibatches for training, validation and testing
310-
n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size
312+
n_train_batches = train_set_x.get_value(borrow=True).shape[0] // batch_size
311313

312314
# numpy random generator
313315
numpy_rng = numpy.random.RandomState(123)
314-
print '... building the model'
316+
print('... building the model')
315317
# construct the Deep Belief Network
316318
dbn = DBN(numpy_rng=numpy_rng, n_ins=28 * 28,
317319
hidden_layers_sizes=[1000, 1000, 1000],
@@ -321,54 +323,56 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
321323
#########################
322324
# PRETRAINING THE MODEL #
323325
#########################
324-
print '... getting the pretraining functions'
326+
print('... getting the pretraining functions')
325327
pretraining_fns = dbn.pretraining_functions(train_set_x=train_set_x,
326328
batch_size=batch_size,
327329
k=k)
328330

329-
print '... pre-training the model'
331+
print('... pre-training the model')
330332
start_time = timeit.default_timer()
331-
## Pre-train layer-wise
332-
for i in xrange(dbn.n_layers):
333+
# Pre-train layer-wise
334+
for i in range(dbn.n_layers):
333335
# go through pretraining epochs
334-
for epoch in xrange(pretraining_epochs):
336+
for epoch in range(pretraining_epochs):
335337
# go through the training set
336338
c = []
337-
for batch_index in xrange(n_train_batches):
339+
for batch_index in range(n_train_batches):
338340
c.append(pretraining_fns[i](index=batch_index,
339341
lr=pretrain_lr))
340-
print 'Pre-training layer %i, epoch %d, cost ' % (i, epoch),
341-
print numpy.mean(c)
342+
print('Pre-training layer %i, epoch %d, cost ' % (i, epoch), end=' ')
343+
print(numpy.mean(c, dtype='float64'))
342344

343345
end_time = timeit.default_timer()
344346
# end-snippet-2
345-
print >> sys.stderr, ('The pretraining code for file ' +
346-
os.path.split(__file__)[1] +
347-
' ran for %.2fm' % ((end_time - start_time) / 60.))
347+
print('The pretraining code for file ' + os.path.split(__file__)[1] +
348+
' ran for %.2fm' % ((end_time - start_time) / 60.), file=sys.stderr)
348349
########################
349350
# FINETUNING THE MODEL #
350351
########################
351352

352353
# get the training, validation and testing function for the model
353-
print '... getting the finetuning functions'
354+
print('... getting the finetuning functions')
354355
train_fn, validate_model, test_model = dbn.build_finetune_functions(
355356
datasets=datasets,
356357
batch_size=batch_size,
357358
learning_rate=finetune_lr
358359
)
359360

360-
print '... finetuning the model'
361+
print('... finetuning the model')
361362
# early-stopping parameters
362-
patience = 4 * n_train_batches # look as this many examples regardless
363-
patience_increase = 2. # wait this much longer when a new best is
364-
# found
365-
improvement_threshold = 0.995 # a relative improvement of this much is
366-
# considered significant
363+
364+
# look as this many examples regardless
365+
patience = 4 * n_train_batches
366+
367+
# wait this much longer when a new best is found
368+
patience_increase = 2.
369+
370+
# a relative improvement of this much is considered significant
371+
improvement_threshold = 0.995
372+
373+
# go through this many minibatches before checking the network on
374+
# the validation set; in this case we check every epoch
367375
validation_frequency = min(n_train_batches, patience / 2)
368-
# go through this many
369-
# minibatches before checking the network
370-
# on the validation set; in this case we
371-
# check every epoch
372376

373377
best_validation_loss = numpy.inf
374378
test_score = 0.
@@ -379,33 +383,29 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
379383

380384
while (epoch < training_epochs) and (not done_looping):
381385
epoch = epoch + 1
382-
for minibatch_index in xrange(n_train_batches):
386+
for minibatch_index in range(n_train_batches):
383387

384-
minibatch_avg_cost = train_fn(minibatch_index)
388+
train_fn(minibatch_index)
385389
iter = (epoch - 1) * n_train_batches + minibatch_index
386390

387391
if (iter + 1) % validation_frequency == 0:
388392

389393
validation_losses = validate_model()
390-
this_validation_loss = numpy.mean(validation_losses)
391-
print(
392-
'epoch %i, minibatch %i/%i, validation error %f %%'
393-
% (
394-
epoch,
395-
minibatch_index + 1,
396-
n_train_batches,
397-
this_validation_loss * 100.
394+
this_validation_loss = numpy.mean(validation_losses, dtype='float64')
395+
print('epoch %i, minibatch %i/%i, validation error %f %%' % (
396+
epoch,
397+
minibatch_index + 1,
398+
n_train_batches,
399+
this_validation_loss * 100.
398400
)
399401
)
400402

401403
# if we got the best validation score until now
402404
if this_validation_loss < best_validation_loss:
403405

404-
#improve patience if loss improvement is good enough
405-
if (
406-
this_validation_loss < best_validation_loss *
407-
improvement_threshold
408-
):
406+
# improve patience if loss improvement is good enough
407+
if (this_validation_loss < best_validation_loss *
408+
improvement_threshold):
409409
patience = max(patience, iter * patience_increase)
410410

411411
# save best validation score and iteration number
@@ -414,28 +414,23 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
414414

415415
# test it on the test set
416416
test_losses = test_model()
417-
test_score = numpy.mean(test_losses)
417+
test_score = numpy.mean(test_losses, dtype='float64')
418418
print((' epoch %i, minibatch %i/%i, test error of '
419419
'best model %f %%') %
420420
(epoch, minibatch_index + 1, n_train_batches,
421-
test_score * 100.))
421+
test_score * 100.))
422422

423423
if patience <= iter:
424424
done_looping = True
425425
break
426426

427427
end_time = timeit.default_timer()
428-
print(
429-
(
430-
'Optimization complete with best validation score of %f %%, '
431-
'obtained at iteration %i, '
432-
'with test performance %f %%'
433-
) % (best_validation_loss * 100., best_iter + 1, test_score * 100.)
434-
)
435-
print >> sys.stderr, ('The fine tuning code for file ' +
436-
os.path.split(__file__)[1] +
437-
' ran for %.2fm' % ((end_time - start_time)
438-
/ 60.))
428+
print(('Optimization complete with best validation score of %f %%, '
429+
'obtained at iteration %i, '
430+
'with test performance %f %%'
431+
) % (best_validation_loss * 100., best_iter + 1, test_score * 100.))
432+
print('The fine tuning code for file ' + os.path.split(__file__)[1] +
433+
' ran for %.2fm' % ((end_time - start_time) / 60.), file=sys.stderr)
439434

440435

441436
if __name__ == '__main__':

0 commit comments

Comments
 (0)