Skip to content

Commit e1f14ba

Browse files
author
Ilia Karmanov
committed
V1.0
K80 and P100
1 parent 804baf7 commit e1f14ba

36 files changed

+2334
-3457
lines changed

CNTK_CNN.ipynb

+55-43
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
"cell_type": "code",
2727
"execution_count": 2,
2828
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"# Force one-gpu\n",
32+
"os.environ[\"CUDA_VISIBLE_DEVICES\"] = \"0\""
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 3,
38+
"metadata": {},
2939
"outputs": [
3040
{
3141
"name": "stdout",
@@ -34,9 +44,11 @@
3444
"OS: linux\n",
3545
"Python: 3.5.2 |Anaconda custom (64-bit)| (default, Jul 2 2016, 17:53:06) \n",
3646
"[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]\n",
37-
"Numpy: 1.13.3\n",
38-
"CNTK: 2.2\n",
39-
"GPU: ['Tesla K80']\n"
47+
"Numpy: 1.14.1\n",
48+
"CNTK: 2.4\n",
49+
"GPU: ['Tesla P100-PCIE-16GB', 'Tesla P100-PCIE-16GB']\n",
50+
"CUDA Version 8.0.61\n",
51+
"CuDNN Version 6.0.21\n"
4052
]
4153
}
4254
],
@@ -45,16 +57,18 @@
4557
"print(\"Python: \", sys.version)\n",
4658
"print(\"Numpy: \", np.__version__)\n",
4759
"print(\"CNTK: \", cntk.__version__)\n",
48-
"print(\"GPU: \", get_gpu_name())"
60+
"print(\"GPU: \", get_gpu_name())\n",
61+
"print(get_cuda_version())\n",
62+
"print(\"CuDNN Version \", get_cudnn_version())"
4963
]
5064
},
5165
{
5266
"cell_type": "code",
53-
"execution_count": 3,
67+
"execution_count": 4,
5468
"metadata": {},
5569
"outputs": [],
5670
"source": [
57-
"def create_symbol():\n",
71+
"def create_symbol(n_classes=N_CLASSES):\n",
5872
" # Weight initialiser from uniform distribution\n",
5973
" # Activation (unless states) is None\n",
6074
" with cntk.layers.default_options(init = cntk.glorot_uniform(), activation = cntk.relu):\n",
@@ -70,34 +84,34 @@
7084
" \n",
7185
" x = Dense(512)(x)\n",
7286
" x = Dropout(0.5)(x)\n",
73-
" x = Dense(N_CLASSES, activation=None)(x)\n",
87+
" x = Dense(n_classes, activation=None)(x)\n",
7488
" return x"
7589
]
7690
},
7791
{
7892
"cell_type": "code",
79-
"execution_count": 4,
93+
"execution_count": 5,
8094
"metadata": {},
8195
"outputs": [],
8296
"source": [
83-
"def init_model(m):\n",
97+
"def init_model(m, labels, lr=LR, momentum=MOMENTUM):\n",
8498
" # Loss (dense labels); check if support for sparse labels\n",
8599
" loss = cntk.cross_entropy_with_softmax(m, labels) \n",
86100
" # Momentum SGD\n",
87101
" # https://github.com/Microsoft/CNTK/blob/master/Manual/Manual_How_to_use_learners.ipynb\n",
88102
" # unit_gain=False: momentum_direction = momentum*old_momentum_direction + gradient\n",
89103
" # if unit_gain=True then ...(1-momentum)*gradient\n",
90104
" learner = cntk.momentum_sgd(m.parameters,\n",
91-
" lr=cntk.learning_rate_schedule(LR, cntk.UnitType.minibatch) ,\n",
92-
" momentum=cntk.momentum_schedule(MOMENTUM), \n",
105+
" lr=cntk.learning_rate_schedule(lr, cntk.UnitType.minibatch) ,\n",
106+
" momentum=cntk.momentum_schedule(momentum), \n",
93107
" unit_gain=False)\n",
94108
" trainer = cntk.Trainer(m, (loss, cntk.classification_error(m, labels)), [learner])\n",
95109
" return trainer"
96110
]
97111
},
98112
{
99113
"cell_type": "code",
100-
"execution_count": 5,
114+
"execution_count": 6,
101115
"metadata": {},
102116
"outputs": [
103117
{
@@ -108,8 +122,8 @@
108122
"Preparing test set...\n",
109123
"(50000, 3, 32, 32) (10000, 3, 32, 32) (50000, 10) (10000, 10)\n",
110124
"float32 float32 float32 float32\n",
111-
"CPU times: user 833 ms, sys: 553 ms, total: 1.39 s\n",
112-
"Wall time: 1.38 s\n"
125+
"CPU times: user 671 ms, sys: 576 ms, total: 1.25 s\n",
126+
"Wall time: 1.25 s\n"
113127
]
114128
}
115129
],
@@ -126,15 +140,15 @@
126140
},
127141
{
128142
"cell_type": "code",
129-
"execution_count": 6,
143+
"execution_count": 7,
130144
"metadata": {},
131145
"outputs": [
132146
{
133147
"name": "stdout",
134148
"output_type": "stream",
135149
"text": [
136-
"CPU times: user 22.6 ms, sys: 28.6 ms, total: 51.2 ms\n",
137-
"Wall time: 76.1 ms\n"
150+
"CPU times: user 24 ms, sys: 32 ms, total: 56 ms\n",
151+
"Wall time: 69 ms\n"
138152
]
139153
}
140154
],
@@ -149,51 +163,50 @@
149163
},
150164
{
151165
"cell_type": "code",
152-
"execution_count": 7,
166+
"execution_count": 8,
153167
"metadata": {},
154168
"outputs": [
155169
{
156170
"name": "stdout",
157171
"output_type": "stream",
158172
"text": [
159-
"CPU times: user 72.1 ms, sys: 224 ms, total: 297 ms\n",
160-
"Wall time: 303 ms\n"
173+
"CPU times: user 119 ms, sys: 116 ms, total: 235 ms\n",
174+
"Wall time: 236 ms\n"
161175
]
162176
}
163177
],
164178
"source": [
165179
"%%time\n",
166-
"trainer = init_model(sym)"
180+
"trainer = init_model(sym, labels)"
167181
]
168182
},
169183
{
170184
"cell_type": "code",
171-
"execution_count": 8,
185+
"execution_count": 9,
172186
"metadata": {},
173187
"outputs": [
174188
{
175189
"name": "stdout",
176190
"output_type": "stream",
177191
"text": [
178-
"Epoch 1 | Accuracy: 0.562500\n",
192+
"Epoch 1 | Accuracy: 0.468750\n",
179193
"Epoch 2 | Accuracy: 0.640625\n",
180-
"Epoch 3 | Accuracy: 0.625000\n",
181-
"Epoch 4 | Accuracy: 0.703125\n",
182-
"Epoch 5 | Accuracy: 0.703125\n",
183-
"Epoch 6 | Accuracy: 0.765625\n",
184-
"Epoch 7 | Accuracy: 0.859375\n",
185-
"Epoch 8 | Accuracy: 0.796875\n",
186-
"Epoch 9 | Accuracy: 0.781250\n",
187-
"Epoch 10 | Accuracy: 0.796875\n",
188-
"CPU times: user 2min 19s, sys: 21.4 s, total: 2min 40s\n",
189-
"Wall time: 2min 43s\n"
194+
"Epoch 3 | Accuracy: 0.609375\n",
195+
"Epoch 4 | Accuracy: 0.578125\n",
196+
"Epoch 5 | Accuracy: 0.812500\n",
197+
"Epoch 6 | Accuracy: 0.781250\n",
198+
"Epoch 7 | Accuracy: 0.671875\n",
199+
"Epoch 8 | Accuracy: 0.843750\n",
200+
"Epoch 9 | Accuracy: 0.796875\n",
201+
"Epoch 10 | Accuracy: 0.843750\n",
202+
"CPU times: user 40.3 s, sys: 13.1 s, total: 53.3 s\n",
203+
"Wall time: 53.2 s\n"
190204
]
191205
}
192206
],
193207
"source": [
194208
"%%time \n",
195-
"# 163s\n",
196-
"# Train model\n",
209+
"# Main training loop: 53s\n",
197210
"for j in range(EPOCHS):\n",
198211
" for data, label in yield_mb(x_train, y_train, BATCHSIZE, shuffle=True):\n",
199212
" trainer.train_minibatch({features: data, labels: label})\n",
@@ -204,22 +217,21 @@
204217
},
205218
{
206219
"cell_type": "code",
207-
"execution_count": 9,
220+
"execution_count": 10,
208221
"metadata": {},
209222
"outputs": [
210223
{
211224
"name": "stdout",
212225
"output_type": "stream",
213226
"text": [
214-
"CPU times: user 850 ms, sys: 337 ms, total: 1.19 s\n",
215-
"Wall time: 1.4 s\n"
227+
"CPU times: user 291 ms, sys: 88.9 ms, total: 379 ms\n",
228+
"Wall time: 408 ms\n"
216229
]
217230
}
218231
],
219232
"source": [
220233
"%%time\n",
221-
"# Predict and then score accuracy\n",
222-
"# (We don't need softmax -> monotonic function)\n",
234+
"# Main evaluation loop: 343ms\n",
223235
"n_samples = (y_test.shape[0]//BATCHSIZE)*BATCHSIZE\n",
224236
"y_guess = np.zeros(n_samples, dtype=np.int)\n",
225237
"y_truth = np.argmax(y_test[:n_samples], axis=-1)\n",
@@ -232,14 +244,14 @@
232244
},
233245
{
234246
"cell_type": "code",
235-
"execution_count": 10,
247+
"execution_count": 11,
236248
"metadata": {},
237249
"outputs": [
238250
{
239251
"name": "stdout",
240252
"output_type": "stream",
241253
"text": [
242-
"Accuracy: 0.780649038462\n"
254+
"Accuracy: 0.7701322115384616\n"
243255
]
244256
}
245257
],
@@ -251,7 +263,7 @@
251263
"metadata": {
252264
"anaconda-cloud": {},
253265
"kernelspec": {
254-
"display_name": "Python [default]",
266+
"display_name": "Python 3",
255267
"language": "python",
256268
"name": "python3"
257269
},

0 commit comments

Comments
 (0)