Skip to content

refactor: share the teacher-forced predict loop - #573

Open
MartinuzziFrancesco wants to merge 1 commit into
masterfrom
fm/dedupe-predict-loop
Open

MartinuzziFrancesco wants to merge 1 commit into
masterfrom
fm/dedupe-predict-loop

Conversation

@MartinuzziFrancesco

Copy link
Copy Markdown
Collaborator

predict(::AbstractLuxLayer) and __predict(::Any, ::AbstractReservoirComputer) now use one __teacher_forced_predict; the Lux-layer path iterates eachcol views instead of copying data[:, t].

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

Additional context

Add any other context about the problem here.

predict(::AbstractLuxLayer) and __predict(::Any, ::AbstractReservoirComputer)
now use one __teacher_forced_predict; the Lux-layer path iterates eachcol
views instead of copying data[:, t].

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

Copy link
Copy Markdown
Member

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

PR: #573

Reviewed head: fbf23ba
Raw SHA-256: d7d765b35220e997f94a5c976d2f701580e47449516c148f2b6bf8e87eb21bb1
Source SHA-256: e99b7e4bc9dd8b8e8f5e4ab856953dff004a7bed689d88c4c1b2dbd110e85ed6
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1d258-58fb-7ae2-94a9-460bf7423820
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes

Risk assessment

  • Risk: high (H1)
  • Verdict: CHANGES
  • Reviewed head: fbf23ba

Review report

VERDICT: CHANGES
Round: 1
Head: fbf23ba
Slot: 1
CI: CI is not green (regress:tests / Extensions (julia 1, windows-latest) / Tests - Extensions (Julia 1))
Session: 01a1d258-58fb-7ae2-94a9-460bf7423820

Risk

high (H1: existing public predict calls with Vector-only wrapped functions are rejected after columns become views)

Blocking findings

  • Verdict: CHANGES
  • Round: 1
  • Blocking priorities: P2
  • Deferred P2 issues: None supplied.

[P2] Preserve copied-column semantics for generic Lux callers

src/predict.jl:92–97 changes the generic AbstractLuxLayer path from data[:, t] copies to views into caller-owned storage. ReservoirChain explicitly supports plain functions (src/layers/lux_layers.jl:73–74), so this changes supported calls, beyond sharing an internal loop.

Confirmed by running both implementations with the same installed package and inputs:

  • For chain = ReservoirChain(sort!) and data = [3 8; 1 6; 2 7], both produce [1 6; 2 7; 3 8]. The base loop leaves data unchanged; the PR overwrites it with that sorted matrix. A prediction can therefore silently alter data reused for training or evaluation.
  • For onlyvector(x::Vector) = 2 .* x, predict(ReservoirChain(onlyvector), data, ps, st) succeeds with the base loop and throws MethodError: no method matching onlyvector(::SubArray{...}) on this head.

Keep the generic Lux path's owned-column behavior while sharing the loop, and add regression tests for input preservation and concrete-vector function dispatch. The existing reservoir-computer fallback already uses views; its behavior need not change.

Non-blocking findings

None.

What I ran

All Julia commands preserved the supplied layered JULIA_DEPOT_PATH and used the requested job TMPDIR. Source and environment writes stayed in scratch; the checkout remained clean. Tests used Julia 1.13.2 with two Julia threads, one precompile task, and bounded memory scopes.

  • Inspected git diff origin/master...HEAD, surrounding implementations, test groups, and affected tests. No root AGENTS.md or CLAUDE.md exists in this checkout. git diff --check origin/master...HEAD passed.
  • Created an exact git archive HEAD scratch copy. julia --startup-file=no --project="$SCRATCH/head" -e 'using Pkg; Pkg.instantiate(;allow_autoprecomp=false)' exited 0. Resolved versions include LuxCore 1.5.4, LinearSolve 5.18.3, SciMLBase 3.58.0, and NNlib 0.9.60.
  • GROUP=All julia --startup-file=no --project="$SCRATCH/head" -e 'using Pkg; Pkg.test(;julia_args=["--startup-file=no", "--threads=2"])' exited 0: 3,924 assertions passed across 37 files, covering Core, Extensions, Interface, Layers, and Models; final output: Testing ReservoirComputing tests passed.
  • julia --startup-file=no --project="$SCRATCH/head" "$SCRATCH/probes.jl" exited 0. It loaded the base src/predict.jl in a separate module and compared it with this head. 53 assertions passed for analytic cumulative outputs, exact base/head equality, threaded final state, Float32/Float64, dense/view inputs, one/multiple columns, empty-input rejection, ESN, and DeepESN. Six further assertions confirmed the two compatibility regressions above; these deliberately assert the observed differing behavior and are not passing regression guards.
  • uv run --locked python --version printed Python 3.15.0 and warning: --locked has no effect when used outside of a project. This repository has no Python project or lockfile; no locked project Python interpreter was available or substituted.
  • Verified the exact head and a clean git status --porcelain after execution. The newest commit has neither Agent-Harness nor Agent-Model trailers.

This independent review was produced by an AI agent using codex-cli 0.164.0, model gpt-6.1-sol; local session 01a1d258-58fb-7ae2-94a9-460bf7423820 (no session URL).

What I did not verify

  • Windows or the supplied failing Windows CI result; the local Extensions tests passed on Linux. No GitHub body, comments, reviews, or CI logs were read.
  • QA, CUDA, documentation builds, other Julia versions, or performance benchmarks.
  • A locked Julia dependency environment: this checkout has no committed manifest or interpreter pin, so the scratch environment was resolved from its Project.toml.
  • No earlier review or author risk rating was inspected. No commits, pushes, GitHub posts, or checkout edits were made.

AUTHOR_GRADE: {"task":"other","score":2,"difficulty":2,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"Small loop refactor passes all 3924 existing assertions, but independent base/head probes confirm caller-data mutation and rejection of formerly working Vector-only wrapped functions; no tests cover the changed input semantics."}

Head link: fbf23ba


🤖 Posted by an AI agent — harness: codex-cli 0.164.0 · model: gpt-6.1-sol
Conversation: local session 01a1d258-58fb-7ae2-94a9-460bf7423820 (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