Skip to content

fix: gradient-breaking mutation, batch bugs - #180

Merged
MartinuzziFrancesco merged 4 commits into
mainfrom
fm/bugs
Sep 17, 2026
Merged

MartinuzziFrancesco merged 4 commits into
mainfrom
fm/bugs

Conversation

@MartinuzziFrancesco

Copy link
Copy Markdown
Owner

No description provided.

MartinuzziFrancesco and others added 4 commits September 17, 2026 19:44
…ross cells

- dense_proj added bias via an in-place mutating loop, which Zygote cannot
  differentiate through. Since bias=true is the default almost everywhere,
  this silently broke gradients for essentially every cell in the library.
  Replaced with a plain broadcast.
- RHNCell: state wasn't broadcast across the batch dimension (crashed for
  batch_size > 1), its couple_carry=true path still computed and paid for an
  unused carry gate, and its forward loop mixed differently-shaped
  iterations in one Julia for loop, which breaks Zygote's reverse-mode AD.
  Fixed all three, added depth validation, and dropped now-stale dead code
  and TODO comments describing bugs that were already fixed.
- MiRU2Cell: a bare `+` instead of `.+` crashed on batched input.
- IntersectionRNNCell: requires input_size == hidden_size but never
  validated or documented it, so mismatched sizes crashed with a cryptic
  broadcast error. Added validation and a docstring note.
- LEMCell, MinimalRNNCell, PeepholeLSTMCell: each had a gate computed from
  the stale pre-update value of a state the same timestep's equations
  require to use post-update (silent, no error/shape mismatch).

Also applied a few production-julia/SciML-style cleanups: const module
globals, using/import grouping, selectdim instead of an isa-branch in
ResLSTMCell, Returns instead of a closure in _chunked_bias.

Added batched forward+gradient regression tests across all layers.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
test_persistent_tasks spins up a subprocess that does its own fresh
package resolution to check for background tasks left running after
`using RecurrentLayers`. That resolution is network/registry-state
sensitive: it hangs locally in constrained network environments, and
fails outright in CI on the Julia prerelease matrix leg with "Unable to
locate InverseFunctions, a dependency of LogExpFunctions" inside Aqua's
own subprocess. Unrelated to this package's actual code; disabling it
the same way ambiguities=false is already disabled for a similar reason.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
- RHN used @layer :noexpand without a matching custom Base.show, unlike
  every other :noexpand layer in the library, so it printed a wall of
  nested type parameters instead of RHN(3 => 5). Added one.
- WMCLSTMCell reused the variable name proj_mh_2 for two different
  projections (forget-gate, then reassigned for the output-gate).
  Correct only because of statement order; renamed the second to
  proj_mh_3 so a future reorder can't silently break it.
- Fixed a typo in a comment documenting MUT2Cell's known, deliberate
  deviation from the original paper.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.92308% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.29%. Comparing base (9fe614a) to head (413de03).

Files with missing lines Patch % Lines
src/cells/rhn_cell.jl 71.79% 11 Missing ⚠️
src/RecurrentLayers.jl 0.00% 2 Missing ⚠️
src/base_functions.jl 50.00% 1 Missing ⚠️
src/cells/peepholelstm_cell.jl 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #180      +/-   ##
==========================================
- Coverage   75.65%   75.29%   -0.37%     
==========================================
  Files          40       40              
  Lines        1787     1789       +2     
==========================================
- Hits         1352     1347       -5     
- Misses        435      442       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@MartinuzziFrancesco
MartinuzziFrancesco merged commit 75b9617 into main Sep 17, 2026
14 checks passed
@MartinuzziFrancesco
MartinuzziFrancesco deleted the fm/bugs branch September 17, 2026 18:14
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.

1 participant