feat(train): the Keras backend gives a Loss that needs a PRNG key one per step

Open
#330 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
keras, python

Research direction

Start with packages/pipekit-train/src/pipekit_train/backends/keras/_losses.py, reading bridge_loss, aux_names, and aux_metrics; then check call_loss in packages/pipekit-train/src/pipekit_train/losses/_losses.py and the Keras adapter design sections cited in the issue. Add per-call keys for training, probing, and validation, then run the train-extras tests and the listed lint, format, and type checks. Done means required-key losses train and receive a fresh key each step.

Written by the indexing model from the issue text.

Description

area:code type:feature

Problem / Request

The Keras backend (#320) bridges a pipekit_train.Loss into a Keras loss, but a Keras loss is called (y_true, y_pred) with no PRNG key. A Loss whose key argument is required, such as a sample-based divergence, therefore cannot train under backend="keras"; #320 refuses it with an error that names this issue. A Loss whose key defaults to None (KL with an analytic divergence) already trains.

User Story

As someone training an amortized posterior with a sample-based loss, I want backend="keras" to hand my Loss a fresh key each step, as the Equinox backend does, so that the same loss trains under both backends.

Design Snapshot

  • Keep a keras.random.SeedGenerator(loop.seed) in the bridged loss and the auxiliary metrics, and call call_loss(loss, y_pred, y_true, key=seed_generator.next()) inside the traced train step. The Equinox backend splits jax.random.key(loop.seed) once per step; matching its key sequence exactly is not required, but one key per step and per call is.
  • The auxiliary-name probe before compile passes a fixed key.
  • Validation passes a key too, so that a stochastic validation metric is defined.
  • Remove the refusal added in #320.

References & Existing Code

  • packages/pipekit-train/src/pipekit_train/backends/keras/_losses.py (bridge_loss, aux_names, aux_metrics)
  • packages/pipekit-train/src/pipekit_train/losses/_losses.py (call_loss, KL)
  • Design: packages/pipekit-train/docs/design/keras_adapter.md §8.2 and §10 ("losses that take a key")

Definition of Done

  • A Loss with a required key trains under backend="keras"
  • Tests pass with train-extras; lint, format and typecheck pass

Testing

  • A loss that adds jax.random.normal(key, ()) * 0 trains, and receives a different key each step
  • KL with its sample-based fallback trains on a toy amortized posterior

Relationships

  • Parent (theme epic): #317
  • Blocked by: #320
Dominant language
Python
Stars
0
Forks
0
Avg merge
3h 50m
Merged PRs (30d)
143

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jejjohnson/pipekit

All issues in jejjohnson/pipekit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.