Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-defined aggregate_fn #2539

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions nvflare/app_common/workflows/base_fedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _check_results(results: List[FLModel]):
raise ValueError(f"Result from client(s) {empty_clients} is empty!")

@staticmethod
def _aggregate_fn(results: List[FLModel]) -> FLModel:
def aggregate_fn(results: List[FLModel]) -> FLModel:
aggregation_helper = WeightedAggregationHelper()
for _result in results:
aggregation_helper.add(
Expand Down Expand Up @@ -141,7 +141,7 @@ def aggregate(self, results: List[FLModel], aggregate_fn=None) -> FLModel:
self._check_results(results)

if not aggregate_fn:
aggregate_fn = self._aggregate_fn
aggregate_fn = self.aggregate_fn

self.info(f"aggregating {len(results)} update(s) at round {self.current_round}")
try:
Expand Down
4 changes: 2 additions & 2 deletions nvflare/app_common/workflows/fedavg.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def run(self) -> None:
results = self.send_model_and_wait(targets=clients, data=model)

aggregate_results = self.aggregate(
results, aggregate_fn=None
) # if no `aggregate_fn` provided, default `WeightedAggregationHelper` is used
results, aggregate_fn=self.aggregate_fn
) # using default aggregate_fn with `WeightedAggregationHelper`. Can overwrite self.aggregrate_fn with signature Callable[List[FLModel], FLModel]

model = self.update_model(model, aggregate_results)

Expand Down
Loading