|
1 | | -import convolutional_mlp, logistic_cg, logistic_sgd, mlp, SdA, dA, rbm , DBN |
2 | | -from nose.plugins.skip import SkipTest |
3 | | -import numpy, theano |
4 | | -import time, sys |
| 1 | +import sys |
| 2 | + |
| 3 | +import numpy |
| 4 | +import theano |
| 5 | + |
| 6 | +import convolutional_mlp, logistic_cg, logistic_sgd |
| 7 | +import mlp, SdA, dA, rbm, DBN |
5 | 8 |
|
6 | 9 |
|
7 | 10 | def test_logistic_sgd(): |
@@ -17,25 +20,24 @@ def test_mlp(): |
17 | 20 |
|
18 | 21 |
|
19 | 22 | def test_convolutional_mlp(): |
20 | | - convolutional_mlp.evaluate_lenet5(n_epochs=5,nkerns=[5,5]) |
| 23 | + convolutional_mlp.evaluate_lenet5(n_epochs=5, nkerns=[5, 5]) |
21 | 24 |
|
22 | 25 |
|
23 | 26 | def test_dA(): |
24 | | - dA.test_dA(training_epochs = 3, output_folder = 'tmp_dA_plots') |
| 27 | + dA.test_dA(training_epochs=3, output_folder='tmp_dA_plots') |
25 | 28 |
|
26 | 29 |
|
27 | 30 | def test_SdA(): |
28 | | - SdA.test_SdA(pretraining_epochs = 2, training_epochs = 3, batch_size = 300) |
| 31 | + SdA.test_SdA(pretraining_epochs=2, training_epochs=3, batch_size=300) |
29 | 32 |
|
30 | 33 |
|
31 | 34 | def test_dbn(): |
32 | | - DBN.test_DBN(pretraining_epochs = 1, training_epochs = 2, batch_size =300) |
33 | | - |
| 35 | + DBN.test_DBN(pretraining_epochs=1, training_epochs=2, batch_size=300) |
34 | 36 |
|
35 | 37 |
|
36 | 38 | def test_rbm(): |
37 | | - rbm.test_rbm(training_epochs = 1, batch_size = 300, n_chains = 1, n_samples = 1, |
38 | | - output_folder = 'tmp_rbm_plots') |
| 39 | + rbm.test_rbm(training_epochs=1, batch_size=300, n_chains=1, n_samples=1, |
| 40 | + output_folder='tmp_rbm_plots') |
39 | 41 |
|
40 | 42 |
|
41 | 43 | def speed(): |
@@ -44,133 +46,186 @@ def speed(): |
44 | 46 | I want it to be compatible with python2.4 so using try: finaly: is not an option. |
45 | 47 | """ |
46 | 48 |
|
47 | | - import theano |
48 | | - algo=['logistic_sgd','logistic_cg','mlp','convolutional_mlp','dA','SdA','DBN','rbm'] |
49 | | - to_exec=[True]*len(algo) |
| 49 | + algo = ['logistic_sgd', 'logistic_cg', 'mlp', 'convolutional_mlp', |
| 50 | + 'dA', 'SdA', 'DBN', 'rbm'] |
| 51 | + to_exec = [True] * len(algo) |
50 | 52 | # to_exec=[False]*len(algo) |
51 | 53 | # to_exec[-1]=True |
52 | | - do_float64=True |
53 | | - do_float32=True |
54 | | - do_gpu=True |
55 | | - |
56 | | - algo_executed = [s for idx,s in enumerate(algo) if to_exec[idx]] |
57 | | - |
58 | | - expected_times_64=numpy.asarray([ 12.42313051, 28.09523582, 106.35365391, 116.79225969, 153.12310314, |
59 | | - 425.09175086, 642.72824597, 652.52828193]) |
60 | | - expected_times_32=numpy.asarray([ 13.29699826, 32.42813158, 68.03559947, 105.54640913, 107.00527334, |
61 | | - 242.41721797, 490.40798998, 528.88854146]) |
62 | | - expected_times_gpu=numpy.asarray([ 3.07663488, 7.55523491, 18.99226785, 9.58915591, 24.13007045, |
63 | | - 24.77524018, 92.66246653, 322.34032917]) |
64 | | - expected_times_64 = [s for idx,s in enumerate(expected_times_64) if to_exec[idx]] |
65 | | - expected_times_32 = [s for idx,s in enumerate(expected_times_32) if to_exec[idx]] |
66 | | - expected_times_gpu = [s for idx,s in enumerate(expected_times_gpu) if to_exec[idx]] |
67 | | - |
68 | | - def time_test(m,l,idx,f,**kwargs): |
| 54 | + do_float64 = True |
| 55 | + do_float32 = True |
| 56 | + do_gpu = True |
| 57 | + |
| 58 | + algo_executed = [s for idx, s in enumerate(algo) if to_exec[idx]] |
| 59 | + #Timming expected are from the buildbot that have |
| 60 | + # an i7-920 @ 2.67GHz with hyperthread enabled for the cpu |
| 61 | + # and an GeForce GTX 285 for the GPU. |
| 62 | + |
| 63 | + expected_times_64 = numpy.asarray([10.7, 23.7, 84.8, 74.9, 124.6, |
| 64 | + 384.9, 414.6, 558.1]) |
| 65 | + expected_times_32 = numpy.asarray([9.8, 25.1, 56.7, 66.5, 85.4, |
| 66 | + 211.0, 245.7, 432.8]) |
| 67 | + # Number with just 1 decimal are new value that are faster with |
| 68 | + # the Theano version 0.5rc2 Other number are older. They are not |
| 69 | + # updated, as we where faster in the past! |
| 70 | + # TODO: find why and fix this! |
| 71 | + |
| 72 | +# Here is the value for the buildbot on February 3th 2012. |
| 73 | +# sgd, cg mlp conv da |
| 74 | +# sda dbn rbm |
| 75 | +# gpu times[3.72957802, 9.94316864, 29.1772666, 9.13857198, 25.91144657, |
| 76 | +# 18.30802011, 53.38651466, 285.41386175] |
| 77 | +# expected [3.076634879, 7.555234910, 18.99226785, 9.58915591, 24.130070450, |
| 78 | +# 24.77524018, 92.66246653, 322.340329170] |
| 79 | +# sgd, cg mlp conv da |
| 80 | +# sda dbn rbm |
| 81 | +#expected/get [0.82492841, 0.75984178, 0.65092691, 1.04930573, 0.93125138 |
| 82 | +# 1.35324519 1.7356905 1.12937868] |
| 83 | + expected_times_gpu = numpy.asarray([3.07663488, 7.55523491, 18.99226785, |
| 84 | + 9.1, 24.13007045, |
| 85 | + 18.3, 53.4, 285.4]) |
| 86 | + expected_times_64 = [s for idx, s in enumerate(expected_times_64) |
| 87 | + if to_exec[idx]] |
| 88 | + expected_times_32 = [s for idx, s in enumerate(expected_times_32) |
| 89 | + if to_exec[idx]] |
| 90 | + expected_times_gpu = [s for idx, s in enumerate(expected_times_gpu) |
| 91 | + if to_exec[idx]] |
| 92 | + |
| 93 | + def time_test(m, l, idx, f, **kwargs): |
69 | 94 | if not to_exec[idx]: |
70 | 95 | return |
71 | 96 | print algo[idx] |
72 | | - ts=m.call_time |
| 97 | + ts = m.call_time |
73 | 98 | try: |
74 | 99 | f(**kwargs) |
75 | 100 | except Exception, e: |
76 | 101 | print >> sys.stderr, 'test', algo[idx], 'FAILED', e |
77 | 102 | l.append(numpy.nan) |
78 | 103 | return |
79 | | - te=m.call_time |
80 | | - l.append(te-ts) |
| 104 | + te = m.call_time |
| 105 | + l.append(te - ts) |
81 | 106 |
|
82 | 107 | def do_tests(): |
83 | | - m=theano.compile.mode.get_default_mode() |
84 | | - l=[] |
85 | | - time_test(m,l,0, logistic_sgd.sgd_optimization_mnist,n_epochs=30) |
86 | | - time_test(m,l,1, logistic_cg.cg_optimization_mnist,n_epochs=30) |
87 | | - time_test(m,l,2, mlp.test_mlp, n_epochs=5) |
88 | | - time_test(m,l,3, convolutional_mlp.evaluate_lenet5, n_epochs=5,nkerns=[5,5]) |
89 | | - time_test(m,l,4, dA.test_dA, training_epochs = 2, output_folder = 'tmp_dA_plots') |
90 | | - time_test(m,l,5, SdA.test_SdA, pretraining_epochs = 1, training_epochs = 2, batch_size = 300) |
91 | | - time_test(m,l,6, DBN.test_DBN, pretraining_epochs = 1, training_epochs = 2, batch_size = 300) |
92 | | - time_test(m,l,7, rbm.test_rbm, training_epochs = 1, batch_size = 300, n_chains = 1, n_samples = 1, output_folder = 'tmp_rbm_plots') |
| 108 | + m = theano.compile.mode.get_default_mode() |
| 109 | + l = [] |
| 110 | + time_test(m, l, 0, logistic_sgd.sgd_optimization_mnist, n_epochs=30) |
| 111 | + time_test(m, l, 1, logistic_cg.cg_optimization_mnist, n_epochs=30) |
| 112 | + time_test(m, l, 2, mlp.test_mlp, n_epochs=5) |
| 113 | + time_test(m, l, 3, convolutional_mlp.evaluate_lenet5, n_epochs=5, |
| 114 | + nkerns=[5, 5]) |
| 115 | + time_test(m, l, 4, dA.test_dA, training_epochs=2, |
| 116 | + output_folde='tmp_dA_plots') |
| 117 | + time_test(m, l, 5, SdA.test_SdA, pretraining_epochs=1, |
| 118 | + training_epochs=2, batch_size=300) |
| 119 | + time_test(m, l, 6, DBN.test_DBN, pretraining_epochs=1, |
| 120 | + training_epochs=2, batch_size=300) |
| 121 | + time_test(m, l, 7, rbm.test_rbm, training_epochs=1, batch_size=300, |
| 122 | + n_chains=1, n_samples=1, output_folder='tmp_rbm_plots') |
93 | 123 | return numpy.asarray(l) |
94 | 124 |
|
95 | | - |
96 | 125 | #test in float64 in FAST_RUN mode on the cpu |
| 126 | + import theano |
97 | 127 | if do_float64: |
98 | | - theano.config.floatX='float64' |
99 | | - theano.config.mode='FAST_RUN' |
100 | | - float64_times=do_tests() |
| 128 | + theano.config.floatX = 'float64' |
| 129 | + theano.config.mode = 'FAST_RUN' |
| 130 | + float64_times = do_tests() |
101 | 131 | print >> sys.stderr, algo_executed |
102 | | - print >> sys.stderr, 'float64 times',float64_times |
103 | | - print >> sys.stderr, 'float64 expected',expected_times_64 |
104 | | - print >> sys.stderr, 'float64 % expected/get',expected_times_64/float64_times |
| 132 | + print >> sys.stderr, 'float64 times', float64_times |
| 133 | + print >> sys.stderr, 'float64 expected', expected_times_64 |
| 134 | + print >> sys.stderr, 'float64 % expected/get', ( |
| 135 | + expected_times_64 / float64_times) |
105 | 136 |
|
106 | 137 | #test in float32 in FAST_RUN mode on the cpu |
107 | | - theano.config.floatX='float32' |
| 138 | + theano.config.floatX = 'float32' |
108 | 139 | if do_float32: |
109 | | - float32_times=do_tests() |
| 140 | + float32_times = do_tests() |
110 | 141 | print >> sys.stderr, algo_executed |
111 | | - print >> sys.stderr, 'float32 times',float32_times |
112 | | - print >> sys.stderr, 'float32 expected',expected_times_32 |
113 | | - print >> sys.stderr, 'float32 % expected/get',expected_times_32/float32_times |
| 142 | + print >> sys.stderr, 'float32 times', float32_times |
| 143 | + print >> sys.stderr, 'float32 expected', expected_times_32 |
| 144 | + print >> sys.stderr, 'float32 % expected/get', ( |
| 145 | + expected_times_32 / float32_times) |
114 | 146 |
|
115 | 147 | if do_float64: |
116 | | - print >> sys.stderr, 'float64/float32',float64_times/float32_times |
| 148 | + print >> sys.stderr, 'float64/float32', ( |
| 149 | + float64_times / float32_times) |
117 | 150 | print >> sys.stderr |
118 | 151 | print >> sys.stderr, 'Duplicate the timing to have everything in one place' |
119 | 152 | print >> sys.stderr, algo_executed |
120 | | - print >> sys.stderr, 'float64 times',float64_times |
121 | | - print >> sys.stderr, 'float64 expected',expected_times_64 |
122 | | - print >> sys.stderr, 'float64 % expected/get',expected_times_64/float64_times |
123 | | - print >> sys.stderr, 'float32 times',float32_times |
124 | | - print >> sys.stderr, 'float32 expected',expected_times_32 |
125 | | - print >> sys.stderr, 'float32 % expected/get',expected_times_32/float32_times |
126 | | - |
127 | | - print >> sys.stderr, 'float64/float32',float64_times/float32_times |
128 | | - print >> sys.stderr, 'expected float64/float32',expected_times_64/float32_times |
| 153 | + print >> sys.stderr, 'float64 times', float64_times |
| 154 | + print >> sys.stderr, 'float64 expected', expected_times_64 |
| 155 | + print >> sys.stderr, 'float64 % expected/get', ( |
| 156 | + expected_times_64 / float64_times) |
| 157 | + print >> sys.stderr, 'float32 times', float32_times |
| 158 | + print >> sys.stderr, 'float32 expected', expected_times_32 |
| 159 | + print >> sys.stderr, 'float32 % expected/get', ( |
| 160 | + expected_times_32 / float32_times) |
| 161 | + |
| 162 | + print >> sys.stderr, 'float64/float32', ( |
| 163 | + float64_times / float32_times) |
| 164 | + print >> sys.stderr, 'expected float64/float32', ( |
| 165 | + expected_times_64 / float32_times) |
129 | 166 |
|
130 | 167 | #test in float32 in FAST_RUN mode on the gpu |
131 | 168 | import theano.sandbox.cuda |
132 | 169 | if do_gpu: |
133 | 170 | theano.sandbox.cuda.use('gpu') |
134 | | - gpu_times=do_tests() |
| 171 | + gpu_times = do_tests() |
135 | 172 | print >> sys.stderr, algo_executed |
136 | | - print >> sys.stderr, 'gpu times',gpu_times |
137 | | - print >> sys.stderr, 'gpu expected',expected_times_gpu |
138 | | - print >> sys.stderr, 'gpu % expected/get',expected_times_gpu/gpu_times |
| 173 | + print >> sys.stderr, 'gpu times', gpu_times |
| 174 | + print >> sys.stderr, 'gpu expected', expected_times_gpu |
| 175 | + print >> sys.stderr, 'gpu % expected/get', ( |
| 176 | + expected_times_gpu / gpu_times) |
| 177 | + |
139 | 178 | if do_float64: |
140 | | - print >> sys.stderr, 'float64/gpu',float64_times/gpu_times |
| 179 | + print >> sys.stderr, 'float64/gpu', float64_times / gpu_times |
141 | 180 |
|
142 | 181 | if (do_float64 + do_float32 + do_gpu) > 1: |
143 | 182 | print >> sys.stderr |
144 | 183 | print >> sys.stderr, 'Duplicate the timing to have everything in one place' |
145 | 184 | print >> sys.stderr, algo_executed |
146 | 185 | if do_float64: |
147 | | - print >> sys.stderr, 'float64 times',float64_times |
148 | | - print >> sys.stderr, 'float64 expected',expected_times_64 |
149 | | - print >> sys.stderr, 'float64 % expected/get',expected_times_64/float64_times |
| 186 | + print >> sys.stderr, 'float64 times', float64_times |
| 187 | + print >> sys.stderr, 'float64 expected', expected_times_64 |
| 188 | + print >> sys.stderr, 'float64 % expected/get', ( |
| 189 | + expected_times_64 / float64_times) |
150 | 190 | if do_float32: |
151 | | - print >> sys.stderr, 'float32 times',float32_times |
152 | | - print >> sys.stderr, 'float32 expected',expected_times_32 |
153 | | - print >> sys.stderr, 'float32 % expected/get',expected_times_32/float32_times |
| 191 | + print >> sys.stderr, 'float32 times', float32_times |
| 192 | + print >> sys.stderr, 'float32 expected', expected_times_32 |
| 193 | + print >> sys.stderr, 'float32 % expected/get', ( |
| 194 | + expected_times_32 / float32_times) |
154 | 195 | if do_gpu: |
155 | | - print >> sys.stderr, 'gpu times',gpu_times |
156 | | - print >> sys.stderr, 'gpu expected',expected_times_gpu |
157 | | - print >> sys.stderr, 'gpu % expected/get',expected_times_gpu/gpu_times |
| 196 | + print >> sys.stderr, 'gpu times', gpu_times |
| 197 | + print >> sys.stderr, 'gpu expected', expected_times_gpu |
| 198 | + print >> sys.stderr, 'gpu % expected/get', ( |
| 199 | + expected_times_gpu / gpu_times) |
158 | 200 |
|
159 | 201 | if do_float64 and do_float32: |
160 | | - print >> sys.stderr, 'float64/float32',float64_times/float32_times |
161 | | - print >> sys.stderr, 'expected float64/float32',expected_times_64/float32_times |
| 202 | + print >> sys.stderr, 'float64/float32', ( |
| 203 | + float64_times / float32_times) |
| 204 | + print >> sys.stderr, 'expected float64/float32', ( |
| 205 | + expected_times_64 / float32_times) |
162 | 206 | if do_float64 and do_gpu: |
163 | | - print >> sys.stderr, 'float64/gpu',float64_times/gpu_times |
164 | | - print >> sys.stderr, 'expected float64/gpu',expected_times_64/gpu_times |
| 207 | + print >> sys.stderr, 'float64/gpu', float64_times / gpu_times |
| 208 | + print >> sys.stderr, 'expected float64/gpu', ( |
| 209 | + expected_times_64 / gpu_times) |
165 | 210 | if do_float32 and do_gpu: |
166 | | - print >> sys.stderr, 'float32/gpu',float32_times/gpu_times |
167 | | - print >> sys.stderr, 'expected float32/gpu',expected_times_32/gpu_times |
| 211 | + print >> sys.stderr, 'float32/gpu', float32_times / gpu_times |
| 212 | + print >> sys.stderr, 'expected float32/gpu', ( |
| 213 | + expected_times_32 / gpu_times) |
| 214 | + |
| 215 | + def compare(x, y): |
| 216 | + ratio = x / y |
| 217 | + # If there is more then 5% difference between the expected |
| 218 | + # time and the real time, we consider this an error. |
| 219 | + return sum((ratio < 0.95) + (ratio > 1.05)) |
168 | 220 |
|
169 | 221 | if do_float64: |
170 | | - print >> sys.stderr, 'speed_failure_float64='+str(sum((expected_times_64/float64_times)>0.95)) |
| 222 | + err = compare(expected_times_64, float64_times) |
| 223 | + print >> sys.stderr, 'speed_failure_float64=' + str(err) |
171 | 224 | if do_float32: |
172 | | - print >> sys.stderr, 'speed_failure_float32='+str(sum((expected_times_32/float32_times)>0.95)) |
| 225 | + err = compare(expected_times_32, float32_times) |
| 226 | + print >> sys.stderr, 'speed_failure_float32=' + str(err) |
173 | 227 | if do_gpu: |
174 | | - print >> sys.stderr, 'speed_failure_gpu='+str(sum((expected_times_gpu/gpu_times)>0.95)) |
| 228 | + err = compare(expected_times_gpu, gpu_times) |
| 229 | + print >> sys.stderr, 'speed_failure_gpu=' + str(err) |
175 | 230 |
|
176 | 231 | assert not numpy.isnan(gpu_times).any() |