From 9d0af9f243c84ff5bd6646b0d17672bd10399d99 Mon Sep 17 00:00:00 2001 From: DarkLight1337 Date: Mon, 4 Nov 2024 09:49:59 +0000 Subject: [PATCH] Fix repeated Signed-off-by: DarkLight1337 --- vllm/entrypoints/chat_utils.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vllm/entrypoints/chat_utils.py b/vllm/entrypoints/chat_utils.py index 9d14b4e59342a..8a5f18c860cb9 100644 --- a/vllm/entrypoints/chat_utils.py +++ b/vllm/entrypoints/chat_utils.py @@ -173,10 +173,13 @@ def _iter_nodes_define_message(chat_template_ast: jinja2.nodes.Template): for loop_ast in chat_template_ast.find_all(jinja2.nodes.For): loop_target = loop_ast.target - for loop_iter_desc in _iter_self_and_descendants(loop_ast.iter): - if _is_var_access(loop_iter_desc, "messages"): - assert isinstance(loop_target, jinja2.nodes.Name) - yield loop_ast, loop_target.name + # yapf: disable + if any( + _is_var_access(loop_iter_desc, "messages") for loop_iter_desc + in _iter_self_and_descendants(loop_ast.iter) + ): # yapf: enable + assert isinstance(loop_target, jinja2.nodes.Name) + yield loop_ast, loop_target.name def _iter_nodes_define_content_item(chat_template_ast: jinja2.nodes.Template): @@ -185,10 +188,13 @@ def _iter_nodes_define_content_item(chat_template_ast: jinja2.nodes.Template): for loop_ast in node.find_all(jinja2.nodes.For): loop_target = loop_ast.target - for loop_iter_desc in _iter_self_and_descendants(loop_ast.iter): - if _is_attr_access(loop_iter_desc, message_varname, "content"): - assert isinstance(loop_target, jinja2.nodes.Name) - yield loop_iter_desc, loop_target.name + # yapf: disable + if any( + _is_attr_access(loop_iter_desc, message_varname, "content") + for loop_iter_desc in _iter_self_and_descendants(loop_ast.iter) + ): # yapf: enable + assert isinstance(loop_target, jinja2.nodes.Name) + yield loop_ast, loop_target.name def _detect_content_format(