RaushanTurganbay HF staff commited on
Commit
c916e6c
·
verified ·
1 Parent(s): 7f0c901

update for chat template

Browse files
Files changed (1) hide show
  1. README.md +19 -0
README.md CHANGED
@@ -97,6 +97,25 @@ output = model.generate(**inputs, max_new_tokens=100)
97
  print(processor.decode(output[0], skip_special_tokens=True))
98
  ```
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  ### Model optimization
101
 
102
  #### 4-bit quantization through `bitsandbytes` library
 
97
  print(processor.decode(output[0], skip_special_tokens=True))
98
  ```
99
 
100
+ -----------
101
+ 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.
102
+ Chat template will load the image for you and return inputs in `torch.Tensor` which you can pass directly to `model.generate()`
103
+
104
+ ```python
105
+ messages = [
106
+ {
107
+ "role": "user",
108
+ "content": [
109
+ {"type": "image", "url": "https://www.ilankelman.org/stopsigns/australia.jpg"}
110
+ {"type": "text", "text": "What is shown in this image?"},
111
+ ],
112
+ },
113
+ ]
114
+
115
+ inputs = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors"pt")
116
+ output = model.generate(**inputs, max_new_tokens=50)
117
+ ```
118
+
119
  ### Model optimization
120
 
121
  #### 4-bit quantization through `bitsandbytes` library