Open the reasoning function to reply to the missing <think> tag

#1
by xldistance - opened

set add_generation_prompt = true,Model responses missing tags

xldistance changed discussion title from Open the reasoning function to reply to the missing thought tag to Open the reasoning function to reply to the missing <think> tag
PKU-DS-LAB org

Thanks for opening this issue!

To help us better understand and address the problem, could you please provide:

  • Your environment details (e.g. transformers version, python version)
  • Steps to reproduce the issue (if applicable)
  • Any error logs or screenshots (if available)

This will help us investigate more efficiently. Thanks for your help!

We've run some tests and suspect this might be a Jupyter Notebook rendering issue—it truncates long outputs, so you saw the ... instead of </think>.
To confirm, please try running the Python code directly in a standard Python environment (like a .py file) and let us know if the problem persists. Thank you so much!

from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "PKU-DS-LAB/FairyR1-32B"
model = AutoModelForCausalLM.from_pretrained(
    model_name,
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)

prompt = "Give me a short introduction to large language model."
messages = [
    {"role": "system", "content": "You are FairyR1, created by PKU-DS-LAB. You are a helpful assistant."},
    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=8192
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print('output:', response)
xldistance changed discussion status to closed

Sign up or log in to comment