Explicitly set return_dict for apply_chat_template (#33372)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2026-01-30 07:27:04 +00:00
committed by GitHub
parent 726d89720c
commit 9432ed8c7e
11 changed files with 22 additions and 10 deletions

View File

@@ -38,8 +38,8 @@ def get_prompt_embeds(
embedding_layer: torch.nn.Module,
):
token_ids = tokenizer.apply_chat_template(
chat, add_generation_prompt=True, return_tensors="pt"
)
chat, add_generation_prompt=True, return_tensors="pt", return_dict=True
).input_ids
prompt_embeds = embedding_layer(token_ids).squeeze(0)
return prompt_embeds

View File

@@ -49,8 +49,8 @@ def main():
# Refer to the HuggingFace repo for the correct format to use
chat = [{"role": "user", "content": "Please tell me about the capital of France."}]
token_ids = tokenizer.apply_chat_template(
chat, add_generation_prompt=True, return_tensors="pt"
)
chat, add_generation_prompt=True, return_tensors="pt", return_dict=True
).input_ids
embedding_layer = transformers_model.get_input_embeddings()
prompt_embeds = embedding_layer(token_ids).squeeze(0)

View File

@@ -27,7 +27,8 @@ def main(client):
messages,
add_generation_prompt=True,
enable_thinking=False,
)
return_dict=True,
).input_ids
payload = {
"model": MODEL_NAME,
"token_ids": token_ids,

View File

@@ -92,7 +92,8 @@ async def test_same_response_as_chat_completions(client, tokenizer, messages):
messages,
add_generation_prompt=True,
enable_thinking=False, # default with Qwen3
)
return_dict=True, # default with Transformers v5
).input_ids
for ignore_eos in [True, False]:
payload = {
@@ -155,7 +156,8 @@ async def test_stop_string_workflow(client, tokenizer, messages):
messages,
add_generation_prompt=True,
enable_thinking=False, # default with Qwen3
)
return_dict=True, # default with Transformers v5
).input_ids
payload = {
"model": MODEL_NAME,
"token_ids": token_ids,
@@ -251,7 +253,8 @@ async def test_generate_with_lora_adapter(client, tokenizer, messages):
messages,
add_generation_prompt=True,
enable_thinking=False, # default with Qwen3
)
return_dict=True, # default with Transformers v5
).input_ids
payload = {
"model": "Alice",
"token_ids": token_ids,

View File

@@ -759,6 +759,7 @@ class IsaacProcessor:
# Regular text message
processed_messages.append(message)
kwargs["return_dict"] = False
return self.tokenizer.apply_chat_template(
processed_messages,
tokenize=tokenize,

View File

@@ -70,6 +70,7 @@ class DeepseekV32Renderer(RendererLike):
content_format="string",
)
kwargs["return_dict"] = False
prompt_raw = tokenizer.apply_chat_template(
conversation=conversation,
messages=messages,
@@ -100,6 +101,7 @@ class DeepseekV32Renderer(RendererLike):
content_format="string",
)
kwargs["return_dict"] = False
prompt_raw = tokenizer.apply_chat_template(
conversation=conversation,
messages=messages,

View File

@@ -70,6 +70,7 @@ class Grok2Renderer(RendererLike):
content_format="string",
)
kwargs["return_dict"] = False
prompt_raw = tokenizer.apply_chat_template(
conversation=conversation,
messages=messages,
@@ -100,6 +101,7 @@ class Grok2Renderer(RendererLike):
content_format="string",
)
kwargs["return_dict"] = False
prompt_raw = tokenizer.apply_chat_template(
conversation=conversation,
messages=messages,

View File

@@ -465,6 +465,7 @@ def safe_apply_chat_template(
chat_template=chat_template,
chat_template_kwargs=kwargs,
)
resolved_kwargs["return_dict"] = False
try:
return tokenizer.apply_chat_template(

View File

@@ -432,6 +432,7 @@ class Grok2Tokenizer(TokenizerLike):
raise ValueError(
"No chat template available. Provide `chat_template` explicitly."
)
kwargs["return_dict"] = False
prompt = hf_chat_utils.apply_chat_template(
conversation=messages,
chat_template=template,

View File

@@ -148,8 +148,8 @@ class HunYuanVLProcessor(ProcessorMixin):
assert 0
def apply_chat_template(self, *args, **kwargs):
token_ids = self.tokenizer.apply_chat_template(*args, **kwargs)
return token_ids
kwargs["return_dict"] = False
return self.tokenizer.apply_chat_template(*args, **kwargs)
def get_imgs_pos(self, doc_ids):
doc_ids = np.array(doc_ids, dtype=np.int64)

View File

@@ -213,6 +213,7 @@ class Qwen3ASRProcessor(ProcessorMixin):
return list(_iter())
def apply_chat_template(self, conversations, chat_template=None, **kwargs):
kwargs["return_dict"] = False
return super().apply_chat_template(conversations, chat_template, **kwargs)
@property