Skip to content

fix: custom trainable readout - #576

Open
MartinuzziFrancesco wants to merge 2 commits into
masterfrom
fm/fix-n4-custom-trainable-readout
Open

MartinuzziFrancesco wants to merge 2 commits into
masterfrom
fm/fix-n4-custom-trainable-readout

Conversation

@MartinuzziFrancesco

Copy link
Copy Markdown
Collaborator

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

MartinuzziFrancesco and others added 2 commits November 19, 2026 21:28
__addreadout only wrote weights into LinearReadout, so a custom
AbstractReservoirTrainableLayer was silently left untrained. Any such layer
whose parameters have a `weight` field now receives the weights, and one
without raises an ArgumentError at training time.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
A custom trainable layer only receives fitted weights when it is the first
trainable layer in the chain, the one feature collection stops at. Later
custom trainable layers keep their parameters. LinearReadout handling is
unchanged.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #576

Reviewed head: ab2abc8
Raw SHA-256: 9e379625cfa3a7a923336ff54131dfc958ffba047c018b37ac2ab1882aece7bd
Source SHA-256: 430570ff2ef4dbaefd4505a90b11b525768eea786b577d8065877a0a14782ebb
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1f5bb-ca03-7383-a2ba-2bfc818ff16c
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium (M2)
  • Verdict: CHANGES
  • Reviewed head: ab2abc8

Review report

VERDICT: CHANGES
Round: 1
Head: ab2abc8
Slot: 1
CI: formatter or lint is not green
Session: 01a1f5bb-ca03-7383-a2ba-2bfc818ff16c
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

medium (M2: training changes predictions on a previously working chain with a custom readout followed by a linear readout)

Blocking findings

  • [P1] src/train.jl:325 installs one fit in two layers. Feature collection stops at the first trainable layer (src/layers/basic.jl:289), but weight installation also overwrites a later LinearReadout. I initialized both layers to identity and trained against a known diagonal map with entries 2 and 3. For held-out input [1, 1], the merge base predicted approximately [2, 3] and the head predicted [4, 9] in both Float32 and Float64. In a second probe, a custom 2 => 1 readout followed by a 1 => 2 linear layer rejected a valid one-row target based on the downstream layer's dimensions (src/train.jl:196). When the first trainable layer is custom, use that same layer for target validation and weight installation. Add a custom-first regression that checks the downstream parameters and the end-to-end prediction against a known map.

  • [P2] src/train.jl:302 accepts incompatible target dimensions for a standalone custom readout. I trained a custom readout with a (1, 2) initial weight against two target rows. train returned a (2, 2) weight and predict silently returned a (2, 4) output for four samples. Validate the fitted shape against the custom layer's declared dimensions or its initialized weight shape when available. Test that a target with the wrong row count fails during training.

  • Blocking priorities: P1, P2

Non-blocking findings

  • src/train.jl:307, src/layers/basic.jl:64, and docs/src/tutorials/train.md:100. The error tells custom layer authors to extend ReservoirComputing.addreadout!. Julia reported Base.ispublic(ReservoirComputing, :addreadout!) == false. The marker docstring describes where feature collection stops and the tutorial describes installing matrices in a standard linear readout. Document the custom weight convention and what shape the fit must have. Declare and document any override hook intended for downstream extension.

What I ran

  • julia --version reported 1.12.4. The repository has no checked-in Julia manifest. I instantiated the project's Project.toml in scratch and used the same resolved manifest for the direct head and merge-base tests.
  • julia --startup-file=no --project=. test/test_train_api.jl with the head test file on the merge-base sources produced 5 passed, 2 failed in the new testset. The installed weight stayed all zeros and the missing-weight case threw no exception. On the head, the same file passed all 29 assertions, including 7/7 in the new testset.
  • julia --startup-file=no --project=. -e 'using Pkg; Pkg.test()' with each of GROUP=Core, GROUP=Layers, and GROUP=Interface on the head passed. The groups reported 1357/1357, 878/878, and 755/755 assertions, respectively.
  • julia --startup-file=no --project=. ../readout_probe.jl mixed on both revisions and julia --startup-file=no --project=. ../shape_probe.jl on the head reproduced the outputs and shapes above. julia --startup-file=no --project=. ../readout_probe.jl custom passed 46/46 assertions on the head, covering fitted weights, preservation of fixed parameters and readout metadata, missing weight, teacher-forced prediction, and closed-loop inference. julia --startup-file=no --project=. ../recurrent_probe.jl custom also passed 10/10 recurrent-state checks. Against a reference recurrence with Float32 and Float64 carry, maximum held-out errors were 1.19e-7 and 0.0, respectively.
  • julia --startup-file=no --project=docs -e 'include(expr -> Meta.isexpr(expr, :call) && first(expr.args) === :deploydocs ? nothing : expr, "docs/make.jl")' exited 0 after doctests and HTML rendering. Documenter emitted HTML-size warnings.
  • Runic 1.13.0 with --check --diff ., typos src/train.jl test/test_train_api.jl, and git diff --check origin/master...HEAD each exited 0 locally.
  • uv run --locked python --version reported Python 3.13.13 and warned that --locked has no effect outside a project. The repository has no uv.lock.

What I did not verify

  • Other Julia versions, GPU, downstream packages, and the remote CI failure. The CI header reflects the supplied check status.

AUTHOR_GRADE: {"task":"bugfix","score":2,"difficulty":3,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"The added tests discriminate on the merge base and standalone custom fitting passes analytic probes. The head silently applies the fit twice in mixed chains and accepts incompatible custom readout dimensions."}

Head link: ab2abc8


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a1f5bb-ca03-7383-a2ba-2bfc818ff16c (no session URL)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants