keras-team/keras · error · ValueError

Cholesky decomposition failed. The input might not be a…

Error message

Cholesky decomposition failed. The input might not be a valid positive definite matrix.

What it means

Raised in the JAX cholesky wrapper after the decomposition runs: eager-mode code checks the result for NaNs (JAX returns NaN instead of raising for invalid inputs) and converts that into this ValueError. It means the input matrix was not Hermitian positive definite, so no valid Cholesky factor exists.

Solutions

  1. Verify the matrix is symmetric/Hermitian and positive definite (check eigenvalues > 0)
  2. Add a small jitter/regularization to the diagonal (A + eps*I) before decomposing
  3. Use a decomposition that tolerates semi-definiteness (e.g. eigenvalue-based sqrt) if appropriate
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at keras/src/backend/jax/ops/linalg.py:18 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/45b703b0b34006c3. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/jax/ops/linalg.py:18

import jax
import jax.numpy as jnp
import jax.scipy as jsp

from keras.src.backend import config
from keras.src.backend.common import dtypes
from keras.src.backend.common.variables import standardize_dtype
from keras.src.backend.jax.ops.core import cast
from keras.src.backend.jax.ops.core import convert_to_tensor


def cholesky(a, upper=False):
    out = jnp.linalg.cholesky(a, upper=upper)
    try:
        # In eager mode, raise for nan to
        # achieve behavior consistency with numpy
        if jnp.any(jnp.isnan(out)):
            raise ValueError(
                "Cholesky decomposition failed. "
                "The input might not be a valid "
                "positive definite matrix."
            )
    except jax.errors.TracerBoolConversionError:
        # Cannot raise for nan in tracing mode
        pass
    return out


def cholesky_inverse(a, upper=False):
    identity = jnp.eye(a.shape[-1], dtype=a.dtype)
    inv_chol = solve_triangular(a, identity, lower=not upper)
    if upper:
        a_inv = jnp.matmul(inv_chol, jnp.transpose(inv_chol))
    else:
        a_inv = jnp.matmul(jnp.transpose(inv_chol), inv_chol)
    return a_inv

View on GitHub (pinned to 7a34a03db6)