keras-team/keras · error · ValueError

Invalid `ord` argument for vector norm. Received: ord=

Error message

Invalid `ord` argument for vector norm. Received: ord={ord}

What it means

Raised by the vector-norm branch of keras/src/backend/tensorflow/linalg.py norm: when the norm is computed over a 1-D slice, only specific ord values are implemented (None, 0, 1, -1, 2, -2, inf, -inf). The received ord matches none of them (e.g. a fractional or arbitrary positive integer), so the dispatch chain falls through to this error.

Solutions

  1. Use a supported vector ord: None, 0, 1, -1, 2, -2, float('inf'), or float('-inf')
  2. For a custom exponent p, compute (sum(abs(x)**p))**(1/p) manually if p is not supported
  3. Pass ord=None for the standard L2 norm
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/tensorflow/linalg.py:96 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/0e82061b6480dca1. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/tensorflow/linalg.py:96

            return tf.sqrt(
                tf.reduce_sum(x * tf.math.conj(x), axis=axis, keepdims=keepdims)
            )
        elif ord == float("inf"):
            return tf.math.reduce_max(
                tf.math.abs(x), axis=axis, keepdims=keepdims
            )
        elif ord == float("-inf"):
            return tf.math.reduce_min(
                tf.math.abs(x), axis=axis, keepdims=keepdims
            )
        elif ord == 0:
            return tf.math.reduce_sum(
                tf.cast(tf.not_equal(x, 0), dtype=x.dtype),
                axis=axis,
                keepdims=keepdims,
            )
        elif isinstance(ord, str):
            raise ValueError(
                f"Invalid `ord` argument for vector norm. Received: ord={ord}"
            )
        else:
            ord = convert_to_tensor(ord, dtype=x.dtype)
            out = tf.math.reduce_sum(
                tf.pow(tf.math.abs(x), ord), axis=axis, keepdims=keepdims
            )
            return tf.pow(out, 1.0 / ord)
    elif num_axes == 2:
        row_axis, col_axis = axis[0], axis[1]
        row_axis = row_axis + ndim if row_axis < 0 else row_axis
        col_axis = col_axis + ndim if col_axis < 0 else col_axis
        if ord is None or ord == "fro":
            return tf.sqrt(
                tf.reduce_sum(x * tf.math.conj(x), axis=axis, keepdims=keepdims)
            )
        elif ord == 1:
            if not keepdims and col_axis > row_axis:

View on GitHub (pinned to 7a34a03db6)