-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathdispatch_tasks.py
More file actions
51 lines (40 loc) · 1.73 KB
/
dispatch_tasks.py
File metadata and controls
51 lines (40 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
A sample script that shows how to distribute multiple tasks to multiple machine
using the database module.
"""
import time
import tensorflow as tf
import tensorlayer as tl
tl.logging.set_verbosity(tl.logging.DEBUG)
# tf.logging.set_verbosity(tf.logging.DEBUG)
# connect to database
db = tl.db.TensorHub(ip='localhost', port=27017, dbname='temp', project_name='tutorial')
# delete existing tasks, models and datasets in this project
db.delete_tasks()
db.delete_model()
db.delete_datasets()
# save dataset into database, then allow other servers to use it
X_train, y_train, X_val, y_val, X_test, y_test = tl.files.load_mnist_dataset(shape=(-1, 784))
db.save_dataset((X_train, y_train, X_val, y_val, X_test, y_test), 'mnist', description='handwriting digit')
# push tasks into database, then allow other servers pull tasks to run
db.create_task(
task_name='mnist', script='task_script.py', hyper_parameters=dict(n_units1=800, n_units2=800),
saved_result_keys=['test_accuracy'], description='800-800'
)
db.create_task(
task_name='mnist', script='task_script.py', hyper_parameters=dict(n_units1=600, n_units2=600),
saved_result_keys=['test_accuracy'], description='600-600'
)
db.create_task(
task_name='mnist', script='task_script.py', hyper_parameters=dict(n_units1=400, n_units2=400),
saved_result_keys=['test_accuracy'], description='400-400'
)
# wait for tasks to finish
while db.check_unfinished_task(task_name='mnist'):
print("waiting runners to finish the tasks")
time.sleep(1)
# get the best model
print("all tasks finished")
sess = tf.InteractiveSession()
net = db.find_top_model(sess=sess, model_name='mlp', sort=[("test_accuracy", -1)])
print("the best accuracy {} is from model {}".format(net._test_accuracy, net._name))