Skip to content

Commit

Permalink
fix expt_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamjajoo committed Sep 17, 2024
1 parent 2c63e78 commit 5861c88
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 44 deletions.
38 changes: 13 additions & 25 deletions src/configs/algo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"epochs": 1000,
"model": "resnet34",
"model_lr": 3e-4,
"batch_size": 128,
"exp_keys": []
"batch_size": 128
}

traditional_fl: ConfigType = {
Expand All @@ -64,7 +63,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"model": "resnet10",
"model_lr": 3e-4,
"batch_size": 256,
"exp_keys": [],
"malicious_type": "normal"
}

Expand Down Expand Up @@ -99,7 +97,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"mask_finetune_last_layer": False,
# params for model
"position": 0,
"exp_keys": [],
}

defkt: ConfigType = {
Expand All @@ -118,7 +115,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
# params for model
"position": 0,
"inp_shape": [128, 3, 32, 32], # This should be a List[int]
"exp_keys": [],
}

fedavg_object_detect: ConfigType = {
Expand All @@ -129,8 +125,7 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"epochs": 10,
"model": "yolo",
"model_lr": 1e-5,
"batch_size": 8,
"exp_keys": [],
"batch_size": 8
}

fediso: ConfigType = {
Expand All @@ -146,8 +141,7 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"batch_size": 16,

# params for model
"position": 0,
"exp_keys": []
"position": 0
}

L2C_users: int = 3
Expand Down Expand Up @@ -177,7 +171,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
# params for model
"position": 0,
"inp_shape": [128, 3, 32, 32], # This should be a List[int]
"exp_keys": []
}

fedcentral: ConfigType = {
Expand All @@ -196,8 +189,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
# params for model
"position": 0,
"inp_shape": [128, 3, 32, 32],

"exp_keys": []
}

fedval: ConfigType = {
Expand Down Expand Up @@ -225,8 +216,7 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"mask_finetune_last_layer": False,

# params for model
"position": 0,
"exp_keys": []
"position": 0,
}

swarm_users: int = 3
Expand Down Expand Up @@ -255,7 +245,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st

# params for model
"position": 0,
"exp_keys": [],
}

fedstatic: ConfigType = {
Expand Down Expand Up @@ -283,7 +272,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st

# params for model
"position": 0,
"exp_keys": [],
}

metaL2C_cifar10: ConfigType = {
Expand Down Expand Up @@ -311,9 +299,7 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st

# params for model
"position": 0,
"inp_shape": [128, 3, 32, 32],

"exp_keys": []
"inp_shape": [128, 3, 32, 32]
}

fedass: ConfigType = {
Expand All @@ -339,8 +325,7 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
"batch_size": 16,

# params for model
"position": 0,
"exp_keys": ["strategy"]
"position": 0
}

feddatarepr: ConfigType = {
Expand Down Expand Up @@ -408,7 +393,6 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
# "alpha_f": 10.0,
#"dreams_keep_best": False, # Use reprs with lowest loss

"exp_keys": ["similarity_metric", "selection_strategy", "consensus"]
}

# List of algorithm configurations
Expand All @@ -430,8 +414,12 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
feddatarepr
]

