From 00c6cf9d438518b596be285ee75749a1d280aee6 Mon Sep 17 00:00:00 2001 From: francotheengineer Date: Fri, 7 Jul 2017 12:04:17 +0100 Subject: [PATCH 1/2] Fixed Deep RNN Multi-gpu implementation to use tf Fixed Deep RNN Multi-gpu implementation to use tf.python.ops.nn.rnn_cell DeviceWrapper class instead of implementing custom class to achieve the same result. It would appear that the custom class shown with the code does not function. --- 14_recurrent_neural_networks.ipynb | 37 +++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/14_recurrent_neural_networks.ipynb b/14_recurrent_neural_networks.ipynb index bc16d31..21394ec 100644 --- a/14_recurrent_neural_networks.ipynb +++ b/14_recurrent_neural_networks.ipynb @@ -107,11 +107,13 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "deletable": true, "editable": true }, + "outputs": [], "source": [ "# Basic RNNs" ] @@ -431,7 +433,7 @@ ] }, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ @@ -711,7 +713,7 @@ ] }, "metadata": {}, - "output_type": "display_data" + "output_type": "execute_result" } ], "source": [ @@ -2210,6 +2212,29 @@ "outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Alternatively, you can use the Tensorflow class DeviceWrapper - note you can define more than one layer per gpu" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "devices = [\"/gpu:0\", \"/gpu:1\", \"/gpu:2\"] \n", + "cells = []\n", + "for dev in devices:\n", + " cell = DeviceWrapper(rnn_cell.BasicRNNCell(num_units=n_neurons), dev)\n", + " cells.append(cell)\n", + "\n", + "self.multiple_lstm_cells = tf.contrib.rnn.MultiRNNCell(cells, state_is_tuple=True)\n", + "outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)" + ] + }, { "cell_type": "code", "execution_count": 76, @@ -3524,7 +3549,7 @@ "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3 + "version": 3.0 }, "file_extension": ".py", "mimetype": "text/x-python", @@ -3538,7 +3563,7 @@ "navigate_menu": true, "number_sections": true, "sideBar": true, - "threshold": 6, + "threshold": 6.0, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false @@ -3546,4 +3571,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From d5707a189801450b483d14d7d06bbd81aef66ee5 Mon Sep 17 00:00:00 2001 From: Aurelien Geron Date: Wed, 18 Oct 2017 09:44:57 +0200 Subject: [PATCH 2/2] Add comment about the DeviceWrapper class since TF 1.1 --- 14_recurrent_neural_networks.ipynb | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/14_recurrent_neural_networks.ipynb b/14_recurrent_neural_networks.ipynb index 833eb37..1f2c6a8 100644 --- a/14_recurrent_neural_networks.ipynb +++ b/14_recurrent_neural_networks.ipynb @@ -369,7 +369,7 @@ ] }, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ @@ -615,7 +615,7 @@ ] }, "metadata": {}, - "output_type": "execute_result" + "output_type": "display_data" } ], "source": [ @@ -1939,23 +1939,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Alternatively, you can use the Tensorflow class DeviceWrapper - note you can define more than one layer per gpu" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "devices = [\"/gpu:0\", \"/gpu:1\", \"/gpu:2\"] \n", - "cells = []\n", - "for dev in devices:\n", - " cell = DeviceWrapper(rnn_cell.BasicRNNCell(num_units=n_neurons), dev)\n", - " cells.append(cell)\n", - "\n", - "self.multiple_lstm_cells = tf.contrib.rnn.MultiRNNCell(cells, state_is_tuple=True)\n", - "outputs, states = tf.nn.dynamic_rnn(multi_layer_cell, X, dtype=tf.float32)" + "Alternatively, since TensorFlow 1.1, you can use the `tf.contrib.rnn.DeviceWrapper` class (alias `tf.nn.rnn_cell.DeviceWrapper` since TF 1.2)." ] }, { @@ -3720,21 +3704,21 @@ "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3.0 + "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.2" }, "nav_menu": {}, "toc": { "navigate_menu": true, "number_sections": true, "sideBar": true, - "threshold": 6.0, + "threshold": 6, "toc_cell": false, "toc_section_display": "block", "toc_window_display": false