keras-team/keras · error · ValueError
Axis is out of bounds for input shape . Received: axis=
Error message
Axis {axis} is out of bounds for input shape {input_shape}. Received: axis={self.axis} What it means
RMSNormalization.compute_output_shape found an axis value that does not index into the declared input shape, i.e. axis >= ndim or axis < -ndim. The layer needs to normalize along existing feature dims, so an out-of-bounds axis (often from a config saved for a different input shape) is rejected during shape inference.
Solutions
- Use an axis within [-len(input_shape), len(input_shape)); the common choice is -1 (last dim)
- Re-check self.axis if the layer was deserialized from a config authored for a different input rank
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/layers/normalization/rms_normalization.py:86 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/2b4450474d22d789.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/normalization/rms_normalization.py:86
x: Input tensor of shape (batch_size, input_dim).
Returns:
The RMS-normalized tensor of the same shape (batch_size, input_dim),
scaled by the learned `scale` parameter.
"""
return ops.rms_normalization(
x, scale=self.scale, axis=self.axis, epsilon=self.epsilon
)
def compute_output_shape(self, input_shape):
if isinstance(self.axis, int):
axes = [self.axis]
else:
axes = self.axis
for axis in axes:
if axis >= len(input_shape) or axis < -len(input_shape):
raise ValueError(
f"Axis {axis} is out of bounds for "
f"input shape {input_shape}. "
f"Received: axis={self.axis}"
)
return input_shape
def get_config(self):
config = {
"axis": self.axis,
"epsilon": self.epsilon,
}
base_config = super().get_config()
return {**base_config, **config}
View on GitHub (pinned to 7a34a03db6)