Skip to content

Instantly share code, notes, and snippets.

@bnaul
Created February 19, 2017 00:13
Show Gist options
  • Save bnaul/45b63a7baec8db37dd8ab8296ec49377 to your computer and use it in GitHub Desktop.
Save bnaul/45b63a7baec8db37dd8ab8296ec49377 to your computer and use it in GitHub Desktop.
import numpy as np
import tensorflow as tf
import keras
from keras import backend as K
from distributed import Client, client
def new_session():
sess = tf.Session()
return sess
def test_simulation(size, sess):
K.set_session(sess)
X = np.random.random((10, 5))
y = np.random.random((10, 1))
model_input = keras.layers.Input((5,))
hidden = keras.layers.Dense(size)(model_input)
model_output = keras.layers.Dense(1)(hidden)
model = keras.models.Model(model_input, model_output)
model.compile(optimizer='sgd', loss='mse')
model.fit(X, y, nb_epoch=10)
if __name__ == '__main__':
SCHEDULER_IP = 'tcp://127.0.0.1:8786'
# SCHEDULER_IP = '169.229.219.178:8786'
client = Client(SCHEDULER_IP)
sess = client.submit(new_session)
res_list = [client.submit(test_simulation, i, sess) for i in range(5, 10)]
# client.wait(res_list)
@mrocklin
Copy link

You can even throw a lock around the entire contents of test_simulation and the system fails.

@alvarouc
Copy link

alvarouc commented Sep 7, 2017

Any updated news on this? I am having the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment