Skip to content

Validate RNN activation attribute lengths - #31675

Open
apsonawane wants to merge 1 commit into
mainfrom
fix/rnn-activation-alpha-beta-length-check
Open

Validate RNN activation attribute lengths#31675
apsonawane wants to merge 1 commit into
mainfrom
fix/rnn-activation-alpha-beta-length-check

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request adds stricter validation for the activation_alpha and activation_beta attributes in the RNN operator to ensure they have the correct number of values, and introduces new unit tests to verify that invalid attribute lengths are properly handled with clear error messages.

Validation improvements in RNN operator:

  • Added checks to ensure that activation_alpha and activation_beta vectors have exactly num_directions elements, with descriptive error messages if the validation fails.

Testing for invalid attribute lengths:

  • Introduced a helper function RunRnnActivationLengthFailureTest and two new unit tests in rnn_op_test.cc to verify that the RNN operator fails to load when activation_alpha or activation_beta have fewer values than required, and that the correct error messages are produced.

Co-authored-by: Copilot <223556219@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 tightens attribute validation for the CPU RNN kernel by enforcing expected lengths for activation_alpha and activation_beta, and adds unit tests to ensure invalid lengths fail model loading with clear error messages.

Changes:

  • Enforce activation_alpha/activation_beta vector lengths during RNN kernel construction.
  • Add a shared test helper plus two new negative tests validating failure behavior for short activation parameter vectors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
onnxruntime/core/providers/cpu/rnn/rnn.h Adds constructor-time activation_alpha/activation_beta length checks for CPU RNN.
onnxruntime/test/providers/cpu/rnn/rnn_op_test.cc Adds helper + new tests that assert model-load failure and error strings for invalid activation parameter lengths.

Comment on lines +33 to +36
ORT_ENFORCE(activation_alpha_.size() == static_cast<size_t>(num_directions),
"RNN op: activation_alpha must have ", num_directions, " values. Actual:", activation_alpha_.size());
ORT_ENFORCE(activation_beta_.size() == static_cast<size_t>(num_directions),
"RNN op: activation_beta must have ", num_directions, " values. Actual:", activation_beta_.size());
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