Skip to content

fix: clamp mingru hidden state before i16 cast - #6

Merged
decahedron1 merged 1 commit into
pykeio:mainfrom
Sal-ami:fix/mingru-clamp
Jul 22, 2026
Merged

decahedron1 merged 1 commit into
pykeio:mainfrom
Sal-ami:fix/mingru-clamp

Conversation

@Sal-ami

@Sal-ami Sal-ami commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

The Q48 accumulator y in mingru can exceed the i16 range after the >> 33 shift. On inputs that push the hidden state high enough, (y >> 33) as i16 wraps silently in release mode, producing incorrect hidden state values with no diagnostic.

This adds a one-line clamp before the cast. The gate g is already clamped to [0, 16777215] on the line above, so the analogous treatment for the output is overdue.

In practice the trained weights probably keep things in range, but "probably" is doing a lot of work for something that affects every forward pass. A silent correctness issue is worse than a crash.

This is a one-line fix. The change is the smallest thing that prevents the bug. No tests because the repo doesn't have a test infrastructure yet and adding a framework for one clamp assertion would be the opposite of lazy. The maintainer can decide if this warrants a targeted regression test.

@decahedron1
decahedron1 merged commit da403ca into pykeio:main Jul 22, 2026
4 checks passed
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