Skip to content

Commit a2e9edc

Browse files
committedMay 7, 2020
code for 30 trials, 75 tests per
1 parent 7538410 commit a2e9edc

7 files changed

+18
-18
lines changed
 

‎1_each_client_partially_iid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def go(self, num, batch):
146146
# assign slices to single client
147147
dataset = tf.data.Dataset.from_tensor_slices((client_sample_x, client_sample_y))
148148
# add to list of client datasets
149-
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(self.SHUFFLE_BUFFER))
149+
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(60000, seed = self.SHUFFLE_SEED, reshuffle_each_iteration=True))
150150

151151
# train
152152
self.build_model()

‎2_some_clients_iid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def go(self, num, batch):
9898
# assign slices to single client
9999
dataset = tf.data.Dataset.from_tensor_slices((client_sample_x, client_sample_y))
100100
# add to list of client datasets
101-
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(self.SHUFFLE_BUFFER))
101+
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(60000, seed = self.SHUFFLE_SEED, reshuffle_each_iteration=True))
102102

103103
# train
104104
self.build_model()

‎3_shard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def go(self, num, batch):
109109
# assign slices to single client
110110
dataset = tf.data.Dataset.from_tensor_slices((client_sample_x, client_sample_y))
111111
# add to list of client datasets
112-
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(self.SHUFFLE_BUFFER))
112+
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(60000, seed = self.SHUFFLE_SEED, reshuffle_each_iteration=True))
113113

114114
# train
115115
self.build_model()

‎4_iid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def go(self, num, batch):
4848
# slice data for single client
4949
dataset = tf.data.Dataset.from_tensor_slices((x_train[x_indices], y_train[y_indices]))
5050
# add to list of client datasets
51-
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(self.SHUFFLE_BUFFER))
51+
self.dataset_list.append(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(60000, seed = self.SHUFFLE_SEED, reshuffle_each_iteration=True))
5252

5353
# train
5454
self.build_model()

‎config.JSON

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"COHORT_SIZE": 5,
44
"NUM_LOCAL_EPOCHS": 10,
55
"LOCAL_BATCH_SIZE": 10,
6-
"SHUFFLE_BUFFER": 100,
6+
"SHUFFLE_SEED": 100,
77
"LEARNING_RATE": 0.215,
88
"TARGET_ACCURACY": 99,
99
"ROUNDS_BETWEEN_TESTS": 1

‎partitioner.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self):
2424
self.MAX_FANOUT = 1
2525
self.NUM_EPOCHS = 1
2626
self.BATCH_SIZE = 1
27-
self.SHUFFLE_BUFFER = 0
27+
self.SHUFFLE_SEED = 0
2828
self.LR = 0.1
2929
self.TARGET = 50
3030
self.TEST_PERIOD = 1
@@ -62,7 +62,7 @@ def prep(self):
6262
self.MAX_FANOUT = math.ceil(options['system']['MAX_THREADS']) # controlls multi-threading
6363
self.NUM_EPOCHS = math.ceil(options['model']['NUM_LOCAL_EPOCHS']) # for client model
6464
self.BATCH_SIZE = math.ceil(options['model']['LOCAL_BATCH_SIZE']) # for client model
65-
self.SHUFFLE_BUFFER = math.ceil(options['model']['SHUFFLE_BUFFER'])
65+
self.SHUFFLE_SEED = math.ceil(options['model']['SHUFFLE_SEED'])
6666
self.LR = options['model']['LEARNING_RATE'] # SGD learning rate
6767
self.TARGET = options['model']['TARGET_ACCURACY'] # target accuracy for model when tested with test set
6868
self.TEST_PERIOD = options['model']['ROUNDS_BETWEEN_TESTS'] # number of rounds between testset evaluation
@@ -97,16 +97,16 @@ def test_num(self, n):
9797

9898
# construct value array
9999
# learning rate chosen/iterates first, batch size second, ...
100-
shuffle_buffer = [100, 200, 300, 400, 500, 600, 700, 800]
101-
percent_data_iid = [0, 20, 40, 60, 80, 100] # schema 1
100+
shuffle_seed = list(range(30))
101+
percent_data_iid = [20, 40, 60, 80, 100] # schema 1
102102
percent_clients_iid = [50] # schema 2
103-
cohort_size = [2, 5, 10, 15, 20, 25, 30]
103+
cohort_size = [2, 5, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 35, 40]
104104
num_epochs = [10] # leave at 10
105105
batch_size = [10]
106106
learning_rate = [0.1]
107107

