Skip to content

Commit f1c0587

Browse files
authored
Merge pull request lisa-lab#172 from abergeron/mixed
Fixes for float16 problems in the DLT
2 parents 5911cd1 + 780cecc commit f1c0587

File tree

7 files changed

+19
-18
lines changed

7 files changed

+19
-18
lines changed

code/DBN.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
340340
c.append(pretraining_fns[i](index=batch_index,
341341
lr=pretrain_lr))
342342
print('Pre-training layer %i, epoch %d, cost ' % (i, epoch), end=' ')
343-
print(numpy.mean(c))
343+
print(numpy.mean(c, dtype='float64'))
344344

345345
end_time = timeit.default_timer()
346346
# end-snippet-2
@@ -391,7 +391,7 @@ def test_DBN(finetune_lr=0.1, pretraining_epochs=100,
391391
if (iter + 1) % validation_frequency == 0:
392392

393393
validation_losses = validate_model()
394-
this_validation_loss = numpy.mean(validation_losses)
394+
this_validation_loss = numpy.mean(validation_losses, dtype='float64')
395395
print('epoch %i, minibatch %i/%i, validation error %f %%' % (
396396
epoch,
397397
minibatch_index + 1,
@@ -414,7 +414,7 @@ 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,

code/SdA.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import theano
4242
import theano.tensor as T
43-
from theano.tensor.shared_randomstreams import RandomStreams
43+
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
4444

4545
from logistic_sgd import LogisticRegression, load_data
4646
from mlp import HiddenLayer
@@ -394,7 +394,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15,
394394
c.append(pretraining_fns[i](index=batch_index,
395395
corruption=corruption_levels[i],
396396
lr=pretrain_lr))
397-
print('Pre-training layer %i, epoch %d, cost %f' % (i, epoch, numpy.mean(c)))
397+
print('Pre-training layer %i, epoch %d, cost %f' % (i, epoch, numpy.mean(c, dtype='float64')))
398398

399399
end_time = timeit.default_timer()
400400

@@ -442,7 +442,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15,
442442

443443
if (iter + 1) % validation_frequency == 0:
444444
validation_losses = validate_model()
445-
this_validation_loss = numpy.mean(validation_losses)
445+
this_validation_loss = numpy.mean(validation_losses, dtype='float64')
446446
print('epoch %i, minibatch %i/%i, validation error %f %%' %
447447
(epoch, minibatch_index + 1, n_train_batches,
448448
this_validation_loss * 100.))
@@ -463,7 +463,7 @@ def test_SdA(finetune_lr=0.1, pretraining_epochs=15,
463463

464464
# test it on the test set
465465
test_losses = test_model()
466-
test_score = numpy.mean(test_losses)
466+
test_score = numpy.mean(test_losses, dtype='float64')
467467
print((' epoch %i, minibatch %i/%i, test error of '
468468
'best model %f %%') %
469469
(epoch, minibatch_index + 1, n_train_batches,

code/dA.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
import theano
4242
import theano.tensor as T
43-
from theano.tensor.shared_randomstreams import RandomStreams
43+
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
4444

4545
from logistic_sgd import load_data
4646
from utils import tile_raster_images
@@ -336,7 +336,7 @@ def test_dA(learning_rate=0.1, training_epochs=15,
336336
for batch_index in range(n_train_batches):
337337
c.append(train_da(batch_index))
338338

339-
print('Training epoch %d, cost ' % epoch, numpy.mean(c))
339+
print('Training epoch %d, cost ' % epoch, numpy.mean(c, dtype='float64'))
340340

341341
end_time = timeit.default_timer()
342342

@@ -394,7 +394,7 @@ def test_dA(learning_rate=0.1, training_epochs=15,
394394
for batch_index in range(n_train_batches):
395395
c.append(train_da(batch_index))
396396

397-
print('Training epoch %d, cost ' % epoch, numpy.mean(c))
397+
print('Training epoch %d, cost ' % epoch, numpy.mean(c, dtype='float64'))
398398

399399
end_time = timeit.default_timer()
400400

code/hmc/hmc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from theano import function, shared
88
from theano import tensor as TT
99
import theano
10+
import theano.sandbox.rng_mrg
1011

1112
sharedX = (lambda X, name:
1213
shared(numpy.asarray(X, dtype=theano.config.floatX), name=name))
@@ -275,14 +276,14 @@ def hmc_updates(positions, stepsize, avg_acceptance_rate, final_pos, accept,
275276
276277
"""
277278

278-
## POSITION UPDATES ##
279+
# POSITION UPDATES #
279280
# broadcast `accept` scalar to tensor with the same dimensions as
280281
# final_pos.
281282
accept_matrix = accept.dimshuffle(0, *(('x',) * (final_pos.ndim - 1)))
282283
# if accept is True, update to `final_pos` else stay put
283284
new_positions = TT.switch(accept_matrix, final_pos, positions)
284285
# end-snippet-5 start-snippet-7
285-
## STEPSIZE UPDATES ##
286+
# STEPSIZE UPDATES #
286287
# if acceptance rate is too low, our sampler is too "noisy" and we reduce
287288
# the stepsize. If it is too high, our sampler is too conservative, we can
288289
# get away with a larger stepsize (resulting in better mixing).
@@ -292,7 +293,7 @@ def hmc_updates(positions, stepsize, avg_acceptance_rate, final_pos, accept,
292293
new_stepsize = TT.clip(_new_stepsize, stepsize_min, stepsize_max)
293294

294295
# end-snippet-7 start-snippet-6
295-
## ACCEPT RATE UPDATES ##
296+
# ACCEPT RATE UPDATES #
296297
# perform exponential moving average
297298
mean_dtype = theano.scalar.upcast(accept.dtype, avg_acceptance_rate.dtype)
298299
new_acceptance_rate = TT.add(
@@ -358,7 +359,7 @@ def new_from_shared_positions(
358359
stepsize = sharedX(initial_stepsize, 'hmc_stepsize')
359360
avg_acceptance_rate = sharedX(target_acceptance_rate,
360361
'avg_acceptance_rate')
361-
s_rng = TT.shared_randomstreams.RandomStreams(seed)
362+
s_rng = theano.sandbox.rng_mrg.MRG_RandomStreams(seed)
362363

363364
# define graph for an `n_steps` HMC simulation
364365
accept, final_pos = hmc_move(

code/lstm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ def train_lstm(
605605
best_p = unzip(tparams)
606606
bad_counter = 0
607607

608-
print( ('Train ', train_err, 'Valid ', valid_err,
609-
'Test ', test_err) )
608+
print('Train ', train_err, 'Valid ', valid_err,
609+
'Test ', test_err)
610610

611611
if (len(history_errs) > patience and
612612
valid_err >= numpy.array(history_errs)[:-patience,

code/rbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import theano.tensor as T
2121
import os
2222

23-
from theano.tensor.shared_randomstreams import RandomStreams
23+
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
2424

2525
from utils import tile_raster_images
2626
from logistic_sgd import load_data

code/rnnrbm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from midi.utils import midiread, midiwrite
2020
import theano
2121
import theano.tensor as T
22-
from theano.tensor.shared_randomstreams import RandomStreams
22+
from theano.sandbox.rng_mrg import MRG_RandomStreams as RandomStreams
2323

2424
#Don't use a python long as this don't work on 32 bits computers.
2525
numpy.random.seed(0xbeef)

0 commit comments

Comments
 (0)