keras-team/keras · error · ValueError
Invalid `ord` argument for vector norm. Received: ord={self.
Error message
Invalid `ord` argument for vector norm. Received: ord={self.ord} What it means
Norm.compute_output_spec checks that string ords ('fro'/'nuc') are only used when the reduction spans 2 axes (a matrix). If axis is None or resolves to a single axis (a vector), a string ord is meaningless and this error is raised.
Source
Thrown at keras/src/ops/linalg.py:309
f"Received: ord={ord}"
)
if isinstance(axis, int):
axis = [axis]
self.ord = ord
self.axis = axis
self.keepdims = keepdims
def compute_output_spec(self, x):
output_dtype = backend.standardize_dtype(x.dtype)
if "int" in output_dtype or output_dtype == "bool":
output_dtype = backend.floatx()
if self.axis is None:
axis = tuple(range(len(x.shape)))
else:
axis = self.axis
num_axes = len(axis)
if num_axes == 1 and isinstance(self.ord, str):
raise ValueError(
"Invalid `ord` argument for vector norm. "
f"Received: ord={self.ord}"
)
elif num_axes == 2 and self.ord not in (
None,
"fro",
"nuc",
float("inf"),
float("-inf"),
1,
-1,
2,
-2,
):
raise ValueError(
"Invalid `ord` argument for matrix norm. "
f"Received: ord={self.ord}"
)View on GitHub (pinned to 7a34a03db6)
Solutions
- For vector norms use ord=None or numeric ords (1, 2, inf).
- Restrict 'fro'/'nuc' to axis settings covering exactly 2 dimensions.
- Branch on tensor rank: strings only when len(axis) == 2.
Example fix
# before row_norms = keras.ops.linalg.norm(X, ord='fro', axis=1) # after row_norms = keras.ops.linalg.norm(X, ord=2, axis=1)
Defensive patterns
Strategy: validation
Validate before calling
axes = tuple(range(len(x.shape))) if axis is None else (axis,)
if len(axes) == 1:
assert not isinstance(ord, str), 'string ord only valid for 2-axis norms' Type guard
def norm_args_consistent(x, ord, axis):
axes = tuple(range(len(x.shape))) if axis is None else (axis,)
return not (len(axes) == 1 and isinstance(ord, str)) Prevention
- Reserve 'fro'/'nuc' for matrix norms only.
- Switch to ord=2 when reducing to per-row vector norms.
When it happens
Trigger: keras.ops.linalg.norm(vector, ord='fro'); Norm(axis=1, ord='nuc') applied to a batch of vectors.
Common situations: Writing generic norm code that passes ord='fro' for all inputs; switching a norm call from full-matrix to per-row reduction without updating ord.
Related errors
- Invalid `ord` argument. Expected one of {'fro', 'nuc'} when
- Unknown activation function '{activation}' cannot be seriali
- Could not interpret activation function identifier: {identif
- ConvNeXt does not support the `channels_first` image data fo
- If using `weights="imagenet"` with `include_top=True`, `clas
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/903d41bb577d8ef4.
Report an issue: GitHub.