keras-team/keras · error · ValueError
Invalid `ord` argument. Expected one of {'fro', 'nuc'} when
Error message
Invalid `ord` argument. Expected one of {'fro', 'nuc'} when using string. Received: ord={ord} What it means
Norm.__init__ validates the ord argument: when a string is supplied it must be exactly 'fro' (Frobenius) or 'nuc' (nuclear). These string norms are only defined for matrices, so anything else — 'l2', 'inf', 'L2' — is rejected at construction time.
Source
Thrown at keras/src/ops/linalg.py:288
x = backend.convert_to_tensor(x)
_assert_2d(x)
if backend.backend() == "tensorflow":
try:
_assert_square(x)
except ValueError as e:
raise ValueError(
f"LU decomposition failed: {e}. LU decomposition is only "
"supported for square matrices in Tensorflow."
)
return backend.linalg.lu_factor(x)
class Norm(Operation):
def __init__(self, ord=None, axis=None, keepdims=False, *, name=None):
super().__init__(name=name)
if isinstance(ord, str):
if ord not in ("fro", "nuc"):
raise ValueError(
"Invalid `ord` argument. "
"Expected one of {'fro', 'nuc'} when using string. "
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.axisView on GitHub (pinned to 7a34a03db6)
Solutions
- Use numeric ords for vectors/matrices: 1, 2, np.inf, -np.inf.
- Use 'fro' or 'nuc' strings only, and only with 2 axes.
- Fix casing/typos: it is 'fro', not 'Fro' or 'frobenius'.
Example fix
# before n = keras.ops.linalg.norm(x, ord='l2') # after n = keras.ops.linalg.norm(x, ord=2)
Defensive patterns
Strategy: validation
Validate before calling
assert not isinstance(ord, str) or ord in ('fro', 'nuc'), ord Type guard
def valid_ord(o):
return o is None or (isinstance(o, (int, float)) and not isinstance(o, bool)) or (isinstance(o, str) and o in ('fro', 'nuc')) Prevention
- Use numeric ords (1, 2, np.inf) for everything except matrix fro/nuc.
- Centralize norm construction behind a small wrapper that validates ord.
When it happens
Trigger: keras.ops.linalg.Norm(ord='l2'); keras.ops.linalg.norm(x, ord='inf'); passing a NumPy-style string not in the allowed set.
Common situations: Porting code from numpy.linalg.norm and assuming string ords exist; typos or casing issues like 'Fro' or 'frobenius'.
Related errors
- Invalid `ord` argument for vector norm. Received: ord={self.
- 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/d12b7ef1b8bca31e.
Report an issue: GitHub.