def __init__(self, user_id, trainloader, testloader, model_name: str, lr=3e-4, epoch=1, seed=123, lr_decay=0.99, decay_step=200): BASE.__init__(self, algorithm='fedsp', seed=seed, epoch=epoch, model_name=model_name, lr=lr, lr_decay=lr_decay, decay_step=decay_step) self.user_id = user_id self.device = torch.device( "cuda" if torch.cuda.is_available() else "cpu") self.trainloader = trainloader self.testloader = testloader self.loss_list = [] self.acc_list = []
def __init__(self, seed=123, rounds=20, epoch=1, clients_per_round=1, eval_interval=1, dataset_name='femnist', model_name='femnist', lr=3e-4, batch_size=1, lr_decay=0.99, decay_step=200, note=''): BASE.__init__(self, algorithm='fedper', seed=seed, epoch=epoch, model_name=model_name, lr=lr, batch_size=batch_size, lr_decay=lr_decay, decay_step=decay_step) self.model_name = model_name self.dataset_name = dataset_name self.base_params = self.model.base.state_dict() self.updates = [] self.selected_clients = [] self.clients_per_round = clients_per_round self.rounds = rounds self.eval_interval = eval_interval self.note = note self.optim = { 'round': 0, 'acc': -1.0, 'ft-acc': -1.0, 'base_params': None, 'loss': 10e8, 'ft-loss': 10e8 } self.train_writer = SummaryWriter( f'/home/tdye/Fed101/visualization/fedper/{dataset_name}_{model_name}_C{clients_per_round}_E{epoch}_B{batch_size}_lr{lr}_train_{note}' ) self.test_writer = SummaryWriter( f'/home/tdye/Fed101/visualization/fedper/{dataset_name}_{model_name}_C{clients_per_round}_E{epoch}_B{batch_size}_lr{lr}_val_{note}' ) self.clients = self.setup_clients() assert self.clients_per_round <= len(self.clients) self.surrogates = self.setup_surrogates() assert len(self.surrogates) == clients_per_round