Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

pipekit-train — the Keras backend

Open In Colab

backend="keras" trains a model with Keras 3’s own compile and fit, on the JAX backend. This notebook first trains a small Keras model with plain Keras, then trains the same model through TrainingLoop, which adds a dataset hash, a metric log, checkpoints that resume and an operator for the registry. It then trains one Equinox emulator under both the Keras and the Equinox backends and compares them. The design is packages/pipekit-train/docs/design/keras_adapter.md.

keras 3.14.1 on jax

1. Toy regression data

Inputs x are drawn from a standard normal, and the targets are y = x w + b + ε with fixed weights w, offset b = 0.3 and noise ε of standard deviation 0.1. The first 512 rows train and the last 128 validate.

(512, 3) (512, 1) (128, 3) (128, 1)

2. A Keras model, with plain Keras

compile, fit and predict: 125 epochs of 16 steps at most, with Keras’s own early stopping on the validation loss.

59 epochs; validation MSE 0.0109

3. The same model through TrainingLoop

The optimiser and loss of compile become optimizer_config and loss, the epochs of fit become a budget of 2,000 steps, and early stopping becomes the pipekit one on the validation MSE, checked every 200 steps. The loop writes each step’s own loss to a JSONL log; Keras would report the running mean since the period began.

steps 2000 | validation {'loss': 0.0102, 'mse': 0.0102}
dataset hash d9ce861eb053b429 | model hash 39f679980f3e0afc

The trained operator’s weights go into a registry as a blob whose bytes depend only on the weights, and load back into a fresh model of the same architecture.

1495 bytes; reloaded predictions equal: True

4. An Equinox emulator, with plain Keras

The emulator is an Equinox MLP written per sample. An EquinoxLayer puts it inside a Keras model, Keras trains copies of its arrays, and .module reads the trained module back.

MLP | validation MSE 0.011207402683794498

5. The emulator through TrainingLoop, under both backends

The same module, data, loss and optimiser config go to backend="equinox" and backend="keras". Both read the same batches in the same order, and the Keras backend builds the optimiser optax would (optax’s defaults, and Adam’s ε placed where optax places it), so the two runs train the same weights up to float32 rounding, which 2,000 steps can amplify. Each returns a JaxModelOp.

equinox JaxModelOp | validation {'mse': 0.01107}
keras JaxModelOp | validation {'loss': 0.01023, 'mse': 0.01023}
largest weight difference between the backends after 2,000 steps: 8.76e-03
<Figure size 1100x360 with 2 Axes>
Python implementation: CPython
Python version       : 3.13.12
IPython version      : 9.19.1

numpy        : 2.4.4
jax          : 0.10.1
keras        : 3.14.1
equinox      : 0.13.8
pipekit_train: 0.3.1

Compiler    : Clang 21.1.4 
OS          : Linux
Release     : 6.8.0-1044-azure
Machine     : x86_64
Processor   : x86_64
CPU cores   : 16
Architecture: 64bit