keras-team/keras · error · ValueError

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

Error message

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

What it means

Raised by the matrix-norm branch of keras/src/backend/tensorflow/linalg.py norm: for norms computed over the last two axes of >=2-D input, only specific ord values are implemented ('fro', 'nuc', 1, -1, 2, -2, and inf variants). The received ord matches none of them, so the dispatch falls through to this sentinel error.

Solutions

  1. Use a supported matrix ord: 'fro', 'nuc', 1, -1, 2, -2, inf, or -inf
  2. For an unsupported custom ord, implement it manually (e.g. via tf.linalg.svd)
  3. Check that ord matches the intended norm type for a matrix input
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

        elif ord in ("nuc", 2, -2):
            x = moveaxis(x, axis, (-2, -1))
            if ord == -2:
                x = tf.math.reduce_min(
                    tf.linalg.svd(x, compute_uv=False), axis=-1
                )
            elif ord == 2:
                x = tf.math.reduce_max(
                    tf.linalg.svd(x, compute_uv=False), axis=-1
                )
            else:
                x = tf.math.reduce_sum(
                    tf.linalg.svd(x, compute_uv=False), axis=-1
                )
            if keepdims:
                x = tf.expand_dims(x, axis[0])
                x = tf.expand_dims(x, axis[1])
        else:
            raise ValueError(
                f"Invalid `ord` argument for matrix norm. Received: ord={ord}"
            )
        return x
    else:
        raise ValueError(f"Invalid axis values. Received: axis={axis}")


def qr(x, mode="reduced"):
    if mode not in {"reduced", "complete"}:
        raise ValueError(
            "`mode` argument value not supported. "
            "Expected one of {'reduced', 'complete'}. "
            f"Received: mode={mode}"
        )
    if mode == "reduced":
        return tf.linalg.qr(x)
    return tf.linalg.qr(x, full_matrices=True)

View on GitHub (pinned to 7a34a03db6)