Skip to content

Commit

Permalink
Merge pull request #4 from aidecentralized/configs
Browse files Browse the repository at this point in the history
config changes
  • Loading branch information
tremblerz authored Jul 1, 2024
2 parents ec8d5b8 + f6a9f62 commit e2585f6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
19 changes: 19 additions & 0 deletions src/configs/algo_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Algorithm Configuration

iid_dispfl_clients_new = {
"algo": "dispfl",
"exp_id": 200,
"exp_type": "iid_dispfl",
"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": []
}

current_config = iid_dispfl_clients_new
11 changes: 11 additions & 0 deletions src/configs/sys_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# System Configuration
system_config = {
"num_users": 4,
"experiment_path": "./experiments/",
"dset": "cifar10",
"dump_dir": "./expt_dump/",
"dpath": "/data/unagi0/anakewat/imgs/",
"seed": 2,
"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
}
42 changes: 31 additions & 11 deletions src/scheduler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,15 +14,15 @@
from algos.fl_ring import FedRingClient, FedRingServer
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
from algos.fl_central import CentralizedCLient, CentralizedServer
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 utils.config_utils import load_config, process_config, get_device_ids
import os

# should be used as: algo_map[algo_name][rank>0](config)
Expand All @@ -37,32 +39,48 @@
"fedring": [FedRingServer,FedRingClient],
"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": 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"]
})

def initialize(self, copy_souce_code=True) -> None:
assert self.config is not None, "Config should be set when initializing"

Expand All @@ -71,7 +89,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:
Expand Down

0 comments on commit e2585f6

Please sign in to comment.