Skip to content

Validate BeamSearch vocab_size against logits width#28774

Merged
tianleiwu merged 2 commits into
mainfrom
tlwu/20260603/icm_3
Jun 4, 2026
Merged

Validate BeamSearch vocab_size against logits width#28774
tianleiwu merged 2 commits into
mainfrom
tlwu/20260603/icm_3

Conversation

@tianleiwu

@tianleiwu tianleiwu commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR hardens generation-path vocab-size handling by rejecting mismatches between the user-supplied vocab_size and the decoder logits width, instead of relying on unsafe span/copy logic.

Key Changes

  • Added session-time validation in the beam-search parameter setup path to reject explicit vocab_size values that do not match the decoder subgraph logits width.
  • Added runtime validation in CPU and CUDA generation helpers before logits span/copy logic uses vocab_size.
  • Added regression tests covering mismatch rejection and the default-size inference path.

Why

A mismatched vocab_size could 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.*'

@tianleiwu tianleiwu changed the title fix(transformers): validate vocab_size against logits width Validate BeamSearch vocab_size against logits width Jun 3, 2026
@tianleiwu
tianleiwu requested a review from Copilot June 3, 2026 20:27

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 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::SetSubgraphParameters to reject mismatched vocab_size vs inferred decoder logits width.
  • Added runtime validation in CPU/CUDA generation helpers to ensure vocab_size matches 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.

Comment thread onnxruntime/contrib_ops/cpu/transformers/beam_search_parameters.cc Outdated
Comment thread onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc Outdated
Comment thread onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc Outdated
Comment thread onnxruntime/test/contrib_ops/beam_search_test.cc Outdated
@tianleiwu tianleiwu changed the title Validate BeamSearch vocab_size against logits width fix(ci): use subprocess for Triton compile helpers Jun 3, 2026
Comment thread tools/ci_build/test_compile_triton.py Fixed
@tianleiwu
tianleiwu force-pushed the tlwu/20260603/icm_3 branch from 1a7ed37 to abe1319 Compare June 3, 2026 21:08
@tianleiwu tianleiwu changed the title fix(ci): use subprocess for Triton compile helpers Validate BeamSearch vocab_size against logits width Jun 3, 2026
@tianleiwu
tianleiwu merged commit 211169c into main Jun 4, 2026
86 checks passed
@tianleiwu
tianleiwu deleted the tlwu/20260603/icm_3 branch June 4, 2026 15:07
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.

4 participants