keras-team/keras · error · ValueError

Input should have its last 2 dimensions fully-defined…

Error message

Input should have its last 2 dimensions fully-defined. Received: input.shape = {x.shape}

What it means

Qr.compute_output_spec needs the last two dimensions (m, n) statically defined to compute the output shapes of Q and R. Unknown (None) trailing dims raise this ValueError; provide a fully specified input shape.

Solutions

  1. Build the model with fully-defined matrix dimensions for QR inputs
  2. Specify the input shape explicitly (e.g. Input(shape=(m, n)))
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/ops/linalg.py:422 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/7f3eabf646a2bbc6. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/ops/linalg.py:422

        super().__init__(name=name)
        if mode not in {"reduced", "complete"}:
            raise ValueError(
                "`mode` argument value not supported. "
                "Expected one of {'reduced', 'complete'}. "
                f"Received: mode={mode}"
            )
        self.mode = mode

    def compute_output_spec(self, x):
        if len(x.shape) < 2:
            raise ValueError(
                "Input should have rank >= 2. Received: "
                f"input.shape = {x.shape}"
            )
        m = x.shape[-2]
        n = x.shape[-1]
        if m is None or n is None:
            raise ValueError(
                "Input should have its last 2 dimensions "
                "fully-defined. Received: "
                f"input.shape = {x.shape}"
            )
        k = min(m, n)
        base = tuple(x.shape[:-2])
        if self.mode == "reduced":
            return (
                KerasTensor(shape=base + (m, k), dtype=x.dtype),
                KerasTensor(shape=base + (k, n), dtype=x.dtype),
            )
        # 'complete' mode.
        return (
            KerasTensor(shape=base + (m, m), dtype=x.dtype),
            KerasTensor(shape=base + (m, n), dtype=x.dtype),
        )

    def call(self, x):

View on GitHub (pinned to 7a34a03db6)