@@ -279,15 +279,14 @@ async def _federation_federation_start_callback(self, source, message):
279
279
280
280
async def _reputation_callback (self , source , message ):
281
281
malicious_nodes = message .arguments # List of malicious nodes
282
- if self .with_reputation :
283
- if len (malicious_nodes ) > 0 and not self ._is_malicious :
284
- if self .is_dynamic_topology :
285
- await self ._disrupt_connection_using_reputation (malicious_nodes )
286
- if self .is_dynamic_aggregation and self .aggregator != self .target_aggregation :
287
- await self ._dynamic_aggregator (
288
- self .aggregator .get_nodes_pending_models_to_aggregate (),
289
- malicious_nodes ,
290
- )
282
+ if self .with_reputation and len (malicious_nodes ) > 0 and not self ._is_malicious :
283
+ if self .is_dynamic_topology :
284
+ await self ._disrupt_connection_using_reputation (malicious_nodes )
285
+ if self .is_dynamic_aggregation and self .aggregator != self .target_aggregation :
286
+ await self ._dynamic_aggregator (
287
+ self .aggregator .get_nodes_pending_models_to_aggregate (),
288
+ malicious_nodes ,
289
+ )
291
290
292
291
async def _federation_federation_models_included_callback (self , source , message ):
293
292
logging .info (f"📝 handle_federation_message | Trigger | Received aggregation finished message from { source } " )
@@ -366,7 +365,7 @@ async def _start_learning(self):
366
365
self .total_rounds = self .config .participant ["scenario_args" ]["rounds" ]
367
366
epochs = self .config .participant ["training_args" ]["epochs" ]
368
367
await self .get_round_lock ().acquire_async ()
369
- self .round = 1
368
+ self .round = 0
370
369
await self .get_round_lock ().release_async ()
371
370
await self .learning_cycle_lock .release_async ()
372
371
print_msg_box (
@@ -433,7 +432,7 @@ async def _dynamic_aggregator(self, aggregated_models_weights, malicious_nodes):
433
432
self .aggregator = self .target_aggregation
434
433
await self .aggregator .update_federation_nodes (self .federation_nodes )
435
434
436
- for subnodes in aggregated_models_weights . keys () :
435
+ for subnodes in aggregated_models_weights :
437
436
sublist = subnodes .split ()
438
437
(submodel , weights ) = aggregated_models_weights [subnodes ]
439
438
for node in sublist :
@@ -458,9 +457,9 @@ def learning_cycle_finished(self):
458
457
return not (self .round < self .total_rounds )
459
458
460
459
async def _learning_cycle (self ):
461
- while self .round is not None and self .round <= self .total_rounds :
460
+ while self .round is not None and self .round < self .total_rounds :
462
461
print_msg_box (
463
- msg = f"Round { self .round } of { self .total_rounds } started. " ,
462
+ msg = f"Round { self .round } of { self .total_rounds - 1 } started (max. { self . total_rounds } rounds) " ,
464
463
indent = 2 ,
465
464
title = "Round information" ,
466
465
)
@@ -476,13 +475,13 @@ async def _learning_cycle(self):
476
475
477
476
await self .get_round_lock ().acquire_async ()
478
477
print_msg_box (
479
- msg = f"Round { self .round } of { self .total_rounds } finished. " ,
478
+ msg = f"Round { self .round } of { self .total_rounds - 1 } finished (max. { self . total_rounds } rounds) " ,
480
479
indent = 2 ,
481
480
title = "Round information" ,
482
481
)
483
482
await self .aggregator .reset ()
484
483
self .trainer .on_round_end ()
485
- self .round = self . round + 1
484
+ self .round += 1
486
485
self .config .participant ["federation_args" ]["round" ] = (
487
486
self .round
488
487
) # Set current round in config (send to the controller)
@@ -492,7 +491,7 @@ async def _learning_cycle(self):
492
491
self .trainer .on_learning_cycle_end ()
493
492
await self .trainer .test ()
494
493
print_msg_box (
495
- msg = "Federated Learning process has been completed. " ,
494
+ msg = f"FL process has been completed successfully (max. { self . total_rounds } rounds reached) " ,
496
495
indent = 2 ,
497
496
title = "End of the experiment" ,
498
497
)
@@ -529,7 +528,7 @@ def reputation_calculation(self, aggregated_models_weights):
529
528
loss_threshold = 0.5
530
529
531
530
current_models = {}
532
- for subnodes in aggregated_models_weights . keys () :
531
+ for subnodes in aggregated_models_weights :
533
532
sublist = subnodes .split ()
534
533
submodel = aggregated_models_weights [subnodes ][0 ]
535
534
for node in sublist :
@@ -564,9 +563,6 @@ def reputation_calculation(self, aggregated_models_weights):
564
563
565
564
async def send_reputation (self , malicious_nodes ):
566
565
logging .info (f"Sending REPUTATION to the rest of the topology: { malicious_nodes } " )
567
- # message = self.cm.mm.generate_federation_message(
568
- # nebula_pb2.FederationMessage.Action.REPUTATION, malicious_nodes
569
- # )
570
566
message = self .cm .create_message ("federation" , "reputation" , arguments = [str (arg ) for arg in (malicious_nodes )])
571
567
await self .cm .send_message_to_neighbors (message )
572
568
@@ -593,7 +589,7 @@ def __init__(
593
589
async def _extended_learning_cycle (self ):
594
590
try :
595
591
await self .attack .attack ()
596
- except :
592
+ except Exception :
597
593
attack_name = self .config .participant ["adversarial_args" ]["attacks" ]
598
594
logging .exception (f"Attack { attack_name } failed" )
599
595
0 commit comments