-
Notifications
You must be signed in to change notification settings - Fork 12
/
kmeans_ec_trigger.py
53 lines (44 loc) · 1.46 KB
/
kmeans_ec_trigger.py
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
52
53
import boto3
import json
from storage.memcached import memcached_operator
def handler(event, context):
function_name = "lambda_core"
# dataset setting
dataset_name = 'higgs'
data_bucket = "higgs-10"
dataset_type = "dense_libsvm"
n_features = 30
host = "127.0.0.1"
port = 11211
tmp_bucket = "tmp-params"
merged_bucket = "merged-params"
# hyper-parameters
n_clusters = 2
n_epochs = 10
threshold = 0.0001
# training setting
sync_mode = "reduce" # reduce or reduce_scatter
n_workers = 10
# lambda payload
payload = dict()
payload['dataset'] = dataset_name
payload['data_bucket'] = data_bucket
payload['dataset_type'] = dataset_type
payload['n_features'] = n_features
payload['tmp_bucket'] = tmp_bucket
payload['merged_bucket'] = merged_bucket
payload['n_clusters'] = n_clusters
payload['n_epochs'] = n_epochs
payload['threshold'] = threshold
payload['sync_mode'] = sync_mode
payload['n_workers'] = n_workers
payload['host'] = host
payload['port'] = port
# invoke functions
lambda_client = boto3.client('lambda')
for i in range(n_workers):
payload['worker_index'] = i
payload['file'] = '{}_{}'.format(i, n_workers)
lambda_client.invoke(FunctionName=function_name,
InvocationType='Event',
Payload=json.dumps(payload))