Last active
August 17, 2018 15:15
-
-
Save stsievert/7389acd62eb6f6d151286214cb51c392 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"Using TensorFlow backend.\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"([autoencoder.AutoEncoder, sklearn.base.BaseEstimator, object],\n", | |
" [keras.engine.training.Model,\n", | |
" keras.engine.network.Network,\n", | |
" keras.engine.base_layer.Layer,\n", | |
" object])" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from distributed import Client\n", | |
"client = Client()\n", | |
"# noisy, clean = autoencoder.get_noisy_mnist(n=64)\n", | |
"\n", | |
"import autoencoder\n", | |
"from distributed.protocol import register_attributes\n", | |
"register_attributes(autoencoder.AutoEncoder)\n", | |
"\n", | |
"model = autoencoder.AutoEncoder()\n", | |
"type(model).mro(), type(model.autoencoder).mro()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"distributed.protocol.core - CRITICAL - Failed to Serialize\n", | |
"Traceback (most recent call last):\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 53, in dumps\n", | |
" for key, value in data.items()\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 54, in <dictcomp>\n", | |
" if type(value) is Serialize}\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/serialize.py\", line 153, in serialize\n", | |
" raise TypeError(msg)\n", | |
"TypeError: Could not serialize object of type Model\n", | |
"distributed.comm.utils - ERROR - Could not serialize object of type Model\n", | |
"Traceback (most recent call last):\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/comm/utils.py\", line 41, in _to_frames\n", | |
" context=context))\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 53, in dumps\n", | |
" for key, value in data.items()\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 54, in <dictcomp>\n", | |
" if type(value) is Serialize}\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/serialize.py\", line 153, in serialize\n", | |
" raise TypeError(msg)\n", | |
"TypeError: Could not serialize object of type Model\n" | |
] | |
} | |
], | |
"source": [ | |
"import pytest\n", | |
"with pytest.raises(TypeError):\n", | |
" model = client.scatter(model.autoencoder)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def setup(return_x_y=False):\n", | |
" from keras.datasets import mnist\n", | |
" from keras.models import Sequential\n", | |
" from keras.layers import Dense, Dropout, Flatten, Conv2D, MaxPooling2D\n", | |
" from keras import backend as K\n", | |
" import keras\n", | |
" img_rows, img_cols = 28, 28\n", | |
" (x_train, y_train), (x_test, y_test) = mnist.load_data()\n", | |
"\n", | |
" x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)\n", | |
" x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)\n", | |
" input_shape = (img_rows, img_cols, 1)\n", | |
"\n", | |
" x_train = x_train.astype('float32') / 255\n", | |
" x_test = x_test.astype('float32') / 255\n", | |
" y_train = keras.utils.to_categorical(y_train, 10)\n", | |
" y_test = keras.utils.to_categorical(y_test, 10)\n", | |
" if return_x_y:\n", | |
" return x_train, y_train\n", | |
"\n", | |
" model = Sequential()\n", | |
" model.add(Conv2D(32, kernel_size=(3, 3),\n", | |
" activation='relu',\n", | |
" input_shape=input_shape))\n", | |
" model.add(Conv2D(64, (3, 3), activation='relu'))\n", | |
" model.add(MaxPooling2D(pool_size=(2, 2)))\n", | |
" model.add(Dropout(0.25))\n", | |
" model.add(Flatten())\n", | |
" model.add(Dense(128, activation='relu'))\n", | |
" model.add(Dropout(0.5))\n", | |
" model.add(Dense(10, activation='softmax'))\n", | |
" return model, x_train, y_train" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"distributed.protocol.core - CRITICAL - Failed to Serialize\n", | |
"Traceback (most recent call last):\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 53, in dumps\n", | |
" for key, value in data.items()\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 54, in <dictcomp>\n", | |
" if type(value) is Serialize}\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/serialize.py\", line 153, in serialize\n", | |
" raise TypeError(msg)\n", | |
"TypeError: Could not serialize object of type Sequential\n", | |
"distributed.comm.utils - ERROR - Could not serialize object of type Sequential\n", | |
"Traceback (most recent call last):\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/comm/utils.py\", line 41, in _to_frames\n", | |
" context=context))\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 53, in dumps\n", | |
" for key, value in data.items()\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/core.py\", line 54, in <dictcomp>\n", | |
" if type(value) is Serialize}\n", | |
" File \"/Users/ssievert/Developer/mrocklin/distributed/distributed/protocol/serialize.py\", line 153, in serialize\n", | |
" raise TypeError(msg)\n", | |
"TypeError: Could not serialize object of type Sequential\n" | |
] | |
} | |
], | |
"source": [ | |
"m, _, _ = setup()\n", | |
"with pytest.raises(TypeError):\n", | |
" client.scatter(m)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think this gist is with modifying the decorator at https://github.com/dask/distributed/blob/4e36660e84b0eb20c1bc4127ba07a1876aefd5c5/distributed/protocol/keras.py#L8 to be
and likewise for serialization.