[Bugfix] Fix incorrect chat template format for Qwen3.5 (#42660)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -363,6 +363,7 @@ def test_resolve_chat_template_kwargs_with_template_name():
|
||||
("microsoft/Phi-3.5-vision-instruct", "string"),
|
||||
("Qwen/Qwen2-VL-2B-Instruct", "openai"),
|
||||
("Qwen/Qwen2.5-VL-3B-Instruct", "openai"),
|
||||
("Qwen/Qwen3.5-4B", "openai"),
|
||||
("fixie-ai/ultravox-v0_5-llama-3_2-1b", "string"),
|
||||
("Qwen/Qwen2-Audio-7B-Instruct", "openai"),
|
||||
("meta-llama/Llama-Guard-3-1B", "openai"),
|
||||
|
||||
@@ -402,6 +402,7 @@ def _iter_nodes_assign_content_item(root: jinja2.nodes.Node):
|
||||
]
|
||||
|
||||
# Search for {%- for content in message['content'] -%} loops
|
||||
# or {%- for item in content -%} loops
|
||||
for loop_ast in root.find_all(jinja2.nodes.For):
|
||||
loop_iter = loop_ast.iter
|
||||
loop_target = loop_ast.target
|
||||
@@ -412,6 +413,10 @@ def _iter_nodes_assign_content_item(root: jinja2.nodes.Node):
|
||||
yield loop_ast, loop_target.name
|
||||
break
|
||||
|
||||
if isinstance(loop_iter, jinja2.nodes.Name) and loop_iter.name == "content":
|
||||
assert isinstance(loop_target, jinja2.nodes.Name)
|
||||
yield loop_ast, loop_target.name
|
||||
|
||||
|
||||
def _try_extract_ast(chat_template: str) -> jinja2.nodes.Template | None:
|
||||
import transformers.utils.chat_template_utils as hf_chat_utils
|
||||
|
||||
Reference in New Issue
Block a user