Skip to content

Validate DynamicQuantizeLSTM recurrence quantization parameter shapes#29254

Open
titaiwangms wants to merge 1 commit into
microsoft:mainfrom
titaiwangms:validate-dynamicquantizelstm-recurrence-shapes
Open

Validate DynamicQuantizeLSTM recurrence quantization parameter shapes#29254
titaiwangms wants to merge 1 commit into
microsoft:mainfrom
titaiwangms:validate-dynamicquantizelstm-recurrence-shapes

Conversation

@titaiwangms

Copy link
Copy Markdown
Contributor

Description

The R_zero_point / R_scale (recurrence) quantization-parameter shape validation in DynamicQuantizeLSTM was inadvertently checking the W (input) quantization parameters instead of the R ones. This change validates the R parameters' own shapes symmetrically with W, so malformed recurrence quantization parameters are rejected with a clear error.

Changes

  • Fix the shape checks so R_zero_point and R_scale are validated against the R tensor's expected shape (previously bound to the W tensor).
  • Add two expect-failure unit tests covering inconsistent recurrence zero-point and scale shapes.

Motivation

Improves input validation and error diagnostics for malformed DynamicQuantizeLSTM recurrence quantization parameters. CPU-only; no behavior change for valid inputs.

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

…er shapes

The recurrence zero-point (R_zero_point) and scale (R_scale) inputs were not run
through the kernel's shape validation: R_zp_shape was bound to w_zp->Shape()
instead of r_zp->Shape(), and the R_scale WeightCheck was passed W_scale_shape
instead of R_scale_shape. As a result a malformed r_zp/r_scale (e.g. a shape
inconsistent with R) was never rejected and downstream code iterated using the
input parameter's element count over the recurrence parameter's buffer.

Bind R_zp_shape to r_zp->Shape() and validate R_scale against R_scale_shape so
the recurrence parameters are checked symmetrically with the input (W) ones.
Add two expect-failure tests that supply R_zero_point / R_scale shapes whose
first dimension does not match num_directions and assert the specific
INVALID_ARGUMENT diagnostics. Status-based validation, so the tests need no
ORT_NO_EXCEPTIONS guard. CPU-only op; no CUDA implementation exists.

Agent-signed-off: Developer (0b207188) [claude-opus-4.8 via copilot]
Co-authored-by: Copilot <223556219+Copilot@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 fixes a bug in the CPU DynamicQuantizeLSTM kernel’s input validation where recurrence quantization parameters (R_scale/R_zero_point) were mistakenly validated using the input-weight (W) parameter shapes. It also adds unit tests to ensure malformed recurrence quantization parameter shapes are rejected with a clear error.

Changes:

  • Correct R_zero_point shape validation to use r_zp->Shape() (instead of w_zp->Shape()).
  • Correct R_scale shape validation to use R_scale_shape (instead of W_scale_shape).
  • Add two negative tests that expect failures for inconsistent R_zero_point / R_scale shapes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
onnxruntime/contrib_ops/cpu/quantization/dynamic_quantize_lstm.cc Fixes the recurrence quantization-parameter shape checks to validate against the actual R_* tensor shapes.
onnxruntime/test/contrib_ops/quantize_lstm_op_test.cc Adds expect-failure tests that confirm incorrect R_scale/R_zero_point shapes are rejected with the intended error message.

@titaiwangms titaiwangms marked this pull request as draft June 25, 2026 16:29
@titaiwangms titaiwangms marked this pull request as ready for review June 25, 2026 16:32
@titaiwangms titaiwangms enabled auto-merge (squash) June 25, 2026 16:45
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