Skip to content

Commit 40f6465

Browse files
committed
fix: clamp mingru hidden state before i16 cast
1 parent a9694e5 commit 40f6465

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/default_predictor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn mingru<const IN_DIM: usize>(features: &[i16], h: &mut [i16], weight: &[i16],
213213
// gate is multiplied by 4 then clamped within [0, 1] in Q24
214214
let g = (temp[64 + i] << 2).clamp(0, 16777215) as i64;
215215
let y = (16777215 - g) * ((h[i] as i64) << 9) as i64 + g * temp[i] as i64; // Q24 * Q24 = Q48
216-
h[i] = (y >> 33) as i16; // back down to Q15
216+
h[i] = (y >> 33).clamp(-32768, 32767) as i16; // back down to Q15
217217
}
218218
}
219219

0 commit comments

Comments
 (0)