From 400a8b287fbd87963fc9dbcb49808438254b5f1b Mon Sep 17 00:00:00 2001 From: raushan Date: Wed, 10 Jul 2024 14:24:40 +0200 Subject: [PATCH] remove default templates (see #31733) --- .../models/llava/processing_llava.py | 54 ------------------- .../llava_next/processing_llava_next.py | 54 ------------------- 2 files changed, 108 deletions(-) diff --git a/src/transformers/models/llava/processing_llava.py b/src/transformers/models/llava/processing_llava.py index debdb3a193307e..96d38c53c947af 100644 --- a/src/transformers/models/llava/processing_llava.py +++ b/src/transformers/models/llava/processing_llava.py @@ -134,57 +134,3 @@ def model_input_names(self): tokenizer_input_names = self.tokenizer.model_input_names image_processor_input_names = self.image_processor.model_input_names return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names)) - - @property - def default_chat_template(self): - """ - This default vicuna template formats inputs in the form of a chat history. For each message in the chat history: - * The template will output the role of the speaker followed by the content of the message. - * Content in the input should be a a list of dicts for each modality (image/text).If the modality is image, the template will output an token - * In the output you will get a formatted prompt as a string - - Example: - - ```python - messages = [{ - "role": "user", - "content": [ - {"type": "text", "text": "What’s the content of this image?"}, - {"type": "image"}, - ], - }, - { - "role": "assistant", - "content": [{"type": "text", "text": "This picture shows a red stop sign."},] - }] - ``` - - Will create outputs like: - ``` - USER: \nWhat is the content of this image? ASSISTANT: This picture shows a red stop sign - ``` - """ - # fmt: off - return ( - "{% for message in messages %}" - "{% if message['role'] == 'system' %}" - "{{ message['content'][0]['text'] }}" - "{% else %}" - "{{ message['role'].upper() + ': '}}" - "{% endif %}" - - "{# Render all images first #}" - "{% for content in message['content'] | selectattr('type', 'equalto', 'image') %}" - "{{ '\n' }}" - "{% endfor %}" - - "{# Render all text finally #}" - "{% for content in message['content'] | selectattr('type', 'equalto', 'text') %}" - "{{ content['text'] + ' '}}" - "{% endfor %}" - "{% endfor %}" - "{% if add_generation_prompt %}" - "{{ 'ASSISTANT:' }}" - "{% endif %}" - ) - # fmt: on diff --git a/src/transformers/models/llava_next/processing_llava_next.py b/src/transformers/models/llava_next/processing_llava_next.py index 5c306cb40c410c..6c2ca2f9028409 100644 --- a/src/transformers/models/llava_next/processing_llava_next.py +++ b/src/transformers/models/llava_next/processing_llava_next.py @@ -138,57 +138,3 @@ def model_input_names(self): tokenizer_input_names = self.tokenizer.model_input_names image_processor_input_names = self.image_processor.model_input_names return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names)) - - @property - def default_chat_template(self): - """ - This default vicuna template formats inputs in the form of a chat history. For each message in the chat history: - * The template will output the role of the speaker followed by the content of the message. - * Content in the input should be a a list of dicts for each modality (image/text).If the modality is image, the template will output an token - * In the output you will get a formatted prompt as a string - - Example: - - ```python - messages = [{ - "role": "user", - "content": [ - {"type": "text", "text": "What’s the content of this image?"}, - {"type": "image"}, - ], - }, - { - "role": "assistant", - "content": [{"type": "text", "text": "This picture shows a red stop sign."},] - }] - ``` - - Will create outputs like: - ``` - USER: \nWhat is the content of this image? ASSISTANT: This picture shows a red stop sign - ``` - """ - # fmt: off - return ( - "{% for message in messages %}" - "{% if message['role'] == 'system' %}" - "{{ message['content'][0]['text'] }}" - "{% else %}" - "{{ message['role'].upper() + ': '}}" - "{% endif %}" - - "{# Render all images first #}" - "{% for content in message['content'] | selectattr('type', 'equalto', 'image') %}" - "{{ '\n' }}" - "{% endfor %}" - - "{# Render all text finally #}" - "{% for content in message['content'] | selectattr('type', 'equalto', 'text') %}" - "{{ content['text'] + ' '}}" - "{% endfor %}" - "{% endfor %}" - "{% if add_generation_prompt %}" - "{{ 'ASSISTANT:' }}" - "{% endif %}" - ) - # fmt: on