-
Notifications
You must be signed in to change notification settings - Fork 12
/
linear_dynamo_trigger.py
73 lines (63 loc) · 2.14 KB
/
linear_dynamo_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import boto3
import json
from storage import DynamoTable
from storage.dynamo import dynamo_operator
def handler(event, context):
function_name = "lambda_core"
# dataset setting
dataset_name = 'higgs'
data_bucket = "higgs-10"
dataset_type = "dense_libsvm" # dense_libsvm
n_features = 30
n_classes = 2
tmp_table_name = "tmp-params"
merged_table_name = "merged-params"
key_col = "key"
# training setting
model = "lr" # lr, svm
optim = "grad_avg" # grad_avg, model_avg, or admm
sync_mode = "reduce" # async, reduce or reduce_scatter
n_workers = 10
# hyper-parameters
lr = 0.01
batch_size = 100000
n_epochs = 2
valid_ratio = .2
n_admm_epochs = 2
lam = 0.01
rho = 0.01
# clear dynamodb table
dynamo_client = dynamo_operator.get_client()
tmp_tb = DynamoTable(dynamo_client, tmp_table_name)
merged_tb = DynamoTable(dynamo_client, tmp_table_name)
tmp_tb.clear(key_col)
merged_tb.clear(key_col)
# lambda payload
payload = dict()
payload['dataset'] = dataset_name
payload['data_bucket'] = data_bucket
payload['dataset_type'] = dataset_type
payload['n_features'] = n_features
payload['n_classes'] = n_classes
payload['n_workers'] = n_workers
payload['tmp_table_name'] = tmp_table_name
payload['merged_table_name'] = merged_table_name
payload['key_col'] = key_col
payload['model'] = model
payload['optim'] = optim
payload['sync_mode'] = sync_mode
payload['lr'] = lr
payload['batch_size'] = batch_size
payload['n_epochs'] = n_epochs
payload['valid_ratio'] = valid_ratio
payload['n_admm_epochs'] = n_admm_epochs
payload['lambda'] = lam
payload['rho'] = rho
# 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))