RaushanTurganbay HF staff commited on
Commit
c518e39
·
verified ·
1 Parent(s): 12a6750

update for chat template

Browse files
Files changed (1) hide show
  1. README.md +19 -0
README.md CHANGED
@@ -117,6 +117,25 @@ output = model.generate(**inputs, max_new_tokens=200, do_sample=False)
117
  print(processor.decode(output[0][2:], skip_special_tokens=True))
118
  ```
119
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  ### Model optimization
121
 
122
  #### 4-bit quantization through `bitsandbytes` library
 
117
  print(processor.decode(output[0][2:], skip_special_tokens=True))
118
  ```
119
 
120
+ -----------
121
+ From transformers>=v4.48, you can also pass image/video url or local path to the conversation history, and let the chat template handle the rest.
122
+ Chat template will load the image for you and return inputs in `torch.Tensor` which you can pass directly to `model.generate()`
123
+
124
+ ```python
125
+ messages = [
126
+ {
127
+ "role": "user",
128
+ "content": [
129
+ {"type": "image", "url": "https://www.ilankelman.org/stopsigns/australia.jpg"}
130
+ {"type": "text", "text": "What is shown in this image?"},
131
+ ],
132
+ },
133
+ ]
134
+
135
+ inputs = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors"pt")
136
+ output = model.generate(**inputs, max_new_tokens=50)
137
+ ```
138
+
139
  ### Model optimization
140
 
141
  #### 4-bit quantization through `bitsandbytes` library