Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transformers 4.41.0 prompt may differ after encode decode #1617

Merged
merged 2 commits into from
May 21, 2024

Conversation

AllentDan
Copy link
Collaborator

The following script failed with the latest transformers. The output differs from the input after encode and decode functions.

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
    'WizardLM/WizardLM-70B-V1.0', trust_remote_code=True)
prompt = ' '
encoded = tokenizer.encode(prompt)
decoded = tokenizer.decode(encoded)  # ' ' was decoded to '<s> ' actually
assert decoded == prompt

@@ -23,6 +23,7 @@ def test_tokenizer(model_path, input, interval, skip_special_tokens):
tokenizer = HuggingFaceTokenizer(model_path)
encoded = tokenizer.encode(input, False, add_special_tokens=False)
output = ''
input = tokenizer.decode(encoded, skip_special_tokens=skip_special_tokens)
Copy link
Collaborator

Choose a reason for hiding this comment

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

这种追改兼容了各transformers的版本吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

只是改了 UT,增量解码我理解只要结果等于普通解码结果就OK。至于普通解码结果是不是一开始的 prompt,这可能是 transformers 关心的

Copy link
Collaborator

Choose a reason for hiding this comment

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

tokenizer.encode的部分需要把 add_special_token=False改成 add_special_token=add_special_token吗?

@lvhan028 lvhan028 merged commit 0a27c96 into InternLM:main May 21, 2024
4 checks passed
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.

None yet

2 participants