keras-team/keras · error · ValueError
Invalid padding ' ', must be 'same' or 'valid'.
Error message
Invalid padding '{padding}', must be 'same' or 'valid'. What it means
Sentinel validation in the JAX backend's pooling helper (_pool in nn.py): before delegating to the JAX reduction, it normalizes the padding argument and only accepts the two canonical mode strings. Anything else (e.g. "SAME", "causal", "full", None) reaches this generic guard.
Solutions
- Use padding="same" or padding="valid" (lowercase, exact strings)
- If adapting code from other frameworks, map their modes: TensorFlow 'SAME'/'VALID' must be lowercased; 'causal' padding is not supported by this op
- Check for typos or accidentally passing a padding list/tuple where a string is expected
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/jax/ops/nn.py:229 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/190a27e6b94fb184.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/jax/ops/nn.py:229
padding="valid",
):
"""Helper function to define pooling functions.
Args:
inputs: input data of shape `N+2`.
initial_value: the initial value for the reduction.
reduce_fn: a reduce function of the form `(T, T) -> T`.
pool_size: a sequence of `N` integers, representing the window size to
reduce over.
strides: a sequence of `N` integers, representing the inter-window
strides (default: `(1, ..., 1)`).
padding: either the string `same` or `valid`.
Returns:
The output of the reduction for each window slice.
"""
if padding not in ("same", "valid"):
raise ValueError(
f"Invalid padding '{padding}', must be 'same' or 'valid'."
)
padding = padding.upper()
return lax.reduce_window(
inputs,
initial_value,
reduce_fn,
pool_size,
strides,
padding,
)
def max_pool(
inputs,
pool_size,
strides=None,
padding="valid",View on GitHub (pinned to 7a34a03db6)