108108
# convert test number to array indices and set constants to array values
109-
self.SHUFFLE_BUFFER = shuffle_buffer[n // (len(percent_data_iid) * len(percent_clients_iid) * len(cohort_size) * len(num_epochs) * len(batch_size) * len(learning_rate))]
109+
self.SHUFFLE_SEED = shuffle_seed[n // (len(percent_data_iid) * len(percent_clients_iid) * len(cohort_size) * len(num_epochs) * len(batch_size) * len(learning_rate))]
110110
n = n % (len(percent_data_iid) * len(percent_clients_iid) * len(cohort_size) * len(num_epochs) * len(batch_size) * len(learning_rate))
111111
self.PERCENT_DATA_IID = percent_data_iid[n // (len(percent_clients_iid) * len(cohort_size) * len(num_epochs) * len(batch_size) * len(learning_rate))]
112112
n = n % (len(percent_clients_iid) * len(cohort_size) * len(num_epochs) * len(batch_size) * len(learning_rate))
@@ -132,11 +132,11 @@ def make_config_csv(self, test, batch):
132132
filename = 'results/' + str(batch) + '/' + str(batch) + '.' + str(test) + '.config.csv'
133133
with open(filename, 'w', newline='') as csvfile:
134134
writer = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
135-
writer.writerow(['COHORT_SIZE', 'NUM_LOCAL_EPOCHS', 'LOCAL_BATCH_SIZE', 'SHUFFLE_BUFFER',
135+
writer.writerow(['COHORT_SIZE', 'NUM_LOCAL_EPOCHS', 'LOCAL_BATCH_SIZE', 'SHUFFLE_SEED',
136136
'LEARNING_RATE', 'TARGET_ACCURACY', 'ROUNDS_BETWEEN_TESTS', 'NUM_CLIENTS', 'NUM_CLASSES_PER',
137137
'MEAN_NUM_DATA_PTS_PER_CLIENT', 'STD_DEV_NUM_DATA_PTS_PER_CLIENT', 'PERCENT_DATA_IID',
138138
'PERCENT_CLIENTS_IID','MAX_THREADS'])
139-
writer.writerow([self.COHORT_SIZE, self.NUM_EPOCHS, self.BATCH_SIZE, self.SHUFFLE_BUFFER,
139+
writer.writerow([self.COHORT_SIZE, self.NUM_EPOCHS, self.BATCH_SIZE, self.SHUFFLE_SEED,
140140
self.LR, self.TARGET, self.TEST_PERIOD, self.CLIENTS, self.SHARDS,
141141
self.NUMDATAPTS_MEAN, self.NUMDATAPTS_STDEV, self.PERCENT_DATA_IID,
142142
self.PERCENT_CLIENTS_IID, self.MAX_FANOUT])
@@ -155,7 +155,7 @@ def load_data(self):
155155

156156
# create sample batch for Keras model wrapper
157157
# note: sample batch is different data type than dataset used in iterative process
158-
self.sample_batch = tf.nest.map_structure(lambda x: x.numpy(), iter(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(self.SHUFFLE_BUFFER)).next())
158+
self.sample_batch = tf.nest.map_structure(lambda x: x.numpy(), iter(dataset.repeat(self.NUM_EPOCHS).batch(self.BATCH_SIZE).shuffle(60000, seed = self.SHUFFLE_SEED, reshuffle_each_iteration=True)).next())
159159

160160
return (x_train, y_train)
161161

@@ -180,7 +180,7 @@ def train(self, test, batch, schema_num):
180180

181181
# preprocess test dataset
182182
testset = tf.data.Dataset.from_tensor_slices((x_test, y_test))
183-
processed_testset = testset.batch(self.BATCH_SIZE).shuffle(self.SHUFFLE_BUFFER)
183+
processed_testset = testset.batch(self.BATCH_SIZE).shuffle(60000, seed = self.SHUFFLE_SEED, reshuffle_each_iteration=True)
184184
model = self.create_compiled_keras_model()
185185

186186
# print(model.count_params())

‎test_tff.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/bash
22

33
#SBATCH --job-name=tff_partition
4-
#SBATCH --nodes=4
5-
#SBATCH --cpus-per-task=10
4+
#SBATCH --nodes=1
5+
#SBATCH --cpus-per-task=6
66
#SBATCH --mem-per-cpu=8g
77
#SBATCH --time=48:00:00
88
#SBATCH --account=tewaria1
@@ -11,7 +11,7 @@
1111
#SBATCH --mail-type=END
1212
#SBATCH --output=results/tff.%A.%a.out
1313

14-
#SBATCH --array=1-336
14+
#SBATCH --array=1-2250
1515

1616
module load python3.7-anaconda
1717
module load cudnn/10.0-v7.6

0 commit comments

Comments
 (0)
Please sign in to comment.