The best alternatives to Keras in 2026 are PyTorch for full control, PyTorch Lightning for a Keras style fit() on top of PyTorch, JAX with Flax NNX for TPUs and research, MLX on Apple silicon, tinygrad for learning how frameworks work, and scikit-learn or XGBoost for tabular data. Before you switch, try changing the Keras 3 backend instead. Keras now runs on JAX, PyTorch or TensorFlow, so a slow or awkward setup can often be fixed with one environment variable rather than a rewrite.

We picked these by the reason people usually give for leaving Keras: they need custom training loops, they want the libraries most open weight models ship with, they train on TPUs or Macs, or they never needed a neural network at all. To check that the swap is practical, we ported one small Keras model to plain PyTorch, Lightning and Flax NNX and trained all of them on the same CPU box on November 19, 2026. Versions below come from PyPI on the same day.

Keras alternatives at a glance

AlternativeAPI levelRuns onBest reason to switchLatest version (PyPI, Nov 19, 2026)
PyTorchLow to mid level, eagerNVIDIA, AMD, Apple (MPS), CPUCustom training loops and the open weight model ecosystemtorch 2.15.0
PyTorch LightningHigh level wrapper over PyTorchSame as PyTorchKeras like Trainer.fit() with PyTorch underneathlightning 2.6.6
JAX with Flax NNXFunctional core, object style layersTPU, NVIDIA, CPUTPUs, large scale research, jit and vmapjax 0.12.1, flax 0.12.12
MLXNumPy like, with PyTorch like mlx.nnApple silicon (CPU and GPU)Training and inference on a Mac with unified memorymlx 0.32.4
tinygradSmall, readable full stackMany backendsLearning how a framework and compiler fit togethertinygrad 0.14.0
scikit-learn and XGBoostEstimator APICPU (XGBoost also GPU)Tabular data where deep learning is overkill1.9.1 and 3.4.1
TensorFlow (low level)Low level ops, tf.functionNVIDIA, TPU, CPUExisting TF Serving or TFLite pipelinestensorflow 2.21.0

Try another Keras 3 backend first

Keras 3 is a multibackend framework. Its GitHub README lists JAX, TensorFlow and PyTorch, plus an OpenVINO backend for inference only. You pick one with the KERAS_BACKEND environment variable or ~/.keras/keras.json, and the Keras getting started page warns that it must be set before you import Keras and cannot change afterwards. The same page says Keras 3 needs Python 3.11 or newer.

import os
os.environ["KERAS_BACKEND"] = "jax"   # or "torch" or "tensorflow"
import keras

One detail caught us out in testing. The default backend is still TensorFlow, so on a machine with only PyTorch or JAX installed, a bare import keras failed with No module named 'tensorflow' until we set the variable. Once it was set, our unchanged model trained on both the torch and jax backends.

So if your complaint is speed, try JAX. If it is that you want to drop into PyTorch code or use PyTorch tools, try the torch backend. If you still use the old tf.keras package, the Keras README says Keras 3 is meant as a drop in replacement when you use the TensorFlow backend, and Keras 2 lives on as the tf-keras package. The migration guide covers the details. Switching frameworks makes sense when the problem is the high level API itself, not the engine under it.

PyTorch: best for full control

PyTorch is where most people go, and the reason is the ecosystem as much as the API. Hugging Face said in its Transformers v5 announcement that it is sunsetting Flax and TensorFlow support to focus on PyTorch, and most fine tuning tools, from PEFT to TRL, assume it. If you want to fine tune open weight LLMs, start with our guide to fine tuning an LLM locally.

The tradeoff is that you write the training loop yourself. Here is our Keras model (Dense(64, relu) then Dense(2)) ported to plain PyTorch:

import torch
from torch import nn

model = nn.Sequential(nn.Linear(20, 64), nn.ReLU(), nn.Linear(64, 2))
opt = torch.optim.Adam(model.parameters(), lr=1e-3)
loss_fn = nn.CrossEntropyLoss()

for epoch in range(5):
    perm = torch.randperm(len(X))
    for i in range(0, len(X), 64):
        idx = perm[i:i + 64]
        opt.zero_grad()
        loss = loss_fn(model(X[idx]), y[idx])
        loss.backward()
        opt.step()

