RaushanTurganbay HF staff commited on
Commit
18dbcdc
·
verified ·
1 Parent(s): 173f753

Update for chat template

Browse files
Files changed (1) hide show
  1. README.md +21 -0
README.md CHANGED
@@ -178,6 +178,27 @@ out = processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_to
178
  print(out)
179
  ```
180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  ### Model optimization
182
 
183
  #### 4-bit quantization through `bitsandbytes` library
 
178
  print(out)
179
  ```
180
 
181
+ -----------
182
+ 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.
183
+ For video you also need to indicate how many `num_frames` to sample from video, otherwise the whole video will be loaded.
184
+ Chat template will load the image/video for you and return inputs in `torch.Tensor` which you can pass directly to `model.generate()`.
185
+
186
+ ```python
187
+ messages = [
188
+ {
189
+ "role": "user",
190
+ "content": [
191
+ {"type": "image", "url": "https://www.ilankelman.org/stopsigns/australia.jpg"}
192
+ {"type": "video", "path": "my_video.mp4"},
193
+ {"type": "text", "text": "What is shown in this image and video?"},
194
+ ],
195
+ },
196
+ ]
197
+
198
+ inputs = processor.apply_chat_template(messages, num_frames=8, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors"pt")
199
+ output = model.generate(**inputs, max_new_tokens=50)
200
+ ```
201
+
202
  ### Model optimization
203
 
204
  #### 4-bit quantization through `bitsandbytes` library