Skip to content

Commit 3aed8a6

Browse files
authored
change apply_chat_template add_generation_prompt param (#2533)
1 parent 3a481a9 commit 3aed8a6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

paddleformers/transformers/tokenizer_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,25 @@ def apply_chat_template(
185185
"tools": [], # Function call definitions
186186
"documents": [] # RAG context documents
187187
}
188+
189+
Note: The legacy PaddleFormers `add_generation_prompt` default was True.
190+
For backward compatibility, we changed the default behavior of the HuggingFace
191+
`apply_chat_template` function from False to True.
192+
193+
In future usage, explicitly pass the `add_generation_prompt` parameter
194+
to clearly specify the intended behavior.
188195
"""
196+
if "add_generation_prompt" not in kwargs:
197+
logger.warning_once(
198+
"Warning: apply_chat_template() called without explicit `add_generation_prompt` "
199+
"parameter. Current default=True differs from Hugging Face's default=False. "
200+
"Always specify this parameter to ensure consistent behavior across versions."
201+
)
202+
203+
# Changed the default behavior:
204+
# Original HF default was False, but we set it to True for compatibility
205+
add_generation_prompt = kwargs.pop("add_generation_prompt", True)
206+
189207
if isinstance(conversation, dict):
190208
messages = conversation.get("messages", None)
191209
tools = conversation.get("tools", None)
@@ -202,12 +220,14 @@ def apply_chat_template(
202220
chat_template=chat_template,
203221
tools=tools,
204222
documents=documents,
223+
add_generation_prompt=add_generation_prompt,
205224
**kwargs,
206225
)
207226
else:
208227
return super().apply_chat_template(
209228
conversation=conversation,
210229
chat_template=chat_template,
230+
add_generation_prompt=add_generation_prompt,
211231
**kwargs,
212232
)
213233

0 commit comments

Comments
 (0)