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
- Use one of 'add', 'max', 'min', 'mul' or None
- For 'sum' semantics use 'add'
- 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
- Use only None/'add'/'max'/'min'/'mul' (case-insensitive) for reduction
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
- Invalid Reduction Key: {key}. Expected keys are "{cls.all()}
- Array inputs to associative_scan must have the same first di
- The number of dimensions in `inputs` must match the number o
- The number of dimensions in `start_indices` must match the n
- Cannot infer argument `num` from shape {x.shape}. Either pro
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/56b5342126c15fb3.
Report an issue: GitHub.