keras-team/keras · error · RuntimeError
Backend ' ' must implement the Trainer class.
Error message
Backend '{backend.backend()}' must implement the Trainer class. What it means
Import-time guard in keras/src/models/model.py: the Trainer class for the currently selected backend could not be resolved. Keras requires each backend (tensorflow, jax, torch, numpy) to provide a Trainer implementation; an unrecognized or misconfigured backend (e.g. a typo in KERAS_BACKEND) leaves Trainer undefined and this error surfaces.
Solutions
- Set KERAS_BACKEND to a supported backend: 'tensorflow', 'jax', 'torch', or 'numpy'
- Ensure the selected backend package is actually installed and importable
- If implementing a custom backend, provide a Trainer class and map it in this dispatch
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/models/model.py:37 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/765be2e74ec4981a.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/models/model.py:37
from keras.src.trainers import trainer as base_trainer
from keras.src.utils import io_utils
from keras.src.utils import summary_utils
from keras.src.utils import traceback_utils
if backend.backend() == "tensorflow":
from keras.src.backend.tensorflow.trainer import (
TensorFlowTrainer as Trainer,
)
elif backend.backend() == "jax":
from keras.src.backend.jax.trainer import JAXTrainer as Trainer
elif backend.backend() == "torch":
from keras.src.backend.torch.trainer import TorchTrainer as Trainer
elif backend.backend() == "numpy":
from keras.src.backend.numpy.trainer import NumpyTrainer as Trainer
elif backend.backend() == "openvino":
from keras.src.backend.openvino.trainer import OpenVINOTrainer as Trainer
else:
raise RuntimeError(
f"Backend '{backend.backend()}' must implement the Trainer class."
)
@keras_export(["keras.Model", "keras.models.Model"])
class Model(Trainer, base_trainer.Trainer, Layer):
"""A model grouping layers into an object with training/inference features.
There are three ways to instantiate a `Model`:
## With the "Functional API"
You start from `Input`,
you chain layer calls to specify the model's forward pass,
and finally, you create your model from inputs and outputs:
```python
inputs = keras.Input(shape=(37,))View on GitHub (pinned to 7a34a03db6)