Skip to content

Fix LSTM clipping before h activation (Issue #27224)#27239

Open
chaya2350 wants to merge 2 commits intomicrosoft:mainfrom
chaya2350:fix-lstm-clipping-issue-27224
Open

Fix LSTM clipping before h activation (Issue #27224)#27239
chaya2350 wants to merge 2 commits intomicrosoft:mainfrom
chaya2350:fix-lstm-clipping-issue-27224

Conversation

@chaya2350
Copy link

This PR fixes Issue #27224 where LSTM cell state (Ct) was not being clipped before applying the h() activation function, which violates the ONNX specification.

Changes

  1. Modified the LSTM forward pass to clip Ct before applying the h() activation function
  2. Fixed SEGFAULT caused by using clip_with_bias_ptr_ with nullptr bias by switching to clip_ignore_bias for Ct clipping

Testing

  • All 10 test suites pass (100%)
  • Specifically verified DynamicQuantLSTMTest.SmallSize which was failing with SEGFAULT before the fix

Related Issue

Fixes #27224

- Add clipping of Ct before applying h activation function
- Complies with ONNX spec requirement for clipping input of activations
- Equation: Ht = ot (.) h(clip(Ct)) instead of Ht = ot (.) h(Ct)
@chaya2350
Copy link
Author

@bac-cab Could you please review this PR? It fixes the issue you reported. Thanks! 🙂

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Issue #27224 by implementing proper clipping of the LSTM cell state (Ct) before applying the h() activation function, as required by the ONNX specification. Previously, the cell state was passed directly to the activation function without clipping, which violated the ONNX LSTM specification.

Changes:

  • Added clipping of cell state Ct before h() activation in the LSTM forward pass
  • Used clip_ignore_bias instead of clip_with_bias_ptr_ to avoid SEGFAULT with nullptr bias
  • Copied Ct to temporary buffer before clipping to preserve the original value

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

No clipping before activation in LSTM

1 participant