Skip to content

Repeated bos_token_id is added when using tokenizer #42221

@Hermit-w

Description

@Hermit-w

The code I use is:

from transformers import AutoTokenizer

messages = [
    {"role": "user", "content": "Hello!"},
    {"role": "assistant", "content": "Hi there!"},
    {"role": "user", "content": "How are you?"}
]

tokenizer = AutoTokenizer.from_pretrained("mistralai/Mixtral-8x22B-Instruct-v0.1")
# first usage
inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt")
decode_text = tokenizer.decode(inputs[0])
print(f"Decoded text: {decode_text}")
# second usage
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
inputs = tokenizer(prompt, return_tensors="pt")
decode_text = tokenizer.decode(inputs['input_ids'][0])
print(f"Decoded text: {decode_text}")

And the results are:

Decoded text: <s>[INST] Hello![/INST] Hi there!</s>[INST] How are you?[/INST]
Decoded text: <s><s>[INST] Hello![/INST] Hi there!</s>[INST] How are you?[/INST]

A repeated <s> is added into the input respectively.

I'm not sure whether this is an expected behaviour, but it does really confused me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions