Skip to content

fix: promote cell scalar hyperparameters with the state eltype - #577

Open
MartinuzziFrancesco wants to merge 1 commit into
masterfrom
fm/fix-n5-int-input-hyperparameters
Open

MartinuzziFrancesco wants to merge 1 commit into
masterfrom
fm/fix-n5-int-input-hyperparameters

Conversation

@MartinuzziFrancesco

Copy link
Copy Markdown
Collaborator

Integer input made T = eltype(inp) an integer type, so convert(T, 0.5) threw InexactError in ESN, EIESN, AdditiveEIESN, ES2N, ResESN, EuSN and the memory cells. T is now promote_type(eltype(inp), eltype(hidden_state)), which is unchanged for Float32 and Float64 inputs.

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

…put eltype

Integer input made T = eltype(inp) an integer type, so convert(T, 0.5)
threw InexactError in ESN, EIESN, AdditiveEIESN, ES2N, ResESN, EuSN and
the memory cells. T is now promote_type(eltype(inp), eltype(hidden_state)),
which is unchanged for Float32 and Float64 inputs.

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: #577

Reviewed head: 8a3f66d
Raw SHA-256: 4f2299ab0c55312e89e5e1dec656e437d27c6389406f6b4397cf017b28a98d32
Source SHA-256: 80f5b8be693a62e105ecc85c8b3ff46a95858f7c02a609672840868f5158fbac
Source: standard-review-v1 (harness-log)
Reviewer session: 01a1f5ca-8325-7682-82fe-a6763e5ebd0d
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: high (H1)
  • Verdict: CHANGES
  • Reviewed head: 8a3f66d

Review report

VERDICT: CHANGES
Round: 1
Head: 8a3f66d
Slot: 1
CI: formatter or lint is not green
Session: 01a1f5ca-8325-7682-82fe-a6763e5ebd0d
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

high (H1: a documented cell call now rejects a numeric carry that the merge base accepted)

Blocking findings

  • [P1] src/layers/esn_cell.jl:188 — Abstractly typed carries now throw or silently widen the result. I ran a one-unit ESNCell with identity activation, Float32 input and reservoir weights of 1 and 0 respectively, and leak 0.5. Calling cell((Float32[2], (Any[1f0],)), ps, st) returned Float32[1.5] on the merge base and threw MethodError: no method matching __format_leak(::Type{Any}, ::Float64) on the head. A custom initializer returning a Matrix{Any} with the same numeric value reproduced the error through the plain-input call. A Real[1f0] carry changed the result element from Float32 to Float64. Preserve a concrete numeric conversion type when promotion yields an abstract type, and add a regression for numeric values stored in an abstractly typed carry.

  • [P2] src/layers/memoryesn_cell.jl:125 and src/layers/memoryresesn_cell.jl:140 — The coefficient type omits the memory carry. With Float32 input and nonlinear carry and a BigFloat memory carry, both cells returned BigFloat results with coefficients already rounded to Float32. In one-unit identity-activation cases, the head returned 3.5 and 1.0 where the recurrence equations gave approximately 3.500000004656613 and 1.000000001862645. Both values reproduced on the merge base. The public RMNResESN model reproduced the first-step rounding with separate init_state and init_memory_state callbacks. Include the memory carry in coefficient type selection and add a mixed-carry precision test for each memory cell.

  • Blocking priorities: P1, P2

Non-blocking findings

None.

What I ran

  • julia --version reported Julia 1.12.4. I used the repository's Julia project with the same locally resolved manifest for the head and merge-base probes. The checkout has no tracked Julia manifest.
  • GROUP=Layers julia --project -e 'using Pkg; Pkg.test()', GROUP=Models julia --project -e 'using Pkg; Pkg.test()', and GROUP=Interface julia --project -e 'using Pkg; Pkg.test()' passed on the head with 878/878, 659/659, and 755/755 checks respectively.
  • julia --project ../added_regression.jl ran the unchanged test block from test/Models/esn_tests.jl against each revision. The merge base errored with InexactError: Int64(0.5). The head passed 12/12 assertions.
  • julia --project ../scalar_probe.jl matched checked inferred returns, output eltypes, carry identity and independently calculated one-unit recurrences for all eight changed cells. Inputs included Int, Float32, Float64 and BigFloat. Hidden states included Float32, Float64 and BigFloat. The head passed 264/264 assertions. The merge base reported 168 passes, 24 numerical failures and 24 errors. All 24 same-eltype cases produced identical outputs across revisions.
  • julia --project ../scalar_probe.jl mixed_memory gave five passes and three precision failures on each revision. julia --project ../api_probe.jl reproduced the two new abstract-carry errors and the result widening. Its integer-input vector-leak case errored with InexactError: Int64(0.25) on the merge base and returned BigFloat[1.25;;] on the head.
  • git diff --check origin/master...HEAD passed. Runic 1.10.0 in check mode exited zero for the changed Julia files.
  • uv run --locked python --version reported Python 3.13.13 and warned that --locked has no effect outside a project. This checkout has no Python lockfile.

What I did not verify

GPU execution, other Julia versions, and the hosted formatter job.

AUTHOR_GRADE: {"task":"bugfix","score":3,"difficulty":3,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"The added test discriminates and the concrete-state probes pass across all eight cells. Abstract carry calls regress and a wider memory carry still loses coefficient precision."}

Head link: 8a3f66d


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a1f5ca-8325-7682-82fe-a6763e5ebd0d (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