[EPIC] pipekit-train: the Keras 3 backend
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
Start with packages/pipekit-train/docs/design/keras_adapter.md and decisions D18–D21 in packages/pipekit-train/docs/design/decisions.md; the issue lists six child tasks, KB-1 through KB-6, to land in order. The central entry point is pipekit_train.backends.keras.run, currently described as raising NotImplementedError. Done means all children and their PRs are merged, CI trains both a KerasModelOp and a JaxModelOp with the Keras backend, and the shipped design names are marked today.
Written by the indexing model from the issue text.
Description
Theme
TrainingLoop(..., backend="keras") trains a Keras 3 model, or an Equinox model, through Keras's own compile and fit on the JAX backend, and returns an operator whose weights round-trip through a ModelRegistry. Today pipekit_train.backends.keras.run raises NotImplementedError.
Parent Wave
None. This is the Keras half of #147 (stateful layers and the Keras backend); the stateful-layer half is #16.
Motivation
The Lightning backend was dropped (D15), so Keras is the one route into TrainingLoop for a model not written in Equinox. Models that already exist in Keras, such as keras-fairkl's FairModelWrapper (a fairness penalty added with add_loss), train today in scripts outside pipekit and lose what the loop gives an Equinox model: a dataset content hash, a step budget, EarlyStopping on validation metrics, checkpoints that resume, HyperSweep ranking, a registry entry and an operator that drops into a pipeline. Equinox users also want Keras tooling (Keras Tuner, Keras preprocessing layers) around their modules, and a benchmark wants one Equinox model trained under both backends.
The full design is packages/pipekit-train/docs/design/keras_adapter.md, with decisions D18 to D21 in packages/pipekit-train/docs/design/decisions.md. In short:
- D18. Wrap
compileandfit. One Keras epoch is one evaluation period P =eval_every_n_steps;fitruns E = ⌈K / P⌉ epochs and a bridge callback stops it at step K =max_steps. The bridge drives the pipekit callbacks and the metric writer, and resets Keras's metrics after each step so the logged loss is the step's loss, not the epoch's running mean. - D19. JAX backend only. The backend sets
KERAS_BACKEND=jaxbefore the firstimport kerasand raises if Keras was imported on another backend. Without this,import kerasfails on a machine without TensorFlow, because Keras's default backend is TensorFlow. - D20.
KerasModelOpinpipekit_train.backends.keras, with a weight blob of a (path, shape, dtype) header and the raw arrays. A.kerasfile is not byte-stable (its metadata records the save time), so it cannot be what the registry hashes. - D21. An operator that is or holds an Equinox module (
JaxOperator,JaxModelOp,EquinoxModelOp) trains as anEquinoxLayer, akeras.layers.JaxLayerover copies of its array leaves, and comes back in the wrapper it was given.
Facts measured on Keras 3.15.1, JAX 0.12.1 and Equinox 0.13.8 that the children rely on:
| Check | Result |
|---|---|
fit with P = 100, K = 250 and a stop at 250 |
250 optimiser steps; the batch generator is read 250 times; validation at 100, 200 and 250 |
logs["loss"] in on_train_batch_end |
the running mean since the epoch began; with reset_metrics() after each step, equal to train_on_batch |
| Validation on 70 samples in batches of 32 | Keras's loss is the exact per-sample mean; a metric returning an averaged scalar is the mean of batch means (3.2899 vs 3.2349) |
| Resume after 200 of 300 steps from weights, optimiser variables and the Grain iterator state | weights equal to the uninterrupted run (difference 0.0) |
An Equinox MLP in a JaxLayer |
one SGD step equals hand-written JAX to 3e-8; Keras deletes the arrays it was given unless they are copied |
| optax against Keras optimisers, 200 steps | SGD identical; Adam and AdamW with matched settings within 1.3e-6; Keras's default epsilon=1e-7 differs from optax's 1e-8 |
Issues
- KB-1 — one Grain batch pipeline for every backend
- KB-2 —
KerasModelOpwith a weight blob (D20) - KB-3 — the Keras backend's
run(D18, D19) - KB-4 — Equinox models under the Keras backend (D21)
- KB-5 — Keras checkpoints that resume
- KB-6 — docs for the Keras backend
Execution Notes
The children land in order, one PR each: KB-1, KB-2, KB-3, KB-4, KB-5, KB-6. KB-3 needs KB-1's shared batches and KB-2's operator; KB-4 and KB-5 extend KB-3's run; KB-6 documents what exists. None depends on #16, which touches backends/equinox/_state.py, not _batches.py.
CI must run the Keras tests: the train-extras dependency group in the root pyproject.toml gains keras, and the backend sets KERAS_BACKEND=jax itself, so CI needs no environment variable.
Parallelism
- Can run in parallel with: #16
- Blocked by (inside this wave): none
- Must complete before: none
Definition of Done
- All child issues closed, their PRs merged
-
TrainingLoop(..., backend="keras")trains aKerasModelOpand aJaxModelOpin CI - The design page's
proposedmarkers for shipped names becometoday
Relationships
- Parent: #147
- Related: #16, #231
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- Avg merge
- 3h 50m
- Merged PRs (30d)
- 143
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jejjohnson/pipekit
-
area:code layer:0-primitives priority:p2 type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
jejjohnson/pipekit#296 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 3/5 1-2 days Newbie friendliness 57/100
jejjohnson/pipekit#411 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 4/5 3-5 days Newbie friendliness 48/100
jejjohnson/pipekit#410 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 5/5 Over a week Newbie friendliness 38/100
jejjohnson/pipekit#409 ·
Maintainers usually reply within 1 day
-
area:code type:feature
Difficulty 3/5 1-2 days Newbie friendliness 75/100
jejjohnson/pipekit#408 ·
Maintainers usually reply within 1 day
All issues in jejjohnson/pipekit
Similar issues
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPossibly taken @jejjohnson claimed this today. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jejjohnson/integrix#144 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
finos/ai-governance-framework#459 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
freelawproject/litigant-portal#1307 ·
Maintainers usually reply within 2 days
-
type/bug
Difficulty 1/5 Under an hour Newbie friendliness 86/100
h2oai/h2o-llmstudio#1163 ·
Maintainers usually reply within 1 day