keras-team/keras · error · ValueError

Invalid axis values. Received: axis=

Error message

Invalid axis values. Received: axis={axis}

What it means

Raised at the end of the norm function in keras/src/backend/tensorflow/linalg.py: after the vector and matrix branches, none of the implemented ord/axis combinations matched the arguments (e.g. axis selects more or fewer than 2 dimensions while a matrix-only ord was given, or the axis length is invalid for the chosen branch). It is the generic fallback of the dispatch chain, naming the axis value at fault.

Solutions

  1. Pass axis as an int or a 1-or-2 element tuple matching the ord type (vector ords with 1 axis, matrix ords with 2 axes)
  2. Use axis=(-2,-1) for matrix norms over the last two dims
  3. Simplify axis=None to let norm reduce over all dimensions
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

                )
            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)


def solve(a, b):
    # tensorflow.linalg.solve only supports same rank inputs
    if b.shape.ndims == a.shape.ndims - 1:
        b = tf.expand_dims(b, axis=-1)

View on GitHub (pinned to 7a34a03db6)