Skip to content

Conversation

@gshtras
Copy link
Collaborator

@gshtras gshtras commented Sep 3, 2025

#17448 fixed in #19449 has now re-appeared
Before 4.56 the exception text was simply
Invalid prefix encountered
With transformers library == 4.56 the error message looks like
Exception: Invalid prefix encountered while decoding stream. Token ID: 30049, Expected prefix: '섬', Actual string: '�����ầ
and doesn't match exactly.
To filter it out and preserve the backwards compatibility with the old one, the common pattern would be to check for whether INVALID_PREFIX_ERR_MSG is included in the new message

Also the API for DecodeStream changed from
def __init__(self, skip_special_tokens):
to
def __init__(self, ids=None, skip_special_tokens=False):

…n't match exactly

Signed-off-by: Gregory Shtrasberg <Gregory.Shtrasberg@amd.com>

Change condition to check for inclusion

Signed-off-by: Gregory Shtrasberg <Gregory.Shtrasberg@amd.com>

Fix DecodeStream API change

Signed-off-by: Gregory Shtrasberg <Gregory.Shtrasberg@amd.com>
@gshtras gshtras force-pushed the transformers_prefix_fix_cont branch from 73e5873 to 4ad2710 Compare September 3, 2025 15:45
@mergify mergify bot added the v1 label Sep 3, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug where an Invalid prefix encountered exception from the transformers library was not being handled correctly due to a change in the exception message format. The fix correctly uses substring checking to handle both old and new message formats and also updates the DecodeStream constructor call to use keyword arguments for better compatibility. I've suggested a minor improvement to make the exception check more robust.

@gshtras gshtras added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 3, 2025
@njhill
Copy link
Member

njhill commented Sep 3, 2025

Thanks @gshtras! There's already a PR addressing this which will be merged asap #24159

@gshtras gshtras closed this Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants