Skip to content

Commit

Permalink
add hex for each expt dump
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamjajoo committed Sep 17, 2024
1 parent 423c9c8 commit 2c63e78
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 34 deletions.
8 changes: 0 additions & 8 deletions src/algos/fl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from algos.base_class import BaseClient, BaseServer
import os
import time
from utils.node_map import NodeMap

class FedAvgClient(BaseClient):
def __init__(self, config: Dict[str, Any], comm_utils: CommunicationManager) -> None:
Expand Down Expand Up @@ -67,19 +66,12 @@ def set_representation(self, representation: OrderedDict[str, Tensor]):
def run_protocol(self):
start_epochs = self.config.get("start_epochs", 0)
total_epochs = self.config["epochs"]
node_map = NodeMap()

for round in range(start_epochs, total_epochs):
self.local_train(round)
self.local_test()
repr = self.get_representation()

if node_map.is_malicious(self.node_id):
state_dict = self.model.state_dict()
for key in state_dict:
state_dict[key] = state_dict[key].zero_()
repr = state_dict

self.client_log_utils.log_summary("Client {} sending done signal to {}".format(self.node_id, self.server_node))
self.comm_utils.send(self.server_node, repr)
self.client_log_utils.log_summary("Client {} waiting to get new model from {}".format(self.node_id, self.server_node))
Expand Down
2 changes: 1 addition & 1 deletion src/configs/algo_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,4 @@ def get_malicious_types(malicious_config_list: List[ConfigType]) -> Dict[str, st
temp_algo_config_list: List[ConfigType] = [
traditional_fl,
malicious_traditional_fl,
]
]
2 changes: 1 addition & 1 deletion src/configs/malicious_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
bad_weights,
data_poisoning,
backdoor_attack
]
]
8 changes: 5 additions & 3 deletions src/utils/config_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Any, Dict, List
import jmespath
import importlib
from utils.node_map import NodeMap
import random
import uuid

def load_config(config_path: str) -> Dict[str, Any]:
path = ".".join(config_path.split(".")[1].split("/")[1:])
Expand All @@ -29,11 +29,13 @@ def process_config(config: Dict[str, Any]) -> Dict[str, Any]:
else:
dset = config["dset"]

experiment_name = "{}_{}users_".format(
unique_id = uuid.uuid4().hex[:8]

experiment_name = "{}_{}users_{}_{}".format(
dset,
config["num_users"],
config["samples_per_user"],
# add a hex uid which is unique
unique_id
)

# for exp_key in config["exp_keys"]:
Expand Down
21 changes: 0 additions & 21 deletions src/utils/node_map.py

This file was deleted.

0 comments on commit 2c63e78

Please sign in to comment.