Validate BeamSearch vocab_size against logits width#28774
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to harden the generation (BeamSearch/GreedySearch) path by validating that the configured vocab_size is compatible with the decoder subgraph logits last-dimension, preventing out-of-bounds reads/copies driven by a mismatched size.
Changes:
- Added validation in
BeamSearchParameters::SetSubgraphParametersto reject mismatchedvocab_sizevs inferred decoder logits width. - Added runtime validation in CPU/CUDA generation helpers to ensure
vocab_sizematches logits width before span/copy logic. - Added unit tests for mismatch rejection and default vocab-size inference.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| onnxruntime/test/contrib_ops/beam_search_test.cc | Adds parameter-level regression tests for vocab-size mismatch handling and default inference. |
| onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc | Adds runtime validation for CUDA BeamSearch/GreedySearch logits processing to guard against vocab/logits width mismatches. |
| onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc | Adds runtime validation for CPU BeamSearch/GreedySearch logits processing to guard against vocab/logits width mismatches. |
| onnxruntime/contrib_ops/cpu/transformers/beam_search_parameters.cc | Adds setup-time validation to reject incompatible vocab_size at subgraph-parameter binding time. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tianleiwu
force-pushed
the
tlwu/20260603/icm_3
branch
from
June 3, 2026 21:08
1a7ed37 to
abe1319
Compare
skottmckay
approved these changes
Jun 4, 2026
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.
Summary
This PR hardens generation-path vocab-size handling by rejecting mismatches between the user-supplied
vocab_sizeand the decoder logits width, instead of relying on unsafe span/copy logic.Key Changes
vocab_sizevalues that do not match the decoder subgraph logits width.vocab_size.Why
A mismatched
vocab_sizecould drive generation helpers to read or copy beyond the real logits width. These guards stop that class of out-of-bounds / DoS risk at both setup time and runtime.Testing
PATH=/home/tlwu/onnxruntime/.venv/bin:$PATH cmake --build . --target onnxruntime_provider_test -j2./onnxruntime_provider_test --gtest_filter='BeamSearchParametersTest.SetSubgraphParametersRejectsMismatchedVocabSize:BeamSearchTest.*:GreedySearchTest.*'