From ba01d02be88d2a0b7c81a81b70d981df77d81636 Mon Sep 17 00:00:00 2001 From: ishaansingh22 Date: Fri, 31 May 2024 05:33:43 +0400 Subject: [PATCH 1/8] first pass at configs --- src/configs/algo_config.py | 66 ++++++++++++++++++++++++++++++++++++++ src/configs/sys_config.py | 21 ++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/configs/algo_config.py create mode 100644 src/configs/sys_config.py diff --git a/src/configs/algo_config.py b/src/configs/algo_config.py new file mode 100644 index 0000000..0dae588 --- /dev/null +++ b/src/configs/algo_config.py @@ -0,0 +1,66 @@ +from src.configs.sys_config import system_config, get_device_ids +# Algorithm Configuration + +iid_dispfl_clients_new = { + "algo": "dispfl", + "exp_id": 200, + "exp_type": "iid_dispfl", + "dset": "cifar10", + "dump_dir": "./expt_dump/", + "dpath": system_config["dataset_path"] + "cifar10", + "seed": 2, + "device_ids": get_device_ids("iid_dispfl"), + "num_clients": system_config["dataset_splits"]["iid"]["num_clients"], + "samples_per_client": system_config["dataset_splits"]["iid"]["samples_per_client"], + "neighbors": 2, + "active_rate": 0.8, + "dense_ratio": 0.5, + "erk_power_scale": 1, + "anneal_factor": 0.5, + "epochs": 1000, + "model": "resnet34", + "model_lr": 3e-4, + "batch_size": 128, + "exp_keys": [] +} + +iid_defkt_clients_new = { + "algo": "defkt", + "exp_id": 200, + "exp_type": "iid_defkt", + "dset": "cifar10", + "dump_dir": "./expt_dump/", + "dpath": system_config["dataset_path"] + "cifar10", + "seed": 2, + "device_ids": get_device_ids("iid_defkt"), + "num_teachers": 1, + "num_clients": system_config["dataset_splits"]["iid"]["num_clients"], + "samples_per_client": system_config["dataset_splits"]["iid"]["samples_per_client"], + "dense_ratio": 0.5, + "erk_power_scale": 1, + "epochs": 1000, + "model": "resnet34", + "model_lr": 3e-4, + "batch_size": 256, + "exp_keys": [] +} + +non_iid_clients = { + "algo": "fedran", + "dpath": system_config["dataset_path"] + "domainnet", + "train_label_distribution": "iid", + "test_label_distribution": "iid", + "samples_per_client": system_config["dataset_splits"]["non_iid"]["samples_per_client"], + "num_clients": system_config["dataset_splits"]["non_iid"]["num_clients"], + "rounds": 210, + "epochs_per_round": 5, + "model": "resnet10", + "local_train_after_aggr": True, + "model_lr": 1e-4, + "batch_size": 16, + "average_last_layer": True, + "position": 0, + "exp_keys": [] +} + +current_config = iid_dispfl_clients_new diff --git a/src/configs/sys_config.py b/src/configs/sys_config.py new file mode 100644 index 0000000..a15858a --- /dev/null +++ b/src/configs/sys_config.py @@ -0,0 +1,21 @@ + +# System Configuration + +system_config = { + "num_users": 4, + "experiment_path": "./experiments/", + "dataset_path": "/data/unagi0/anakewat/imgs/", + "device_ids": { + "iid_dispfl": {"node_0": [2], "node_1": [3], "node_2": [4], "node_3": [5], "node_4": [2]}, + "iid_defkt": {"node_0": [4], "node_1": [4], "node_2": [4], "node_3": [4]}, + "non_iid": {"node_0": [0], "node_1": [1], "node_2": [2], "node_3": [3]} + }, + "dataset_splits": { + "iid": {"num_clients": 4, "samples_per_client": 500}, + "non_iid": {"num_clients": 8, "samples_per_client": 32} + } +} + + +def get_device_ids(algo): + return system_config["device_ids"].get(algo, {}) From ac74bcaad83bbec2df0aed231ce945b2d7eda6b9 Mon Sep 17 00:00:00 2001 From: ishaansingh22 Date: Sat, 8 Jun 2024 14:33:06 +0530 Subject: [PATCH 2/8] Config changes --- src/configs/algo_config.py | 46 ------------------------------------ src/configs/sys_config.py | 4 +++- src/scheduler.py | 48 +++++++++++++++++++++++++++----------- 3 files changed, 37 insertions(+), 61 deletions(-) diff --git a/src/configs/algo_config.py b/src/configs/algo_config.py index 0dae588..fb0ae87 100644 --- a/src/configs/algo_config.py +++ b/src/configs/algo_config.py @@ -1,17 +1,10 @@ -from src.configs.sys_config import system_config, get_device_ids # Algorithm Configuration iid_dispfl_clients_new = { "algo": "dispfl", "exp_id": 200, "exp_type": "iid_dispfl", - "dset": "cifar10", - "dump_dir": "./expt_dump/", - "dpath": system_config["dataset_path"] + "cifar10", "seed": 2, - "device_ids": get_device_ids("iid_dispfl"), - "num_clients": system_config["dataset_splits"]["iid"]["num_clients"], - "samples_per_client": system_config["dataset_splits"]["iid"]["samples_per_client"], "neighbors": 2, "active_rate": 0.8, "dense_ratio": 0.5, @@ -24,43 +17,4 @@ "exp_keys": [] } -iid_defkt_clients_new = { - "algo": "defkt", - "exp_id": 200, - "exp_type": "iid_defkt", - "dset": "cifar10", - "dump_dir": "./expt_dump/", - "dpath": system_config["dataset_path"] + "cifar10", - "seed": 2, - "device_ids": get_device_ids("iid_defkt"), - "num_teachers": 1, - "num_clients": system_config["dataset_splits"]["iid"]["num_clients"], - "samples_per_client": system_config["dataset_splits"]["iid"]["samples_per_client"], - "dense_ratio": 0.5, - "erk_power_scale": 1, - "epochs": 1000, - "model": "resnet34", - "model_lr": 3e-4, - "batch_size": 256, - "exp_keys": [] -} - -non_iid_clients = { - "algo": "fedran", - "dpath": system_config["dataset_path"] + "domainnet", - "train_label_distribution": "iid", - "test_label_distribution": "iid", - "samples_per_client": system_config["dataset_splits"]["non_iid"]["samples_per_client"], - "num_clients": system_config["dataset_splits"]["non_iid"]["num_clients"], - "rounds": 210, - "epochs_per_round": 5, - "model": "resnet10", - "local_train_after_aggr": True, - "model_lr": 1e-4, - "batch_size": 16, - "average_last_layer": True, - "position": 0, - "exp_keys": [] -} - current_config = iid_dispfl_clients_new diff --git a/src/configs/sys_config.py b/src/configs/sys_config.py index a15858a..415b650 100644 --- a/src/configs/sys_config.py +++ b/src/configs/sys_config.py @@ -4,7 +4,9 @@ system_config = { "num_users": 4, "experiment_path": "./experiments/", - "dataset_path": "/data/unagi0/anakewat/imgs/", + "dset": "cifar10", + "dump_dir": "./expt_dump/", + "dpath": "/data/unagi0/anakewat/imgs/", "device_ids": { "iid_dispfl": {"node_0": [2], "node_1": [3], "node_2": [4], "node_3": [5], "node_4": [2]}, "iid_defkt": {"node_0": [4], "node_1": [4], "node_2": [4], "node_3": [4]}, diff --git a/src/scheduler.py b/src/scheduler.py index fff2592..cf7433a 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -1,5 +1,7 @@ from mpi4py import MPI -import torch, random, numpy +import torch +import random +import numpy from algos.base_class import BaseNode from algos.fl import FedAvgClient, FedAvgServer from algos.isolated import IsolatedServer @@ -9,7 +11,7 @@ from algos.fl_weight import FedWeightClient, FedWeightServer from algos.swarm import SWARMClient, SWARMServer from algos.DisPFL import DisPFLClient, DisPFLServer -from algos.def_kt import DefKTClient,DefKTServer +from algos.def_kt import DefKTClient, DefKTServer from algos.fedfomo import FedFomoClient, FedFomoServer from algos.L2C import L2CClient, L2CServer from algos.MetaL2C import MetaL2CClient, MetaL2CServer @@ -18,6 +20,7 @@ from algos.fl_val import FedValClient, FedValServer from utils.log_utils import copy_source_code, check_and_create_path from utils.config_utils import load_config, process_config +from configs.sys_config import get_device_ids import os # should be used as: algo_map[algo_name][rank>0](config) @@ -25,38 +28,53 @@ algo_map = { "fedavg": [FedAvgServer, FedAvgClient], "isolated": [IsolatedServer], - "fedran": [FedRanServer,FedRanClient], + "fedran": [FedRanServer, FedRanClient], "fedass": [FedAssServer, FedAssClient], - "fediso": [FedIsoServer,FedIsoClient], - "fedweight": [FedWeightServer,FedWeightClient], - "swarm" : [SWARMServer, SWARMClient], + "fediso": [FedIsoServer, FedIsoClient], + "fedweight": [FedWeightServer, FedWeightClient], + "swarm": [SWARMServer, SWARMClient], "dispfl": [DisPFLServer, DisPFLClient], - "defkt": [DefKTServer,DefKTClient], + "defkt": [DefKTServer, DefKTClient], "fedfomo": [FedFomoServer, FedFomoClient], - "l2c": [L2CServer,L2CClient], - "metal2c": [MetaL2CServer,MetaL2CClient], + "l2c": [L2CServer, L2CClient], + "metal2c": [MetaL2CServer, MetaL2CClient], "centralized": [CentralizedServer, CentralizedCLient], "feddatarepr": [FedDataRepServer, FedDataRepClient], "fedval": [FedValServer, FedValClient], } + def get_node(config: dict, rank) -> BaseNode: algo_name = config["algo"] - return algo_map[algo_name][rank>0](config) + return algo_map[algo_name][rank > 0](config) class Scheduler(): """ Manages the overall orchestration of experiments """ + def __init__(self) -> None: pass - def assign_config_by_path(self, config_path) -> None: - self.config = load_config(config_path) - def install_config(self) -> None: self.config = process_config(self.config) + def assign_config_by_path(self, sys_config_path, algo_config_path): + self.sys_config = load_config(sys_config_path) + self.algo_config = load_config(algo_config_path) + self.merge_configs() + + def merge_configs(self): + self.config = self.algo_config.copy() + self.config.update({ + "dset": "cifar10", + "dump_dir": "./expt_dump/", + "dpath": self.sys_config["dataset_path"] + "cifar10", + "num_clients": self.sys_config["dataset_splits"]["iid"]["num_clients"], + "samples_per_client": self.sys_config["dataset_splits"]["iid"]["samples_per_client"], + "device_ids": get_device_ids("iid_dispfl") + }) + def initialize(self, copy_souce_code=True) -> None: assert self.config is not None, "Config should be set when initializing" @@ -65,7 +83,9 @@ def initialize(self, copy_souce_code=True) -> None: # Base clients modify the seed later on seed = self.config["seed"] - torch.manual_seed(seed); random.seed(seed); numpy.random.seed(seed) + torch.manual_seed(seed) + random.seed(seed) + numpy.random.seed(seed) if rank == 0: if copy_souce_code: From 5d751e0fa516f2388075a64c6dab8fd984496d12 Mon Sep 17 00:00:00 2001 From: ishaan <66063951+ishaansingh22@users.noreply.github.com> Date: Wed, 12 Jun 2024 09:27:10 -0400 Subject: [PATCH 3/8] Update algo_config.py --- src/configs/algo_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/configs/algo_config.py b/src/configs/algo_config.py index fb0ae87..e22e2d5 100644 --- a/src/configs/algo_config.py +++ b/src/configs/algo_config.py @@ -4,7 +4,6 @@ "algo": "dispfl", "exp_id": 200, "exp_type": "iid_dispfl", - "seed": 2, "neighbors": 2, "active_rate": 0.8, "dense_ratio": 0.5, From c5318c7022f160a7274893babecd89c994ef36b0 Mon Sep 17 00:00:00 2001 From: ishaan <66063951+ishaansingh22@users.noreply.github.com> Date: Wed, 12 Jun 2024 09:27:30 -0400 Subject: [PATCH 4/8] Update sys_config.py --- src/configs/sys_config.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/configs/sys_config.py b/src/configs/sys_config.py index 415b650..bfc4147 100644 --- a/src/configs/sys_config.py +++ b/src/configs/sys_config.py @@ -1,4 +1,3 @@ - # System Configuration system_config = { @@ -7,14 +6,15 @@ "dset": "cifar10", "dump_dir": "./expt_dump/", "dpath": "/data/unagi0/anakewat/imgs/", + "seed": 2, "device_ids": { "iid_dispfl": {"node_0": [2], "node_1": [3], "node_2": [4], "node_3": [5], "node_4": [2]}, "iid_defkt": {"node_0": [4], "node_1": [4], "node_2": [4], "node_3": [4]}, "non_iid": {"node_0": [0], "node_1": [1], "node_2": [2], "node_3": [3]} }, "dataset_splits": { - "iid": {"num_clients": 4, "samples_per_client": 500}, - "non_iid": {"num_clients": 8, "samples_per_client": 32} + "iid": {"samples_per_user": 500}, + "non_iid": {"samples_per_user": 32} } } From ade4564a24c6ff30fc1a6e83ad5e392baba7d84e Mon Sep 17 00:00:00 2001 From: ishaan <66063951+ishaansingh22@users.noreply.github.com> Date: Wed, 12 Jun 2024 09:27:52 -0400 Subject: [PATCH 5/8] Update scheduler.py --- src/scheduler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scheduler.py b/src/scheduler.py index 37e7110..b27f80a 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -76,8 +76,8 @@ def merge_configs(self): "dset": "cifar10", "dump_dir": "./expt_dump/", "dpath": self.sys_config["dataset_path"] + "cifar10", - "num_clients": self.sys_config["dataset_splits"]["iid"]["num_clients"], - "samples_per_client": self.sys_config["dataset_splits"]["iid"]["samples_per_client"], + "num_users": self.sys_config["num_users"], + "samples_per_user": self.sys_config["dataset_splits"]["iid"]["samples_per_user"], "device_ids": get_device_ids("iid_dispfl") }) From 9cd6cb0f0a09f8de62f7c1e775bf49f218f67694 Mon Sep 17 00:00:00 2001 From: ishaan <66063951+ishaansingh22@users.noreply.github.com> Date: Thu, 27 Jun 2024 14:25:04 -0400 Subject: [PATCH 6/8] move device_id processing to scheduler --- src/configs/sys_config.py | 11 +---------- src/scheduler.py | 5 ++--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/configs/sys_config.py b/src/configs/sys_config.py index bfc4147..c47a351 100644 --- a/src/configs/sys_config.py +++ b/src/configs/sys_config.py @@ -1,5 +1,4 @@ # System Configuration - system_config = { "num_users": 4, "experiment_path": "./experiments/", @@ -7,17 +6,9 @@ "dump_dir": "./expt_dump/", "dpath": "/data/unagi0/anakewat/imgs/", "seed": 2, - "device_ids": { - "iid_dispfl": {"node_0": [2], "node_1": [3], "node_2": [4], "node_3": [5], "node_4": [2]}, - "iid_defkt": {"node_0": [4], "node_1": [4], "node_2": [4], "node_3": [4]}, - "non_iid": {"node_0": [0], "node_1": [1], "node_2": [2], "node_3": [3]} - }, + "device_ids": {} "dataset_splits": { "iid": {"samples_per_user": 500}, "non_iid": {"samples_per_user": 32} } } - - -def get_device_ids(algo): - return system_config["device_ids"].get(algo, {}) diff --git a/src/scheduler.py b/src/scheduler.py index b27f80a..10b82bd 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -22,8 +22,7 @@ from algos.fl_data_repr import FedDataRepClient, FedDataRepServer from algos.fl_val import FedValClient, FedValServer from utils.log_utils import copy_source_code, check_and_create_path -from utils.config_utils import load_config, process_config -from configs.sys_config import get_device_ids +from utils.config_utils import load_config, process_config, get_device_ids import os # should be used as: algo_map[algo_name][rank>0](config) @@ -78,7 +77,7 @@ def merge_configs(self): "dpath": self.sys_config["dataset_path"] + "cifar10", "num_users": self.sys_config["num_users"], "samples_per_user": self.sys_config["dataset_splits"]["iid"]["samples_per_user"], - "device_ids": get_device_ids("iid_dispfl") + "device_ids": get_device_ids(num_clients=fedcentral_client, num_client_per_gpu=6, available_gpus=[0, 1,2, 3, 4, 5, 6, 7]) }) def initialize(self, copy_souce_code=True) -> None: From ee4dc39396612b1b694940370290bf9fc3f7088f Mon Sep 17 00:00:00 2001 From: ishaan <66063951+ishaansingh22@users.noreply.github.com> Date: Fri, 28 Jun 2024 23:29:28 -0400 Subject: [PATCH 7/8] fix configs --- src/configs/sys_config.py | 7 ++----- src/scheduler.py | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/configs/sys_config.py b/src/configs/sys_config.py index c47a351..b2a20b6 100644 --- a/src/configs/sys_config.py +++ b/src/configs/sys_config.py @@ -6,9 +6,6 @@ "dump_dir": "./expt_dump/", "dpath": "/data/unagi0/anakewat/imgs/", "seed": 2, - "device_ids": {} - "dataset_splits": { - "iid": {"samples_per_user": 500}, - "non_iid": {"samples_per_user": 32} - } + "device_ids": {"node_0": [5], "node_1": [5],"node_2": [5], "node_3": [2], "node_4": [2], "node_5": [3], "node_6": [3], "node_7": [3], "node_8": [3]}, + "dataset_splits": {"samples_per_user": 500}, #iid, same structure for non_iid } diff --git a/src/scheduler.py b/src/scheduler.py index 10b82bd..62a155e 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -76,8 +76,8 @@ def merge_configs(self): "dump_dir": "./expt_dump/", "dpath": self.sys_config["dataset_path"] + "cifar10", "num_users": self.sys_config["num_users"], - "samples_per_user": self.sys_config["dataset_splits"]["iid"]["samples_per_user"], - "device_ids": get_device_ids(num_clients=fedcentral_client, num_client_per_gpu=6, available_gpus=[0, 1,2, 3, 4, 5, 6, 7]) + "samples_per_user": self.sys_config["dataset_splits"]["samples_per_user"], + "device_ids": self.sys_config["device_ids"] }) def initialize(self, copy_souce_code=True) -> None: From f6a9f621326281d9be488d45653aa86fc5145aca Mon Sep 17 00:00:00 2001 From: ishaan <66063951+ishaansingh22@users.noreply.github.com> Date: Sun, 30 Jun 2024 23:07:50 -0400 Subject: [PATCH 8/8] removed hardcoding from scheduler --- src/scheduler.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/scheduler.py b/src/scheduler.py index 62a155e..3dbb332 100644 --- a/src/scheduler.py +++ b/src/scheduler.py @@ -72,10 +72,11 @@ def assign_config_by_path(self, sys_config_path, algo_config_path): def merge_configs(self): self.config = self.algo_config.copy() self.config.update({ - "dset": "cifar10", - "dump_dir": "./expt_dump/", - "dpath": self.sys_config["dataset_path"] + "cifar10", + "dset": self.sys_config["dset"], + "dump_dir": self.sys_config["dump_dir"], + "dpath": self.sys_config["dpath"], "num_users": self.sys_config["num_users"], + "seed": self.config["seed"], "samples_per_user": self.sys_config["dataset_splits"]["samples_per_user"], "device_ids": self.sys_config["device_ids"] })