keras-team/keras · error · ValueError

`sparse=True` is not supported with the

Error message

`sparse=True` is not supported with the {backend.backend()} backend

What it means

Raised in InputLayer.__init__ after construction: the active backend (identified by backend.backend(), e.g. jax or numpy) does not set SUPPORTS_SPARSE_TENSORS, yet sparse=True was requested (or inherited from an input tensor). It is a capability guard, not a malformed-argument error.

Solutions

  1. Switch to a backend that supports sparse tensors such as TensorFlow
  2. Set sparse=False and densify the data before feeding it to the model
  3. Keep sparse tensors only in preprocessing and convert to dense for model input
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at keras/src/layers/core/input_layer.py:99 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/312520d77cfb70a2. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/layers/core/input_layer.py:99

                    "same time."
                )
            if batch_size is not None and batch_shape is not None:
                raise ValueError(
                    "You cannot pass both `batch_size` and `batch_shape` "
                    "at the same time."
                )
            if shape is None and batch_shape is None:
                raise ValueError("You must pass a `shape` argument.")

            if shape is not None:
                shape = backend.standardize_shape(shape)
                batch_shape = (batch_size,) + shape

        self._batch_shape = backend.standardize_shape(batch_shape)
        self._dtype = backend.standardize_dtype(dtype)
        self.sparse = bool(sparse)
        if self.sparse and not backend.SUPPORTS_SPARSE_TENSORS:
            raise ValueError(
                f"`sparse=True` is not supported with the {backend.backend()} "
                "backend"
            )
        self.ragged = bool(ragged)
        if self.ragged and not backend.SUPPORTS_RAGGED_TENSORS:
            raise ValueError(
                f"`ragged=True` is not supported with the {backend.backend()} "
                "backend"
            )

        if input_tensor is None:
            input_tensor = backend.KerasTensor(
                shape=batch_shape,
                dtype=dtype,
                sparse=sparse,
                ragged=ragged,
                name=name,
            )

View on GitHub (pinned to 7a34a03db6)