-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Llava chat template examples #30130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" PyTorch Llava model.""" | ||
"""PyTorch Llava model.""" | ||
|
||
from dataclasses import dataclass | ||
from typing import List, Optional, Tuple, Union | ||
|
||
|
@@ -388,16 +389,16 @@ def forward( | |
>>> model = LlavaForConditionalGeneration.from_pretrained("llava-hf/llava-1.5-7b-hf") | ||
>>> processor = AutoProcessor.from_pretrained("llava-hf/llava-1.5-7b-hf") | ||
|
||
>>> prompt = "<image>\nUSER: What's the content of the image?\nASSISTANT:" | ||
>>> prompt = "USER: <image>\nWhat's the content of the image? ASSISTANT:" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT this prompt put the |
||
>>> url = "https://www.ilankelman.org/stopsigns/australia.jpg" | ||
>>> image = Image.open(requests.get(url, stream=True).raw) | ||
|
||
>>> inputs = processor(text=prompt, images=image, return_tensors="pt") | ||
|
||
>>> # Generate | ||
>>> generate_ids = model.generate(**inputs, max_length=30) | ||
>>> generate_ids = model.generate(**inputs, max_new_tokens=15) | ||
>>> processor.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0] | ||
"\nUSER: What's the content of the image?\nASSISTANT: The image features a stop sign on a street corner" | ||
"USER: \nWhat's the content of the image? ASSISTANT: The image features a busy city street with a stop sign prominently displayed" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we expecting to have this double spacing here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I did find this a bit weird, but it seems to be the default behaviour of the decoding |
||
```""" | ||
|
||
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we should prepend the system prompt here, but I think it can be excluded for the purposes of keeping the demo simple.