Skip to content

Commit

Permalink
[Core] Merge pull request #235 from EricDinging/fix-dryrun
Browse files Browse the repository at this point in the history
Fix dryrun device not found & fedyogi argument order
  • Loading branch information
fanlai0990 authored Sep 5, 2023
2 parents 6872099 + 5aa9492 commit faab283
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/dry_run/customized_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

class Customized_Client(TorchClient):
"""Basic client component in Federated Learning"""

def train(self, client_data, model, conf):
"""We flip the label of the malicious client"""
device = conf.cuda_device if conf.use_cuda else torch.device(
'cpu')

client_id = conf.client_id

logging.info(f"Start to train (CLIENT: {client_id}) ...")
device = conf.device

model = model.to(device=device)
model.train()

Expand Down
4 changes: 2 additions & 2 deletions fedscale/cloud/internal/torch_model_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def set_weights(self, weights: List[np.ndarray]):
Set the model's weights to the numpy weights array.
:param weights: numpy weights array
"""
current_grad_weights = [param.data.clone() for param in self.model.state_dict().values()]
last_grad_weights = [param.data.clone() for param in self.model.state_dict().values()]
new_state_dict = {
name: torch.from_numpy(np.asarray(weights[i], dtype=np.float32))
for i, name in enumerate(self.model.state_dict().keys())
Expand All @@ -34,7 +34,7 @@ def set_weights(self, weights: List[np.ndarray]):
if self.optimizer:
weights_origin = copy.deepcopy(weights)
weights = [torch.tensor(x) for x in weights_origin]
self.optimizer.update_round_gradient(weights, current_grad_weights, self.model)
self.optimizer.update_round_gradient(last_grad_weights, weights, self.model)

def get_weights(self) -> List[np.ndarray]:
"""
Expand Down

0 comments on commit faab283

Please sign in to comment.