That is about ten lines Keras hid behind compile() and fit(). In exchange you control every step, which is what people with custom losses, multiple optimizers or unusual batching want. Install it with the selector on the PyTorch get started page so you get the right CUDA or CPU build.

  • Pros: biggest model and tooling ecosystem; easy debugging in eager mode; runs on NVIDIA, AMD and Apple GPUs.
  • Cons: more boilerplate than Keras; you own checkpointing, logging and distributed setup unless you add a wrapper.

PyTorch Lightning: closest to the Keras workflow

If what you like about Keras is fit(), Lightning is the shortest move. Its README describes it as organized PyTorch: you put the model and training step in a LightningModule, and a Trainer handles the loop, mixed precision, multiple GPUs and checkpoints. Install it with pip install lightning and import it as import lightning as L.

import lightning as L

class Classifier(L.LightningModule):
    def __init__(self):
        super().__init__()
        self.net = nn.Sequential(nn.Linear(20, 64), nn.ReLU(), nn.Linear(64, 2))

    def training_step(self, batch, batch_idx):
        x, y = batch
        return nn.functional.cross_entropy(self.net(x), y)

    def configure_optimizers(self):
        return torch.optim.Adam(self.parameters(), lr=1e-3)

L.Trainer(max_epochs=5).fit(Classifier(), train_loader)

Keras vs PyTorch Lightning comes down to this: Keras 3 can switch engines, while Lightning commits you to PyTorch but gives you its whole ecosystem and an easy path to scale from one GPU to many nodes. The Lightning docs cover Fabric too, for people who want to keep their own loop and only hand off device and precision handling.

  • Pros: Keras like ergonomics; plain PyTorch modules inside; scaling handled for you.
  • Cons: another layer to learn and upgrade; PyTorch only.

JAX with Flax NNX: best for TPUs and research

JAX is a NumPy style array library with automatic differentiation and compilation through jit. It has no layer library of its own, so you add one. Google's Flax documentation recommends the NNX API, which uses ordinary Python objects for layers and feels close to PyTorch. Optax supplies the optimizers. Our port:

from flax import nnx
import optax

class Classifier(nnx.Module):
    def __init__(self, rngs):
        self.l1 = nnx.Linear(20, 64, rngs=rngs)
        self.l2 = nnx.Linear(64, 2, rngs=rngs)

    def __call__(self, x):
        return self.l2(nnx.relu(self.l1(x)))

model = Classifier(nnx.Rngs(0))
opt = nnx.Optimizer(model, optax.adam(1e-3), wrt=nnx.Param)

@nnx.jit
def train_step(model, opt, x, y):
    def loss_fn(model):
        logits = model(x)
        return optax.softmax_cross_entropy_with_integer_labels(logits, y).mean()
    loss, grads = nnx.value_and_grad(loss_fn)(model)
    opt.update(model, grads)
    return loss

On our box the jitted Flax loop and the Keras jax backend each finished five epochs in a little over one second, while the eager PyTorch, Lightning and Keras torch runs took roughly 19 to 28 seconds. Treat that as a hint, not a benchmark: it is a tiny model on a shared CPU, where per step Python overhead dominates and compilation wins easily. Keras vs Flax is mostly a question of how much you want to see. Keras on the jax backend gives you JAX speed with the Keras API, and Flax gives you the JAX functional style directly. Compare the two ecosystems in PyTorch vs JAX.

  • Pros: strong TPU support; jit, vmap and grad compose cleanly; fast compiled steps.
  • Cons: smaller ecosystem for open weight LLMs; functional ideas take time to learn.

MLX: best on a Mac

MLX is Apple's array framework for Apple silicon. Its README says the Python API closely follows NumPy, that mlx.nn and mlx.optimizers closely follow PyTorch, and that arrays live in unified memory, so CPU and GPU share data without copies. That makes it a natural choice if you train or fine tune on a MacBook. It does nothing for NVIDIA or TPU users. See MLX vs PyTorch for a full comparison.

tinygrad: best for learning how frameworks work

