Skip to content

Commit f06ff06

Browse files
authored
Merge pull request #12 from larsid/release/1.5.0
Release/1.5.0
2 parents 63461ec + 7520127 commit f06ff06

66 files changed

Lines changed: 880 additions & 3198 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 21 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ class MNIST(Task):
102102
return IidPartitioner()
103103

104104
def preprocess_dataset(self, dataset: Dataset, training: bool) -> Dataset:
105-
return Dataset(x=tf.divide(dataset.x, 255.0), y=dataset.y)
105+
x = tf.cast(dataset.x, tf.float32) / 255.0
106+
x_normalized = (x - 0.5) / 0.5
107+
return Dataset(x=x_normalized, y=dataset.y)
106108

107109
def model(self) -> models.Model:
108110
return cnn3(
@@ -117,10 +119,10 @@ class MNIST(Task):
117119
def train_configs(self) -> TrainConfigs:
118120
return TrainConfigs(
119121
batch_size=16,
120-
epochs=2,
122+
epochs=1,
121123
num_clients=4,
122124
num_partitions=4,
123-
num_rounds=10,
125+
num_rounds=3,
124126
seed_data=42,
125127
shuffle_data=True,
126128
)
@@ -148,9 +150,7 @@ Use `FLExperiment` to assemble the experiment:
148150
5. Register remote workers (for distributed execution)
149151
6. Link clusters with network resources to define topology
150152

151-
> When the worker host `cpu_clock` is set to `BASE_COMPUTE_UNIT`, all resource `cpu_clock` values are interpreted in Docker CPU units (e.g., millicores) instead of GHz.
152-
153-
![Experiment Topology](https://i.postimg.cc/NjtcwR0S/experiment-topology.png)
153+
![Experiment Topology](https://i.postimg.cc/pTyZYWyx/experiment-topology.png)
154154

155155
```py
156156
from netfl.core.experiment import FLExperiment
@@ -160,41 +160,40 @@ from netfl.utils.resources import (
160160
DeviceResource,
161161
ClusterResource,
162162
ClusterResourceType,
163-
BASE_COMPUTE_UNIT,
164163
)
165164

166165
from task import FLTask
167166

168167

169168
task = FLTask()
170-
num_clients = task.train_configs().num_clients
169+
clients_per_edge = task.train_configs().num_clients // 2
171170

172-
worker_host_resource = WorkerHostResource(cpu_clock=BASE_COMPUTE_UNIT)
171+
worker_host_resource = WorkerHostResource()
173172

174173
server_resource = DeviceResource(
175174
name="server",
176-
cpu_cores=1,
177-
cpu_clock=1.0,
178-
memory=1024,
175+
cpu_cores=8,
176+
cpu_clock=2.0,
177+
memory=4096,
179178
network_resource=NetworkResource(bw=1000),
180179
worker_host_resource=worker_host_resource,
181180
)
182181

183182
client_a_resource = DeviceResource(
184183
name="client_a",
185-
cpu_cores=1,
186-
cpu_clock=0.5,
187-
memory=512,
184+
cpu_cores=4,
185+
cpu_clock=1.2,
186+
memory=1024,
188187
network_resource=NetworkResource(bw=100),
189188
worker_host_resource=worker_host_resource,
190189
)
191190

192191
client_b_resource = DeviceResource(
193192
name="client_b",
194-
cpu_cores=1,
195-
cpu_clock=0.25,
196-
memory=512,
197-
network_resource=NetworkResource(bw=50),
193+
cpu_cores=4,
194+
cpu_clock=1.5,
195+
memory=2048,
196+
network_resource=NetworkResource(bw=1000),
198197
worker_host_resource=worker_host_resource,
199198
)
200199

@@ -207,13 +206,13 @@ cloud_resource = ClusterResource(
207206
edge_0_resource = ClusterResource(
208207
name="edge_0",
209208
type=ClusterResourceType.EDGE,
210-
device_resources=(num_clients // 2) * [client_a_resource],
209+
device_resources=clients_per_edge * [client_a_resource],
211210
)
212211

213212
edge_1_resource = ClusterResource(
214213
name="edge_1",
215214
type=ClusterResourceType.EDGE,
216-
device_resources=(num_clients // 2) * [client_b_resource],
215+
device_resources=clients_per_edge * [client_b_resource],
217216
)
218217

219218
exp = FLExperiment(
@@ -267,43 +266,7 @@ RunWorker -p=5000
267266
python3 experiment.py
268267
```
269268

270-
## Running a NetFL Experiment without a Customized Network Topology Using Docker Compose
271-
272-
### 1. Clone the repository
273-
274-
```
275-
git clone https://github.com/larsid/netfl.git
276-
```
277-
278-
### 2. Create the Task
279-
280-
In the project root directory, create or modify a **NetFL Task** and name the file `task.py`. Refer to the examples in the `examples` folder for guidance on task creation.
281-
282-
### 3. Create the Infrastructure
283-
284-
Use Docker Compose to set up the infrastructure, including the server and clients:
285-
286-
```
287-
docker compose up -d
288-
```
289-
290-
### 4. View Training Results
291-
292-
To check the server logs, run:
293-
294-
```
295-
docker logs server
296-
```
297-
298-
Training logs are also stored in the `logs/` folder within the project root directory.
299-
300-
### 5. Shut Down the Infrastructure
301-
302-
To stop and remove all running containers, use the following command:
303-
304-
```
305-
docker compose down
306-
```
269+
> The experiment result files are saved in the `logs` folder located in the directory where the experiment script is executed.
307270
308271
## More information
309272

docker-compose.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

examples/cifar10/experiment.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,40 @@
55
DeviceResource,
66
ClusterResource,
77
ClusterResourceType,
8-
BASE_COMPUTE_UNIT,
98
)
109

1110
from task import FLTask
1211

1312

1413
task = FLTask()
15-
num_clients = task.train_configs().num_clients
14+
clients_per_edge = task.train_configs().num_clients // 2
1615

17-
worker_host_resource = WorkerHostResource(cpu_clock=BASE_COMPUTE_UNIT)
16+
worker_host_resource = WorkerHostResource()
1817

1918
server_resource = DeviceResource(
2019
name="server",
21-
cpu_cores=1,
22-
cpu_clock=1.0,
23-
memory=1024,
20+
cpu_cores=8,
21+
cpu_clock=2.0,
22+
memory=4096,
2423
network_resource=NetworkResource(bw=1000),
2524
worker_host_resource=worker_host_resource,
2625
)
2726

2827
client_a_resource = DeviceResource(
2928
name="client_a",
30-
cpu_cores=1,
31-
cpu_clock=0.5,
32-
memory=512,
29+
cpu_cores=4,
30+
cpu_clock=1.2,
31+
memory=1024,
3332
network_resource=NetworkResource(bw=100),
3433
worker_host_resource=worker_host_resource,
3534
)
3635

3736
client_b_resource = DeviceResource(
3837
name="client_b",
39-
cpu_cores=1,
40-
cpu_clock=0.25,
41-
memory=512,
42-
network_resource=NetworkResource(bw=50),
38+
cpu_cores=4,
39+
cpu_clock=1.5,
40+
memory=2048,
41+
network_resource=NetworkResource(bw=1000),
4342
worker_host_resource=worker_host_resource,
4443
)
4544

@@ -52,13 +51,13 @@
5251
edge_0_resource = ClusterResource(
5352
name="edge_0",
5453
type=ClusterResourceType.EDGE,
55-
device_resources=(num_clients // 2) * [client_a_resource],
54+
device_resources=clients_per_edge * [client_a_resource],
5655
)
5756

5857
edge_1_resource = ClusterResource(
5958
name="edge_1",
6059
type=ClusterResourceType.EDGE,
61-
device_resources=(num_clients // 2) * [client_b_resource],
60+
device_resources=clients_per_edge * [client_b_resource],
6261
)
6362

6463
exp = FLExperiment(

examples/cifar10/task.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any
22

33
import tensorflow as tf
4-
from keras import models, optimizers
4+
from keras import models, optimizers, layers
55
from flwr.server.strategy import Strategy, FedAvg
66

77
from netfl.core.task import Task, Dataset, DatasetInfo, DatasetPartitioner, TrainConfigs
@@ -23,13 +23,19 @@ def dataset_partitioner(self) -> DatasetPartitioner:
2323
return IidPartitioner()
2424

2525
def preprocess_dataset(self, dataset: Dataset, training: bool) -> Dataset:
26-
return Dataset(x=tf.divide(dataset.x, 255.0), y=dataset.y)
26+
x = tf.cast(dataset.x, tf.float32) / 255.0
27+
x_normalized = (x - 0.5) / 0.5
28+
return Dataset(x=x_normalized, y=dataset.y)
2729

2830
def model(self) -> models.Model:
2931
return cnn3(
3032
input_shape=(32, 32, 3),
3133
output_classes=10,
3234
optimizer=optimizers.SGD(learning_rate=0.01),
35+
augmentation_layers=[
36+
layers.RandomFlip("horizontal"),
37+
layers.RandomTranslation(0.1, 0.1),
38+
],
3339
)
3440

3541
def aggregation_strategy(self) -> tuple[type[Strategy], dict[str, Any]]:
@@ -38,10 +44,10 @@ def aggregation_strategy(self) -> tuple[type[Strategy], dict[str, Any]]:
3844
def train_configs(self) -> TrainConfigs:
3945
return TrainConfigs(
4046
batch_size=16,
41-
epochs=2,
47+
epochs=1,
4248
num_clients=4,
4349
num_partitions=4,
44-
num_rounds=10,
50+
num_rounds=3,
4551
seed_data=42,
4652
shuffle_data=True,
4753
)
-63.6 KB
Binary file not shown.

examples/mnist/experiment.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,40 @@
55
DeviceResource,
66
ClusterResource,
77
ClusterResourceType,
8-
BASE_COMPUTE_UNIT,
98
)
109

1110
from task import FLTask
1211

1312

1413
task = FLTask()
15-
num_clients = task.train_configs().num_clients
14+
clients_per_edge = task.train_configs().num_clients // 2
1615

17-
worker_host_resource = WorkerHostResource(cpu_clock=BASE_COMPUTE_UNIT)
16+
worker_host_resource = WorkerHostResource()
1817

1918
server_resource = DeviceResource(
2019
name="server",
21-
cpu_cores=1,
22-
cpu_clock=1.0,
23-
memory=1024,
20+
cpu_cores=8,
21+
cpu_clock=2.0,
22+
memory=4096,
2423
network_resource=NetworkResource(bw=1000),
2524
worker_host_resource=worker_host_resource,
2625
)
2726

2827
client_a_resource = DeviceResource(
2928
name="client_a",
30-
cpu_cores=1,
31-
cpu_clock=0.5,
32-
memory=512,
29+
cpu_cores=4,
30+
cpu_clock=1.2,
31+
memory=1024,
3332
network_resource=NetworkResource(bw=100),
3433
worker_host_resource=worker_host_resource,
3534
)
3635

3736
client_b_resource = DeviceResource(
3837
name="client_b",
39-
cpu_cores=1,
40-
cpu_clock=0.25,
41-
memory=512,
42-
network_resource=NetworkResource(bw=50),
38+
cpu_cores=4,
39+
cpu_clock=1.5,
40+
memory=2048,
41+
network_resource=NetworkResource(bw=1000),
4342
worker_host_resource=worker_host_resource,
4443
)
4544

@@ -52,13 +51,13 @@
5251
edge_0_resource = ClusterResource(
5352
name="edge_0",
5453
type=ClusterResourceType.EDGE,
55-
device_resources=(num_clients // 2) * [client_a_resource],
54+
device_resources=clients_per_edge * [client_a_resource],
5655
)
5756

5857
edge_1_resource = ClusterResource(
5958
name="edge_1",
6059
type=ClusterResourceType.EDGE,
61-
device_resources=(num_clients // 2) * [client_b_resource],
60+
device_resources=clients_per_edge * [client_b_resource],
6261
)
6362

6463
exp = FLExperiment(

0 commit comments

Comments
 (0)