keras-team/keras · error · ValueError

Invalid value for argument `aggregation`. Expected one of…

Error message

Invalid value for argument `aggregation`. Expected one of `None`, `'none'`, `'mean'`, `'sum'`, `'only_first_replica'`. Received: aggregation={aggregation}

What it means

Raised in Variable.__init__ by the whitelist check on the aggregation argument. Only distributed-training aggregation strategies None/'none'/'mean'/'sum'/'only_first_replica' are recognized; any other string (typically a typo) triggers this guard before the variable is created.

Solutions

  1. Use one of None, 'none', 'mean', 'sum', or 'only_first_replica' for aggregation
  2. Omit aggregation to keep the default ('none')
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/common/variables.py:121 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/d1031a102c758776. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/common/variables.py:121

        name=None,
        layout=None,
        **kwargs,
    ):
        name = name or auto_name(self.__class__.__name__)
        if not isinstance(name, str) or "/" in name:
            raise ValueError(
                "Argument `name` must be a string and "
                "cannot contain character `/`. "
                f"Received: name={name}"
            )
        if aggregation not in (
            None,
            "none",
            "mean",
            "sum",
            "only_first_replica",
        ):
            raise ValueError(
                "Invalid value for argument `aggregation`. Expected "
                "one of `None`, `'none'`, `'mean'`, `'sum'`, "
                "`'only_first_replica'`. "
                f"Received: aggregation={aggregation}"
            )
        if aggregation is None:
            aggregation = "none"
        if synchronization not in (
            None,
            "none",
            "on_read",
            "on_write",
            "auto",
        ):
            raise ValueError(
                "Invalid value for argument `synchronization`. Expected "
                "one of `None`, `'none'`, `'on_read'`, `'on_write'`, "
                "`'auto'`. "

View on GitHub (pinned to 7a34a03db6)