Skip to content

aggregate_arrayrecords/aggregate_metricrecords raise ZeroDivisionError when the weighting total is zero (Message API) #7708

Description

@Atishyy27

Describe the bug

aggregate_arrayrecords and aggregate_metricrecords in framework/py/flwr/serverapp/strategy/strategy_utils.py divide by the summed weighting metric with no zero guard:

total_weight = sum(weights)
weight_factors = [w / total_weight for w in weights]   # ZeroDivisionError when total_weight == 0

If every reply reports 0 for the weighting metric (default num-examples) — e.g. a round where each client's local partition is empty after filtering — total_weight is 0.0 and this raises ZeroDivisionError, crashing aggregate_train/aggregate_evaluate in the ServerApp.

validate_message_reply_consistency only checks the weighting key exists and isn't a list; it never checks the sum. These two functions are the default aggregators for FedAvg and every subclass (FedProx, FedAdam, FedMedian, Krum, FedTrimmedAvg, …), so it affects the whole strategy family.

This is the same class as #7645/#7646, but in the new Message-API module (serverapp/strategy/strategy_utils.py), which those PRs don't touch.

Steps to reproduce

Aggregate a round where every reply's weighting metric is 0ZeroDivisionError: float division by zero.

Expected behavior

Raise a clear InconsistentMessageReplies explaining the total is zero, consistent with the other checks in this module.

Fix + regression test ready; will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions