Views
No views yet

| Model | VQA v2 | TextVQA | ScienceQA | POPE | MMMU (Test) | MMMU (Eval) | GQA | MM-VET |
|---|---|---|---|---|---|---|---|---|
| Score | 70.84 | 46.71 | 58.97 | 84.1 | 28.6 | 30.4 | 54.79 | 23.9 |
transformers with the following script:pip install -U transformers accelerate flash_attn1import torch
2import transformers
3from transformers import AutoModelForCausalLM, AutoTokenizer
4from PIL import Image
5import warnings
6
7# disable some warnings
8transformers.logging.set_verbosity_error()
9transformers.logging.disable_progress_bar()
10warnings.filterwarnings('ignore')
11
12# set device
13torch.set_default_device('cuda') # or 'cpu'
14
15# create model
16model = AutoModelForCausalLM.from_pretrained(
17 'qnguyen3/nanoLLaVA',
18 torch_dtype=torch.float16,
19 device_map='auto',
20 trust_remote_code=True)
21tokenizer = AutoTokenizer.from_pretrained(
22 'qnguyen3/nanoLLaVA',
23 trust_remote_code=True)
24
25# text prompt
26prompt = 'Describe this image in detail'
27
28messages = [
29 {"role": "user", "content": f'<image>\n{prompt}'}
30]
31text = tokenizer.apply_chat_template(
32 messages,
33 tokenize=False,
34 add_generation_prompt=True
35)
36
37print(text)
38
39text_chunks = [tokenizer(chunk).input_ids for chunk in text.split('<image>')]
40input_ids = torch.tensor(text_chunks[0] + [-200] + text_chunks[1], dtype=torch.long).unsqueeze(0)
41
42# image, sample images can be found in images folder
43image = Image.open('/path/to/image.png')
44image_tensor = model.process_images([image], model.config).to(dtype=model.dtype)
45
46# generate
47output_ids = model.generate(
48 input_ids,
49 images=image_tensor,
50 max_new_tokens=2048,
51 use_cache=True)[0]
52
53print(tokenizer.decode(output_ids[input_ids.shape[1]:], skip_special_tokens=True).strip())\n at the end of <|im_end|>:<|im_start|>system
Answer the question<|im_end|><|im_start|>user
<image>
What is the picture about?<|im_end|><|im_start|>assistant| Image | Example |
|---|---|
![]() | What is the text saying? "Small but mighty". How does the text correlate to the context of the image? The text seems to be a playful or humorous representation of a small but mighty figure, possibly a mouse or a mouse toy, holding a weightlifting bar. |