tinygrad describes itself as something between PyTorch and micrograd: a tensor library with autograd, an IR and compiler, a JIT, and nn and optim modules, kept small enough to read. It is a good pick if you left Keras because it felt like a black box and you want to see how kernels get fused. It is not where you go for pretrained models or production support. Our tinygrad vs TensorFlow guide covers where it fits.

scikit-learn and XGBoost: best for tabular data

Plenty of Keras projects are small classifiers on spreadsheet style data. For those, a neural network is often the wrong tool. scikit-learn gives you linear models, random forests and gradient boosting behind a single fit() and predict() API, and XGBoost adds fast gradient boosted trees with GPU support. Both train in seconds on a laptop and are easier to explain than a deep model. Our TensorFlow vs scikit-learn guide covers when each one wins.

Alternatives to PyTorch and TensorFlow

The same logic answers the two related questions. Alternatives to PyTorch: JAX with Flax NNX if you train on TPUs or want compiled functional code, MLX on a Mac, Keras 3 if you want a higher level API that can still run on PyTorch, and tinygrad for learning. Alternatives to TensorFlow: PyTorch for most new projects, JAX for Google style research and TPU work, and Keras 3 on JAX or PyTorch if you like the Keras API but want off TensorFlow. Note that the Keras compatibility matrix pairs Keras 3.15.1 with TensorFlow 2.20.0, while PyPI already shows TensorFlow 2.21.0, so pin versions if you stay on the TensorFlow backend. For a three way breakdown, read TensorFlow vs PyTorch vs Keras.

How to choose

  1. You need custom training loops or want to fine tune open weight LLMs: PyTorch.
  2. You like fit() and want PyTorch's ecosystem: PyTorch Lightning.
  3. You train on TPUs or want maximum compiled speed: JAX with Flax NNX, or Keras on the jax backend.
  4. You work on a Mac: MLX.
  5. You want to understand framework internals: tinygrad.
  6. Your data is a table: scikit-learn or XGBoost first.

For a ranked view of every framework by job, see the best ML frameworks for Python.

Who should stay on Keras

Stay if your models are standard layers, you teach or learn deep learning, or you want one codebase that can move between JAX, PyTorch and TensorFlow. KerasHub adds pretrained models on the same API, and the Keras getting started page links more than 150 worked examples. Keras is also still actively patched: version 3.15.1 in July 2026 shipped security fixes for model and dataset loading, per its GitHub release notes. Switching costs a rewrite, so make sure the problem is Keras itself and not the backend under it. If the real pain is setup, our guide to using TensorFlow in Jupyter Notebook fixes the usual kernel and import errors.

FAQ

What is the best alternative to Keras?

For most people it is PyTorch, because the open weight model ecosystem and most fine tuning tools are built on it. If you want to keep a Keras style fit() loop, use PyTorch Lightning. If you train on TPUs, use JAX with Flax NNX.

Is Keras still worth learning in 2026?

Yes, if you want a high level API for standard models or a gentle start in deep learning. Keras 3 runs on JAX, PyTorch or TensorFlow, so the skills carry across engines. If your goal is LLM fine tuning, learn PyTorch alongside it.

Should I switch the Keras backend instead of switching frameworks?

Often, yes. Setting KERAS_BACKEND to jax or torch before importing Keras runs the same model on a different engine. In our test, an unchanged model trained on both. Switch frameworks only if you need lower level control or tools that expect plain PyTorch or JAX code.

Is PyTorch Lightning easier than Keras?

Not quite. Keras needs less code for a standard model. Lightning asks you to write a LightningModule with a training step and optimizer, then handles the loop, devices and checkpoints for you. It sits between Keras and plain PyTorch.

Can I use Keras with PyTorch?

Yes. Keras 3 supports PyTorch as a backend. Install torch, set KERAS_BACKEND=torch before the import, and Keras layers run on PyTorch. The Keras getting started page says it works with the latest torch release.

What is a good alternative to TensorFlow in Python?

PyTorch for most new deep learning projects, JAX for TPU and research work, and scikit-learn or XGBoost when the data is tabular. If you like the Keras API, Keras 3 on the JAX or PyTorch backend lets you leave TensorFlow without leaving Keras.