Skip to content

Commit 8a15c26

Browse files
[Frontend] Add missing chat templates for various MLLMs (#17758)
Signed-off-by: DarkLight1337 <[email protected]>
1 parent 043e4c4 commit 8a15c26

11 files changed

+30
-33
lines changed

docs/source/serving/multimodal_inputs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ A chat template is **required** to use Chat Completions API.
216216

217217
Although most models come with a chat template, for others you have to define one yourself.
218218
The chat template can be inferred based on the documentation on the model's HuggingFace repo.
219-
For example, LLaVA-1.5 (`llava-hf/llava-1.5-7b-hf`) requires a chat template that can be found here: <gh-file:examples/template_llava.jinja>
219+
For example, DeepSeek-VL2 requires a chat template that can be found here: <gh-file:examples/template_deepseek_vl2.jinja>
220220
:::
221221

222222
### Image Inputs

examples/online_serving/openai_chat_completion_client_for_multimodal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Launch the vLLM server with the following command:
66
77
(single image inference with Llava)
8-
vllm serve llava-hf/llava-1.5-7b-hf --chat-template template_llava.jinja
8+
vllm serve llava-hf/llava-1.5-7b-hf
99
1010
(multi-image inference with Phi-3.5-vision-instruct)
1111
vllm serve microsoft/Phi-3.5-vision-instruct --task generate \

examples/template_chameleon.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{%- for message in messages -%}
2+
{{- message['content'] -}}
3+
{%- endfor -%}

examples/template_florence2.jinja

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{%- for message in messages -%}
2-
{%- if message['role'] == 'user' -%}
3-
{{- message['content'] -}}
4-
{%- elif message['role'] == 'assistant' -%}
5-
{{- message['content'] -}}
6-
{%- endif -%}
2+
{{- message['content'] -}}
73
{%- endfor -%}

examples/template_fuyu.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{%- for message in messages -%}
2+
{{- message['content'] + '\n' -}}
3+
{%- endfor -%}

examples/template_llava.jinja

Lines changed: 0 additions & 23 deletions
This file was deleted.

examples/template_paligemma.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{%- for message in messages -%}
2+
{{- message['content'] -}}
3+
{%- endfor -%}

examples/template_qwen_vl.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{%- for message in messages -%}
2+
{{- message['content'] -}}
3+
{%- endfor -%}

examples/template_qwen_vl_chat.jinja

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{%- for message in messages -%}
2+
{{- '<|im_start|>' + message['role'] + '\n' + message['content'] -}}
3+
{%- if (loop.last and add_generation_prompt) or not loop.last -%}
4+
{{- '<|im_end|>' + '\n' -}}
5+
{%- endif -%}
6+
{%- endfor -%}
7+
8+
{%- if add_generation_prompt and messages[-1]['role'] != 'assistant' -%}
9+
{{- '<|im_start|>assistant\n' -}}
10+
{%- endif -%}

tests/entrypoints/test_chat_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,7 @@ def test_resolve_content_format_hf_defined(model, expected_format):
900900
[("template_alpaca.jinja", "string"),
901901
("template_baichuan.jinja", "string"),
902902
("template_blip2.jinja", "string"),
903+
("template_chameleon.jinja", "string"),
903904
("template_chatglm.jinja", "string"),
904905
("template_chatglm2.jinja", "string"),
905906
("template_chatml.jinja", "string"),
@@ -908,9 +909,12 @@ def test_resolve_content_format_hf_defined(model, expected_format):
908909
("template_falcon_180b.jinja", "string"),
909910
("template_falcon.jinja", "string"),
910911
("template_florence2.jinja", "string"),
912+
("template_fuyu.jinja", "string"),
911913
("template_inkbot.jinja", "string"),
912-
("template_llava.jinja", "string"),
914+
("template_paligemma.jinja", "string"),
913915
("template_teleflm.jinja", "string"),
916+
("template_qwen_vl.jinja", "string"),
917+
("template_qwen_vl_chat.jinja", "string"),
914918
("template_vlm2vec.jinja", "openai"),
915919
("tool_chat_template_granite_20b_fc.jinja", "string"),
916920
("tool_chat_template_hermes.jinja", "string"),

0 commit comments

Comments
 (0)