# Temp List of algorithm configurations
temp_algo_config_list: List[ConfigType] = [
# Malicious List of algorithm configurations
malicious_algo_config_list: List[ConfigType] = [
traditional_fl,
malicious_traditional_fl,
malicious_traditional_fl
]

default_config_list: List[ConfigType] = [
traditional_fl
]
37 changes: 25 additions & 12 deletions src/configs/sys_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# is to simulate different real-world scenarios without changing the algorithm configuration.
from typing import TypeAlias, Dict, List, Union, Tuple, Optional
# from utils.config_utils import get_sliding_window_support, get_device_ids
from .algo_config import algo_config_list, temp_algo_config_list
from .algo_config import algo_config_list, malicious_algo_config_list, default_config_list
import random

ConfigType: TypeAlias = Dict[str, Union[
Expand Down Expand Up @@ -115,13 +115,14 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"device_ids": {"node_0": [0], "node_1": [0],"node_2": [0], "node_3": [0]},
# use this when the list needs to be imported from the algo_config
# "algo": get_algo_configs(num_users=3, algo_configs=algo_configs_list),
"algo": get_algo_configs(num_users=3, algo_configs=temp_algo_config_list),
"algo": get_algo_configs(num_users=3, algo_configs=malicious_algo_config_list),
"samples_per_user": 1000, #TODO: To model scenarios where different users have different number of samples
# we need to make this a dictionary with user_id as key and number of samples as value
"train_label_distribution": "iid", # Either "iid", "non_iid" "support"
"test_label_distribution": "iid", # Either "iid", "non_iid" "support"
"test_samples_per_user": 200, # Only for non_iid test distribution
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

mpi_non_iid_sys_config = {
Expand All @@ -136,11 +137,13 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"dpath": "./datasets/imgs/cifar10/",
"load_existing": False,
"device_ids": get_device_ids(num_users=3, gpus_available=[0, 3]),
"algo": get_algo_configs(num_users=3, algo_configs=default_config_list),
"train_label_distribution": "non_iid", # Either "iid", "non_iid" "support",
"test_label_distribution": "non_iid", # Either "iid" "support",
"samples_per_user": 256,
"test_samples_per_user": 100,
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

L2C_users = 3
Expand All @@ -156,12 +159,14 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"dpath": "./datasets/imgs/cifar10/",
"load_existing": False,
"device_ids": get_device_ids(num_users=3, gpus_available=[1, 2]),
"algo": get_algo_configs(num_users=3, algo_configs=default_config_list),
"train_label_distribution": "iid", # Either "iid", "non_iid" "support",
"test_label_distribution": "iid", # Either "iid" "support",
"samples_per_user": 32,
"test_samples_per_user": 32,
"validation_prop": 0.05,
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

mpi_metaL2C_support_sys_config = {
Expand All @@ -176,13 +181,15 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"dpath": "./datasets/imgs/cifar10/",
"load_existing": False,
"device_ids": get_device_ids(num_users=3, gpus_available=[1, 2]),
"algo": get_algo_configs(num_users=3, algo_configs=default_config_list),
"train_label_distribution": "support", # Either "iid", "non_iid" "support",
"test_label_distribution": "support", # Either "iid" "support",
"support" : sliding_window_8c_4cpc_support,
"samples_per_user": 32,
"test_samples_per_user": 32,
"validation_prop": 0.05,
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

mpi_digitfive_sys_config = {
Expand All @@ -195,7 +202,7 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"load_existing": False,
"dump_dir": "./expt_dump/",
"device_ids": get_device_ids(num_users=3, gpus_available=[6, 7]),

"algo": get_algo_configs(num_users=3, algo_configs=default_config_list),
# Dataset params
"dset": get_digit_five_support(3),#get_camelyon17_support(fedcentral_client), #get_domainnet_support(fedcentral_client),
"dpath": digit_five_dpath, #wilds_dpath,#domainnet_dpath,
Expand All @@ -204,7 +211,8 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"samples_per_user": 256,
"test_samples_per_class": 100,
"community_type": "dataset",
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

swarm_users = 3
Expand All @@ -218,7 +226,7 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"load_existing": False,
"dump_dir": "./expt_dump/",
"device_ids": get_device_ids(num_users=swarm_users, gpus_available=[3, 4]),

"algo": get_algo_configs(num_users=swarm_users, algo_configs=default_config_list),
# Dataset params
"dset": get_domainnet_support(swarm_users),#get_camelyon17_support(fedcentral_client), #get_domainnet_support(fedcentral_client),
"dpath": domainnet_dpath, #wilds_dpath,#domainnet_dpath,
Expand All @@ -227,7 +235,8 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"samples_per_user": 32,
"test_samples_per_class": 100,
"community_type": "dataset",
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

object_detect_system_config = {
Expand All @@ -241,11 +250,13 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
# The device_ids dictionary depicts the GPUs on which the nodes reside.
# For a single-GPU environment, the config will look as follows (as it follows a 0-based indexing):
"device_ids": {"node_0": [1], "node_1": [2]},
"algo": get_algo_configs(num_users=2, algo_configs=default_config_list),
"samples_per_user": 100, #TODO: To model scenarios where different users have different number of samples
# we need to make this a dictionary with user_id as key and number of samples as value
"train_label_distribution": "iid",
"test_label_distribution": "iid",
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

num_users = 20
Expand All @@ -261,10 +272,12 @@ def get_digit_five_support(num_users:int, domains:List[str]=DIGIT_FIVE):
"dpath": "./datasets/imgs/cifar10/",
"seed": 2,
"device_ids": get_device_ids(num_users, gpu_ids),
"algo": get_algo_configs(num_users=num_users, algo_configs=default_config_list),
"samples_per_user": 50000 // num_users, # distributed equally
"train_label_distribution": "iid",
"test_label_distribution": "iid",
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal"
"folder_deletion_signal_path":"./expt_dump/folder_deletion.signal",
"exp_keys": []
}

# current_config = grpc_system_config
Expand Down
14 changes: 7 additions & 7 deletions src/utils/config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ def process_config(config: Dict[str, Any]) -> Dict[str, Any]:
unique_id
)

# for exp_key in config["exp_keys"]:
# item = jmespath.search(exp_key, config)
# assert item is not None
# key = exp_key.split(".")[-1]
# assert key is not None
# # experiment_name += "_{}_{}".format(key, item)
# experiment_name += "_{}".format(item)
for exp_key in config["exp_keys"]:
item = jmespath.search(exp_key, config)
assert item is not None
key = exp_key.split(".")[-1]
assert key is not None
# experiment_name += "_{}_{}".format(key, item)
experiment_name += "_{}".format(item)

experiments_folder = config["dump_dir"]
results_path = experiments_folder + experiment_name + f"_seed{config['seed']}"
Expand Down

0 comments on commit 5861c88

Please sign in to comment.