Repository navigation
fix: clamp mingru hidden state before i16 cast - #6
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Q48 accumulator
yinmingrucan exceed the i16 range after the>> 33shift. On inputs that push the hidden state high enough,(y >> 33) as i16wraps silently in release mode, producing incorrect hidden state values with no diagnostic.This adds a one-line clamp before the cast. The gate
gis 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.