RaushanTurganbay HF staff commited on
Commit
de12112
·
verified ·
1 Parent(s): 03b8560

Update for chat template

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