keras-team/keras · error · ValueError

Invalid reduction: {reduction}. Supported values are: None,

Error message

Invalid reduction: {reduction}. Supported values are: None, 'add', 'max', 'min', 'mul'.

What it means

scatter_update supports only a fixed set of reduction modes when merging duplicate indices: 'add', 'max', 'min', 'mul' (or None for overwrite). Anything else, after lowercasing, raises.

Source

Thrown at keras/src/ops/core.py:417

            `"mul"`: Updates are multiplied with existing values.

    Returns:
        A tensor, has the same shape and dtype as `inputs`.

    Example:

    Using `reduction="add"` to accumulate values at the same index:

    >>> inputs = np.zeros((4,))
    >>> indices = [[0], [0], [1]]
    >>> updates = np.array([1., 1., 1.])
    >>> keras.ops.scatter_update(inputs, indices, updates, reduction="add")
    array([2., 1., 0., 0.])
    """
    if reduction is not None:
        reduction = reduction.lower()
        if reduction not in ("add", "max", "min", "mul"):
            raise ValueError(
                f"Invalid reduction: {reduction}. "
                "Supported values are: None, 'add', 'max', 'min', 'mul'."
            )
    if any_symbolic_tensors((inputs, indices, updates)):
        return ScatterUpdate(reduction=reduction).symbolic_call(
            inputs, indices, updates
        )
    return backend.core.scatter_update(
        inputs, indices, updates, reduction=reduction
    )


class Slice(Operation):
    def __init__(self, shape, *, name=None):
        super().__init__(name=name)
        self.shape = shape

    def call(self, inputs, start_indices):

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Use one of 'add', 'max', 'min', 'mul' or None
  2. For 'sum' semantics use 'add'
  3. For mean reduction, scatter_add then divide by counts manually

Example fix

# before
keras.ops.scatter_update(x, idx, upd, reduction='sum')

# after
keras.ops.scatter_update(x, idx, upd, reduction='add')
Defensive patterns

Strategy: validation

Validate before calling

assert reduction in (None, 'add', 'max', 'min', 'mul')

Try / catch

try:
    keras.ops.scatter_update(x, i, u, reduction=r)
except ValueError:
    keras.ops.scatter_update(x, i, u)

Prevention

When it happens

Trigger: keras.ops.scatter_update(x, idx, upd, reduction='sum') or reduction='mean'

Common situations: Typing 'mean', 'sum', or 'avg' out of habit from other scatter APIs (torch scatter, jax)

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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