Validate DynamicQuantizeLSTM recurrence quantization parameter shapes#29254
Open
titaiwangms wants to merge 1 commit into
Open
Validate DynamicQuantizeLSTM recurrence quantization parameter shapes#29254titaiwangms wants to merge 1 commit into
titaiwangms wants to merge 1 commit into
Conversation
…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>
Contributor
There was a problem hiding this comment.
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_pointshape validation to user_zp->Shape()(instead ofw_zp->Shape()). - Correct
R_scaleshape validation to useR_scale_shape(instead ofW_scale_shape). - Add two negative tests that expect failures for inconsistent
R_zero_point/R_scaleshapes.
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. |
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.
Description
The
R_zero_point/R_scale(recurrence) quantization-parameter shape validation inDynamicQuantizeLSTMwas inadvertently checking theW(input) quantization parameters instead of theRones. This change validates theRparameters' own shapes symmetrically withW, so malformed recurrence quantization parameters are rejected with a clear error.Changes
R_zero_pointandR_scaleare validated against theRtensor's expected shape (previously bound to theWtensor).Motivation
Improves input validation and error diagnostics for malformed
DynamicQuantizeLSTMrecurrence quantization parameters. CPU-only; no behavior change for valid inputs.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com