keras-team/keras · error · RuntimeError
Backend ' ' must implement a layer mixin class.
Error message
Backend '{backend.backend()}' must implement a layer mixin class. What it means
Raised at import time when the Layer base class cannot find a backend mixin for the active backend name returned by backend.backend(); only 'tensorflow', 'jax', and 'torch' have mapped mixin classes, so any other backend string leaves BackendLayer unbound and this guard fires.
Solutions
- Set the KERAS_BACKEND environment variable (or backend global in ~/.keras/keras.json) to 'tensorflow', 'jax', or 'torch' before importing Keras
- If running a custom backend, register a Layer mixin class for it in keras.src.backend.<name>.layer and make backend.backend() return that name
- Verify no code overwrites keras.backend.backend() with an unsupported string
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at keras/src/layers/layer.py:65 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/bcdb4d0784107e09.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/layers/layer.py:65
from keras.src.ops.operation import Operation
from keras.src.quantizers.quantization_config import validate_and_resolve_config
from keras.src.utils import python_utils
from keras.src.utils import summary_utils
from keras.src.utils import traceback_utils
from keras.src.utils import tracking
if backend.backend() == "tensorflow":
from keras.src.backend.tensorflow.layer import TFLayer as BackendLayer
elif backend.backend() == "jax":
from keras.src.backend.jax.layer import JaxLayer as BackendLayer
elif backend.backend() == "torch":
from keras.src.backend.torch.layer import TorchLayer as BackendLayer
elif backend.backend() == "numpy":
from keras.src.backend.numpy.layer import NumpyLayer as BackendLayer
elif backend.backend() == "openvino":
from keras.src.backend.openvino.layer import OpenvinoLayer as BackendLayer
else:
raise RuntimeError(
f"Backend '{backend.backend()}' must implement a layer mixin class."
)
@keras_export(["keras.Layer", "keras.layers.Layer"])
class Layer(BackendLayer, Operation):
"""This is the class from which all layers inherit.
A layer is a callable object that takes as input one or more tensors and
that outputs one or more tensors. It involves *computation*, defined
in the `call()` method, and a *state* (weight variables). State can be
created:
* in `__init__()`, for instance via `self.add_weight()`;
* in the optional `build()` method, which is invoked by the first
`__call__()` to the layer, and supplies the shape(s) of the input(s),
which may not have been known at initialization time.
View on GitHub (pinned to 7a34a03db6)