Skip to content

Fix array eos_token_id handling - #1463

Merged
Baiju Meswani (baijumeswani) merged 5 commits into
mainfrom
ryanunderhill/fix_multi_eos
May 9, 2025
Merged

Fix array eos_token_id handling#1463
Baiju Meswani (baijumeswani) merged 5 commits into
mainfrom
ryanunderhill/fix_multi_eos

Conversation

@RyanUnderhill

Copy link
Copy Markdown
Contributor

The previous approach to tweak the logit values would change the behavior of continuous decoding models by modifying which eos token id was chosen.

This change turns the EOS token id into an array in all places and preserves which EOS token was chosen in the output.

Fixes Issue #1412

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 the handling of EOS token ids by converting the former single integer representation into an array throughout the codebase so that the chosen EOS token is preserved.

  • The EOS token id field in configuration and related components is now represented as an array (vector).
  • Comparisons and kernel launches have been updated to iterate over EOS token ids instead of using a single value.
  • Removed obsolete code related to handling a singular EOS token in favor of the new array-based approach.

Reviewed Changes

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

Show a summary per file
File Description
src/smartptrs.h Removed obsolete EOS array launching function.
src/search.cpp Updated EOS token id checking and beam score updates with iteration over EOS token ids.
src/models/logits.{h,cpp} Removed legacy HandleEOSArray logic adapting EOS token id handling.
src/generators.h Introduced a helper "contains" for EOS array membership checks.
src/cuda/* Updated CUDA kernels and interfaces to support iterating over EOS token ids.
src/config.{h,cpp} Changed EOS token configuration from an int to a vector. Also ensured a default value if unset.
src/beam_search_scorer* Updated scorer APIs and condition checks to support EOS token arrays.
Comments suppressed due to low confidence (1)

src/config.h:84

  • Since the EOS token id is now always handled as an array, consider renaming this field to 'eos_token_ids' to clearly reflect that it holds multiple values.
int eos_token_id{};              // The id of the end-of-stream token.

Comment thread src/cuda/search_cuda.cpp Outdated

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 updates the handling of the EOS token ID by converting it from a single integer to an array throughout the codebase, ensuring that multiple EOS tokens can be managed consistently.

  • Updated EOS handling in search, logits, CUDA kernels, and beam search scorer components.
  • Removed obsolete functions (e.g. LaunchHandleEOSArray) from the device interface and adjusted related CUDA kernel logic.
  • Modified configuration parsing to convert a single EOS token into a vector and propagate it appropriately.

Reviewed Changes

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

Show a summary per file
File Description
src/smartptrs.h Removed the LaunchHandleEOSArray function from DeviceInterface.
src/search.cpp Updated EOS token checks to iterate over the EOS token array using the contains helper.
src/models/logits.{h,cpp} Removed EOS array handling functionality to align with the new array approach.
src/generators.h Added a generic contains function for checking EOS tokens in a container.
src/cuda/* Renamed variables from eos_meet to eos_seen and updated CUDA kernels accordingly.
src/config.{h,cpp} Revised configuration for EOS tokens: now using a vector and converting single values to a one-element vector.
src/beam_search_scorer.{h,cpp,cuh,cu} Updated beam search scorer to accept and process multiple EOS tokens consistently.
Comments suppressed due to low confidence (3)

src/config.h:85

  • [nitpick] Consider renaming 'eos_token_id' to 'eos_token_ids' for clarity and consistency with other parts of the codebase where multiple EOS tokens are handled.
std::vector<int> eos_token_id;  // The end-of-stream tokens (when set as a single value it is converted to a vector with one value).

src/beam_search_scorer.cpp:125

  • [nitpick] For clarity, ensure that 'eos_token_id_' clearly indicates it is a collection; consider renaming it to 'eos_token_ids_' if it holds multiple values.
if (contains(eos_token_id_, next_token)) {

src/smartptrs.h:122

  • Ensure that the removal of 'LaunchHandleEOSArray' from the DeviceInterface is fully propagated to all implementations so that no calling code expects this function.
virtual void LaunchHandleEOSArray(float* /*batch_logits*/, int /*batch_beam_size*/, int /*vocab_size*/, const int32_t* /*eos_token_ids*/, int /*eos_token_ids_count*/) { assert(false); }

Comment thread src/config.cpp
Comment thread src/cuda/beam_search_scorer_cuda.cpp
@baijumeswani
Baiju Meswani (baijumeswani) enabled auto-merge (squash) May 9, 2025 00:31
@baijumeswani
Baiju Meswani (baijumeswani) deleted the ryanunderhill/fix_multi_eos branch May 9, 2025 01:10
Baiju Meswani (baijumeswani) added a commit that referenced this pull request May 14, 2025
Address previous PR review comments from #1470 (#1473)
Address QNN specific regressions (#1470)
Fix array eos_token_id handling (#1463)
Constrained decoding integration (#1381)
Remove BF16 CPU from valid GQA configuration (#1469)
Avoid adding providers if not requested (#1464)
Persist provider options across ClearProviders, AppendProvider where
possible (#1454)
Fix accuracy issues with Gemma models (#1448)
Add bfloat16 support in model builder (#1447)
Add final norm for LoRA models (#1446)

Update version to 0.8.0-rc3

---------

Co-authored-by: kunal-vaishnavi <115581922+kunal-vaishnavi@users.noreply.github.com>
Co-authored-by: Nenad Banfic <46795300+nenad1002@users.noreply.github.com>
Co-authored-by: Nenad Banfic <nebanfic@microsoft.com>
Co-authored-by: Baiju Meswani <bmeswani@microsoft.com>
Co-authored-by: Abhishek Jindal <abjindal@microsoft.com>
Co-authored-by: Ying Xiong <yingxiong@microsoft.com>
Co-authored-by: Michał Moskal <michal@moskal.me>
Co-authored-by: Kunal Vaishnavi <kvaishnavi@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants