Skip to content

Commit

Permalink
remove default templates (see huggingface#31733)
Browse files Browse the repository at this point in the history
  • Loading branch information
zucchini-nlp committed Jul 10, 2024
1 parent 07a91be commit 400a8b2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 108 deletions.
54 changes: 0 additions & 54 deletions src/transformers/models/llava/processing_llava.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <image> 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: <image>\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') %}"
"{{ '<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
54 changes: 0 additions & 54 deletions src/transformers/models/llava_next/processing_llava_next.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <image> 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: <image>\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') %}"
"{{ '<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

0 comments on commit 400a8b2

Please sign in to comment.