pipekit-train: support `eqx.nn.State` for stateful layers (BatchNorm, etc.) (v0.2, Q4)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- machine-learning
Research direction
Start with the v0.1 TrainState and train_step, then read TrainTask.loss_fn and _SynthesisedTask to understand the existing stateless path. Check the Orbax bridge and TrainingLoop integration before designing state persistence. Done means a tiny eqx.nn.BatchNorm model trains through TrainingLoop, running statistics survive save_state/restore_state, stateless behavior remains unchanged, and the docstring and ADR note are updated.
Written by the indexing model from the issue text.
Description
Problem / Request
Add support for eqx.nn.State so BatchNorm-like stateful layers can be trained. The v0.1 TrainState doesn't carry per-layer running statistics.
boundaries.md Q4: "BatchNorm and similar layers that carry running statistics need eqx.nn.State. The Equinox adapter's TrainState should probably carry an optional eqx.nn.State alongside the model."
Motivation
- Many real models use BatchNorm (CNN classifiers, U-Nets). Without
eqx.nn.Statethey can't be trained via this adapter. - Straightforward extension; just adds a code path. The shape of the fix is documented.
Proposed API
class TrainState(eqx.Module):
model: eqx.Module
state: eqx.nn.State | None # NEW — optional stateful-layer state
opt_state: optax.OptState
step: jax.Array
train_step threads state through:
def train_step(train_state, batch, key, task, optimizer):
(loss, (aux, new_state)) = grad_fn(train_state.model, batch, key, train_state.state)
...
return TrainState(model=new_model, state=new_state, ...), aux
TrainTask.loss_fn becomes optionally state-aware:
- If task has
stateful = True: signature isloss_fn(model, batch, key, state) -> (loss, (aux, new_state)). - Otherwise: existing v0.1 signature, ignored
state.
_SynthesisedTask detects stateful layers via eqx.is_inexact_array partition and wires accordingly.
Implementation Steps
-
TrainState.state: eqx.nn.State | Nonefield. -
TrainState.createbuilds initial state viaeqx.nn.State(model)when the model contains stateful layers. -
train_stepthreadsstate; defaultloss_fnignores it for backwards compat. -
_SynthesisedTaskdetects stateful models and adjusts the call. - Save/restore preserves the
statePyTree (extend Orbax bridge). - Test: train a tiny CNN with
eqx.nn.BatchNorm; assert running stats update across steps and are preserved throughsave_state/restore_state.
Definition of Done
- BatchNorm-using model trains end-to-end via
TrainingLoop. - Existing stateless model paths unchanged.
- Docstring + ADR note.
Relationships
- Parent: pipekit-train v0.2
- 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