Skip to content

Commit

Permalink
add traceback
Browse files Browse the repository at this point in the history
  • Loading branch information
Wrede committed May 17, 2024
1 parent 0af7a7c commit 4e76902
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions fedn/network/combiner/aggregators/fedavg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import traceback

from fedn.common.log_config import logger
from fedn.network.combiner.aggregators.aggregatorbase import AggregatorBase


class Aggregator(AggregatorBase):
""" Local SGD / Federated Averaging (FedAvg) aggregator. Computes a weighted mean
"""Local SGD / Federated Averaging (FedAvg) aggregator. Computes a weighted mean
of parameter updates.
:param id: A reference to id of :class: `fedn.network.combiner.Combiner`
Expand Down Expand Up @@ -48,8 +50,7 @@ def combine_models(self, helper=None, delete_models=True, parameters=None):
nr_aggregated_models = 0
total_examples = 0

logger.info(
"AGGREGATOR({}): Aggregating model updates... ".format(self.name))
logger.info("AGGREGATOR({}): Aggregating model updates... ".format(self.name))

while not self.model_updates.empty():
try:
Expand All @@ -61,28 +62,26 @@ def combine_models(self, helper=None, delete_models=True, parameters=None):
logger.info("AGGREGATOR({}): Loading model metadata {}.".format(self.name, model_update.model_update_id))
model_next, metadata = self.load_model_update(model_update, helper)

logger.info(
"AGGREGATOR({}): Processing model update {}, metadata: {} ".format(self.name, model_update.model_update_id, metadata))
logger.info("AGGREGATOR({}): Processing model update {}, metadata: {} ".format(self.name, model_update.model_update_id, metadata))

# Increment total number of examples
total_examples += metadata["num_examples"]

if nr_aggregated_models == 0:
model = model_next
else:
model = helper.increment_average(
model, model_next, metadata["num_examples"], total_examples)
model = helper.increment_average(model, model_next, metadata["num_examples"], total_examples)

nr_aggregated_models += 1
# Delete model from storage
if delete_models:
self.modelservice.temp_model_storage.delete(model_update.model_update_id)
logger.info(
"AGGREGATOR({}): Deleted model update {} from storage.".format(self.name, model_update.model_update_id))
logger.info("AGGREGATOR({}): Deleted model update {} from storage.".format(self.name, model_update.model_update_id))
self.model_updates.task_done()
except Exception as e:
logger.error(
"AGGREGATOR({}): Error encoutered while processing model update {}, skipping this update.".format(self.name, e))
tb = traceback.format_exc()
logger.error(f"AGGREGATOR({self.name}): Error encoutered while processing model update: {e}")
logger.error(tb)
self.model_updates.task_done()

data["nr_aggregated_models"] = nr_aggregated_models
Expand Down

0 comments on commit 4e76902

Please sign in to comment.